Search in sources :

Example 21 with BoundRequestBuilder

use of org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project Singularity by HubSpot.

the class SingularityWebhookSender method executeWebhookAsync.

// TODO handle retries, errors.
private <T> CompletableFuture<Response> executeWebhookAsync(String uri, Object payload, AbstractSingularityWebhookAsyncHandler<T> handler) {
    LOG.trace("Sending {} to {}", payload, uri);
    BoundRequestBuilder postRequest = http.preparePost(uri);
    postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
    try {
        postRequest.setBody(objectMapper.writeValueAsBytes(payload));
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
    CompletableFuture<Response> webhookFuture = new CompletableFuture<>();
    try {
        handler.setCompletableFuture(webhookFuture);
        postRequest.execute(handler);
    } catch (Throwable t) {
        LOG.warn("Couldn't execute webhook to {}", uri, t);
        if (handler.shouldDeleteUpdateDueToQueueAboveCapacity()) {
            handler.deleteWebhookUpdate();
        }
        webhookFuture.completeExceptionally(t);
    }
    return webhookFuture;
}
Also used : Response(com.ning.http.client.Response) BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 22 with BoundRequestBuilder

use of org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project Singularity by HubSpot.

the class BaragonLoadBalancerClientImpl method getState.

@Override
public SingularityLoadBalancerUpdate getState(LoadBalancerRequestId loadBalancerRequestId) {
    final String uri = getLoadBalancerUri(loadBalancerRequestId);
    final BoundRequestBuilder requestBuilder = httpClient.prepareGet(uri);
    loadBalancerQueryParams.ifPresent(stringStringMap -> addAllQueryParams(requestBuilder, stringStringMap));
    return sendRequestWrapper(loadBalancerRequestId, LoadBalancerMethod.CHECK_STATE, requestBuilder.build(), BaragonRequestState.UNKNOWN);
}
Also used : BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder)

Example 23 with BoundRequestBuilder

use of org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project Singularity by HubSpot.

the class BaragonLoadBalancerClientImpl method cancel.

@Override
public SingularityLoadBalancerUpdate cancel(LoadBalancerRequestId loadBalancerRequestId) {
    final String uri = getLoadBalancerUri(loadBalancerRequestId);
    final BoundRequestBuilder requestBuilder = httpClient.prepareDelete(uri);
    loadBalancerQueryParams.ifPresent(stringStringMap -> addAllQueryParams(requestBuilder, stringStringMap));
    return sendRequestWrapper(loadBalancerRequestId, LoadBalancerMethod.CANCEL, requestBuilder.build(), BaragonRequestState.UNKNOWN);
}
Also used : BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder)

Aggregations

BoundRequestBuilder (com.ning.http.client.AsyncHttpClient.BoundRequestBuilder)21 IOException (java.io.IOException)13 Response (com.ning.http.client.Response)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 ExecutionException (java.util.concurrent.ExecutionException)3 SingularityLoadBalancerUpdate (com.hubspot.singularity.SingularityLoadBalancerUpdate)2 FluentCaseInsensitiveStringsMap (com.ning.http.client.FluentCaseInsensitiveStringsMap)2 Request (com.ning.http.client.Request)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 BoundRequestBuilder (org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder)2 Response (org.apache.apex.shaded.ning19.com.ning.http.client.Response)2 Cookie (org.apache.apex.shaded.ning19.com.ning.http.client.cookie.Cookie)2 WebSocketUpgradeHandler (org.apache.apex.shaded.ning19.com.ning.http.client.ws.WebSocketUpgradeHandler)2 JsonParseException (org.codehaus.jackson.JsonParseException)2 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)2 JSONException (org.codehaus.jettison.json.JSONException)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 BaragonRequest (com.hubspot.baragon.models.BaragonRequest)1 BaragonResponse (com.hubspot.baragon.models.BaragonResponse)1 BaragonServiceState (com.hubspot.baragon.models.BaragonServiceState)1