X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fakraino%2Fvalidation%2Fui%2Fclient%2Fnexus%2FNexusExecutorClient.java;h=ffd27a8ed6c76487d88e02f42808e0bb32e5ccfc;hb=ca3ea7d1c8ddbdc60adb7f51426c2c6509158097;hp=33e53dbd9f07c6a520af58fcd8674d0baeeaa15a;hpb=147ecf7bf79ea9967a121d0038103151a38ebef2;p=validation.git diff --git a/ui/src/main/java/org/akraino/validation/ui/client/nexus/NexusExecutorClient.java b/ui/src/main/java/org/akraino/validation/ui/client/nexus/NexusExecutorClient.java index 33e53db..ffd27a8 100644 --- a/ui/src/main/java/org/akraino/validation/ui/client/nexus/NexusExecutorClient.java +++ b/ui/src/main/java/org/akraino/validation/ui/client/nexus/NexusExecutorClient.java @@ -45,7 +45,7 @@ import org.akraino.validation.ui.entity.BlueprintInstance; import org.akraino.validation.ui.entity.LabInfo; import org.akraino.validation.ui.entity.ValidationDbTestResult; import org.akraino.validation.ui.entity.WRobotDbTestResult; -import org.akraino.validation.ui.service.DbResultAdapter; +import org.akraino.validation.ui.service.DbAdapter; import org.apache.commons.httpclient.HttpException; import org.json.JSONObject; import org.json.XML; @@ -79,7 +79,7 @@ import com.sun.jersey.client.urlconnection.URLConnectionClientHandler; public final class NexusExecutorClient { @Autowired - DbResultAdapter dbAdapter; + DbAdapter dbAdapter; private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(NexusExecutorClient.class); @@ -156,9 +156,9 @@ public final class NexusExecutorClient { public ValidationDbTestResult getResult(@Nonnull String name, @Nonnull String version, @Nonnull String siloText, @Nonnull String timestamp) - throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException, - IOException, KeyManagementException, NoSuchAlgorithmException, ParseException, NullPointerException { - String nexusUrl = this.baseurl + "/" + siloText + "/" + name + "/" + version; + throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException, + IOException, KeyManagementException, NoSuchAlgorithmException, ParseException, NullPointerException { + String nexusUrl = this.baseurl + "/" + siloText + "/" + "bluval_results/" + name + "/" + version; LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get validation nexus test result"); WebResource webResource = this.client.resource(nexusUrl + "/"); LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString()); @@ -215,9 +215,9 @@ public final class NexusExecutorClient { public List getResults(@Nonnull String name, @Nonnull String version, @Nonnull String siloText, int noOfLastElements) - throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException, - IOException, KeyManagementException, NoSuchAlgorithmException, ParseException { - String nexusUrl = this.baseurl + "/" + siloText + "/" + name + "/" + version; + throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException, + IOException, KeyManagementException, NoSuchAlgorithmException, ParseException { + String nexusUrl = this.baseurl + "/" + siloText + "/" + "bluval_results/" + name + "/" + version; LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get validation Nexus test results"); WebResource webResource = this.client.resource(nexusUrl + "/"); LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString()); @@ -254,7 +254,7 @@ public final class NexusExecutorClient { vDbResult.setTimestamp(timestamp); vDbResults.add(vDbResult); } - } catch (IllegalArgumentException | HttpException | NullPointerException | NoSuchElementException ex) { + } catch (HttpException | RuntimeException ex) { LOGGER.warn(EELFLoggerDelegate.auditLogger, "Exception occured while retrieving timestamp : " + timestamp + " result." + UserUtils.getStackTrace(ex)); continue; @@ -265,9 +265,9 @@ public final class NexusExecutorClient { public List getResults(@Nonnull String name, @Nonnull String version, @Nonnull String siloText, @Nonnull Date date) - throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException, - IOException, KeyManagementException, NoSuchAlgorithmException, ParseException, NullPointerException { - String nexusUrl = this.baseurl + "/" + siloText + "/" + name + "/" + version; + throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException, + IOException, KeyManagementException, NoSuchAlgorithmException, ParseException, NullPointerException { + String nexusUrl = this.baseurl + "/" + siloText + "/" + "bluval_results/" + name + "/" + version; LOGGER.debug(EELFLoggerDelegate.applicationLogger, "Trying to get validation Nexus results based on date"); WebResource webResource = this.client.resource(nexusUrl + "/"); LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString()); @@ -287,7 +287,7 @@ public final class NexusExecutorClient { timestamp = timestamp.substring(0, timestamp.length() - 1); ValidationDbTestResult vDbResult = this.getResult(name, version, siloText, timestamp); vDbResults.add(vDbResult); - } catch (IllegalArgumentException | HttpException | NullPointerException ex) { + } catch (HttpException | RuntimeException ex) { LOGGER.warn(EELFLoggerDelegate.auditLogger, "Exception occured while retrieving timestamp results. " + UserUtils.getStackTrace(ex)); continue; @@ -298,9 +298,9 @@ public final class NexusExecutorClient { public ValidationDbTestResult getLastResultBasedOnOutcome(@Nonnull String name, @Nonnull String version, @Nonnull String siloText, List layers, Boolean optional, boolean outcome) - throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException, - IOException, KeyManagementException, NoSuchAlgorithmException, ParseException, NullPointerException { - String nexusUrl = this.baseurl + "/" + siloText + "/" + name + "/" + version; + throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException, + IOException, KeyManagementException, NoSuchAlgorithmException, ParseException, NullPointerException { + String nexusUrl = this.baseurl + "/" + siloText + "/" + "bluval_results/" + name + "/" + version; LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get last result based on outcome"); WebResource webResource = this.client.resource(nexusUrl + "/"); LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString()); @@ -351,7 +351,7 @@ public final class NexusExecutorClient { } } return vDbResult; - } catch (IllegalArgumentException | HttpException | NullPointerException ex) { + } catch (HttpException | RuntimeException ex) { LOGGER.warn(EELFLoggerDelegate.auditLogger, "Error when trying to retrieve results. " + UserUtils.getStackTrace(ex)); continue; @@ -362,9 +362,9 @@ public final class NexusExecutorClient { public ValidationDbTestResult getLastResultBasedOnOutcome(@Nonnull String name, @Nonnull String version, @Nonnull String siloText, Boolean allLayers, Boolean optional, boolean outcome) - throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException, - IOException, KeyManagementException, NoSuchAlgorithmException, ParseException, NullPointerException { - String nexusUrl = this.baseurl + "/" + siloText + "/" + name + "/" + version; + throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException, + IOException, KeyManagementException, NoSuchAlgorithmException, ParseException, NullPointerException { + String nexusUrl = this.baseurl + "/" + siloText + "/" + "bluval_results/" + name + "/" + version; LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get last result based on outcome"); WebResource webResource = this.client.resource(nexusUrl + "/"); LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString()); @@ -409,7 +409,7 @@ public final class NexusExecutorClient { continue; } return vDbResult; - } catch (IllegalArgumentException | HttpException | NullPointerException ex) { + } catch (HttpException | RuntimeException ex) { LOGGER.warn(EELFLoggerDelegate.auditLogger, "Error when trying to retrieve results. " + UserUtils.getStackTrace(ex)); continue; @@ -420,9 +420,10 @@ public final class NexusExecutorClient { public List getWRobotTestResults(@Nonnull String name, @Nonnull String version, @Nonnull String siloText, @Nonnull String timestamp) - throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException, - IOException, KeyManagementException, NoSuchAlgorithmException { - String nexusUrl = this.baseurl + "/" + siloText + "/" + name + "/" + version + "/" + timestamp + "/results"; + throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException, + IOException, KeyManagementException, NoSuchAlgorithmException { + String nexusUrl = this.baseurl + "/" + siloText + "/" + "bluval_results/" + name + "/" + version + "/" + + timestamp + "/results"; List listOfwrappers = new ArrayList(); LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get the blueprint layers"); WebResource webResource = this.client.resource(nexusUrl + "/"); @@ -443,6 +444,9 @@ public final class NexusExecutorClient { continue; } List robotTestResults = getRobotTestResults(nexusUrl + "/" + layer); + if (robotTestResults.size() < 1) { + continue; + } WRobotNexusTestResult wrapper = new WRobotNexusTestResult(); wrapper.setLayer(layer); wrapper.setRobotNexusTestResults(robotTestResults); @@ -472,24 +476,31 @@ public final class NexusExecutorClient { List elements = document.getElementsByTag("body").get(0).getElementsByTag("table").get(0) .getElementsByTag("tbody").get(0).getElementsByTag("tr"); for (int i = 2; i < elements.size(); i++) { - String testSuiteName = elements.get(i).getElementsByTag("td").get(0).getElementsByTag("a").get(0).text(); - testSuiteName = testSuiteName.substring(0, testSuiteName.length() - 1); - webResource = this.client.resource(resultsUrl + "/" + testSuiteName + "/output.xml"); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString()); - response = webResource.get(ClientResponse.class); - if (response.getStatus() != 200) { - throw new HttpException("Could not retrieve test suite result from Nexus. HTTP error code : " - + response.getStatus() + " and message: " + response.getEntity(String.class)); + try { + String testSuiteName = elements.get(i).getElementsByTag("td").get(0).getElementsByTag("a").get(0) + .text(); + testSuiteName = testSuiteName.substring(0, testSuiteName.length() - 1); + webResource = this.client.resource(resultsUrl + "/" + testSuiteName + "/output.xml"); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString()); + response = webResource.get(ClientResponse.class); + if (response.getStatus() != 200) { + throw new HttpException("Could not retrieve test suite result from Nexus. HTTP error code : " + + response.getStatus() + " and message: " + response.getEntity(String.class)); + } + String result = response.getEntity(String.class); + JSONObject xmlJSONObj = XML.toJSONObject(result); + ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); + mapper.setSerializationInclusion(Include.NON_NULL); + RobotTestResult robotTestResult = mapper.readValue(xmlJSONObj.toString(), RobotTestResult.class); + robotTestResult.setName(testSuiteName); + rTestResults.add(robotTestResult); + } catch (Exception ex) { + LOGGER.warn(EELFLoggerDelegate.auditLogger, + "Exception occured while retrieving robot results. " + UserUtils.getStackTrace(ex)); + continue; } - String result = response.getEntity(String.class); - JSONObject xmlJSONObj = XML.toJSONObject(result); - ObjectMapper mapper = new ObjectMapper(); - mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); - mapper.setSerializationInclusion(Include.NON_NULL); - RobotTestResult robotTestResult = mapper.readValue(xmlJSONObj.toString(), RobotTestResult.class); - robotTestResult.setName(testSuiteName); - rTestResults.add(robotTestResult); } return rTestResults; }