Search in sources :

Example 26 with OctaneResponse

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

the class GithubV3FetchHandler method getRateLimitationInfo.

/**
 * RE
 *
 * @param baseUrl
 * @param logConsumer
 * @return
 * @throws IOException
 */
private RateLimitationInfo getRateLimitationInfo(String baseUrl, Consumer<String> logConsumer) throws IOException {
    String rateUrl = baseUrl + "/rate_limit";
    OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setUrl(rateUrl).setMethod(HttpMethod.GET);
    OctaneResponse response = restClient.executeRequest(request);
    if (response.getStatus() == HttpStatus.SC_OK && response.getHeaders().containsKey("X-RateLimit-Limit")) {
        RateLimitationInfo info = new RateLimitationInfo();
        fillRateLimitationInfo(response, info);
        long minToNextReset = (info.getReset() - System.currentTimeMillis() / 1000) / 60;
        logConsumer.accept(String.format("RateLimit Info: Limit-%s; Remaining-%s; Reset in %s min. ", info.getLimit(), info.getRemaining(), minToNextReset));
        return info;
    } else {
        return null;
    }
}
Also used : OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest)

Example 27 with OctaneResponse

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

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

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

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

the class CoverageServiceImpl method pushCoverageWithPreflight.

private void pushCoverageWithPreflight(CoverageQueueItem queueItem) {
    // preflight
    if (!isSonarReportRelevant(queueItem.jobId)) {
        return;
    }
    // get coverage report content
    InputStream coverageReport = configurer.pluginServices.getCoverageReport(queueItem.jobId, queueItem.buildId, queueItem.reportFileName);
    if (coverageReport == null) {
        logger.info(configurer.octaneConfiguration.getLocationForLog() + "no log for " + queueItem + " found, abandoning");
        return;
    }
    // push coverage
    OctaneResponse response = pushCoverage(queueItem.jobId, queueItem.buildId, queueItem.reportType, coverageReport);
    if (response.getStatus() == HttpStatus.SC_OK) {
        logger.info(configurer.octaneConfiguration.getLocationForLog() + "successfully pushed coverage of " + queueItem + ", CorrelationId - " + response.getCorrelationId());
    } else if (response.getStatus() == HttpStatus.SC_SERVICE_UNAVAILABLE || response.getStatus() == HttpStatus.SC_BAD_GATEWAY) {
        throw new TemporaryException("temporary failed to push coverage of " + queueItem + ", status: " + HttpStatus.SC_SERVICE_UNAVAILABLE);
    } else {
        throw new PermanentException("permanently failed to push coverage of " + queueItem + ", status: " + response.getStatus());
    }
}
Also used : TemporaryException(com.hp.octane.integrations.exceptions.TemporaryException) InputStream(java.io.InputStream) PermanentException(com.hp.octane.integrations.exceptions.PermanentException) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse)

Aggregations

OctaneResponse (com.hp.octane.integrations.dto.connectivity.OctaneResponse)36 OctaneRequest (com.hp.octane.integrations.dto.connectivity.OctaneRequest)27 IOException (java.io.IOException)14 PermanentException (com.hp.octane.integrations.exceptions.PermanentException)10 TemporaryException (com.hp.octane.integrations.exceptions.TemporaryException)10 OctaneRestClient (com.hp.octane.integrations.services.rest.OctaneRestClient)10 HashMap (java.util.HashMap)7 InputStream (java.io.InputStream)4 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 HttpResponse (org.apache.http.HttpResponse)3 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)3 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)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 Header (org.apache.http.Header)2