Search in sources :

Example 1 with Request

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

the class QueryExecutor method getServerInfo.

public ServerInfo getServerInfo(URI server) {
    URI uri = uriBuilderFrom(server).replacePath("/v1/info").build();
    Request request = prepareGet().setUri(uri).build();
    return httpClient.execute(request, createJsonResponseHandler(serverInfoCodec));
}
Also used : Request(io.airlift.http.client.Request) URI(java.net.URI)

Example 2 with Request

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

the class HttpQueryStatsClient method getQueryStats.

@Override
public Optional<QueryStats> getQueryStats(String queryId) {
    URI uri = uriBuilderFrom(baseUri).appendPath("/v1/query").appendPath(queryId).build();
    Request request = prepareGet().setUri(uri).build();
    return httpClient.execute(request, new GetQueryStatsResponseHandler());
}
Also used : Request(io.airlift.http.client.Request) URI(java.net.URI)

Example 3 with Request

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

the class RemoteNodeMemory method asyncRefresh.

public void asyncRefresh(MemoryPoolAssignmentsRequest assignments) {
    Duration sinceUpdate = nanosSince(lastUpdateNanos.get());
    if (nanosSince(lastWarningLogged.get()).toMillis() > 1_000 && sinceUpdate.toMillis() > 10_000 && future.get() != null) {
        log.warn("Memory info update request to %s has not returned in %s", memoryInfoUri, sinceUpdate.toString(SECONDS));
        lastWarningLogged.set(System.nanoTime());
    }
    if (sinceUpdate.toMillis() > 1_000 && future.get() == null) {
        Request request = preparePost().setUri(memoryInfoUri).setHeader(CONTENT_TYPE, JSON_UTF_8.toString()).setBodyGenerator(jsonBodyGenerator(assignmentsRequestJsonCodec, assignments)).build();
        HttpResponseFuture<JsonResponse<MemoryInfo>> responseFuture = httpClient.executeAsync(request, createFullJsonResponseHandler(memoryInfoCodec));
        future.compareAndSet(null, responseFuture);
        Futures.addCallback(responseFuture, new FutureCallback<JsonResponse<MemoryInfo>>() {

            @Override
            public void onSuccess(@Nullable JsonResponse<MemoryInfo> result) {
                lastUpdateNanos.set(System.nanoTime());
                future.compareAndSet(responseFuture, null);
                long version = currentAssignmentVersion.get();
                if (result != null) {
                    if (result.hasValue()) {
                        memoryInfo.set(ofNullable(result.getValue()));
                    }
                    if (result.getStatusCode() != OK.code()) {
                        log.warn("Error fetching memory info from %s returned status %d: %s", memoryInfoUri, result.getStatusCode(), result.getStatusMessage());
                        return;
                    }
                }
                currentAssignmentVersion.compareAndSet(version, assignments.getVersion());
            }

            @Override
            public void onFailure(Throwable t) {
                log.warn("Error fetching memory info from %s: %s", memoryInfoUri, t.getMessage());
                lastUpdateNanos.set(System.nanoTime());
                future.compareAndSet(responseFuture, null);
            }
        });
    }
}
Also used : Request(io.airlift.http.client.Request) Duration(io.airlift.units.Duration) JsonResponse(io.airlift.http.client.FullJsonResponseHandler.JsonResponse)

Example 4 with Request

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

the class RemoteNodeState method asyncRefresh.

public synchronized void asyncRefresh() {
    Duration sinceUpdate = nanosSince(lastUpdateNanos.get());
    if (nanosSince(lastWarningLogged.get()).toMillis() > 1_000 && sinceUpdate.toMillis() > 10_000 && future.get() != null) {
        log.warn("Node state update request to %s has not returned in %s", stateInfoUri, sinceUpdate.toString(SECONDS));
        lastWarningLogged.set(System.nanoTime());
    }
    if (sinceUpdate.toMillis() > 1_000 && future.get() == null) {
        Request request = prepareGet().setUri(stateInfoUri).setHeader(CONTENT_TYPE, JSON_UTF_8.toString()).build();
        HttpResponseFuture<JsonResponse<NodeState>> responseFuture = httpClient.executeAsync(request, createFullJsonResponseHandler(jsonCodec(NodeState.class)));
        future.compareAndSet(null, responseFuture);
        Futures.addCallback(responseFuture, new FutureCallback<JsonResponse<NodeState>>() {

            @Override
            public void onSuccess(@Nullable JsonResponse<NodeState> result) {
                lastUpdateNanos.set(System.nanoTime());
                future.compareAndSet(responseFuture, null);
                if (result != null) {
                    if (result.hasValue()) {
                        nodeState.set(ofNullable(result.getValue()));
                    }
                    if (result.getStatusCode() != OK.code()) {
                        log.warn("Error fetching node state from %s returned status %d: %s", stateInfoUri, result.getStatusCode(), result.getStatusMessage());
                        return;
                    }
                }
            }

            @Override
            public void onFailure(Throwable t) {
                log.warn("Error fetching node state from %s: %s", stateInfoUri, t.getMessage());
                lastUpdateNanos.set(System.nanoTime());
                future.compareAndSet(responseFuture, null);
            }
        });
    }
}
Also used : NodeState(com.facebook.presto.spi.NodeState) Request(io.airlift.http.client.Request) Duration(io.airlift.units.Duration) JsonResponse(io.airlift.http.client.FullJsonResponseHandler.JsonResponse)

Example 5 with Request

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

the class HttpRemoteTask method sendUpdate.

private synchronized void sendUpdate() {
    TaskStatus taskStatus = getTaskStatus();
    // don't update if the task hasn't been started yet or if it is already finished
    if (!needsUpdate.get() || taskStatus.getState().isDone()) {
        return;
    }
    // if we have an old request outstanding, cancel it
    if (currentRequest != null && Duration.nanosSince(currentRequestStartNanos).compareTo(requestTimeout) >= 0) {
        needsUpdate.set(true);
        currentRequest.cancel(true);
        currentRequest = null;
        currentRequestStartNanos = 0;
    }
    // if there is a request already running, wait for it to complete
    if (this.currentRequest != null && !this.currentRequest.isDone()) {
        return;
    }
    // if throttled due to error, asynchronously wait for timeout and try again
    ListenableFuture<?> errorRateLimit = updateErrorTracker.acquireRequestPermit();
    if (!errorRateLimit.isDone()) {
        errorRateLimit.addListener(this::sendUpdate, executor);
        return;
    }
    List<TaskSource> sources = getSources();
    Optional<PlanFragment> fragment = Optional.empty();
    if (sendPlan.get()) {
        fragment = Optional.of(planFragment);
    }
    TaskUpdateRequest updateRequest = new TaskUpdateRequest(session.toSessionRepresentation(), fragment, sources, outputBuffers.get());
    HttpUriBuilder uriBuilder = getHttpUriBuilder(taskStatus);
    Request request = preparePost().setUri(uriBuilder.build()).setHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString()).setBodyGenerator(jsonBodyGenerator(taskUpdateRequestCodec, updateRequest)).build();
    updateErrorTracker.startRequest();
    ListenableFuture<JsonResponse<TaskInfo>> future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskInfoCodec));
    currentRequest = future;
    currentRequestStartNanos = System.nanoTime();
    // The needsUpdate flag needs to be set to false BEFORE adding the Future callback since callback might change the flag value
    // and does so without grabbing the instance lock.
    needsUpdate.set(false);
    Futures.addCallback(future, new SimpleHttpResponseHandler<>(new UpdateResponseHandler(sources), request.getUri(), stats), executor);
}
Also used : TaskUpdateRequest(com.facebook.presto.server.TaskUpdateRequest) Request(io.airlift.http.client.Request) TaskUpdateRequest(com.facebook.presto.server.TaskUpdateRequest) TaskStatus(com.facebook.presto.execution.TaskStatus) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) JsonResponse(io.airlift.http.client.FullJsonResponseHandler.JsonResponse) HttpUriBuilder(io.airlift.http.client.HttpUriBuilder) TaskSource(com.facebook.presto.TaskSource)

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