Search in sources :

Example 1 with OctaneRequest

use of com.hp.octane.integrations.dto.connectivity.OctaneRequest in project octane-ci-java-sdk by MicroFocus.

the class TestExecutionServiceImpl method validateSuiteRun.

private void validateSuiteRun(Long workspaceId, Long suiteId) throws IOException {
    // https://almoctane-eur.saas.microfocus.com/internal-api/shared_spaces/274001/workspaces/1002/je/executors/validate-auto-suite?force=false&rerun=false&suite_run_id=&test_suite_id=6009
    String url = configurer.octaneConfiguration.getUrl() + RestService.SHARED_SPACE_INTERNAL_API_PATH_PART + configurer.octaneConfiguration.getSharedSpace() + "/workspaces/" + workspaceId + "/je/executors/validate-auto-suite?force=false&rerun=false&suite_run_id=&test_suite_id=" + suiteId;
    OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.GET).setUrl(url);
    OctaneResponse octaneResponse = restService.obtainOctaneRestClient().execute(request);
    if (octaneResponse.getStatus() != 200) {
        throw new RuntimeException(octaneResponse.getBody());
    }
}
Also used : OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest)

Example 2 with OctaneRequest

use of com.hp.octane.integrations.dto.connectivity.OctaneRequest in project octane-ci-java-sdk by MicroFocus.

the class TestExecutionServiceImpl method runSuiteRun.

private void runSuiteRun(Long workspaceId, Long suiteRunId) throws IOException {
    // https://admhelp.microfocus.com/octane/en/latest/Online/Content/API/Trigger_Suite_Run.htm?Highlight=Trigger%20Suite%20Run
    String url = configurer.octaneConfiguration.getUrl() + RestService.SHARED_SPACE_API_PATH_PART + configurer.octaneConfiguration.getSharedSpace() + "/workspaces/" + workspaceId + "/suite_runs/" + suiteRunId + "/run_auto";
    OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.POST).setUrl(url);
    OctaneResponse octaneResponse = restService.obtainOctaneRestClient().execute(request);
    if (octaneResponse.getStatus() != 201) {
        throw new RuntimeException("runSuiteRun failed with status " + octaneResponse.getStatus() + ", message : " + octaneResponse.getBody());
    }
}
Also used : OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest)

Example 3 with OctaneRequest

use of com.hp.octane.integrations.dto.connectivity.OctaneRequest 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 4 with OctaneRequest

use of com.hp.octane.integrations.dto.connectivity.OctaneRequest 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);
    }
}
Also used : TemporaryException(com.hp.octane.integrations.exceptions.TemporaryException) InterruptedIOException(java.io.InterruptedIOException) RequestTimeoutException(com.hp.octane.integrations.exceptions.RequestTimeoutException) PermanentException(com.hp.octane.integrations.exceptions.PermanentException) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 5 with OctaneRequest

use of com.hp.octane.integrations.dto.connectivity.OctaneRequest in project octane-ci-java-sdk by MicroFocus.

the class ExistingIssuesInOctane method getRemoteIdsOpenVulnsFromOctane.

public List<String> getRemoteIdsOpenVulnsFromOctane(String jobId, String runId, String remoteTag) throws IOException {
    Map<String, String> headers = new HashMap<>();
    headers.put(RestService.CONTENT_TYPE_HEADER, ContentType.APPLICATION_JSON.getMimeType());
    boolean base64 = ConfigurationParameterFactory.isEncodeCiJobBase64(octaneConfiguration);
    String encodedJobId = base64 ? CIPluginSDKUtils.urlEncodeBase64(jobId) : CIPluginSDKUtils.urlEncodeQueryParam(jobId);
    String url = getOpenVulnerabilitiesContextPath(octaneConfiguration.getUrl(), octaneConfiguration.getSharedSpace()) + "?instance-id=" + octaneConfiguration.getInstanceId() + String.format("&job-ci-id=%s&build-ci-id=%s&state=open&remote-tag=%s", encodedJobId, CIPluginSDKUtils.urlEncodeQueryParam(runId), CIPluginSDKUtils.urlEncodeQueryParam(remoteTag));
    if (base64) {
        url = CIPluginSDKUtils.addParameterEncode64ToUrl(url);
    }
    OctaneRequest request = DTOFactory.getInstance().newDTO(OctaneRequest.class).setMethod(HttpMethod.GET).setUrl(url).setHeaders(headers);
    OctaneResponse response = octaneRestClient.execute(request);
    logger.info(octaneConfiguration.getLocationForLog() + "vulnerabilities retrieve was completed; status: " + response.getStatus() + ", response: " + response.getBody());
    if (response.getStatus() == HttpStatus.SC_OK) {
        logger.info(octaneConfiguration.getLocationForLog() + "retrieved existing vulnerabilities from Octane.");
    } else {
        logger.error(octaneConfiguration.getLocationForLog() + "Error retrieving existing vulnerabilities from Octane.");
        throw new IOException();
    }
    return CIPluginSDKUtils.getObjectMapper().readValue(response.getBody(), List.class);
}
Also used : HashMap(java.util.HashMap) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) IOException(java.io.IOException)

Aggregations

OctaneRequest (com.hp.octane.integrations.dto.connectivity.OctaneRequest)30 OctaneResponse (com.hp.octane.integrations.dto.connectivity.OctaneResponse)27 IOException (java.io.IOException)12 OctaneRestClient (com.hp.octane.integrations.services.rest.OctaneRestClient)11 PermanentException (com.hp.octane.integrations.exceptions.PermanentException)8 HashMap (java.util.HashMap)8 TemporaryException (com.hp.octane.integrations.exceptions.TemporaryException)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 PipelineContextList (com.hp.octane.integrations.dto.pipelines.PipelineContextList)3 RequestTimeoutException (com.hp.octane.integrations.exceptions.RequestTimeoutException)3 ResourceNotFoundException (com.hp.octane.integrations.exceptions.ResourceNotFoundException)3 InterruptedIOException (java.io.InterruptedIOException)3 LinkedHashMap (java.util.LinkedHashMap)3 OctaneConfiguration (com.hp.octane.integrations.OctaneConfiguration)2 PipelineContext (com.hp.octane.integrations.dto.pipelines.PipelineContext)2 OctaneConnectivityException (com.hp.octane.integrations.exceptions.OctaneConnectivityException)2 URISyntaxException (java.net.URISyntaxException)2 URIBuilder (org.apache.http.client.utils.URIBuilder)2 OctaneClient (com.hp.octane.integrations.OctaneClient)1 OctaneConnectivityStatus (com.hp.octane.integrations.dto.general.OctaneConnectivityStatus)1