From 8db26abe758e700622cf9bdd849d5484dc5deeb8 Mon Sep 17 00:00:00 2001 From: davco01a Date: Thu, 19 Mar 2020 12:02:24 -0400 Subject: [PATCH 1/4] pipelines --- .../java/application/rest/StackUtils.java | 51 ++++++++++++++----- .../java/application/rest/StacksAccess.java | 12 ++--- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/main/java/application/rest/StackUtils.java b/src/main/java/application/rest/StackUtils.java index 9a896bc..4a55ab8 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,20 +259,22 @@ 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"); + long asset_id=getAssetId(url, org, project, release, namespace, kabaneroSpecStacksGitRelease.getAssetName()); - 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 (kabaneroSpecStacksGitRelease.getAssetName().contentEquals((String)assetObj.get("name"))) { - asset_id=(Long)assetObj.get("id"); - } - } +// 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; +// +// 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; diff --git a/src/main/java/application/rest/StacksAccess.java b/src/main/java/application/rest/StacksAccess.java index 78256c9..ef4d501 100644 --- a/src/main/java/application/rest/StacksAccess.java +++ b/src/main/java/application/rest/StacksAccess.java @@ -359,14 +359,10 @@ 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 { From ce0396a5fe0cc125f41a5208194cecea2a9b4d3d Mon Sep 17 00:00:00 2001 From: davco01a Date: Thu, 19 Mar 2020 13:42:20 -0400 Subject: [PATCH 2/4] default pipeline --- src/main/java/application/rest/StacksAccess.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/application/rest/StacksAccess.java b/src/main/java/application/rest/StacksAccess.java index ef4d501..0bac9bb 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); } } From 2d4047d3bb74d8c8c1d10feb13bc04d52c695e05 Mon Sep 17 00:00:00 2001 From: davco01a Date: Thu, 19 Mar 2020 15:28:44 -0400 Subject: [PATCH 3/4] narrow pipeline spec to name and version --- src/main/java/application/rest/StackUtils.java | 4 ++-- src/main/java/application/rest/StacksAccess.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/application/rest/StackUtils.java b/src/main/java/application/rest/StackUtils.java index 4a55ab8..82c4741 100644 --- a/src/main/java/application/rest/StackUtils.java +++ b/src/main/java/application/rest/StackUtils.java @@ -661,7 +661,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 @@ -679,7 +679,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 0bac9bb..b075861 100644 --- a/src/main/java/application/rest/StacksAccess.java +++ b/src/main/java/application/rest/StacksAccess.java @@ -357,7 +357,6 @@ public Response syncStacks(@Context final HttpServletRequest request) { System.out.println("pipelineElement: "+pipelineElement.toString()); stackPipelines.add(pipelineElement); foundOneCustomPipeline=true; - } tempPipelines = stackPipelines; } else { @@ -367,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); } } From 0096099dcb6eae7709e7b8bf1026c5cba89f808f Mon Sep 17 00:00:00 2001 From: davco01a Date: Thu, 19 Mar 2020 16:29:56 -0400 Subject: [PATCH 4/4] remove commented code --- src/main/java/application/rest/StackUtils.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/main/java/application/rest/StackUtils.java b/src/main/java/application/rest/StackUtils.java index 82c4741..9554aac 100644 --- a/src/main/java/application/rest/StackUtils.java +++ b/src/main/java/application/rest/StackUtils.java @@ -261,21 +261,6 @@ public static List getStackFromGIT(String user, String pw, KabaneroSpecStacksRep long asset_id=getAssetId(url, org, project, release, namespace, kabaneroSpecStacksGitRelease.getAssetName()); -// 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; -// -// 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");