use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class SCMDataServiceImpl method pushSCMDataByRestAPI.
private void pushSCMDataByRestAPI(String jobId, String buildId, InputStream scmData) 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.urlEncodeQueryParam(jobId);
String encodedBuildId = CIPluginSDKUtils.urlEncodeQueryParam(buildId);
String url = getSCMDataContextPath(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.PUT).setUrl(url).setHeaders(headers).setBody(scmData);
OctaneResponse response = octaneRestClient.execute(request);
if (response.getStatus() == HttpStatus.SC_OK) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "scmData for " + jobId + " #" + buildId + ", push SUCCEED : " + response.getBody());
} else if (response.getStatus() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
throw new TemporaryException("scmData push FAILED, service unavailable");
} else {
throw new PermanentException("scmData push FAILED, status " + response.getStatus() + "; dropping this item from the queue \n" + response.getBody());
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class SonarServiceImpl method retrieveAndPushSonarDataToOctane.
private void retrieveAndPushSonarDataToOctane(SonarBuildCoverageQueueItem queueItem) {
// preflight
if (!coverageService.isSonarReportRelevant(queueItem.jobId)) {
return;
}
StringBuilder errorMessage = new StringBuilder().append("failed to inject sonarqube coverage data to octane for project key: ").append(queueItem.projectKey).append(" with ciIdentity: ").append(configurer.octaneConfiguration.getInstanceId()).append(" with jobId: ").append(queueItem.jobId).append(" with buildId: ").append(queueItem.buildId);
try {
// retrieve coverage report from Sonar
Integer pageIndex = 0;
BuildCoverage buildCoverageReport = dtoFactory.newDTO(BuildCoverage.class);
JsonNode jsonReport;
do {
pageIndex++;
InputStream reportStream = getPageFromSonar(queueItem, pageIndex);
jsonReport = CIPluginSDKUtils.getObjectMapper().readTree(reportStream);
buildCoverageReport.mergeSonarCoverageReport(jsonReport);
} while (SonarUtils.sonarReportHasAnotherPage(pageIndex, jsonReport));
// push coverage to Octane
OctaneResponse response = coverageService.pushCoverage(queueItem.jobId, queueItem.buildId, CoverageReportType.SONAR_REPORT, dtoFactory.dtoToJsonStream(buildCoverageReport));
if (response.getStatus() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
errorMessage.append(" with status code: ").append(response.getStatus());
throw new TemporaryException(errorMessage.toString());
} else if (response.getStatus() != HttpStatus.SC_OK) {
errorMessage.append(" with status code: ").append(response.getStatus()).append(" and response body: ").append(response.getBody());
throw new PermanentException(errorMessage.toString());
}
} catch (Throwable throwable) {
logger.error(configurer.octaneConfiguration.getLocationForLog() + errorMessage.toString(), throwable);
throw new PermanentException(throwable);
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class TestsServiceImpl method doPreflightAndPushTestResult.
private void doPreflightAndPushTestResult(TestsResultQueueItem queueItem) {
// validate test result - first to be done as it is the cheapest to 'fail fast'
InputStream testsResultA = configurer.pluginServices.getTestsResult(queueItem.jobId, queueItem.buildId);
if (testsResultA == null) {
logger.warn(configurer.octaneConfiguration.getLocationForLog() + "test result of " + queueItem + " resolved to be NULL, skipping");
return;
}
try {
// preflight
InputStream testsResultB;
boolean isRelevant = isTestsResultRelevant(queueItem.jobId, queueItem.rootJobId);
logger.info(configurer.octaneConfiguration.getLocationForLog() + "test results preflight " + queueItem + " = " + isRelevant);
if (!isRelevant) {
return;
}
if (!this.configurationService.isOctaneVersionGreaterOrEqual("15.1.60")) {
try {
// for 15.1.60 - instance id is passed by query param
// for earlier version - instance id is part of test result body
String testResultXML = CIPluginSDKUtils.inputStreamToUTF8String(testsResultA);
testResultXML = testResultXML.replaceAll("<build.*?>", "<build server_id=\"" + configurer.octaneConfiguration.getInstanceId() + "\" job_id=\"" + queueItem.jobId + "\" build_id=\"" + queueItem.buildId + "\"/>").replace("</build>", // remove closing build element if exist
"");
testsResultB = new ByteArrayInputStream(testResultXML.getBytes(Charsets.UTF_8));
} catch (Exception e) {
throw new PermanentException("failed to update ci server instance ID in the test results XML");
}
} else {
testsResultB = testsResultA;
}
// push
try {
OctaneResponse response = pushTestsResult(testsResultB, queueItem.jobId, queueItem.buildId);
if (response.getStatus() == HttpStatus.SC_ACCEPTED) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "successfully pushed test results for " + queueItem + "; status: " + response.getStatus() + ", response: " + response.getBody() + ", CorrelationId - " + response.getCorrelationId());
} else if (response.getStatus() == HttpStatus.SC_SERVICE_UNAVAILABLE || response.getStatus() == HttpStatus.SC_BAD_GATEWAY) {
throw new TemporaryException("push request TEMPORARILY failed with status " + response.getStatus());
} else {
throw new PermanentException("push request PERMANENTLY failed with status " + response.getStatus());
}
} catch (IOException ioe) {
throw new TemporaryException("failed to perform push test results request for " + queueItem, ioe);
} finally {
try {
testsResultB.close();
} catch (IOException e) {
logger.warn(configurer.octaneConfiguration.getLocationForLog() + "failed to close test result file after push test for " + queueItem);
}
}
} finally {
try {
testsResultA.close();
} catch (IOException e) {
logger.warn(configurer.octaneConfiguration.getLocationForLog() + "failed to close test result file after push test for " + queueItem);
}
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class FODServiceImpl method scanIsCompleted.
private boolean scanIsCompleted(Long releaseId, Long scanId) {
try {
Scan completeScan = FODReleaseService.getCompleteScan(releaseId, scanId);
if (completeScan == null) {
return false;
}
logger.debug(configurer.octaneConfiguration.getLocationForLog() + "scan:" + scanId + " is:" + completeScan.status);
if (completeScan.status == null) {
return false;
}
// Scan that has not started, and not in progress is completed.
return (!Scan.IN_PROGRESS.equals(completeScan.status) && !Scan.NOT_STARTED.equals(completeScan.status) && !Scan.QUEUED.equals(completeScan.status));
} catch (PermanentException e) {
throw e;
} catch (TemporaryException e) {
throw e;
} catch (Exception e) {
return false;
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class FODServiceImpl method getVulnerabilitiesScanResultStream.
@Override
public InputStream getVulnerabilitiesScanResultStream(VulnerabilitiesQueueItem queueItem) throws IOException {
logger.debug(configurer.octaneConfiguration.getLocationForLog() + "Entered getVulnerabilitiesScanResultStream");
String targetDir = getTargetDir(configurer.pluginServices.getAllowedOctaneStorage(), queueItem.getJobId(), queueItem.getBuildId());
logger.debug(configurer.octaneConfiguration.getLocationForLog() + "getVulnerabilitiesScanResultStream target Dir:" + targetDir);
InputStream cachedScanResult = getCachedScanResult(targetDir);
if (cachedScanResult != null) {
logger.warn("results " + queueItem.toString() + "are cached!");
return cachedScanResult;
}
enrichItemWithFODParams(queueItem);
PplnRunStatus pplnRunStatus = fodScanIsStillInProgress(queueItem);
if (pplnRunStatus.continuePolling) {
return null;
} else if (pplnRunStatus.tryGetIssues) {
List<OctaneIssue> octaneIssues = fetchIssues(queueItem, getRelease(queueItem).toString());
cacheIssues(targetDir, octaneIssues);
return serializeIssues(octaneIssues);
} else {
throw new PermanentException(queueItem.getJobId() + "#" + queueItem.getBuildId() + " , Polling is stopped");
}
}
Aggregations