Search in sources :

Example 16 with Request

use of com.facebook.airlift.http.client.Request in project presto by prestodb.

the class DistributedResourceGroupInfoResource method getResourceGroupInfoFromCoordinator.

private ListenableFuture<ResourceGroupInfo> getResourceGroupInfoFromCoordinator(UriInfo uriInfo, InternalNode coordinatorNode) throws IOException {
    String scheme = uriInfo.getRequestUri().getScheme();
    URI uri = uriInfo.getRequestUriBuilder().queryParam("includeLocalInfoOnly", true).scheme(scheme).host(coordinatorNode.getHostAndPort().toInetAddress().getHostName()).port(coordinatorNode.getInternalUri().getPort()).build();
    Request request = prepareGet().setUri(uri).build();
    return httpClient.executeAsync(request, createJsonResponseHandler(jsonCodec));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(com.facebook.airlift.http.client.Request) URI(java.net.URI)

Example 17 with Request

use of com.facebook.airlift.http.client.Request in project presto by prestodb.

the class TestQueryStateInfoResource method setup.

@BeforeClass
public void setup() {
    Request request1 = preparePost().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/statement").build()).setBodyGenerator(createStaticBodyGenerator(LONG_LASTING_QUERY, UTF_8)).setHeader(PRESTO_USER, "user1").build();
    queryResults = client.execute(request1, createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
    client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
    Request request2 = preparePost().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/statement").build()).setBodyGenerator(createStaticBodyGenerator(LONG_LASTING_QUERY, UTF_8)).setHeader(PRESTO_USER, "user2").build();
    QueryResults queryResults2 = client.execute(request2, createJsonResponseHandler(jsonCodec(QueryResults.class)));
    client.execute(prepareGet().setUri(queryResults2.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
    // queries are started in the background, so they may not all be immediately visible
    while (true) {
        List<BasicQueryInfo> queryInfos = client.execute(prepareGet().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/query").build()).build(), createJsonResponseHandler(listJsonCodec(BasicQueryInfo.class)));
        if ((queryInfos.size() == 2) && queryInfos.stream().allMatch(info -> info.getState() == RUNNING)) {
            break;
        }
    }
}
Also used : JsonCodec(com.facebook.airlift.json.JsonCodec) Assert.assertEquals(com.facebook.presto.testing.assertions.Assert.assertEquals) Builder.preparePost(com.facebook.airlift.http.client.Request.Builder.preparePost) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) QueryResults(com.facebook.presto.client.QueryResults) Test(org.testng.annotations.Test) JettyHttpClient(com.facebook.airlift.http.client.jetty.JettyHttpClient) JsonCodec.listJsonCodec(com.facebook.airlift.json.JsonCodec.listJsonCodec) UnexpectedResponseException(com.facebook.airlift.http.client.UnexpectedResponseException) JsonResponseHandler.createJsonResponseHandler(com.facebook.airlift.http.client.JsonResponseHandler.createJsonResponseHandler) StaticBodyGenerator.createStaticBodyGenerator(com.facebook.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator) AfterClass(org.testng.annotations.AfterClass) TpchPlugin(com.facebook.presto.tpch.TpchPlugin) RUNNING(com.facebook.presto.execution.QueryState.RUNNING) PRESTO_USER(com.facebook.presto.client.PrestoHeaders.PRESTO_USER) UTF_8(java.nio.charset.StandardCharsets.UTF_8) BeforeClass(org.testng.annotations.BeforeClass) Assert.assertNotNull(org.testng.Assert.assertNotNull) JsonCodec.jsonCodec(com.facebook.airlift.json.JsonCodec.jsonCodec) HttpClient(com.facebook.airlift.http.client.HttpClient) Closeables.closeQuietly(com.facebook.airlift.testing.Closeables.closeQuietly) HttpUriBuilder.uriBuilderFrom(com.facebook.airlift.http.client.HttpUriBuilder.uriBuilderFrom) List(java.util.List) Request(com.facebook.airlift.http.client.Request) Assert.assertTrue(org.testng.Assert.assertTrue) Builder.prepareGet(com.facebook.airlift.http.client.Request.Builder.prepareGet) Request(com.facebook.airlift.http.client.Request) QueryResults(com.facebook.presto.client.QueryResults) BeforeClass(org.testng.annotations.BeforeClass)

Example 18 with Request

use of com.facebook.airlift.http.client.Request in project presto by prestodb.

the class HttpRpcShuffleClient method acknowledgeResultsAsync.

@Override
public void acknowledgeResultsAsync(long nextToken) {
    URI uri = uriBuilderFrom(location).appendPath(String.valueOf(nextToken)).appendPath("acknowledge").build();
    httpClient.executeAsync(prepareGet().setUri(uri).build(), new ResponseHandler<Void, RuntimeException>() {

        @Override
        public Void handleException(Request request, Exception exception) {
            log.debug(exception, "Acknowledge request failed: %s", uri);
            return null;
        }

        @Override
        public Void handle(Request request, Response response) {
            if (familyForStatusCode(response.getStatusCode()) != HttpStatus.Family.SUCCESSFUL) {
                log.debug("Unexpected acknowledge response code: %s", response.getStatusCode());
            }
            return null;
        }
    });
}
Also used : PagesResponse.createPagesResponse(com.facebook.presto.operator.PageBufferClient.PagesResponse.createPagesResponse) Response(com.facebook.airlift.http.client.Response) PagesResponse(com.facebook.presto.operator.PageBufferClient.PagesResponse) PagesResponse.createEmptyPagesResponse(com.facebook.presto.operator.PageBufferClient.PagesResponse.createEmptyPagesResponse) Request(com.facebook.airlift.http.client.Request) URI(java.net.URI) ResponseTooLargeException(com.facebook.airlift.http.client.ResponseTooLargeException) IOException(java.io.IOException)

Example 19 with Request

use of com.facebook.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();
}
Also used : ServiceDescriptorsRepresentation(com.facebook.airlift.discovery.client.ServiceDescriptorsRepresentation) ServiceDescriptor(com.facebook.airlift.discovery.client.ServiceDescriptor) ImmutableList(com.google.common.collect.ImmutableList) Request(com.facebook.airlift.http.client.Request) URI(java.net.URI)

Example 20 with Request

use of com.facebook.airlift.http.client.Request in project presto by prestodb.

the class DistributedQueryInfoResource method getQueryStateFromCoordinator.

private ListenableFuture<List<QueryStateInfo>> getQueryStateFromCoordinator(UriInfo uriInfo, InternalNode coordinatorNode) throws IOException {
    URI uri = uriInfo.getRequestUriBuilder().queryParam("includeLocalQueryOnly", true).scheme(coordinatorNode.getInternalUri().getScheme()).host(coordinatorNode.getHostAndPort().toInetAddress().getHostName()).port(coordinatorNode.getInternalUri().getPort()).build();
    Request request = prepareGet().setUri(uri).build();
    return httpClient.executeAsync(request, createJsonResponseHandler(jsonCodec));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(com.facebook.airlift.http.client.Request) URI(java.net.URI)

Aggregations

Request (com.facebook.airlift.http.client.Request)40 URI (java.net.URI)16 Test (org.testng.annotations.Test)14 QueryResults (com.facebook.presto.client.QueryResults)7 ResponseHandler (com.facebook.airlift.http.client.ResponseHandler)5 TaskStatus (com.facebook.presto.execution.TaskStatus)5 AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler (com.facebook.presto.server.smile.AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler)5 FullSmileResponseHandler.createFullSmileResponseHandler (com.facebook.presto.server.smile.FullSmileResponseHandler.createFullSmileResponseHandler)5 List (java.util.List)5 HttpUriBuilder (com.facebook.airlift.http.client.HttpUriBuilder)4 Response (com.facebook.airlift.http.client.Response)4 JsonCodec (com.facebook.airlift.json.JsonCodec)4 SimpleHttpResponseHandler (com.facebook.presto.server.SimpleHttpResponseHandler)4 TaskUpdateRequest (com.facebook.presto.server.TaskUpdateRequest)4 NodeState (com.facebook.presto.spi.NodeState)4 Duration (io.airlift.units.Duration)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 SmileCodec (com.facebook.airlift.json.smile.SmileCodec)3 BaseResponse (com.facebook.presto.server.smile.BaseResponse)3 TestingPrestoServer (com.facebook.presto.server.testing.TestingPrestoServer)3