Search in sources :

Example 16 with Request

use of io.airlift.http.client.Request in project presto by prestodb.

the class HttpRemoteTask method cancel.

@Override
public synchronized void cancel() {
    try (SetThreadName ignored = new SetThreadName("HttpRemoteTask-%s", taskId)) {
        TaskStatus taskStatus = getTaskStatus();
        if (taskStatus.getState().isDone()) {
            return;
        }
        // send cancel to task and ignore response
        HttpUriBuilder uriBuilder = getHttpUriBuilder(taskStatus).addParameter("abort", "false");
        Request request = prepareDelete().setUri(uriBuilder.build()).build();
        scheduleAsyncCleanupRequest(new Backoff(MAX_CLEANUP_RETRY_TIME, MAX_CLEANUP_RETRY_TIME), request, "cancel");
    }
}
Also used : SetThreadName(io.airlift.concurrent.SetThreadName) HttpUriBuilder(io.airlift.http.client.HttpUriBuilder) Request(io.airlift.http.client.Request) TaskUpdateRequest(com.facebook.presto.server.TaskUpdateRequest) TaskStatus(com.facebook.presto.execution.TaskStatus)

Example 17 with Request

use of io.airlift.http.client.Request in project presto by prestodb.

the class TaskInfoFetcher method sendNextRequest.

private synchronized void sendNextRequest() {
    TaskStatus taskStatus = getTaskInfo().getTaskStatus();
    if (!running) {
        return;
    }
    // we already have the final task info
    if (isDone(getTaskInfo())) {
        stop();
        return;
    }
    // if we have an outstanding request
    if (future != null && !future.isDone()) {
        return;
    }
    // if throttled due to error, asynchronously wait for timeout and try again
    ListenableFuture<?> errorRateLimit = errorTracker.acquireRequestPermit();
    if (!errorRateLimit.isDone()) {
        errorRateLimit.addListener(this::sendNextRequest, executor);
        return;
    }
    HttpUriBuilder httpUriBuilder = uriBuilderFrom(taskStatus.getSelf());
    URI uri = summarizeTaskInfo ? httpUriBuilder.addParameter("summarize").build() : httpUriBuilder.build();
    Request request = prepareGet().setUri(uri).setHeader(CONTENT_TYPE, JSON_UTF_8.toString()).build();
    errorTracker.startRequest();
    future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskInfoCodec));
    currentRequestStartNanos.set(System.nanoTime());
    Futures.addCallback(future, new SimpleHttpResponseHandler<>(this, request.getUri(), stats), executor);
}
Also used : HttpUriBuilder(io.airlift.http.client.HttpUriBuilder) Request(io.airlift.http.client.Request) TaskStatus(com.facebook.presto.execution.TaskStatus) URI(java.net.URI)

Example 18 with Request

use of io.airlift.http.client.Request in project presto by prestodb.

the class BenchmarkQueryRunner method getAllNodes.

private List<URI> getAllNodes(URI server) {
    Request request = prepareGet().setUri(uriBuilderFrom(server).replacePath("/v1/service/presto").build()).build();
    JsonResponseHandler<ServiceDescriptorsRepresentation> responseHandler = createJsonResponseHandler(jsonCodec(ServiceDescriptorsRepresentation.class));
    ServiceDescriptorsRepresentation serviceDescriptors = httpClient.execute(request, responseHandler);
    ImmutableList.Builder<URI> addresses = ImmutableList.builder();
    for (ServiceDescriptor serviceDescriptor : serviceDescriptors.getServiceDescriptors()) {
        String httpUri = serviceDescriptor.getProperties().get("http");
        if (httpUri != null) {
            addresses.add(URI.create(httpUri));
        }
    }
    return addresses.build();
}
Also used : ServiceDescriptorsRepresentation(io.airlift.discovery.client.ServiceDescriptorsRepresentation) ServiceDescriptor(io.airlift.discovery.client.ServiceDescriptor) ImmutableList(com.google.common.collect.ImmutableList) Request(io.airlift.http.client.Request) URI(java.net.URI)

Example 19 with Request

use of io.airlift.http.client.Request in project presto by prestodb.

the class TestServer method testInvalidSessionError.

@Test
public void testInvalidSessionError() throws Exception {
    String invalidTimeZone = "this_is_an_invalid_time_zone";
    Request request = preparePost().setHeader(PRESTO_USER, "user").setUri(uriFor("/v1/statement")).setBodyGenerator(createStaticBodyGenerator("show catalogs", UTF_8)).setHeader(PRESTO_SOURCE, "source").setHeader(PRESTO_CATALOG, "catalog").setHeader(PRESTO_SCHEMA, "schema").setHeader(PRESTO_TIME_ZONE, invalidTimeZone).build();
    QueryResults queryResults = client.execute(request, createJsonResponseHandler(jsonCodec(QueryResults.class)));
    QueryError queryError = queryResults.getError();
    assertNotNull(queryError);
    TimeZoneNotSupportedException expected = new TimeZoneNotSupportedException(invalidTimeZone);
    assertEquals(queryError.getErrorCode(), expected.getErrorCode().getCode());
    assertEquals(queryError.getErrorName(), expected.getErrorCode().getName());
    assertEquals(queryError.getErrorType(), expected.getErrorCode().getType().name());
    assertEquals(queryError.getMessage(), expected.getMessage());
}
Also used : Request(io.airlift.http.client.Request) QueryError(com.facebook.presto.client.QueryError) TimeZoneNotSupportedException(com.facebook.presto.spi.type.TimeZoneNotSupportedException) QueryResults(com.facebook.presto.client.QueryResults) Test(org.testng.annotations.Test)

Example 20 with Request

use of io.airlift.http.client.Request in project airpal by airbnb.

the class QueryInfoClient method from.

public BasicQueryInfo from(URI infoUri) {
    infoUri = checkNotNull(infoUri, "infoUri is null");
    Request request = prepareGet().setHeader(USER_AGENT, USER_AGENT_VALUE).setHeader(ACCEPT, MediaType.JSON_UTF_8.toString()).setUri(infoUri).build();
    Exception cause = null;
    long start = System.nanoTime();
    long attempts = 0;
    FullJsonResponseHandler.JsonResponse<BasicQueryInfo> response;
    try {
        response = httpClient.execute(request, queryInfoHandler);
        if (response.getStatusCode() == HttpStatus.OK.code() && response.hasValue()) {
            return response.getValue();
        }
    } catch (RuntimeException e) {
        log.error("Caught error in QueryInfoClient load", e);
    }
    return null;
}
Also used : FullJsonResponseHandler.createFullJsonResponseHandler(io.airlift.http.client.FullJsonResponseHandler.createFullJsonResponseHandler) FullJsonResponseHandler(io.airlift.http.client.FullJsonResponseHandler) Request(io.airlift.http.client.Request)

Aggregations

Request (io.airlift.http.client.Request)20 URI (java.net.URI)8 HttpUriBuilder (io.airlift.http.client.HttpUriBuilder)5 Test (org.testng.annotations.Test)5 QueryResults (com.facebook.presto.client.QueryResults)4 TaskStatus (com.facebook.presto.execution.TaskStatus)4 TaskUpdateRequest (com.facebook.presto.server.TaskUpdateRequest)4 ImmutableList (com.google.common.collect.ImmutableList)3 JsonResponse (io.airlift.http.client.FullJsonResponseHandler.JsonResponse)3 Duration (io.airlift.units.Duration)3 List (java.util.List)3 SetThreadName (io.airlift.concurrent.SetThreadName)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 PRESTO_PAGES (com.facebook.presto.PrestoMediaTypes.PRESTO_PAGES)1 TaskSource (com.facebook.presto.TaskSource)1 QueryError (com.facebook.presto.client.QueryError)1 QueryInfo (com.facebook.presto.execution.QueryInfo)1 PagesSerde (com.facebook.presto.execution.buffer.PagesSerde)1 SerializedPage (com.facebook.presto.execution.buffer.SerializedPage)1