use of com.facebook.airlift.http.client.Request in project presto by prestodb.
the class WorkerResource method proxyJsonResponse.
private Response proxyJsonResponse(String nodeId, String workerPath) {
Set<InternalNode> nodes = nodeManager.getNodes(NodeState.ACTIVE);
InternalNode node = nodes.stream().filter(n -> n.getNodeIdentifier().equals(nodeId)).findFirst().orElseThrow(() -> new WebApplicationException(NOT_FOUND));
Request request = prepareGet().setUri(uriBuilderFrom(node.getInternalUri()).appendPath(workerPath).build()).build();
InputStream responseStream = httpClient.execute(request, new StreamingJsonResponseHandler());
return Response.ok(responseStream, APPLICATION_JSON_TYPE).build();
}
use of com.facebook.airlift.http.client.Request in project presto by prestodb.
the class TestServer method testTransactionSupport.
@Test
public void testTransactionSupport() {
Request request = preparePost().setUri(uriFor("/v1/statement")).setBodyGenerator(createStaticBodyGenerator("start transaction", UTF_8)).setHeader(PRESTO_USER, "user").setHeader(PRESTO_SOURCE, "source").setHeader(PRESTO_TRANSACTION_ID, "none").build();
JsonResponse<QueryResults> queryResults = client.execute(request, createFullJsonResponseHandler(QUERY_RESULTS_CODEC));
ImmutableList.Builder<List<Object>> data = ImmutableList.builder();
while (true) {
if (queryResults.getValue().getData() != null) {
data.addAll(queryResults.getValue().getData());
}
if (queryResults.getValue().getNextUri() == null) {
break;
}
queryResults = client.execute(prepareGet().setUri(queryResults.getValue().getNextUri()).build(), createFullJsonResponseHandler(QUERY_RESULTS_CODEC));
}
assertNull(queryResults.getValue().getError());
assertNotNull(queryResults.getHeader(PRESTO_STARTED_TRANSACTION_ID));
}
use of com.facebook.airlift.http.client.Request in project presto by prestodb.
the class TestServer method testNoTransactionSupport.
@Test
public void testNoTransactionSupport() {
Request request = preparePost().setUri(uriFor("/v1/statement")).setBodyGenerator(createStaticBodyGenerator("start transaction", UTF_8)).setHeader(PRESTO_USER, "user").setHeader(PRESTO_SOURCE, "source").build();
QueryResults queryResults = client.execute(request, createJsonResponseHandler(QUERY_RESULTS_CODEC));
while (queryResults.getNextUri() != null) {
queryResults = client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_CODEC));
}
assertNotNull(queryResults.getError());
assertEquals(queryResults.getError().getErrorCode(), INCOMPATIBLE_CLIENT.toErrorCode().getCode());
}
use of com.facebook.airlift.http.client.Request in project presto by prestodb.
the class TestServer method testQuery.
@Test
public void testQuery() {
// start query
Request request = preparePost().setUri(uriFor("/v1/statement")).setBodyGenerator(createStaticBodyGenerator("show catalogs", UTF_8)).setHeader(PRESTO_USER, "user").setHeader(PRESTO_SOURCE, "source").setHeader(PRESTO_CATALOG, "catalog").setHeader(PRESTO_SCHEMA, "schema").setHeader(PRESTO_CLIENT_INFO, "{\"clientVersion\":\"testVersion\"}").addHeader(PRESTO_SESSION, QUERY_MAX_MEMORY + "=1GB").addHeader(PRESTO_SESSION, JOIN_DISTRIBUTION_TYPE + "=partitioned," + HASH_PARTITION_COUNT + " = 43").addHeader(PRESTO_PREPARED_STATEMENT, "foo=select * from bar").addHeader(PRESTO_SESSION_FUNCTION, format("%s=%s", urlEncode(SERIALIZED_SQL_FUNCTION_ID_ADD), urlEncode(SERIALIZED_SQL_FUNCTION_ADD))).build();
QueryResults queryResults = client.execute(request, createJsonResponseHandler(QUERY_RESULTS_CODEC));
ImmutableList.Builder<List<Object>> data = ImmutableList.builder();
while (queryResults.getNextUri() != null) {
queryResults = client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_CODEC));
if (queryResults.getData() != null) {
data.addAll(queryResults.getData());
}
}
assertNull(queryResults.getError());
// get the query info
BasicQueryInfo queryInfo = server.getQueryManager().getQueryInfo(new QueryId(queryResults.getId()));
// verify session properties
assertEquals(queryInfo.getSession().getSystemProperties(), ImmutableMap.builder().put(QUERY_MAX_MEMORY, "1GB").put(JOIN_DISTRIBUTION_TYPE, "partitioned").put(HASH_PARTITION_COUNT, "43").build());
// verify client info in session
assertEquals(queryInfo.getSession().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
// verify prepared statements
assertEquals(queryInfo.getSession().getPreparedStatements(), ImmutableMap.builder().put("foo", "select * from bar").build());
// verify session functions
assertEquals(queryInfo.getSession().getSessionFunctions(), ImmutableMap.of(SQL_FUNCTION_ID_ADD, SQL_FUNCTION_ADD));
// only the system catalog exists by default
List<List<Object>> rows = data.build();
assertEquals(rows, ImmutableList.of(ImmutableList.of("system")));
}
use of com.facebook.airlift.http.client.Request in project presto by prestodb.
the class ResourceManagerProxy method performRequest.
public void performRequest(HttpServletRequest servletRequest, AsyncResponse asyncResponse, URI remoteUri) {
try {
BodyGenerator bodyGenerator = new InputStreamBodyGenerator(servletRequest.getInputStream());
Request request = createRequest(servletRequest, servletRequest.getMethod(), remoteUri, bodyGenerator);
ListenableFuture<ProxyResponse> proxyResponse = httpClient.executeAsync(request, new ResponseHandler());
ListenableFuture<Response> future = transform(proxyResponse, this::toResponse, executor);
setupAsyncResponse(servletRequest, asyncResponse, future);
} catch (IOException e) {
asyncResponse.resume(e);
}
}
Aggregations