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

Commit

Permalink
clean up and keyword check on deactivate
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Feb 6, 2020
1 parent 156bc60 commit a6550a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 108 deletions.
107 changes: 5 additions & 102 deletions src/main/java/application/rest/StackUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,25 +177,7 @@ public static Kabanero getKabaneroForNamespace(String namespace) {
return null;
}

public static List<Map> getMasterStacks(Kabanero k) {

ArrayList<Map> maps = new ArrayList<Map>();
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;
Expand Down Expand Up @@ -248,32 +230,7 @@ public static List streamLineMasterMap(List<Map> list) {
return aList;
}

// public static List filterActiveCollections(List<Map> fromKabanero) {
// ArrayList<Map> activeCollections = new ArrayList<Map>();
//
// 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<Map> allStacks = new ArrayList<Map>();
Expand Down Expand Up @@ -302,34 +259,7 @@ public static List allStacks(StackList fromKabanero) {
return allStacks;
}

public static List filterInActiveCollections(List<Map> fromKabanero) {
ArrayList<Map> inActiveCollections = new ArrayList<Map>();

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;
}




Expand Down Expand Up @@ -435,20 +365,7 @@ public static List filterStacksToActivate(List<Map> fromGit, StackList fromKaban
}


private static List<Map> multiVersionStacksMaps(StackList fromKabanero) {
List<Map> kabMaps = new ArrayList<Map>();
for (Stack s : fromKabanero.getItems()) {
List<StackSpecVersions> 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<StackSpecVersions> getKabInstanceVersions(StackList fromKabanero, String name) {
for (Stack s : fromKabanero.getItems()) {
Expand All @@ -470,21 +387,7 @@ public static Stack getKabInstance(StackList fromKabanero, String name) {



public static List isVerionInGitForStack(List<Map> fromGit, List<Map> 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<Map> fromGit, String version, String name) {
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/application/rest/StacksAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<StackSpecVersions> kabSpecVersions=StackUtils.getKabInstanceVersions(fromKabanero, name);
List<StackSpecVersions> 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();
Expand Down

0 comments on commit a6550a6

Please sign in to comment.