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