use of com.facebook.airlift.http.client.Request in project presto by prestodb.
the class TestTaskInfoResource method testGetTaskInfo.
@Test
public void testGetTaskInfo() {
String sql = "SELECT * FROM tpch.sf1.customer WHERE tpch.sf1.customer.nationkey = 1";
ResultWithQueryId<MaterializedResult> result = queryRunner.executeWithQueryId(queryRunner.getDefaultSession(), sql);
QueryId queryId = result.getQueryId();
Optional<StageInfo> stageInfo = server.getQueryManager().getFullQueryInfo(queryId).getOutputStage();
if (stageInfo.isPresent()) {
Stream<TaskInfo> latestTaskInfo = stageInfo.get().getAllStages().stream().flatMap(stage -> stage.getLatestAttemptExecutionInfo().getTasks().stream());
Iterable<TaskInfo> iterableTaskInfo = latestTaskInfo::iterator;
for (TaskInfo taskInfo : iterableTaskInfo) {
URI taskURI = taskUri("v1/taskInfo/", taskInfo.getTaskId().toString());
Request taskInfoRequest = prepareGet().setUri(taskURI).build();
TaskInfo responseTaskInfo = client.execute(taskInfoRequest, createJsonResponseHandler(jsonCodec(TaskInfo.class)));
compareTasks(taskInfo, responseTaskInfo);
}
} else {
fail("StageInfo not present");
}
}
use of com.facebook.airlift.http.client.Request in project presto by prestodb.
the class TestTaskInfoResource method testInvalidQueryId.
@Test
public void testInvalidQueryId() {
String invalidTaskId = queryIdGenerator.createNextQueryId().toString() + ".0.0.0";
URI invalidTaskURI = taskUri("v1/taskInfo/", invalidTaskId);
Request taskInfoRequest = prepareGet().setUri(invalidTaskURI).build();
StringResponseHandler.StringResponse stringResponse = client.execute(taskInfoRequest, createStringResponseHandler());
assertEquals(stringResponse.getStatusCode(), 404);
}
use of com.facebook.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 = setContentTypeHeaders(isBinaryTransportEnabled, preparePost()).setUri(memoryInfoUri).setBodyGenerator(createBodyGenerator(assignments)).build();
ResponseHandler responseHandler;
if (isBinaryTransportEnabled) {
responseHandler = createFullSmileResponseHandler((SmileCodec<MemoryInfo>) memoryInfoCodec);
} else {
responseHandler = createAdaptingJsonResponseHandler((JsonCodec<MemoryInfo>) memoryInfoCodec);
}
HttpResponseFuture<BaseResponse<MemoryInfo>> responseFuture = httpClient.executeAsync(request, responseHandler);
future.compareAndSet(null, responseFuture);
Futures.addCallback(responseFuture, new FutureCallback<BaseResponse<MemoryInfo>>() {
@Override
public void onSuccess(@Nullable BaseResponse<MemoryInfo> result) {
lastUpdateNanos.set(System.nanoTime());
future.compareAndSet(responseFuture, null);
long version = currentAssignmentVersion.get();
if (result != null) {
if (result.hasValue()) {
memoryInfo.set(Optional.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);
}
}, directExecutor());
}
}
use of com.facebook.airlift.http.client.Request in project presto by prestodb.
the class TestExchangeClient method testInitialRequestLimit.
@Test
public void testInitialRequestLimit() {
DataSize bufferCapacity = new DataSize(16, MEGABYTE);
DataSize maxResponseSize = new DataSize(DEFAULT_MAX_PAGE_SIZE_IN_BYTES, BYTE);
CountDownLatch countDownLatch = new CountDownLatch(1);
MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(maxResponseSize) {
@Override
public Response handle(Request request) {
if (!awaitUninterruptibly(countDownLatch, 10, SECONDS)) {
throw new UncheckedTimeoutException();
}
return super.handle(request);
}
};
List<URI> locations = new ArrayList<>();
int numLocations = 16;
List<DataSize> expectedMaxSizes = new ArrayList<>();
// add pages
for (int i = 0; i < numLocations; i++) {
URI location = URI.create("http://localhost:" + (8080 + i));
locations.add(location);
processor.addPage(location, createPage(DEFAULT_MAX_PAGE_SIZE_IN_BYTES));
processor.addPage(location, createPage(DEFAULT_MAX_PAGE_SIZE_IN_BYTES));
processor.addPage(location, createPage(DEFAULT_MAX_PAGE_SIZE_IN_BYTES));
processor.setComplete(location);
expectedMaxSizes.add(maxResponseSize);
}
try (ExchangeClient exchangeClient = createExchangeClient(processor, bufferCapacity, maxResponseSize)) {
for (int i = 0; i < numLocations; i++) {
exchangeClient.addLocation(locations.get(i), TaskId.valueOf("taskid.0.0." + i));
}
exchangeClient.noMoreLocations();
assertFalse(exchangeClient.isClosed());
long start = System.nanoTime();
countDownLatch.countDown();
// wait for a page to be fetched
do {
// there is no thread coordination here, so sleep is the best we can do
assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
sleepUninterruptibly(100, MILLISECONDS);
} while (exchangeClient.getStatus().getBufferedPages() < 16);
// Client should have sent 16 requests for a single page (0) and gotten them back
// The memory limit should be hit immediately and then it doesn't fetch the third page from each
assertEquals(exchangeClient.getStatus().getBufferedPages(), 16);
assertTrue(exchangeClient.getStatus().getBufferedBytes() > 0);
List<PageBufferClientStatus> pageBufferClientStatuses = exchangeClient.getStatus().getPageBufferClientStatuses();
assertEquals(16, pageBufferClientStatuses.stream().filter(status -> status.getPagesReceived() == 1).mapToInt(PageBufferClientStatus::getPagesReceived).sum());
assertEquals(processor.getRequestMaxSizes(), expectedMaxSizes);
for (int i = 0; i < numLocations * 3; i++) {
assertNotNull(getNextPage(exchangeClient));
}
do {
// there is no thread coordination here, so sleep is the best we can do
assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
sleepUninterruptibly(100, MILLISECONDS);
} while (processor.getRequestMaxSizes().size() < 64);
for (int i = 0; i < 48; i++) {
expectedMaxSizes.add(maxResponseSize);
}
assertEquals(processor.getRequestMaxSizes(), expectedMaxSizes);
}
}
use of com.facebook.airlift.http.client.Request in project presto by prestodb.
the class PinotClusterInfoFetcher method doHttpActionWithHeaders.
public String doHttpActionWithHeaders(Request.Builder requestBuilder, Optional<String> requestBody, Optional<String> rpcService) {
requestBuilder = requestBuilder.setHeader(HttpHeaders.ACCEPT, APPLICATION_JSON);
if (requestBody.isPresent()) {
requestBuilder.setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON);
}
if (rpcService.isPresent()) {
requestBuilder.setHeader(pinotConfig.getCallerHeaderParam(), pinotConfig.getCallerHeaderValue()).setHeader(pinotConfig.getServiceHeaderParam(), rpcService.get());
}
if (requestBody.isPresent()) {
requestBuilder.setBodyGenerator(StaticBodyGenerator.createStaticBodyGenerator(requestBody.get(), StandardCharsets.UTF_8));
}
pinotConfig.getExtraHttpHeaders().forEach(requestBuilder::setHeader);
Request request = requestBuilder.build();
long startTime = ticker.read();
long duration;
StringResponseHandler.StringResponse response;
try {
response = httpClient.execute(request, createStringResponseHandler());
} finally {
duration = ticker.read() - startTime;
}
pinotMetrics.monitorRequest(request, response, duration, TimeUnit.NANOSECONDS);
String responseBody = response.getBody();
if (PinotUtils.isValidPinotHttpResponseCode(response.getStatusCode())) {
return responseBody;
} else {
throw new PinotException(PINOT_HTTP_ERROR, Optional.empty(), String.format("Unexpected response status: %d for request %s to url %s, with headers %s, full response %s", response.getStatusCode(), requestBody.orElse(""), request.getUri(), request.getHeaders(), responseBody));
}
}
Aggregations