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;
}
}
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);
}
}
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());
}
}
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;
}
}
}
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());
}
}
Aggregations