Search in sources :

Example 1 with ServerInfo

use of com.facebook.presto.client.ServerInfo in project presto by prestodb.

the class QueryExecutor method getServerInfo.

public ServerInfo getServerInfo(URI server) {
    HttpUrl url = HttpUrl.get(server);
    if (url == null) {
        throw new ClientException("Invalid server URL: " + server);
    }
    url = url.newBuilder().encodedPath("/v1/info").build();
    Request request = new Request.Builder().url(url).build();
    JsonResponse<ServerInfo> response = JsonResponse.execute(SERVER_INFO_CODEC, httpClient, request);
    if (!response.hasValue()) {
        throw new RuntimeException(format("Request to %s failed: %s [Error: %s]", server, response, response.getResponseBody()));
    }
    return response.getValue();
}
Also used : ServerInfo(com.facebook.presto.client.ServerInfo) Request(okhttp3.Request) ClientException(com.facebook.presto.client.ClientException) HttpUrl(okhttp3.HttpUrl)

Example 2 with ServerInfo

use of com.facebook.presto.client.ServerInfo in project presto by prestodb.

the class TestQueryExecutor method testGetServerInfo.

@Test
public void testGetServerInfo() throws Exception {
    ServerInfo expected = new ServerInfo(UNKNOWN, "test", true, false, Optional.of(Duration.valueOf("2m")));
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, "application/json").setBody(SERVER_INFO_CODEC.toJson(expected)));
    QueryExecutor executor = new QueryExecutor(new OkHttpClient());
    ServerInfo actual = executor.getServerInfo(server.url("/v1/info").uri());
    assertEquals(actual.getEnvironment(), "test");
    assertEquals(actual.getUptime(), Optional.of(Duration.valueOf("2m")));
    assertEquals(server.getRequestCount(), 1);
    assertEquals(server.takeRequest().getPath(), "/v1/info");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) OkHttpClient(okhttp3.OkHttpClient) ServerInfo(com.facebook.presto.client.ServerInfo) Test(org.testng.annotations.Test)

Aggregations

ServerInfo (com.facebook.presto.client.ServerInfo)2 ClientException (com.facebook.presto.client.ClientException)1 HttpUrl (okhttp3.HttpUrl)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.testng.annotations.Test)1