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 #62 from davco01a/latest
Browse files Browse the repository at this point in the history
Exception handling for GIT Retry limited exceeded
  • Loading branch information
tseelbach committed Sep 28, 2019
2 parents 59b4090 + be9e809 commit fbf6fd5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
28 changes: 25 additions & 3 deletions src/main/java/application/rest/CollectionsAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class CollectionsAccess {
private static String version = "v1alpha1";

private static Map envMap = System.getenv();
// should be array

private static String group = "kabanero.io";
// should be array
private static String namespace = (String) envMap.get("KABANERO_CLI_NAMESPACE");
Expand Down Expand Up @@ -85,8 +85,16 @@ public Response listCollections(@Context final HttpServletRequest request) {
resp.put("message", "your login token has expired, please login again");
return Response.status(401).entity(resp).build();
}
ArrayList<Map> masterCollections = (ArrayList<Map>) CollectionsUtils
ArrayList masterCollections = (ArrayList) CollectionsUtils
.getMasterCollectionWithREST(getUser(request), PAT, namespace);
String firstElem = masterCollections.get(0).toString();
if (firstElem!=null) {
if (firstElem.contains("http code 429:")) {
JSONObject resp = new JSONObject();
resp.put("message", firstElem);
return Response.status(503).entity(resp).build();
}
}
JSONArray ja = convertMapToJSON(CollectionsUtils.streamLineMasterMap(masterCollections));
System.out.println("master collectionfor namespace: "+namespace+" kab group: " + group +"="+ ja);
msg.put("master collections", ja);
Expand Down Expand Up @@ -138,6 +146,9 @@ public Response listCollections(@Context final HttpServletRequest request) {

} catch (Exception e) {
e.printStackTrace();
JSONObject resp = new JSONObject();
resp.put("message", e.getMessage());
return Response.status(500).entity(resp).build();
}
return Response.ok(msg).build();
}
Expand Down Expand Up @@ -202,8 +213,16 @@ public Response refreshCollections(@Context final HttpServletRequest request) {
return Response.status(401).entity(resp).build();
}

List<Map> masterCollections = (ArrayList<Map>) CollectionsUtils
ArrayList masterCollections = (ArrayList) CollectionsUtils
.getMasterCollectionWithREST(getUser(request), PAT, namespace);
String firstElem = masterCollections.get(0).toString();
if (firstElem!=null) {
if (firstElem.contains("http code 429:")) {
JSONObject resp = new JSONObject();
resp.put("message", firstElem);
return Response.status(503).entity(resp).build();
}
}
System.out.println(" ");
System.out.println("List of active master collections= "+masterCollections);

Expand All @@ -224,6 +243,9 @@ public Response refreshCollections(@Context final HttpServletRequest request) {
System.out.println("exception cause: " + e.getCause());
System.out.println("exception message: " + e.getMessage());
e.printStackTrace();
JSONObject resp = new JSONObject();
resp.put("message", e.getMessage());
return Response.status(500).entity(resp).build();
}
System.out.println("starting refresh");

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/application/rest/CollectionsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ private static String getFromGit(String url, String user, String pw) {
}

System.out.println("Response Code : " + response.getStatusLine().getStatusCode());

if (response.getStatusLine().getStatusCode()==429) {
return "http code 429: GIT retry Limited Exceeded, please try again in 2 minutes";
}

BufferedReader rd = null;
try {
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
Expand Down Expand Up @@ -111,8 +114,16 @@ public static List getMasterCollectionWithREST(String user, String pw, String na
String response = null;
try {
response = getFromGit(url, user, pw);
if (response!=null) {
if (response.contains("http code 429:")) {
ArrayList<String> list= new ArrayList();
list.add(response);
return list;
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
System.out.println("response = " + response);
ArrayList<Map> list = null;
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/application/rest/KubeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ public static int deleteKubeResource(ApiClient client, String namespace, String
try {
CustomObjectsApi customApi = new CustomObjectsApi(client);
V1DeleteOptions body = new V1DeleteOptions();
customApi.deleteNamespacedCustomObject(group, version, namespace, plural, name, body, null, null, null);
Object resp = customApi.deleteNamespacedCustomObject(group, version, namespace, plural, name, body, null, null, null);
System.out.println("response from delete: "+resp);
} catch(ApiException ex) {
int code = ex.getCode();
if ( code == 404) {
Expand All @@ -388,6 +389,9 @@ public static int deleteKubeResource(ApiClient client, String namespace, String
}
logger.error("Unable to delete resource", ex);
throw ex;
} catch(Exception ex) {
logger.error("Unable to delete resource", ex);
throw ex;
}
return 0;
}
Expand Down

0 comments on commit fbf6fd5

Please sign in to comment.