use of com.hubspot.horizon.HttpResponse in project Singularity by HubSpot.
the class SingularityMesosClient method getFromMesos.
private HttpResponse getFromMesos(String uri) {
HttpResponse response = null;
final long start = System.currentTimeMillis();
LOG.debug("Fetching {} from mesos", uri);
try {
response = httpClient.execute(HttpRequest.newBuilder().setUrl(uri).build());
LOG.debug("Response {} - {} after {}", response.getStatusCode(), uri, JavaUtils.duration(start));
} catch (Exception e) {
throw new MesosClientException(String.format("Exception fetching %s after %s", uri, JavaUtils.duration(start)), e);
}
if (!response.isSuccess()) {
throw new MesosClientException(String.format("Invalid response code from %s : %s", uri, response.getStatusCode()));
}
return response;
}
use of com.hubspot.horizon.HttpResponse in project Singularity by HubSpot.
the class SingularityMesosClient method getSlaveResourceUsage.
@Override
public List<MesosTaskMonitorObject> getSlaveResourceUsage(String hostname) {
final String uri = String.format(MESOS_SLAVE_STATISTICS_URL, hostname);
HttpResponse response = getFromMesos(uri);
try {
return response.getAs(TASK_MONITOR_TYPE_REFERENCE);
} catch (Exception e) {
throw new MesosClientException(String.format("Unable to deserialize task monitor object from %s", uri), e);
}
}
use of com.hubspot.horizon.HttpResponse in project Singularity by HubSpot.
the class SingularityClient method createDeployForSingularityRequest.
public SingularityRequestParent createDeployForSingularityRequest(String requestId, SingularityDeploy pendingDeploy, Optional<Boolean> deployUnpause, Optional<String> message, Optional<SingularityRequest> updatedRequest) {
final Function<String, String> requestUri = (String host) -> String.format(DEPLOYS_FORMAT, getApiBase(host));
HttpResponse response = post(requestUri, String.format("new deploy %s", new SingularityDeployKey(requestId, pendingDeploy.getId())), Optional.of(new SingularityDeployRequest(pendingDeploy, deployUnpause, message, updatedRequest)));
return getAndLogRequestAndDeployStatus(response.getAs(SingularityRequestParent.class));
}
use of com.hubspot.horizon.HttpResponse in project Singularity by HubSpot.
the class SingularityClient method deleteWithParams.
private <T> Optional<T> deleteWithParams(Function<String, String> hostToUrl, String type, String id, Optional<?> body, Optional<Map<String, Object>> queryParams, Optional<Class<T>> clazz) {
LOG.info("Deleting {} {} from Singularity", type, id);
final long start = System.currentTimeMillis();
HttpResponse response = executeRequest(hostToUrl, Method.DELETE, body, queryParams.or(Collections.emptyMap()));
if (response.getStatusCode() == 404) {
LOG.info("{} ({}) was not found", type, id);
return Optional.absent();
}
checkResponse(type, response);
LOG.info("Deleted {} ({}) from Singularity in %sms", type, id, System.currentTimeMillis() - start);
if (clazz.isPresent()) {
return Optional.of(response.getAs(clazz.get()));
}
return Optional.absent();
}
use of com.hubspot.horizon.HttpResponse in project Singularity by HubSpot.
the class SingularityClient method getSingleWithParams.
private <T> Optional<T> getSingleWithParams(Function<String, String> hostToUrl, String type, String id, Optional<Map<String, Object>> queryParams, Class<T> clazz) {
final long start = System.currentTimeMillis();
HttpResponse response = executeGetSingleWithParams(hostToUrl, type, id, queryParams);
if (response.getStatusCode() == 404) {
return Optional.absent();
}
checkResponse(type, response);
LOG.info("Got {} {} in {}ms", type, id, System.currentTimeMillis() - start);
return Optional.fromNullable(response.getAs(clazz));
}
Aggregations