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 #204 from davco01a/issue202a
Browse files Browse the repository at this point in the history
issue 202 - pull code for gather app info for a stack
  • Loading branch information
s1cyan authored Jun 4, 2020
2 parents 35c671d + fa7d977 commit 36c2094
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions src/main/java/application/rest/StacksAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -762,40 +762,43 @@ public Response describeStack(@Context final HttpServletRequest request,

group="apps";
String listVersion="v1";
boolean checkForApps = false;

try {
List deployments = KubeUtils.listResources2(apiClient, group, listVersion, "deployments",namespace);
for (Object obj: deployments) {
Map map = (Map)obj;
Map metadata = (Map)map.get("metadata");
System.out.println("metadata = "+metadata);
Map labels = (Map)metadata.get("labels");
if (labels!=null) {
System.out.println("labels = "+labels);
String id = (String)labels.get("stack.appsody.dev/id");
String ver = (String)labels.get("stack.appsody.dev/version");
System.out.println("id = "+id+" version = "+ver);
if (id!=null && ver!=null) {
if (checkForApps) {
try {
List deployments = KubeUtils.listResources2(apiClient, group, listVersion, "deployments",namespace);
for (Object obj: deployments) {
Map map = (Map)obj;
Map metadata = (Map)map.get("metadata");
System.out.println("metadata = "+metadata);
Map labels = (Map)metadata.get("labels");
if (labels!=null) {
System.out.println("labels = "+labels);
String id = (String)labels.get("stack.appsody.dev/id");
String ver = (String)labels.get("stack.appsody.dev/version");
System.out.println("id = "+id+" version = "+ver);
if (id.contentEquals(name) && ver.contentEquals(version)) {
appNames.add((String)metadata.get("name"));
if (id!=null && ver!=null) {
System.out.println("id = "+id+" version = "+ver);
if (id.contentEquals(name) && ver.contentEquals(version)) {
appNames.add((String)metadata.get("name"));
}
}
}
}
} catch (ApiException apie) {
apie.printStackTrace();
System.out.println("response body: "+apie.getResponseBody());
JSONObject resp = new JSONObject();
resp.put("message", "response error: "+apie.getResponseBody());
return Response.status(400).entity(resp).header("Content-Security-Policy", "default-src 'self'").header("X-Content-Type-Options","nosniff").build();
}

catch (Exception e) {
e.printStackTrace();
JSONObject resp = new JSONObject();
resp.put("message", "unexpected error: "+e.getMessage());
return Response.status(500).entity(resp).header("Content-Security-Policy", "default-src 'self'").header("X-Content-Type-Options","nosniff").build();
}
} catch (ApiException apie) {
apie.printStackTrace();
System.out.println("response body: "+apie.getResponseBody());
JSONObject resp = new JSONObject();
resp.put("message", "response error: "+apie.getResponseBody());
return Response.status(400).entity(resp).header("Content-Security-Policy", "default-src 'self'").header("X-Content-Type-Options","nosniff").build();
}

catch (Exception e) {
e.printStackTrace();
JSONObject resp = new JSONObject();
resp.put("message", "unexpected error: "+e.getMessage());
return Response.status(500).entity(resp).header("Content-Security-Policy", "default-src 'self'").header("X-Content-Type-Options","nosniff").build();
}

StackApi api = new StackApi(apiClient);
Expand Down Expand Up @@ -900,7 +903,9 @@ public Response describeStack(@Context final HttpServletRequest request,
msg.put("kabanero digest", kabDigest);
msg.put("image digest", imageDigest);
msg.put("project", namespace);
msg.put("applications", appNames.toString());
if (checkForApps) {
msg.put("applications", appNames.toString());
}
return Response.ok(msg).header("Content-Security-Policy", "default-src 'self'").header("X-Content-Type-Options","nosniff").build();
} catch (ApiException apie) {
apie.printStackTrace();
Expand Down

0 comments on commit 36c2094

Please sign in to comment.