Search in sources :

Example 11 with OctaneRestClient

use of com.hp.octane.integrations.services.rest.OctaneRestClient in project octane-ci-java-sdk by MicroFocus.

the class PipelineContextServiceImpl method getJobConfiguration.

@Override
public PipelineContextList getJobConfiguration(String serverIdentity, String jobName) throws IOException {
    String url = getConfigurationUrl(serverIdentity, 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.GET).setUrl(url).setHeaders(headers);
    OctaneResponse response = octaneRestClient.execute(request);
    validateResponse(HttpStatus.SC_OK, response);
    PipelineContextList result = dtoFactory.dtoFromJson(response.getBody(), PipelineContextList.class);
    return result;
}
Also used : HashMap(java.util.HashMap) 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 12 with OctaneRestClient

use of com.hp.octane.integrations.services.rest.OctaneRestClient in project octane-ci-java-sdk by MicroFocus.

the class BridgeServiceImpl method putAbridgedResult.

private int putAbridgedResult(String selfIdentity, String taskId, InputStream contentJSON) {
    OctaneRestClient octaneRestClientImpl = restService.obtainOctaneRestClient();
    Map<String, String> headers = new LinkedHashMap<>();
    headers.put(RestService.CONTENT_TYPE_HEADER, ContentType.APPLICATION_JSON.getMimeType());
    OctaneRequest octaneRequest = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.PUT).setUrl(configurer.octaneConfiguration.getUrl() + RestService.SHARED_SPACE_INTERNAL_API_PATH_PART + configurer.octaneConfiguration.getSharedSpace() + RestService.ANALYTICS_CI_PATH_PART + "servers/" + selfIdentity + "/tasks/" + taskId + "/result").setHeaders(headers).setBody(contentJSON);
    try {
        OctaneResponse octaneResponse = octaneRestClientImpl.execute(octaneRequest);
        return octaneResponse.getStatus();
    } catch (IOException ioe) {
        logger.error(configurer.octaneConfiguration.getLocationForLog() + "failed to submit abridged task's result", ioe);
        return 0;
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) OctaneRestClient(com.hp.octane.integrations.services.rest.OctaneRestClient) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with OctaneRestClient

use of com.hp.octane.integrations.services.rest.OctaneRestClient 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());
    }
}
Also used : TemporaryException(com.hp.octane.integrations.exceptions.TemporaryException) 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)

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