use of com.hp.octane.integrations.exceptions.TemporaryException 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.TemporaryException 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);
}
}
use of com.hp.octane.integrations.exceptions.TemporaryException in project octane-ci-java-sdk by MicroFocus.
the class VulnerabilitiesServiceImpl method pushVulnerabilities.
private void pushVulnerabilities(InputStream vulnerabilities, String jobId, String buildId) throws IOException {
OctaneRestClient octaneRestClient = restService.obtainOctaneRestClient();
Map<String, String> headers = new HashMap<>();
headers.put(RestService.CONTENT_TYPE_HEADER, ContentType.APPLICATION_JSON.getMimeType());
boolean base64 = isEncodeBase64();
String encodedJobId = base64 ? CIPluginSDKUtils.urlEncodeBase64(jobId) : CIPluginSDKUtils.urlEncodePathParam(jobId);
String encodedBuildId = CIPluginSDKUtils.urlEncodePathParam(buildId);
String url = getVulnerabilitiesContextPath(configurer.octaneConfiguration.getUrl(), configurer.octaneConfiguration.getSharedSpace()) + "?instance-id=" + configurer.octaneConfiguration.getInstanceId() + "&job-ci-id=" + encodedJobId + "&build-ci-id=" + encodedBuildId;
if (base64) {
url = CIPluginSDKUtils.addParameterEncode64ToUrl(url);
}
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.POST).setUrl(url).setHeaders(headers).setBody(vulnerabilities);
OctaneResponse response = octaneRestClient.execute(request);
logger.info(configurer.octaneConfiguration.getLocationForLog() + "vulnerabilities pushed; status: " + response.getStatus() + ", response: " + response.getBody());
if (response.getStatus() == HttpStatus.SC_ACCEPTED) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "vulnerabilities push SUCCEED for " + jobId + " #" + buildId);
} else if (response.getStatus() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
throw new TemporaryException("vulnerabilities push FAILED, service unavailable");
} else {
throw new PermanentException("vulnerabilities push FAILED, status " + response.getStatus() + "; dropping this item from the queue \n" + response.getBody());
}
}
use of com.hp.octane.integrations.exceptions.TemporaryException in project octane-ci-java-sdk by MicroFocus.
the class VulnerabilitiesServiceImpl method vulnerabilitiesPreflightRequest.
private Date vulnerabilitiesPreflightRequest(String jobId, String buildId) throws IOException {
OctaneResponse response = getBaselineDateFromOctane(jobId, buildId);
if (response.getStatus() == HttpStatus.SC_OK) {
if (response.getBody() == null || "".equals(response.getBody())) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "vulnerabilities data of " + jobId + " #" + buildId + " is not relevant to Octane");
return null;
} else {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "vulnerabilities data of " + jobId + " #" + buildId + " found to be relevant to Octane");
boolean forTest = false;
// backward compatibility with Octane
if ("true".equals(response.getBody()) || forTest) {
return DateUtils.getDateFromUTCString("2000-01-01", "yyyy-MM-dd");
}
return DateUtils.getDateFromUTCString(response.getBody(), DateUtils.octaneFormat);
}
}
if (response.getStatus() == HttpStatus.SC_SERVICE_UNAVAILABLE || response.getStatus() == HttpStatus.SC_BAD_GATEWAY) {
throw new TemporaryException("vulnerabilities preflight request FAILED, service unavailable");
} else {
throw new PermanentException("vulnerabilities preflight request FAILED with " + response.getStatus() + "");
}
}
use of com.hp.octane.integrations.exceptions.TemporaryException in project octane-ci-java-sdk by MicroFocus.
the class SSCRestClientImpl method sendGetRequest.
@Override
public CloseableHttpResponse sendGetRequest(SSCProjectConfiguration sscProjectConfiguration, String url) {
HttpGet request = new HttpGet(url);
request.addHeader("Authorization", "FortifyToken " + getToken(sscProjectConfiguration, false));
request.addHeader("Accept", "application/json");
request.addHeader("Host", getNetHost(sscProjectConfiguration.getSSCUrl()));
CloseableHttpResponse response;
try {
response = httpClient.execute(request);
// 401. Access..
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
request.removeHeaders("Authorization");
request.addHeader("Authorization", "FortifyToken " + getToken(sscProjectConfiguration, true));
response = httpClient.execute(request);
}
return response;
} catch (IOException e) {
throw new TemporaryException(e);
} catch (Exception e) {
throw new PermanentException(e);
}
}
Aggregations