Search in sources :

Example 1 with HttpResponse

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;
}
Also used : HttpResponse(com.hubspot.horizon.HttpResponse)

Example 2 with HttpResponse

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);
    }
}
Also used : HttpResponse(com.hubspot.horizon.HttpResponse)

Example 3 with HttpResponse

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));
}
Also used : SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) HttpResponse(com.hubspot.horizon.HttpResponse) SingularityRequestParent(com.hubspot.singularity.SingularityRequestParent)

Example 4 with HttpResponse

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();
}
Also used : HttpResponse(com.hubspot.horizon.HttpResponse)

Example 5 with HttpResponse

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));
}
Also used : HttpResponse(com.hubspot.horizon.HttpResponse)

Aggregations

HttpResponse (com.hubspot.horizon.HttpResponse)15 SingularityDeployKey (com.hubspot.singularity.SingularityDeployKey)8 TypeReference (com.fasterxml.jackson.core.type.TypeReference)7 RetryException (com.github.rholder.retry.RetryException)7 Retryer (com.github.rholder.retry.Retryer)7 RetryerBuilder (com.github.rholder.retry.RetryerBuilder)7 StopStrategies (com.github.rholder.retry.StopStrategies)7 WaitStrategies (com.github.rholder.retry.WaitStrategies)7 Optional (com.google.common.base.Optional)7 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)7 ImmutableList (com.google.common.collect.ImmutableList)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 Builder (com.google.common.collect.ImmutableMap.Builder)7 Inject (com.google.inject.Inject)7 Named (com.google.inject.name.Named)7 HttpClient (com.hubspot.horizon.HttpClient)7 HttpRequest (com.hubspot.horizon.HttpRequest)7 Method (com.hubspot.horizon.HttpRequest.Method)7 RetryStrategy (com.hubspot.horizon.RetryStrategy)7 MesosFileChunkObject (com.hubspot.mesos.json.MesosFileChunkObject)7