Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #146 from davco01a/latest
Browse files Browse the repository at this point in the history
Heterogeneous default and custom pipelines
  • Loading branch information
s1cyan authored Mar 19, 2020
2 parents 860924e + 0096099 commit a63bed0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
42 changes: 26 additions & 16 deletions src/main/java/application/rest/StackUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -636,7 +646,7 @@ public static List<Stack> packageStackObjects(List<Map> stacks, Map versionedSta
specVersion.setDesiredState("active");
specVersion.setVersion((String) stack.get("version"));
specVersion.setImages((List<StackSpecImages>) stack.get("images"));
specVersion.setPipelines((List<KabaneroSpecStacksPipelines>) versionedStackMap.get(name));
specVersion.setPipelines((List<KabaneroSpecStacksPipelines>) versionedStackMap.get(name+"-"+version));
versions.add(specVersion);
}
// creating stack object to add to new stacks List
Expand All @@ -654,7 +664,7 @@ public static List<Stack> packageStackObjects(List<Map> stacks, Map versionedSta
specVersion.setVersion(version);
specVersion.setImages((List<StackSpecImages>) stack.get("images"));

specVersion.setPipelines((List<KabaneroSpecStacksPipelines>) versionedStackMap.get(name));
specVersion.setPipelines((List<KabaneroSpecStacksPipelines>) versionedStackMap.get(name+"-"+version));
System.out.println("packageStackObjects one specVersion: "+specVersion);
versions.add(specVersion);
updateStacks.add(stackObj);
Expand Down
23 changes: 7 additions & 16 deletions src/main/java/application/rest/StacksAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,8 @@ public Response syncStacks(@Context final HttpServletRequest request) {
List<KabaneroSpecStacksPipelines> 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);
}
}

Expand All @@ -359,14 +354,9 @@ public Response syncStacks(@Context final HttpServletRequest request) {
ArrayList<KabaneroSpecStacksPipelines> 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 {
Expand All @@ -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);
}

}
Expand Down

0 comments on commit a63bed0

Please sign in to comment.