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 #85 from davco01a/latest
Browse files Browse the repository at this point in the history
Activate and version change at the same time
  • Loading branch information
s1cyan authored Nov 1, 2019
2 parents 70e4956 + f0a549f commit 04751e0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
28 changes: 28 additions & 0 deletions src/main/java/application/rest/CollectionsAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,18 @@ public Response refreshCollections(@Context final HttpServletRequest request) {

// iterate over version change collections and update
try {

for (Object o : versionChangeCollections) {
Map m = (Map)o;
try {

String state = getDesiredState(versionChangeCollections, activateCollections);
if (state!=null) {
m.put("desiredState", state);
}
JsonObject jo = makeJSONBody(m, namespace);
System.out.println("json object for version change: " + jo);

KubeUtils.updateResource(apiClient, group, version, plural, namespace, m.get("name").toString(),
jo);
System.out.println(
Expand All @@ -396,6 +403,7 @@ public Response refreshCollections(@Context final HttpServletRequest request) {
m.put("status", m.get("name") + "version change failed");
m.put("exception", e.getMessage());
}

}
} catch (Exception e) {
System.out.println("exception cause: " + e.getCause());
Expand All @@ -422,6 +430,26 @@ public Response refreshCollections(@Context final HttpServletRequest request) {
System.out.println("finishing refresh");
return Response.ok(msg).build();
}

private String getDesiredState(List<Map> versionColls, List<Map> activateColls) {
String state=null;
if (activateColls!=null) {
for (Map map : versionColls) {
String name = (String) map.get("name");
name = name.trim();
boolean match = false;
for (Map map1 : activateColls) {
String name1 = (String) map1.get("name");
String desiredState = (String) map1.get("desiredState");
name1 = name1.trim();
if (name1.contentEquals(name)) {
state=desiredState;
}
}
}
}
return state;
}

private JSONArray convertMapToJSON(List<Map> list) {
JSONArray ja = new JSONArray();
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/application/rest/CollectionsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,7 @@ public static List filterVersionChanges(List<Map> fromGit, List<Map> fromKabaner
if (name.contentEquals(name1)) {
if (!version1.contentEquals(version)) {
match = false;
status = (String) statusMap.get("status");

if (status == null) {
status = (String) spec.get("desiredState");
}
status = (String) spec.get("desiredState");
}
}
}
Expand Down

0 comments on commit 04751e0

Please sign in to comment.