Search in sources :

Example 1 with BaragonServiceState

use of com.hubspot.baragon.models.BaragonServiceState in project Singularity by HubSpot.

the class BaragonLoadBalancerClientImpl method getUpstreamsForRequest.

public List<LoadBalancerUpstream> getUpstreamsForRequest(String singularityRequestId) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    final String loadBalancerStateUri = getLoadBalancerStateUri(singularityRequestId);
    final BoundRequestBuilder requestBuilder = httpClient.prepareGet(loadBalancerStateUri);
    final Request request = requestBuilder.build();
    LOG.debug("Sending load balancer {} request for {} to {}", request.getMethod(), singularityRequestId, request.getUrl());
    ListenableFuture<Response> future = httpClient.executeRequest(request);
    Response response = future.get(loadBalancerTimeoutMillis, TimeUnit.MILLISECONDS);
    LOG.debug("Load balancer {} request {} returned with code {}", request.getMethod(), singularityRequestId, response.getStatusCode());
    Optional<BaragonServiceState> maybeBaragonServiceState = Optional.ofNullable(objectMapper.readValue(response.getResponseBodyAsBytes(), BaragonServiceState.class));
    return maybeBaragonServiceState.map(BaragonServiceState::getUpstreams).orElse(Collections.emptyList()).stream().map(LoadBalancerUpstream::fromBaragonUpstream).collect(Collectors.toList());
}
Also used : Response(com.ning.http.client.Response) BaragonResponse(com.hubspot.baragon.models.BaragonResponse) BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) BaragonServiceState(com.hubspot.baragon.models.BaragonServiceState) Request(com.ning.http.client.Request) SingularityRequest(com.hubspot.singularity.SingularityRequest) BaragonRequest(com.hubspot.baragon.models.BaragonRequest)

Aggregations

BaragonRequest (com.hubspot.baragon.models.BaragonRequest)1 BaragonResponse (com.hubspot.baragon.models.BaragonResponse)1 BaragonServiceState (com.hubspot.baragon.models.BaragonServiceState)1 SingularityRequest (com.hubspot.singularity.SingularityRequest)1 BoundRequestBuilder (com.ning.http.client.AsyncHttpClient.BoundRequestBuilder)1 Request (com.ning.http.client.Request)1 Response (com.ning.http.client.Response)1