use of com.facebook.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());
}
use of com.facebook.airlift.http.client.Request in project presto by prestodb.
the class DistributedQueryRunner method getCoordinatorInfoState.
private NodeState getCoordinatorInfoState(int coordinator) {
URI uri = URI.create(getCoordinator(coordinator).getBaseUrl().toString() + "/v1/info/state");
Request request = prepareGet().setHeader(PRESTO_USER, DEFAULT_USER).setUri(uri).build();
NodeState state = client.execute(request, createJsonResponseHandler(jsonCodec(NodeState.class)));
return state;
}
use of com.facebook.airlift.http.client.Request in project presto by prestodb.
the class TestPageBufferClient method testExceptionFromResponseHandler.
@Test
public void testExceptionFromResponseHandler() throws Exception {
DataSize expectedMaxSize = new DataSize(10, Unit.MEGABYTE);
TestingTicker ticker = new TestingTicker();
AtomicReference<Duration> tickerIncrement = new AtomicReference<>(new Duration(0, TimeUnit.SECONDS));
TestingHttpClient.Processor processor = (input) -> {
Duration delta = tickerIncrement.get();
ticker.increment(delta.toMillis(), TimeUnit.MILLISECONDS);
throw new RuntimeException("Foo");
};
CyclicBarrier requestComplete = new CyclicBarrier(2);
TestingClientCallback callback = new TestingClientCallback(requestComplete);
URI location = URI.create("http://localhost:8080");
PageBufferClient client = new PageBufferClient(new HttpRpcShuffleClient(new TestingHttpClient(processor, scheduler), location), new Duration(30, TimeUnit.SECONDS), true, location, Optional.empty(), callback, scheduler, ticker, pageBufferClientCallbackExecutor);
assertStatus(client, location, "queued", 0, 0, 0, 0, "not scheduled");
// request processor will throw exception, verify the request is marked a completed
// this starts the error stopwatch
client.scheduleRequest(expectedMaxSize);
requestComplete.await(10, TimeUnit.SECONDS);
assertEquals(callback.getPages().size(), 0);
assertEquals(callback.getCompletedRequests(), 1);
assertEquals(callback.getFinishedBuffers(), 0);
assertEquals(callback.getFailedBuffers(), 0);
assertStatus(client, location, "queued", 0, 1, 1, 1, "not scheduled");
// advance time forward, but not enough to fail the client
tickerIncrement.set(new Duration(30, TimeUnit.SECONDS));
// verify that the client has not failed
client.scheduleRequest(expectedMaxSize);
requestComplete.await(10, TimeUnit.SECONDS);
assertEquals(callback.getPages().size(), 0);
assertEquals(callback.getCompletedRequests(), 2);
assertEquals(callback.getFinishedBuffers(), 0);
assertEquals(callback.getFailedBuffers(), 0);
assertStatus(client, location, "queued", 0, 2, 2, 2, "not scheduled");
// advance time forward beyond the minimum error duration
tickerIncrement.set(new Duration(31, TimeUnit.SECONDS));
// verify that the client has failed
client.scheduleRequest(expectedMaxSize);
requestComplete.await(10, TimeUnit.SECONDS);
assertEquals(callback.getPages().size(), 0);
assertEquals(callback.getCompletedRequests(), 3);
assertEquals(callback.getFinishedBuffers(), 0);
assertEquals(callback.getFailedBuffers(), 1);
assertInstanceOf(callback.getFailure(), PageTransportTimeoutException.class);
assertContains(callback.getFailure().getMessage(), WORKER_NODE_ERROR + " (http://localhost:8080/0 - 3 failures, failure duration 31.00s, total failed request time 31.00s)");
assertStatus(client, location, "queued", 0, 3, 3, 3, "not scheduled");
}
use of com.facebook.airlift.http.client.Request in project presto by prestodb.
the class TaskInfoFetcher method sendMetadataUpdates.
private synchronized void sendMetadataUpdates(MetadataUpdates results) {
TaskStatus taskStatus = getTaskInfo().getTaskStatus();
// we already have the final task info
if (isDone(getTaskInfo())) {
stop();
return;
}
// outstanding request?
if (metadataUpdateFuture != null && !metadataUpdateFuture.isDone()) {
// this should never happen
return;
}
byte[] metadataUpdatesJson = metadataUpdatesCodec.toBytes(results);
Request request = setContentTypeHeaders(isBinaryTransportEnabled, preparePost()).setUri(uriBuilderFrom(taskStatus.getSelf()).appendPath("metadataresults").build()).setBodyGenerator(createStaticBodyGenerator(metadataUpdatesJson)).build();
errorTracker.startRequest();
metadataUpdateFuture = httpClient.executeAsync(request, new ResponseHandler<Response, RuntimeException>() {
@Override
public Response handleException(Request request, Exception exception) {
throw propagate(request, exception);
}
@Override
public Response handle(Request request, Response response) {
return response;
}
});
currentRequestStartNanos.set(System.nanoTime());
}
use of com.facebook.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 (!started.get() || !needsUpdate.get() || taskStatus.getState().isDone()) {
return;
}
// 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<byte[]> fragment = sendPlan.get() ? Optional.of(planFragment.toBytes(planFragmentCodec)) : Optional.empty();
Optional<TableWriteInfo> writeInfo = sendPlan.get() ? Optional.of(tableWriteInfo) : Optional.empty();
TaskUpdateRequest updateRequest = new TaskUpdateRequest(session.toSessionRepresentation(), session.getIdentity().getExtraCredentials(), fragment, sources, outputBuffers.get(), writeInfo);
byte[] taskUpdateRequestJson = taskUpdateRequestCodec.toBytes(updateRequest);
taskUpdateRequestSize.add(taskUpdateRequestJson.length);
if (taskUpdateRequestJson.length > maxTaskUpdateSizeInBytes) {
failTask(new PrestoException(EXCEEDED_TASK_UPDATE_SIZE_LIMIT, format("TaskUpdate size of %d Bytes has exceeded the limit of %d Bytes", taskUpdateRequestJson.length, maxTaskUpdateSizeInBytes)));
}
if (fragment.isPresent()) {
stats.updateWithPlanSize(taskUpdateRequestJson.length);
} else {
if (ThreadLocalRandom.current().nextDouble() < UPDATE_WITHOUT_PLAN_STATS_SAMPLE_RATE) {
// This is to keep track of the task update size even when the plan fragment is NOT present
stats.updateWithoutPlanSize(taskUpdateRequestJson.length);
}
}
HttpUriBuilder uriBuilder = getHttpUriBuilder(taskStatus);
Request request = setContentTypeHeaders(binaryTransportEnabled, preparePost()).setUri(uriBuilder.build()).setBodyGenerator(createStaticBodyGenerator(taskUpdateRequestJson)).build();
ResponseHandler responseHandler;
if (binaryTransportEnabled) {
responseHandler = createFullSmileResponseHandler((SmileCodec<TaskInfo>) taskInfoCodec);
} else {
responseHandler = createAdaptingJsonResponseHandler((JsonCodec<TaskInfo>) taskInfoCodec);
}
updateErrorTracker.startRequest();
ListenableFuture<BaseResponse<TaskInfo>> future = httpClient.executeAsync(request, responseHandler);
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.getHttpResponseStats(), REMOTE_TASK_ERROR), executor);
}
Aggregations