use of com.hp.octane.integrations.dto.connectivity.OctaneRequest in project octane-ci-java-sdk by MicroFocus.
the class ConfigurationServiceImpl method resetOctaneRootsCache.
@Override
public Future<Boolean> resetOctaneRootsCache() {
if (isOctaneRootsCacheActivated() && isOctaneVersionGreaterOrEqual(OCTANE_ROOTS_VERSION) && !configurer.octaneConfiguration.isDisabled()) {
return octaneRootsCacheExecutor.submit(() -> {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "resetOctaneRootCache started");
try {
long startTime = System.currentTimeMillis();
String url = configurer.octaneConfiguration.getUrl() + RestService.SHARED_SPACE_INTERNAL_API_PATH_PART + configurer.octaneConfiguration.getSharedSpace() + String.format(PIPELINE_ROOTS_URL, configurer.octaneConfiguration.getInstanceId());
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.GET).setUrl(url);
OctaneResponse response = restService.obtainOctaneRestClient().execute(request, configurer.octaneConfiguration);
octaneRoots = mapper.readValue(response.getBody(), mapper.getTypeFactory().constructCollectionType(Set.class, String.class));
logger.info(configurer.octaneConfiguration.getLocationForLog() + "resetOctaneRootCache: successfully update octane roots, found " + octaneRoots.size() + " roots, processing time is " + ((System.currentTimeMillis() - startTime) / 1000) + " seconds");
return true;
} catch (Exception e) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "Failed to resetOctaneRootCache : " + e.getMessage());
return false;
}
});
} else {
if (octaneRoots != null) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "resetOctaneRootsCache : cache is cleared");
}
octaneRoots = null;
return CompletableFuture.completedFuture(false);
}
}
use of com.hp.octane.integrations.dto.connectivity.OctaneRequest in project octane-ci-java-sdk by MicroFocus.
the class CoverageServiceImpl method isSonarReportRelevant.
@Override
public boolean isSonarReportRelevant(String jobId) {
if (jobId == null || jobId.isEmpty()) {
throw new IllegalArgumentException("job ID MUST NOT be null nor empty");
}
boolean result = false;
OctaneResponse response;
boolean base64 = isEncodeBase64();
String encodedJobId = base64 ? CIPluginSDKUtils.urlEncodeBase64(jobId) : CIPluginSDKUtils.urlEncodePathParam(jobId);
// get result
try {
String url = getAnalyticsContextPath(configurer.octaneConfiguration.getUrl(), configurer.octaneConfiguration.getSharedSpace()) + "servers/" + CIPluginSDKUtils.urlEncodePathParam(configurer.octaneConfiguration.getInstanceId()) + "/jobs/" + encodedJobId + "/workspaceId";
if (base64) {
url = CIPluginSDKUtils.addParameterEncode64ToUrl(url);
}
OctaneRequest preflightRequest = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.GET).setUrl(url);
response = restService.obtainOctaneRestClient().execute(preflightRequest);
if (response.getStatus() == HttpStatus.SC_SERVICE_UNAVAILABLE || response.getStatus() == HttpStatus.SC_BAD_GATEWAY) {
throw new TemporaryException("preflight request failed with status " + response.getStatus());
} else if (response.getStatus() != HttpStatus.SC_OK && response.getStatus() != HttpStatus.SC_NO_CONTENT) {
throw new PermanentException("preflight request failed with status " + response.getStatus());
}
} catch (IOException ioe) {
throw new TemporaryException("failed to perform preflight request", ioe);
}
// parse result
if (response.getStatus() == HttpStatus.SC_OK && response.getBody() != null && !response.getBody().isEmpty()) {
try {
String[] wss = CIPluginSDKUtils.getObjectMapper().readValue(response.getBody(), String[].class);
if (wss.length > 0) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "coverage of " + jobId + " found " + wss.length + " interested workspace/s in Octane, dispatching the coverage");
result = true;
} else {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "coverage of " + jobId + ", found no interested workspace in Octane");
}
} catch (IOException ioe) {
throw new PermanentException("failed to parse preflight response '" + response.getBody() + "' for '" + jobId + "'");
}
}
return result;
}
use of com.hp.octane.integrations.dto.connectivity.OctaneRequest in project octane-ci-java-sdk by MicroFocus.
the class CoverageServiceImpl method pushCoverage.
@Override
public OctaneResponse pushCoverage(String jobId, String buildId, CoverageReportType reportType, InputStream coverageReport) {
if (jobId == null || jobId.isEmpty()) {
throw new IllegalArgumentException("job ID MUST NOT be null nor empty");
}
if (buildId == null || buildId.isEmpty()) {
throw new IllegalArgumentException("build ID MUST NOT be null nor empty");
}
if (reportType == null) {
throw new IllegalArgumentException("report type MUST NOT be null");
}
if (coverageReport == null) {
throw new IllegalArgumentException("coverage report data MUST NOT be null");
}
boolean base64 = isEncodeBase64();
String tempJobId = jobId;
if (base64) {
tempJobId = CIPluginSDKUtils.urlEncodeBase64(jobId);
}
String url;
try {
url = new URIBuilder(getAnalyticsContextPath(configurer.octaneConfiguration.getUrl(), configurer.octaneConfiguration.getSharedSpace()) + "coverage").setParameter("ci-server-identity", configurer.octaneConfiguration.getInstanceId()).setParameter("ci-job-id", tempJobId).setParameter("ci-build-id", buildId).setParameter("file-type", reportType.name()).toString();
if (base64) {
url = CIPluginSDKUtils.addParameterEncode64ToUrl(url);
}
} catch (URISyntaxException urise) {
throw new PermanentException("failed to build URL to push coverage report", urise);
}
String correlationId = CIPluginSDKUtils.getNextCorrelationId();
Map<String, String> headers = new HashMap<>();
headers.put(CORRELATION_ID_HEADER, correlationId);
OctaneRequest pushCoverageRequest = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.PUT).setUrl(url).setHeaders(headers).setBody(coverageReport);
try {
return restService.obtainOctaneRestClient().execute(pushCoverageRequest);
} catch (IOException ioe) {
throw new TemporaryException("failed to push coverage report", ioe);
}
}
use of com.hp.octane.integrations.dto.connectivity.OctaneRequest in project octane-ci-java-sdk by MicroFocus.
the class GithubV3FetchHandler method getPagedEntities.
/**
* @param url
* @param entityType
* @param pageSize
* @param maxTotal
* @param minUpdateTime
* @param <T>
* @return
*/
private <T extends Entity & SupportUpdatedTime> List<T> getPagedEntities(String url, Class<T> entityType, int pageSize, int maxTotal, long minUpdateTime) {
try {
List<T> result = new ArrayList<>();
boolean finished;
String myUrl = url + (url.contains("?") ? "" : "?") + "&per_page=" + pageSize;
do {
finished = true;
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setUrl(myUrl).setMethod(HttpMethod.GET);
OctaneResponse response = restClient.executeRequest(request);
List<T> collection = JsonConverter.convertCollection(response.getBody(), entityType);
result.addAll(collection);
myUrl = getNextPageLink(response);
if (myUrl != null) {
finished = false;
}
// remove outdated items
for (int i = result.size() - 1; i >= 0 && minUpdateTime > 0; i--) {
if (result.get(i).getUpdatedTime() <= minUpdateTime) {
result.remove(i);
}
}
// remove exceeding items
while (result.size() > maxTotal) {
result.remove(result.size() - 1);
finished = true;
}
} while (!finished);
return result;
} catch (Exception e) {
throw new RuntimeException("Failed to getPagedEntities : " + e.getMessage(), e);
}
}
use of com.hp.octane.integrations.dto.connectivity.OctaneRequest in project octane-ci-java-sdk by MicroFocus.
the class EntitiesServiceImpl method getPagedEntities.
@Override
public ResponseEntityList getPagedEntities(String url) {
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);
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.GET).setUrl(url).setHeaders(headers);
OctaneResponse response = executeRequest(octaneRestClient, request);
ResponseEntityList pagedEntityList = parseBody(HttpStatus.SC_OK, response);
return pagedEntityList;
}
Aggregations