use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.
the class PipelineContextServiceImpl method deleteTestsFromPipelineNodes.
@Override
public void deleteTestsFromPipelineNodes(String jobName, long pipelineId, long workspaceId) throws IOException {
String url = getWorkspaceAnalyticsContextPath(configurer.octaneConfiguration.getUrl(), configurer.octaneConfiguration.getSharedSpace(), workspaceId) + String.format("pipelines/%s/jobs/%s/tests", pipelineId, CIPluginSDKUtils.urlEncodePathParam(jobName));
OctaneRestClient octaneRestClient = restService.obtainOctaneRestClient();
Map<String, String> headers = new HashMap<>();
headers.put(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.DELETE).setUrl(url).setHeaders(headers);
OctaneResponse response = octaneRestClient.execute(request);
validateResponse(HttpStatus.SC_OK, response);
// Object result = response.getBody();
// return;
}
use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.
the class BitbucketServerFetchHandler method getPagedEntities.
private <T extends Entity & SupportUpdatedTime> List<T> getPagedEntities(String url, Class<T> entityType, int pageSize, int maxTotal, Long minUpdateTime) {
try {
// https://developer.atlassian.com/server/confluence/pagination-in-the-rest-api/
List<T> result = new ArrayList<>();
boolean finished;
int limit = pageSize;
int start = 0;
do {
String myUrl = url + (url.contains("?") ? "" : "?") + String.format("&limit=%d&start=%d", limit, start);
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setUrl(myUrl).setMethod(HttpMethod.GET);
OctaneResponse response = restClient.executeRequest(request);
if (response.getStatus() != HttpStatus.SC_OK) {
throw new RuntimeException(String.format("Request to '%s' is ended with result %d : %s", myUrl, response.getStatus(), JsonConverter.getErrorMessage(response.getBody())));
}
EntityCollection<T> collection = JsonConverter.convertCollection(response.getBody(), entityType);
result.addAll(collection.getValues());
finished = collection.isLastPage() || result.size() > maxTotal;
limit = collection.getLimit();
start = collection.getStart() + collection.getLimit();
// remove outdated items
if (minUpdateTime != null) {
for (int i = result.size() - 1; i >= 0; i--) {
if (result.get(i).getUpdatedTime() <= minUpdateTime) {
result.remove(i);
finished = true;
} else {
break;
}
}
}
} while (!finished);
// remove exceeded items
while (result.size() > maxTotal) {
result.remove(result.size() - 1);
}
return result;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Failed to getPagedEntities : " + e.getMessage(), e);
}
}
use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.
the class EntitiesServiceImpl method updateEntities.
@Override
public List<Entity> updateEntities(Long workspaceId, String entityCollectionName, String jsonData) {
OctaneRestClient octaneRestClient = restService.obtainOctaneRestClient();
Map<String, String> headers = new HashMap<>();
headers.put(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
headers.put(CONTENT_TYPE_HEADER, ContentType.APPLICATION_JSON.getMimeType());
headers.put(OctaneRestClient.CLIENT_TYPE_HEADER, OctaneRestClient.CLIENT_TYPE_VALUE);
String url = buildEntityUrl(workspaceId, entityCollectionName, null, null, null, null, null);
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.PUT).setUrl(url).setBody(jsonData).setHeaders(headers);
OctaneResponse response = executeRequest(octaneRestClient, request);
ResponseEntityList responseEntityList = parseBody(HttpStatus.SC_OK, response);
return responseEntityList.getData();
}
use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.
the class EntitiesServiceImpl method deleteEntities.
@Override
public List<Entity> deleteEntities(Long workspaceId, String entityCollectionName, Collection<String> conditions) {
// SEND REQUEST
OctaneRestClient octaneRestClient = restService.obtainOctaneRestClient();
Map<String, String> headers = new HashMap<>();
headers.put(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
headers.put(OctaneRestClient.CLIENT_TYPE_HEADER, OctaneRestClient.CLIENT_TYPE_VALUE);
String url = buildEntityUrl(workspaceId, entityCollectionName, conditions, null, null, null, null);
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.DELETE).setUrl(url).setHeaders(headers);
OctaneResponse response = executeRequest(octaneRestClient, request);
ResponseEntityList responseEntityList = parseBody(HttpStatus.SC_OK, response);
return responseEntityList.getData();
}
use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.
the class EventsServiceImpl method sendEventsData.
private void sendEventsData(CIEventsList eventsList, String correlationId) {
Map<String, String> headers = new HashMap<>();
headers.put(CONTENT_TYPE_HEADER, ContentType.APPLICATION_JSON.getMimeType());
headers.put(CORRELATION_ID_HEADER, correlationId);
OctaneRequest octaneRequest = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.PUT).setUrl(configurer.octaneConfiguration.getUrl() + SHARED_SPACE_INTERNAL_API_PATH_PART + configurer.octaneConfiguration.getSharedSpace() + ANALYTICS_CI_PATH_PART + "events?ci_server_identity=" + configurer.octaneConfiguration.getInstanceId()).setHeaders(headers).setTimeoutSec(60).setBody(dtoFactory.dtoToJsonStream(eventsList));
OctaneResponse octaneResponse;
try {
octaneResponse = restService.obtainOctaneRestClient().execute(octaneRequest);
} catch (InterruptedIOException ie) {
String msg = "!!!!!!!!!!!!!!!!!!! request timeout" + ie.getClass().getCanonicalName() + " - " + ie.getMessage();
throw new RequestTimeoutException(msg);
} catch (IOException ioe) {
throw new TemporaryException(ioe);
}
if (octaneResponse.getStatus() == HttpStatus.SC_SERVICE_UNAVAILABLE || octaneResponse.getStatus() == HttpStatus.SC_BAD_GATEWAY) {
throw new TemporaryException("PUT events failed with status " + octaneResponse.getStatus());
} else if (octaneResponse.getStatus() == HttpStatus.SC_UNAUTHORIZED || octaneResponse.getStatus() == HttpStatus.SC_FORBIDDEN) {
CIPluginSDKUtils.doWait(30000);
throw new PermanentException("PUT events failed with status " + octaneResponse.getStatus());
} else if (octaneResponse.getStatus() != HttpStatus.SC_OK) {
if (CIPluginSDKUtils.isServiceTemporaryUnavailable(octaneResponse.getBody())) {
throw new TemporaryException("Saas service is temporary unavailable.");
}
throw new PermanentException("PUT events failed with status " + octaneResponse.getStatus());
}
}
Aggregations