use of com.hp.octane.integrations.dto.connectivity.OctaneRequest in project octane-ci-java-sdk by MicroFocus.
the class VulnerabilitiesServiceImpl method pushVulnerabilities.
private void pushVulnerabilities(InputStream vulnerabilities, String jobId, String buildId) 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.urlEncodePathParam(jobId);
String encodedBuildId = CIPluginSDKUtils.urlEncodePathParam(buildId);
String url = getVulnerabilitiesContextPath(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.POST).setUrl(url).setHeaders(headers).setBody(vulnerabilities);
OctaneResponse response = octaneRestClient.execute(request);
logger.info(configurer.octaneConfiguration.getLocationForLog() + "vulnerabilities pushed; status: " + response.getStatus() + ", response: " + response.getBody());
if (response.getStatus() == HttpStatus.SC_ACCEPTED) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "vulnerabilities push SUCCEED for " + jobId + " #" + buildId);
} else if (response.getStatus() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
throw new TemporaryException("vulnerabilities push FAILED, service unavailable");
} else {
throw new PermanentException("vulnerabilities push FAILED, status " + response.getStatus() + "; dropping this item from the queue \n" + response.getBody());
}
}
use of com.hp.octane.integrations.dto.connectivity.OctaneRequest in project octane-ci-java-sdk by MicroFocus.
the class VulnerabilitiesServiceImpl method getBaselineDateFromOctane.
private OctaneResponse getBaselineDateFromOctane(String jobId, String buildId) throws IOException {
boolean base64 = isEncodeBase64();
String encodedJobId = base64 ? CIPluginSDKUtils.urlEncodeBase64(jobId) : CIPluginSDKUtils.urlEncodeQueryParam(jobId);
String encodedBuildId = CIPluginSDKUtils.urlEncodeQueryParam(buildId);
String url = getVulnerabilitiesPreFlightContextPath(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 preflightRequest = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.GET).setUrl(url);
return restService.obtainOctaneRestClient().execute(preflightRequest);
}
use of com.hp.octane.integrations.dto.connectivity.OctaneRequest in project octane-ci-java-sdk by MicroFocus.
the class PipelineContextServiceImpl method updatePipeline.
@Override
public PipelineContext updatePipeline(String serverIdentity, String jobName, PipelineContext pipelineContext) throws IOException {
String url = getConfigurationUrl(serverIdentity, jobName);
validateReleaseAndMilestone(pipelineContext);
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());
PipelineContextList list = dtoFactory.newDTO(PipelineContextList.class).setData(Arrays.asList(pipelineContext));
String jsonData = dtoFactory.dtoToJson(list);
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.PUT).setUrl(url).setBody(jsonData).setHeaders(headers);
OctaneResponse response = octaneRestClient.execute(request);
validateResponse(HttpStatus.SC_OK, response);
PipelineContextList resultList = dtoFactory.dtoFromJson(response.getBody(), PipelineContextList.class);
// we might receive several pipeline context from other workspaces.
// find updated context by id
PipelineContext result = resultList.getData().stream().filter(p -> p.getContextEntityId() == pipelineContext.getContextEntityId()).findFirst().get();
return result;
}
use of com.hp.octane.integrations.dto.connectivity.OctaneRequest 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.OctaneRequest 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);
}
}
Aggregations