use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class SonarServiceImpl method getPageFromSonar.
private InputStream getPageFromSonar(SonarBuildCoverageQueueItem queueItem, Integer page) {
String sonarURL = queueItem.sonarURL;
String projectKey = queueItem.projectKey;
String token = queueItem.sonarToken;
StringBuilder errorMessage = new StringBuilder().append("failed to get data from sonar for project key: ").append(projectKey);
try {
URIBuilder uriBuilder = new URIBuilder(sonarURL + COMPONENT_TREE_URI);
uriBuilder.setParameter("metricKeys", "lines_to_cover,uncovered_lines").setParameter("component", projectKey).setParameter("qualifiers", "FIL,TRK").setParameter("ps", "500").setParameter("p", page.toString());
HttpClient httpClient = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(uriBuilder.build());
setTokenInHttpRequest(request, token);
HttpResponse httpResponse = httpClient.execute(request);
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
errorMessage.append(" with status code: ").append(statusCode).append(" and response body: ").append(EntityUtils.toString(httpResponse.getEntity(), "UTF-8"));
throw new PermanentException(errorMessage.toString());
} else {
return httpResponse.getEntity().getContent();
}
} catch (PermanentException e) {
throw e;
} catch (Exception e) {
logger.error(configurer.octaneConfiguration.getLocationForLog() + errorMessage.toString(), e);
throw new PermanentException(errorMessage.toString(), e);
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class SonarUtils method getDataFromSonar.
public static InputStream getDataFromSonar(String projectKey, String token, URIBuilder uriQuery) {
StringBuilder errorMessage = new StringBuilder().append("failed to get data from sonar for project key: ").append(projectKey);
try {
HttpClient httpClient = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(uriQuery.build());
setTokenInHttpRequest(request, token);
HttpResponse httpResponse = httpClient.execute(request);
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
return httpResponse.getEntity().getContent();
} else if (statusCode == HttpStatus.SC_BAD_REQUEST) {
errorMessage.append(" with status code: ").append(statusCode).append(" and response body: ").append(EntityUtils.toString(httpResponse.getEntity(), "UTF-8"));
throw new TemporaryException(errorMessage.toString());
} else {
errorMessage.append(" with status code: ").append(statusCode).append(" and response body: ").append(EntityUtils.toString(httpResponse.getEntity(), "UTF-8"));
throw new PermanentException(errorMessage.toString());
}
} catch (HttpHostConnectException e) {
throw new TemporaryException(errorMessage.toString(), e);
} catch (Exception e) {
throw new PermanentException(errorMessage.toString(), e);
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class FODConnector method getSpeceficFODEntity.
@Override
public <T> T getSpeceficFODEntity(String rawURL, Class<T> targetClass) {
try {
T fetchedEntityInstance = targetClass.newInstance();
String rawResponse = getRawResponseFromFOD(rawURL);
// Deserialize.
T entityFetched = new ObjectMapper().readValue(rawResponse, TypeFactory.defaultInstance().constructType((fetchedEntityInstance).getClass()));
return entityFetched;
} catch (PermanentException e) {
throw e;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of com.hp.octane.integrations.exceptions.PermanentException 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());
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class LogsServiceImpl method preflightRequest.
private String[] preflightRequest(OctaneConfiguration octaneConfiguration, String encodedServerId, String encodedJobId, String encodedRootJobId, boolean base64) {
String[] result = new String[0];
OctaneResponse response;
// get result
String url = getAnalyticsContextPath(configurer.octaneConfiguration.getUrl(), octaneConfiguration.getSharedSpace()) + "servers/" + encodedServerId + "/jobs/" + encodedJobId + "/workspaceId";
if (encodedRootJobId != null && !encodedRootJobId.isEmpty()) {
url += "?rootJobId=" + encodedRootJobId;
}
if (base64) {
url = CIPluginSDKUtils.addParameterEncode64ToUrl(url);
}
try {
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_UNAUTHORIZED || response.getStatus() == HttpStatus.SC_FORBIDDEN) {
CIPluginSDKUtils.doWait(30000);
throw new PermanentException("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() + ". JobId: '" + encodedJobId + "'. Request URL : " + url);
}
} catch (IOException ioe) {
throw new TemporaryException(ioe);
}
// parse result
if (response.getBody() != null && !response.getBody().isEmpty()) {
try {
result = CIPluginSDKUtils.getObjectMapper().readValue(response.getBody(), String[].class);
} catch (IOException ioe) {
if (CIPluginSDKUtils.isServiceTemporaryUnavailable(response.getBody())) {
throw new TemporaryException("Saas service is temporary unavailable.");
} else {
throw new PermanentException("failed to parse preflight response '" + response.getBody() + "' for '" + encodedJobId + "'");
}
}
}
return result;
}
Aggregations