From fa7d97769ccd8e4bff7e8ad62cfa00d39933ec8c Mon Sep 17 00:00:00 2001 From: davco01a Date: Thu, 4 Jun 2020 17:42:27 -0400 Subject: [PATCH] fix --- .../java/application/rest/StacksAccess.java | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/src/main/java/application/rest/StacksAccess.java b/src/main/java/application/rest/StacksAccess.java index dde455d..41c15e0 100644 --- a/src/main/java/application/rest/StacksAccess.java +++ b/src/main/java/application/rest/StacksAccess.java @@ -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); @@ -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();