use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class TestsServiceImpl method pushTestsResult.
public OctaneResponse pushTestsResult(InputStream testsResult, String jobId, String buildId) throws IOException {
if (testsResult == null) {
throw new IllegalArgumentException("tests result MUST NOT be null");
}
if (jobId == null || jobId.isEmpty()) {
throw new IllegalArgumentException("job ID MUST NOT be null nor empty");
}
if (buildId == null || buildId.isEmpty()) {
throw new IllegalArgumentException("build ID MUST NOT be null nor empty");
}
OctaneRestClient octaneRestClient = restService.obtainOctaneRestClient();
Map<String, String> headers = new HashMap<>();
headers.put(RestService.CONTENT_TYPE_HEADER, ContentType.APPLICATION_XML.getMimeType());
headers.put(CORRELATION_ID_HEADER, CIPluginSDKUtils.getNextCorrelationId());
String tempJobId = jobId;
boolean base64 = isEncodeBase64();
if (base64) {
tempJobId = CIPluginSDKUtils.urlEncodeBase64(jobId);
}
String uri;
try {
uri = new URIBuilder(getAnalyticsContextPath(configurer.octaneConfiguration.getUrl(), configurer.octaneConfiguration.getSharedSpace()) + "test-results").addParameter("skip-errors", "false").addParameter("instance-id", configurer.octaneConfiguration.getInstanceId()).addParameter("job-ci-id", tempJobId).addParameter("build-ci-id", buildId).build().toString();
} catch (URISyntaxException urise) {
throw new PermanentException("failed to build URL to Octane's 'test-results' resource", urise);
}
if (base64) {
uri = CIPluginSDKUtils.addParameterEncode64ToUrl(uri);
}
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.POST).setUrl(uri).setHeaders(headers).setBody(testsResult).setTimeoutSec(// give 2 min for case of big number of tests
60 * 2);
try {
return octaneRestClient.execute(request);
} catch (InterruptedIOException ie) {
throw new RequestTimeoutException("!!!!!!!!!!!!!!!!!!! request timeout during pushTestsResult : " + ie.getClass().getCanonicalName() + " - " + ie.getMessage());
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class TestsServiceImpl method isTestsResultRelevant.
public boolean isTestsResultRelevant(String jobId, String rootJobId) {
String serverCiId = configurer.octaneConfiguration.getInstanceId();
if (jobId == null || jobId.isEmpty()) {
throw new IllegalArgumentException("job CI ID MUST NOT be null nor empty");
}
boolean base64 = isEncodeBase64();
String jobIdEncoded = base64 ? CIPluginSDKUtils.urlEncodeBase64(jobId) : CIPluginSDKUtils.urlEncodePathParam(jobId);
String rootJobIdEncoded = base64 ? CIPluginSDKUtils.urlEncodeBase64(rootJobId) : CIPluginSDKUtils.urlEncodeQueryParam(rootJobId);
String url = getAnalyticsContextPath(configurer.octaneConfiguration.getUrl(), configurer.octaneConfiguration.getSharedSpace()) + "servers/" + CIPluginSDKUtils.urlEncodePathParam(serverCiId) + "/jobs/" + jobIdEncoded + "/tests-result-preflight";
if (rootJobId != null && !rootJobId.isEmpty()) {
url += "?rootJobId=" + rootJobIdEncoded;
}
if (base64) {
url = CIPluginSDKUtils.addParameterEncode64ToUrl(url);
logger.info("Using base64, " + url);
}
OctaneRequest preflightRequest = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.GET).setTimeoutSec(60).setUrl(url);
try {
OctaneResponse response = restService.obtainOctaneRestClient().execute(preflightRequest);
if (response.getStatus() == HttpStatus.SC_OK) {
return String.valueOf(true).equals(response.getBody());
} else if (response.getStatus() == HttpStatus.SC_SERVICE_UNAVAILABLE || response.getStatus() == HttpStatus.SC_BAD_GATEWAY) {
throw new TemporaryException("preflight request failed with status " + response.getStatus());
} else if (response.getStatus() == HttpStatus.SC_UNAUTHORIZED || response.getStatus() == HttpStatus.SC_FORBIDDEN) {
CIPluginSDKUtils.doWait(30000);
throw new PermanentException("preflight request failed with status " + response.getStatus());
} else {
throw new PermanentException("preflight request failed with status " + response.getStatus() + ". JobId: '" + jobId + "'. Request URL : " + url);
}
} catch (InterruptedIOException ie) {
throw new RequestTimeoutException("!!!!!!!!!!!!!!!!!!! request timeout during preflight : " + ie.getClass().getCanonicalName() + " - " + ie.getMessage());
} catch (IOException ioe) {
throw new TemporaryException(ioe);
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class SonarVulnerabilitiesServiceImpl method createQueryForSonarVulnerability.
private URIBuilder createQueryForSonarVulnerability(Integer page, VulnerabilitiesQueueItem queueItem) {
String projectKey = queueItem.getAdditionalProperties().get(PROJECT_KEY_KEY);
String sonarURL = queueItem.getAdditionalProperties().get(SONAR_URL_KEY);
URIBuilder uriBuilder;
try {
uriBuilder = new URIBuilder(sonarURL + ISSUES_SEARCH_URI);
uriBuilder.setParameter("types", "VULNERABILITY").setParameter("componentKeys", projectKey).setParameter("severities", "MINOR,MAJOR,CRITICAL,BLOCKER").setParameter("ps", "500").setParameter("p", page.toString());
if (queueItem.getBaselineDate() != null) {
uriBuilder.setParameter("createdAfter", DateUtils.convertDateToString(queueItem.getBaselineDate(), DateUtils.sonarFormat));
}
} catch (URISyntaxException e) {
logger.error(e);
throw new PermanentException(e);
}
return uriBuilder;
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class SonarVulnerabilitiesServiceImpl method createQueryForSonarRule.
private URIBuilder createQueryForSonarRule(String sonarURL, String sonarRuleKey) {
URIBuilder uriBuilder;
try {
uriBuilder = new URIBuilder(sonarURL + RULES_SEARCH_URI);
uriBuilder.setParameter("rule_key", sonarRuleKey);
} catch (URISyntaxException e) {
logger.error(e);
throw new PermanentException(e);
}
return uriBuilder;
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class SSCProjectConnector method sendGetEntity.
private String sendGetEntity(String urlSuffix) {
String url = sscProjectConfiguration.getSSCUrl() + "/api/v1/" + urlSuffix;
CloseableHttpResponse response = sscRestClient.sendGetRequest(sscProjectConfiguration, url);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
throw new TemporaryException("SSC Server is not available:" + response.getStatusLine().getStatusCode());
} else if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new PermanentException("Error from SSC:" + response.getStatusLine().getStatusCode());
}
try {
return CIPluginSDKUtils.inputStreamToUTF8String(response.getEntity().getContent());
} catch (IOException e) {
throw new PermanentException(e);
} finally {
EntityUtils.consumeQuietly(response.getEntity());
HttpClientUtils.closeQuietly(response);
}
}
Aggregations