Search in sources :

Example 1 with OctaneRestClient

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());
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) RequestTimeoutException(com.hp.octane.integrations.exceptions.RequestTimeoutException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PermanentException(com.hp.octane.integrations.exceptions.PermanentException) URISyntaxException(java.net.URISyntaxException) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) OctaneRestClient(com.hp.octane.integrations.services.rest.OctaneRestClient) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 2 with OctaneRestClient

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());
    }
}
Also used : TemporaryException(com.hp.octane.integrations.exceptions.TemporaryException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PermanentException(com.hp.octane.integrations.exceptions.PermanentException) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) OctaneRestClient(com.hp.octane.integrations.services.rest.OctaneRestClient)

Example 3 with OctaneRestClient

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;
}
Also used : HashMap(java.util.HashMap) PipelineContext(com.hp.octane.integrations.dto.pipelines.PipelineContext) PipelineContextList(com.hp.octane.integrations.dto.pipelines.PipelineContextList) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) OctaneRestClient(com.hp.octane.integrations.services.rest.OctaneRestClient)

Example 4 with OctaneRestClient

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;
}
Also used : HashMap(java.util.HashMap) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) OctaneRestClient(com.hp.octane.integrations.services.rest.OctaneRestClient)

Example 5 with OctaneRestClient

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();
}
Also used : OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) OctaneRestClient(com.hp.octane.integrations.services.rest.OctaneRestClient)

Aggregations

OctaneRestClient (com.hp.octane.integrations.services.rest.OctaneRestClient)13 OctaneRequest (com.hp.octane.integrations.dto.connectivity.OctaneRequest)11 OctaneResponse (com.hp.octane.integrations.dto.connectivity.OctaneResponse)10 HashMap (java.util.HashMap)7 LinkedHashMap (java.util.LinkedHashMap)4 PipelineContextList (com.hp.octane.integrations.dto.pipelines.PipelineContextList)3 PermanentException (com.hp.octane.integrations.exceptions.PermanentException)3 InterruptedIOException (java.io.InterruptedIOException)3 PipelineContext (com.hp.octane.integrations.dto.pipelines.PipelineContext)2 TemporaryException (com.hp.octane.integrations.exceptions.TemporaryException)2 IOException (java.io.IOException)2 RequestTimeoutException (com.hp.octane.integrations.exceptions.RequestTimeoutException)1 SocketException (java.net.SocketException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1