use of com.hp.octane.integrations.services.rest.OctaneRestClient 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.services.rest.OctaneRestClient 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.services.rest.OctaneRestClient in project octane-ci-java-sdk by MicroFocus.
the class PipelineContextServiceImpl method updatePipeline.
@Override
public PipelineContext updatePipeline(String serverIdentity, String jobName, PipelineContext pipelineContext) throws IOException {
String url = getConfigurationUrl(serverIdentity, jobName);
validateReleaseAndMilestone(pipelineContext);
OctaneRestClient octaneRestClient = restService.obtainOctaneRestClient();
Map<String, String> headers = new HashMap<>();
headers.put(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
headers.put(CONTENT_TYPE_HEADER, ContentType.APPLICATION_JSON.getMimeType());
PipelineContextList list = dtoFactory.newDTO(PipelineContextList.class).setData(Arrays.asList(pipelineContext));
String jsonData = dtoFactory.dtoToJson(list);
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.PUT).setUrl(url).setBody(jsonData).setHeaders(headers);
OctaneResponse response = octaneRestClient.execute(request);
validateResponse(HttpStatus.SC_OK, response);
PipelineContextList resultList = dtoFactory.dtoFromJson(response.getBody(), PipelineContextList.class);
// we might receive several pipeline context from other workspaces.
// find updated context by id
PipelineContext result = resultList.getData().stream().filter(p -> p.getContextEntityId() == pipelineContext.getContextEntityId()).findFirst().get();
return result;
}
use of com.hp.octane.integrations.services.rest.OctaneRestClient in project octane-ci-java-sdk by MicroFocus.
the class PipelineContextServiceImpl method deleteTestsFromPipelineNodes.
@Override
public void deleteTestsFromPipelineNodes(String jobName, long pipelineId, long workspaceId) throws IOException {
String url = getWorkspaceAnalyticsContextPath(configurer.octaneConfiguration.getUrl(), configurer.octaneConfiguration.getSharedSpace(), workspaceId) + String.format("pipelines/%s/jobs/%s/tests", pipelineId, CIPluginSDKUtils.urlEncodePathParam(jobName));
OctaneRestClient octaneRestClient = restService.obtainOctaneRestClient();
Map<String, String> headers = new HashMap<>();
headers.put(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.DELETE).setUrl(url).setHeaders(headers);
OctaneResponse response = octaneRestClient.execute(request);
validateResponse(HttpStatus.SC_OK, response);
// Object result = response.getBody();
// return;
}
use of com.hp.octane.integrations.services.rest.OctaneRestClient in project octane-ci-java-sdk by MicroFocus.
the class EntitiesServiceImpl method updateEntities.
@Override
public List<Entity> updateEntities(Long workspaceId, String entityCollectionName, String jsonData) {
OctaneRestClient octaneRestClient = restService.obtainOctaneRestClient();
Map<String, String> headers = new HashMap<>();
headers.put(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
headers.put(CONTENT_TYPE_HEADER, ContentType.APPLICATION_JSON.getMimeType());
headers.put(OctaneRestClient.CLIENT_TYPE_HEADER, OctaneRestClient.CLIENT_TYPE_VALUE);
String url = buildEntityUrl(workspaceId, entityCollectionName, null, null, null, null, null);
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.PUT).setUrl(url).setBody(jsonData).setHeaders(headers);
OctaneResponse response = executeRequest(octaneRestClient, request);
ResponseEntityList responseEntityList = parseBody(HttpStatus.SC_OK, response);
return responseEntityList.getData();
}
Aggregations