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());
}
Aggregations