diff --git a/src/main/java/application/rest/StackUtils.java b/src/main/java/application/rest/StackUtils.java index 9a896bc..9554aac 100644 --- a/src/main/java/application/rest/StackUtils.java +++ b/src/main/java/application/rest/StackUtils.java @@ -52,6 +52,7 @@ import io.kabanero.v1alpha2.models.KabaneroSpecStacksPipelines; import io.kabanero.v1alpha2.models.KabaneroSpecStacksRepositories; import io.kubernetes.client.ApiClient; +import io.kubernetes.client.ApiException; import io.kubernetes.client.apis.CoreV1Api; import io.kubernetes.client.models.V1ContainerStatus; import io.kubernetes.client.models.V1Pod; @@ -212,6 +213,28 @@ public static Kabanero getKabaneroForNamespace(String namespace) { } + public static long getAssetId(String url, String org, String project, String release, String namespace, String assetName) throws ApiException, IOException { + + String get_release_url = "https://api."+url+"/repos/"+org+"/"+project+"/releases/tags/"+release; + + String response = getFromGit(get_release_url, null, KubeUtils.getSecret(namespace, url),"json"); + + JSONObject asset_metadata=new JSONObject(); + + asset_metadata = JSONObject.parse(response); + + JSONArray assets = (JSONArray) asset_metadata.get("assets"); + long asset_id=0; + + for (Object obj:assets) { + JSONObject assetObj = (JSONObject) obj; + if (assetName.contentEquals((String)assetObj.get("name"))) { + asset_id=(Long)assetObj.get("id"); + } + } + return asset_id; + } + public static List getStackFromGIT(String user, String pw, KabaneroSpecStacksRepositories r,String namespace) throws Exception { String response = null; @@ -236,21 +259,8 @@ public static List getStackFromGIT(String user, String pw, KabaneroSpecStacksRep project = kabaneroSpecStacksGitRelease.getProject(); release = kabaneroSpecStacksGitRelease.getRelease(); - String get_release_url = "https://api."+url+"/repos/"+org+"/"+project+"/releases/tags/"+release; - - response = getFromGit(get_release_url, null, KubeUtils.getSecret(namespace,secret_url),"json"); - - JSONObject asset_metadata = JSONObject.parse(response); - JSONArray assets = (JSONArray) asset_metadata.get("assets"); - long asset_id=0; + long asset_id=getAssetId(url, org, project, release, namespace, kabaneroSpecStacksGitRelease.getAssetName()); - for (Object obj:assets) { - JSONObject assetObj = (JSONObject) obj; - if (kabaneroSpecStacksGitRelease.getAssetName().contentEquals((String)assetObj.get("name"))) { - asset_id=(Long)assetObj.get("id"); - } - } - String get_asset_url = "https://"+url+"/api/v3/repos/"+org+"/"+project+"/releases/assets/"+asset_id; response = getFromGit(get_asset_url, null, KubeUtils.getSecret(namespace,secret_url),"octet-stream"); @@ -636,7 +646,7 @@ public static List packageStackObjects(List stacks, Map versionedSta specVersion.setDesiredState("active"); specVersion.setVersion((String) stack.get("version")); specVersion.setImages((List) stack.get("images")); - specVersion.setPipelines((List) versionedStackMap.get(name)); + specVersion.setPipelines((List) versionedStackMap.get(name+"-"+version)); versions.add(specVersion); } // creating stack object to add to new stacks List @@ -654,7 +664,7 @@ public static List packageStackObjects(List stacks, Map versionedSta specVersion.setVersion(version); specVersion.setImages((List) stack.get("images")); - specVersion.setPipelines((List) versionedStackMap.get(name)); + specVersion.setPipelines((List) versionedStackMap.get(name+"-"+version)); System.out.println("packageStackObjects one specVersion: "+specVersion); versions.add(specVersion); updateStacks.add(stackObj); diff --git a/src/main/java/application/rest/StacksAccess.java b/src/main/java/application/rest/StacksAccess.java index 78256c9..b075861 100644 --- a/src/main/java/application/rest/StacksAccess.java +++ b/src/main/java/application/rest/StacksAccess.java @@ -330,13 +330,8 @@ public Response syncStacks(@Context final HttpServletRequest request) { List defaultPipelines = kab.getSpec().getStacks().getPipelines(); if (defaultPipelines != null) { for (KabaneroSpecStacksPipelines defaultPipelineElement : defaultPipelines) { - KabaneroSpecStacksPipelines pipeline = new KabaneroSpecStacksPipelines(); - KabaneroSpecStacksHttps https = new KabaneroSpecStacksHttps(); - https.setUrl(defaultPipelineElement.getHttps().getUrl()); - pipeline.setHttps(https); - pipeline.setSha256(defaultPipelineElement.getSha256()); - pipeline.setId(defaultPipelineElement.getId()); - pipelines.add(pipeline); + System.out.println("defaultPipelineElement: "+defaultPipelineElement.toString()); + pipelines.add(defaultPipelineElement); } } @@ -359,14 +354,9 @@ public Response syncStacks(@Context final HttpServletRequest request) { ArrayList tempPipelines = null; if (r.getPipelines()!=null && r.getPipelines().size() > 0) { for (KabaneroSpecStacksPipelines pipelineElement : r.getPipelines()) { - KabaneroSpecStacksPipelines stackPipeline = new KabaneroSpecStacksPipelines(); - KabaneroSpecStacksHttps https = new KabaneroSpecStacksHttps(); - https.setUrl(pipelineElement.getHttps().getUrl()); - stackPipeline.setHttps(https); - stackPipeline.setSha256(pipelineElement.getSha256()); - stackPipeline.setId(pipelineElement.getId()); - stackPipelines.add(stackPipeline); - foundOneCustomPipeline=true; + System.out.println("pipelineElement: "+pipelineElement.toString()); + stackPipelines.add(pipelineElement); + foundOneCustomPipeline=true; } tempPipelines = stackPipelines; } else { @@ -376,7 +366,8 @@ public Response syncStacks(@Context final HttpServletRequest request) { for (Object o:stacksFromRest) { Map m = (Map)o; String name = (String) m.get("id"); - versionedStackPipelineMap.put(name, tempPipelines); + String version = (String) m.get("version"); + versionedStackPipelineMap.put(name+"-"+version, tempPipelines); } }