Search in sources :

Example 26 with OctaneRequest

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

the class GithubV3FetchHandler method getEntity.

private <T extends Entity> T getEntity(String url, Class<T> entityType, RateLimitationInfo rateLimitationInfo) {
    try {
        OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setUrl(url).setMethod(HttpMethod.GET);
        OctaneResponse response = restClient.executeRequest(request);
        if (response.getStatus() == HttpStatus.SC_NOT_FOUND) {
            throw new ResourceNotFoundException(String.format("URL %s not found", url));
        }
        if (rateLimitationInfo != null) {
            fillRateLimitationInfo(response, rateLimitationInfo);
        }
        return JsonConverter.convert(response.getBody(), entityType);
    } catch (ResourceNotFoundException notFoundException) {
        throw notFoundException;
    } catch (Exception e) {
        throw new RuntimeException("Failed to getEntity : " + e.getMessage(), e);
    }
}
Also used : OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) ResourceNotFoundException(com.hp.octane.integrations.exceptions.ResourceNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ResourceNotFoundException(com.hp.octane.integrations.exceptions.ResourceNotFoundException)

Example 27 with OctaneRequest

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

the class ConfigurationServiceImpl method validateConfigurationAndGetConnectivityStatus.

@Override
public OctaneConnectivityStatus validateConfigurationAndGetConnectivityStatus() throws IOException {
    OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.GET).setUrl(configurer.octaneConfiguration.getUrl() + RestService.SHARED_SPACE_INTERNAL_API_PATH_PART + configurer.octaneConfiguration.getSharedSpace() + CONNECTIVITY_STATUS_URL);
    OctaneResponse response = restService.obtainOctaneRestClient().execute(request, configurer.octaneConfiguration);
    if (response.getStatus() == 401) {
        throw new OctaneConnectivityException(response.getStatus(), OctaneConnectivityException.AUTHENTICATION_FAILURE_KEY, OctaneConnectivityException.AUTHENTICATION_FAILURE_MESSAGE);
    } else if (response.getStatus() == 403) {
        throw new OctaneConnectivityException(response.getStatus(), OctaneConnectivityException.AUTHORIZATION_FAILURE_KEY, OctaneConnectivityException.AUTHORIZATION_FAILURE_MESSAGE);
    } else if (response.getStatus() == 404) {
        throw new OctaneConnectivityException(response.getStatus(), OctaneConnectivityException.CONN_SHARED_SPACE_INVALID_KEY, OctaneConnectivityException.CONN_SHARED_SPACE_INVALID_MESSAGE);
    } else if (response.getStatus() == 200) {
        OctaneConnectivityStatus octaneConnectivityStatus = DTOFactory.getInstance().dtoFromJson(response.getBody(), OctaneConnectivityStatus.class);
        return octaneConnectivityStatus;
    } else {
        throw new OctaneConnectivityException(response.getStatus(), OctaneConnectivityException.UNEXPECTED_FAILURE_KEY, OctaneConnectivityException.UNEXPECTED_FAILURE_MESSAGE + ": " + response.getStatus());
    }
}
Also used : OctaneConnectivityException(com.hp.octane.integrations.exceptions.OctaneConnectivityException) OctaneConnectivityStatus(com.hp.octane.integrations.dto.general.OctaneConnectivityStatus) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest)

Example 28 with OctaneRequest

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

the class MfMBTConverter method handleMbtDataRetrieval.

private void handleMbtDataRetrieval(List<TestToRunData> tests, Map<String, String> globalParameters) {
    if (shouldRetrieveMbtData(tests)) {
        OctaneClient octaneClient = OctaneSDK.getClientByInstanceId(globalParameters.get(OCTANE_CONFIG_ID_PARAMETER_NAME));
        OctaneConfiguration octaneConfig = octaneClient.getConfigurationService().getConfiguration();
        String url = octaneConfig.getUrl() + "/api" + "/shared_spaces/" + octaneConfig.getSharedSpace() + "/workspaces/" + globalParameters.get(OCTANE_WORKSPACE_PARAMETER_NAME) + "/suite_runs/" + globalParameters.get(SUITE_RUN_ID_PARAMETER_NAME) + "/get_suite_data";
        Map<String, String> headers = new HashMap<>();
        headers.put(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
        headers.put(OctaneRestClient.CLIENT_TYPE_HEADER, OctaneRestClient.CLIENT_TYPE_VALUE);
        OctaneRequest request = DTOFactory.getInstance().newDTO(OctaneRequest.class).setMethod(HttpMethod.GET).setHeaders(headers).setUrl(url);
        try {
            OctaneResponse octaneResponse = octaneClient.getRestService().obtainOctaneRestClient().execute(request);
            if (octaneResponse != null && octaneResponse.getStatus() == HttpStatus.SC_OK) {
                Map<String, String> parsedResponse = parseSuiteRunDataJson(octaneResponse.getBody());
                if (parsedResponse != null) {
                    for (TestToRunData test : tests) {
                        String runID = test.getParameter(INNER_RUN_ID_PARAMETER);
                        test.addParameters(MBT_DATA, parsedResponse.get(runID));
                    }
                }
            } else {
                logger.error("Failed to get response {}", (octaneResponse != null ? octaneResponse.getStatus() : "(null)"));
                return;
            }
        } catch (IOException e) {
            logger.error("Failed to get response ", e);
            return;
        }
    }
}
Also used : OctaneClient(com.hp.octane.integrations.OctaneClient) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) TestToRunData(com.hp.octane.integrations.executor.TestToRunData)

Example 29 with OctaneRequest

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

the class FetchHandler method pingRepository.

public SCMRepositoryLinks pingRepository(String repoApiBaseUrl, Consumer<String> logConsumer) throws IOException {
    OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setUrl(repoApiBaseUrl).setMethod(HttpMethod.GET);
    try {
        OctaneResponse response = restClient.executeRequest(request);
        if (response.getStatus() == HttpStatus.SC_OK) {
            logConsumer.accept("Ping repository : Ok");
            return parseSCMRepositoryLinks(response.getBody());
        }
        logConsumer.accept("Ping repository : " + response.getStatus() + "; " + parseRequestError(response));
        if (response.getStatus() == HttpStatus.SC_NOT_FOUND) {
            throw new IllegalArgumentException("Repository not found. Please validate that project/user name and repository name are spelled correctly.");
        }
        if (response.getStatus() == HttpStatus.SC_UNAUTHORIZED) {
            throw new IllegalArgumentException("Unauthorized, validate correctness of credentials.");
        }
        throw new IllegalArgumentException("Unexpected exception");
    } catch (HttpHostConnectException e) {
        throw new IOException("Repository is not available. Please validate that URL and proxy settings are set correctly.");
    }
}
Also used : HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) IOException(java.io.IOException)

Example 30 with OctaneRequest

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

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