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