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