import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
-import java.util.NoSuchElementException;
import javax.annotation.Nonnull;
import org.akraino.validation.ui.entity.WRobotDbTestResult;
import org.akraino.validation.ui.service.DbAdapter;
import org.apache.commons.httpclient.HttpException;
+import org.json.JSONException;
import org.json.JSONObject;
import org.json.XML;
import org.jsoup.Jsoup;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
}
public List<String> getResource(String endpoint)
- throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
- IOException, KeyManagementException, NoSuchAlgorithmException, ParseException {
+ throws IndexOutOfBoundsException, HttpException, NullPointerException {
List<String> resources = new ArrayList<String>();
String nexusUrl = this.baseurl;
if (endpoint != null) {
}
public List<String> getResource(@Nonnull String endpoint1, @Nonnull String endpoint2)
- throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
- IOException, KeyManagementException, NoSuchAlgorithmException, ParseException {
+ throws IndexOutOfBoundsException, HttpException, NullPointerException {
String endpoint = endpoint1 + "/" + endpoint2;
return this.getResource(endpoint);
}
public List<String> getResource(@Nonnull String endpoint1, @Nonnull String endpoint2, @Nonnull String endpoint3)
- throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
- IOException, KeyManagementException, NoSuchAlgorithmException, ParseException {
+ throws IndexOutOfBoundsException, HttpException, NullPointerException {
String endpoint = endpoint1 + "/" + endpoint2 + "/" + endpoint3;
return this.getResource(endpoint);
}
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 {
+ @Nonnull String timestamp) throws IndexOutOfBoundsException, HttpException, 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 + "/");
}
List<WRobotNexusTestResult> wTestResults = getWRobotTestResults(name, version, siloText, timestamp);
if (wTestResults.size() < 1) {
- throw new RuntimeException("No robot test results could be obtained.");
+ return null;
}
vDbResult.setResult(determineResult(wTestResults));
List<WRobotDbTestResult> wDbResults = new ArrayList<WRobotDbTestResult>();
for (WRobotNexusTestResult wTestResult : wTestResults) {
- WRobotDbTestResult wDbResult = new WRobotDbTestResult();
- wDbResult.setLayer(wTestResult.getLayer());
- ObjectMapper mapper = new ObjectMapper();
- wDbResult.setRobotTestResults(mapper.writeValueAsString(wTestResult.getRobotNexusTestResults()));
- wDbResults.add(wDbResult);
+ try {
+ WRobotDbTestResult wDbResult = new WRobotDbTestResult();
+ wDbResult.setLayer(wTestResult.getLayer());
+ ObjectMapper mapper = new ObjectMapper();
+ wDbResult.setRobotTestResults(mapper.writeValueAsString(wTestResult.getRobotNexusTestResults()));
+ wDbResults.add(wDbResult);
+ } catch (JsonProcessingException e) {
+ LOGGER.warn(EELFLoggerDelegate.auditLogger,
+ "Exception occured while processing JSON. " + UserUtils.getStackTrace(e));
+ }
}
vDbResult.setWRobotDbTestResults(new HashSet<WRobotDbTestResult>(wDbResults));
return vDbResult;
public List<ValidationDbTestResult> getResults(@Nonnull String name, @Nonnull String version,
@Nonnull String siloText, int noOfLastElements)
- throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
- IOException, KeyManagementException, NoSuchAlgorithmException, ParseException {
+ throws IndexOutOfBoundsException, HttpException, NullPointerException {
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 + "/");
timestamp = timestamp.substring(0, timestamp.length() - 1);
ValidationDbTestResult vDbResult = dbAdapter.getValidationTestResult(siloText, timestamp);
if (vDbResult == null || vDbResult.getDateStorage() == null) {
- vDbResults.add(this.getResult(name, version, siloText, timestamp));
+ ValidationDbTestResult vDbResult2 = this.getResult(name, version, siloText, timestamp);
+ if (vDbResult2 == null) {
+ continue;
+ }
+ vDbResults.add(vDbResult2);
} else {
// Just to avoid deletion of already received validation timestamp results
vDbResult = new ValidationDbTestResult();
vDbResult.setTimestamp(timestamp);
vDbResults.add(vDbResult);
}
- } catch (HttpException | RuntimeException ex) {
+ } catch (HttpException | IndexOutOfBoundsException | NullPointerException ex) {
LOGGER.warn(EELFLoggerDelegate.auditLogger, "Exception occured while retrieving timestamp : "
+ timestamp + " result." + UserUtils.getStackTrace(ex));
- continue;
}
}
return vDbResults;
public List<ValidationDbTestResult> getResults(@Nonnull String name, @Nonnull String version,
@Nonnull String siloText, @Nonnull Date date)
- throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
- IOException, KeyManagementException, NoSuchAlgorithmException, ParseException, NullPointerException {
+ throws IndexOutOfBoundsException, HttpException, NullPointerException, ParseException {
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 + "/");
String timestamp = elements.get(i).getElementsByTag("td").get(0).getElementsByTag("a").get(0).text();
timestamp = timestamp.substring(0, timestamp.length() - 1);
ValidationDbTestResult vDbResult = this.getResult(name, version, siloText, timestamp);
+ if (vDbResult == null) {
+ continue;
+ }
vDbResults.add(vDbResult);
- } catch (HttpException | RuntimeException ex) {
+ } catch (HttpException | IndexOutOfBoundsException | NullPointerException ex) {
LOGGER.warn(EELFLoggerDelegate.auditLogger,
"Exception occured while retrieving timestamp results. " + UserUtils.getStackTrace(ex));
- continue;
}
}
return vDbResults;
public ValidationDbTestResult getLastResultBasedOnOutcome(@Nonnull String name, @Nonnull String version,
@Nonnull String siloText, List<String> layers, Boolean optional, boolean outcome)
- throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
- IOException, KeyManagementException, NoSuchAlgorithmException, ParseException, NullPointerException {
+ throws IndexOutOfBoundsException, HttpException, 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 + "/");
String elementTimestamp = element.getElementsByTag("td").get(0).getElementsByTag("a").get(0).text();
elementTimestamp = elementTimestamp.substring(0, elementTimestamp.length() - 1);
ValidationDbTestResult vDbResult = this.getResult(name, version, siloText, elementTimestamp);
+ if (vDbResult == null) {
+ continue;
+ }
if (vDbResult.getResult() != outcome) {
continue;
}
}
}
return vDbResult;
- } catch (HttpException | RuntimeException ex) {
+ } catch (HttpException | IndexOutOfBoundsException | NullPointerException ex) {
LOGGER.warn(EELFLoggerDelegate.auditLogger,
"Error when trying to retrieve results. " + UserUtils.getStackTrace(ex));
- continue;
}
}
return null;
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 {
+ throws IndexOutOfBoundsException, HttpException, 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 + "/");
String elementTimestamp = element.getElementsByTag("td").get(0).getElementsByTag("a").get(0).text();
elementTimestamp = elementTimestamp.substring(0, elementTimestamp.length() - 1);
ValidationDbTestResult vDbResult = this.getResult(name, version, siloText, elementTimestamp);
+ if (vDbResult == null) {
+ continue;
+ }
if (vDbResult.getResult() != outcome) {
continue;
}
continue;
}
return vDbResult;
- } catch (HttpException | RuntimeException ex) {
+ } catch (HttpException | IndexOutOfBoundsException | NullPointerException ex) {
LOGGER.warn(EELFLoggerDelegate.auditLogger,
"Error when trying to retrieve results. " + UserUtils.getStackTrace(ex));
- continue;
}
}
return null;
public List<WRobotNexusTestResult> getWRobotTestResults(@Nonnull String name, @Nonnull String version,
@Nonnull String siloText, @Nonnull String timestamp)
- throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
- IOException, KeyManagementException, NoSuchAlgorithmException {
+ throws IndexOutOfBoundsException, HttpException, NullPointerException {
String nexusUrl = this.baseurl + "/" + siloText + "/" + "bluval_results/" + name + "/" + version + "/"
+ timestamp + "/results";
- List<WRobotNexusTestResult> listOfwrappers = new ArrayList<WRobotNexusTestResult>();
+ List<WRobotNexusTestResult> listOfWrappers = new ArrayList<WRobotNexusTestResult>();
LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get the blueprint layers");
WebResource webResource = this.client.resource(nexusUrl + "/");
LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString());
try {
String layer = elements.get(i).getElementsByTag("td").get(0).getElementsByTag("a").get(0).text();
layer = layer.substring(0, layer.length() - 1);
- if (layer.contains("test")) {
+ if (layer.contains("test") || layer.contains("service") || layer.contains("home")) {
continue;
}
List<RobotTestResult> robotTestResults = getRobotTestResults(nexusUrl + "/" + layer);
WRobotNexusTestResult wrapper = new WRobotNexusTestResult();
wrapper.setLayer(layer);
wrapper.setRobotNexusTestResults(robotTestResults);
- listOfwrappers.add(wrapper);
- } catch (IllegalArgumentException | HttpException | NullPointerException ex) {
+ listOfWrappers.add(wrapper);
+ } catch (IndexOutOfBoundsException | HttpException | NullPointerException ex) {
LOGGER.warn(EELFLoggerDelegate.auditLogger,
- "Exception occured while retrieving robot results. " + UserUtils.getStackTrace(ex));
- continue;
+ "Exception occured while retrieving wrapped robot results. " + UserUtils.getStackTrace(ex));
}
}
- return listOfwrappers;
+ return listOfWrappers;
}
private List<RobotTestResult> getRobotTestResults(String resultsUrl)
- throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
- IOException, KeyManagementException, NoSuchAlgorithmException {
+ throws IndexOutOfBoundsException, HttpException, NullPointerException {
List<RobotTestResult> rTestResults = new ArrayList<RobotTestResult>();
LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get test suites results");
WebResource webResource = this.client.resource(resultsUrl + "/");
}
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;
+ try {
+ 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.error(EELFLoggerDelegate.errorLogger, "Exception occured while deserializing for resource "
+ + resultsUrl + " " + UserUtils.getStackTrace(ex));
+ }
+ } catch (IOException | JSONException ex) {
+ LOGGER.warn(EELFLoggerDelegate.auditLogger, "Exception occured while retrieving robot results from "
+ + resultsUrl + " . " + UserUtils.getStackTrace(ex));
}
}
return rTestResults;
return desiredElements;
}
- private TestInfoYaml getTestInfo(String timestampUrl) throws JsonParseException, JsonMappingException, IOException {
+ private TestInfoYaml getTestInfo(String timestampUrl) {
LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get test info");
WebResource webResource = this.client.resource(timestampUrl + "/results/test_info.yaml");
LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString());
ClientResponse response = webResource.get(ClientResponse.class);
if (response.getStatus() != 200) {
+ LOGGER.warn(EELFLoggerDelegate.auditLogger, "No test_info.yaml file was found");
+ return null;
+ }
+ try {
+ String testInfo = response.getEntity(String.class);
+ ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
+ Object obj;
+ obj = yamlReader.readValue(testInfo, Object.class);
+ 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);
+ ObjectMapper jsonWriter = new ObjectMapper();
+ return mapper.readValue(jsonWriter.writeValueAsString(obj), TestInfoYaml.class);
+ } catch (IOException e) {
+ LOGGER.error(EELFLoggerDelegate.errorLogger,
+ "Error when parsing test_info.yaml file. " + UserUtils.getStackTrace(e));
return null;
}
- String testInfo = response.getEntity(String.class);
- ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
- Object obj = yamlReader.readValue(testInfo, Object.class);
- 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);
- ObjectMapper jsonWriter = new ObjectMapper();
- return mapper.readValue(jsonWriter.writeValueAsString(obj), TestInfoYaml.class);
}
}