diff --git a/src/main/java/application/rest/StackUtils.java b/src/main/java/application/rest/StackUtils.java index 46b5424..f528597 100644 --- a/src/main/java/application/rest/StackUtils.java +++ b/src/main/java/application/rest/StackUtils.java @@ -177,25 +177,7 @@ public static Kabanero getKabaneroForNamespace(String namespace) { return null; } - public static List getMasterStacks(Kabanero k) { - - ArrayList maps = new ArrayList(); - try { - HashMap map = new HashMap(); - KabaneroSpecStacks kabaneroSpecStacks = k.getSpec().getStacks(); - kabaneroSpecStacks.getRepositories(); - kabaneroSpecStacks.getPipelines(); // take as is and set as list into stack CR being created - //stack.getImages ?? -// for (??:??) { -// -// } - return maps; - } catch (Exception e) { - e.printStackTrace(); - } - - return null; - } + public static List getStackFromGIT(String user, String pw, String url) { String response = null; @@ -248,32 +230,7 @@ public static List streamLineMasterMap(List list) { return aList; } -// public static List filterActiveCollections(List fromKabanero) { -// ArrayList activeCollections = new ArrayList(); -// -// try { -// for (Map map : fromKabanero) { -// HashMap activeMap = new HashMap(); -// System.out.println("working on one collection: " + map); -// Map metadata = (Map) map.get("metadata"); -// String name = (String) metadata.get("name"); -// name = name.trim(); -// Map spec = (Map) map.get("spec"); -// String version = (String) spec.get("version"); -// Map status = (Map) map.get("status"); -// String statusStr = (String) status.get("status"); -// if ("active".contentEquals(statusStr)) { -// activeMap.put("name", name); -// activeMap.put("version", version); -// activeMap.put("status","active"); -// activeCollections.add(activeMap); -// } -// } -// } catch (Exception e) { -// e.printStackTrace(); -// } -// return activeCollections; -// } + public static List allStacks(StackList fromKabanero) { ArrayList allStacks = new ArrayList(); @@ -302,34 +259,7 @@ public static List allStacks(StackList fromKabanero) { return allStacks; } - public static List filterInActiveCollections(List fromKabanero) { - ArrayList inActiveCollections = new ArrayList(); - - try { - for (Map map : fromKabanero) { - HashMap inActiveMap = new HashMap(); - //System.out.println("working on one collection: " + map); - Map metadata = (Map) map.get("metadata"); - String name = (String) metadata.get("name"); - name = name.trim(); - Map spec = (Map) map.get("spec"); - String version = (String) spec.get("version"); - Map status = (Map) map.get("status"); - String statusStr = (String) status.get("status"); - if ("inactive".contentEquals(statusStr)) { - inActiveMap.put("name", name); - inActiveMap.put("version", version); - inActiveMap.put("status","inactive"); - inActiveCollections.add(inActiveMap); - } - } - - - } catch (Exception e) { - e.printStackTrace(); - } - return inActiveCollections; - } + @@ -435,20 +365,7 @@ public static List filterStacksToActivate(List fromGit, StackList fromKaban } - private static List multiVersionStacksMaps(StackList fromKabanero) { - List kabMaps = new ArrayList(); - for (Stack s : fromKabanero.getItems()) { - List versions = s.getSpec().getVersions(); - Map map=new HashMap(); - for (StackSpecVersions version: versions) { - map.put("name",s.getMetadata().getName()); - map.put("version",version.getVersion()); - map.put("desiredState", version.getDesiredState()); - } - kabMaps.add(map); - } - return kabMaps; - } + public static List getKabInstanceVersions(StackList fromKabanero, String name) { for (Stack s : fromKabanero.getItems()) { @@ -470,21 +387,7 @@ public static Stack getKabInstance(StackList fromKabanero, String name) { - public static List isVerionInGitForStack(List fromGit, List stacksToDelete) { - - for(Map stack : stacksToDelete) { - String name = (String) stack.get("name"); - int i=0; - for(Map stack2 : stacksToDelete) { - String name2 = (String) stack2.get("name"); - if (name.contentEquals(name2)) { - i++; - } - } - stack.put("count", i); - } - return null; - } + public static boolean isStackVersionInGit(List fromGit, String version, String name) { diff --git a/src/main/java/application/rest/StacksAccess.java b/src/main/java/application/rest/StacksAccess.java index aeda401..3f342ad 100644 --- a/src/main/java/application/rest/StacksAccess.java +++ b/src/main/java/application/rest/StacksAccess.java @@ -674,18 +674,26 @@ public Response deActivateStack(@Context final HttpServletRequest request, msg.put("status", "Stack name: " + name + " 404 not found"); return Response.status(400).entity(msg).build(); } - List kabSpecVersions=StackUtils.getKabInstanceVersions(fromKabanero, name); + List kabSpecVersions=null; + if (version!=null) { + kabSpecVersions=StackUtils.getKabInstanceVersions(fromKabanero, name); - for (StackSpecVersions versionFromKab:kabSpecVersions) { - if (version.contentEquals(versionFromKab.getVersion())) { - versionFromKab.setDesiredState("inactive"); + for (StackSpecVersions versionFromKab:kabSpecVersions) { + if (version.contentEquals(versionFromKab.getVersion())) { + versionFromKab.setDesiredState("inactive"); + } } + } else { + System.out.println("no version number supplied for stack: "+name); + msg.put("status", "no version number supplied for stack: "+name); + return Response.status(400).entity(msg).build(); + } System.out.println(kabStack.getSpec().getName()+" stack for patch deactivate: " + kabStack.toString()); kabStack.getSpec().setVersions(kabSpecVersions);; api.patchStack(namespace, kabStack.getMetadata().getName(), kabStack); - System.out.println("*** " + "Collection name: " + name + " deactivated"); - msg.put("status", "Stack name: " + name + "version: "+version+" deactivated"); + System.out.println("*** " + "Stack name: " + name + " deactivated"); + msg.put("status", "Stack name: " + name + " version: "+version+" deactivated"); return Response.ok(msg).build(); } catch (ApiException apie) { apie.printStackTrace();