Search in sources :

Example 26 with Request

use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.

the class WorkerTaskRunnerQueryAdpaterTest method testEnableWorker.

@Test
public void testEnableWorker() throws Exception {
    final URL workerUrl = new URL("https://worker-host2/druid/worker/v1/enable");
    final String workerResponse = "{\"worker-host2\":\"enabled\"}";
    Capture<Request> capturedRequest = getHttpClientRequestCapture(HttpResponseStatus.OK, workerResponse);
    EasyMock.replay(workerTaskRunner, taskMaster, httpClient);
    workerTaskRunnerQueryAdapter.enableWorker("worker-host2");
    Assert.assertEquals(HttpMethod.POST, capturedRequest.getValue().getMethod());
    Assert.assertEquals(workerUrl, capturedRequest.getValue().getUrl());
}
Also used : Request(org.apache.druid.java.util.http.client.Request) URL(java.net.URL) Test(org.junit.Test)

Example 27 with Request

use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.

the class AbstractQueryResourceTestClient method query.

public List<Map<String, Object>> query(String url, QueryType query) {
    try {
        String expectedResponseType = this.contentTypeHeader;
        Request request = new Request(HttpMethod.POST, new URL(url));
        request.setContent(this.contentTypeHeader, encoderDecoderMap.get(this.contentTypeHeader).encode(query));
        if (this.acceptHeader != null) {
            expectedResponseType = this.acceptHeader;
            request.addHeader(HttpHeaders.Names.ACCEPT, this.acceptHeader);
        }
        BytesFullResponseHolder response = httpClient.go(request, new BytesFullResponseHandler()).get();
        if (!response.getStatus().equals(HttpResponseStatus.OK)) {
            throw new ISE("Error while querying[%s] status[%s] content[%s]", url, response.getStatus(), new String(response.getContent(), StandardCharsets.UTF_8));
        }
        String responseType = response.getResponse().headers().get(HttpHeaders.Names.CONTENT_TYPE);
        if (!expectedResponseType.equals(responseType)) {
            throw new ISE("Content-Type[%s] in HTTP response does not match the expected[%s]", responseType, expectedResponseType);
        }
        return this.encoderDecoderMap.get(responseType).decode(response.getContent());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : BytesFullResponseHolder(org.apache.druid.java.util.http.client.response.BytesFullResponseHolder) Request(org.apache.druid.java.util.http.client.Request) ISE(org.apache.druid.java.util.common.ISE) URL(java.net.URL) IOException(java.io.IOException) BytesFullResponseHandler(org.apache.druid.java.util.http.client.response.BytesFullResponseHandler)

Example 28 with Request

use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.

the class AbstractQueryResourceTestClient method queryAsync.

public Future<StatusResponseHolder> queryAsync(String url, QueryType query) {
    try {
        Request request = new Request(HttpMethod.POST, new URL(url));
        request.setContent(MediaType.APPLICATION_JSON, encoderDecoderMap.get(MediaType.APPLICATION_JSON).encode(query));
        return httpClient.go(request, StatusResponseHandler.getInstance());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Request(org.apache.druid.java.util.http.client.Request) URL(java.net.URL) IOException(java.io.IOException)

Example 29 with Request

use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.

the class CompactionResourceTestClient method getDataSourceCompactionConfig.

public DataSourceCompactionConfig getDataSourceCompactionConfig(String dataSource) throws Exception {
    String url = StringUtils.format("%sconfig/compaction/%s", getCoordinatorURL(), StringUtils.urlEncode(dataSource));
    StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(url)), responseHandler).get();
    if (!response.getStatus().equals(HttpResponseStatus.OK)) {
        throw new ISE("Error while getting compaction config status[%s] content[%s]", response.getStatus(), response.getContent());
    }
    return jsonMapper.readValue(response.getContent(), new TypeReference<DataSourceCompactionConfig>() {
    });
}
Also used : DataSourceCompactionConfig(org.apache.druid.server.coordinator.DataSourceCompactionConfig) Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ISE(org.apache.druid.java.util.common.ISE) URL(java.net.URL)

Example 30 with Request

use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.

the class CompactionResourceTestClient method deleteCompactionConfig.

public void deleteCompactionConfig(final String dataSource) throws Exception {
    String url = StringUtils.format("%sconfig/compaction/%s", getCoordinatorURL(), StringUtils.urlEncode(dataSource));
    StatusResponseHolder response = httpClient.go(new Request(HttpMethod.DELETE, new URL(url)), responseHandler).get();
    if (!response.getStatus().equals(HttpResponseStatus.OK)) {
        throw new ISE("Error while deleting compaction config status[%s] content[%s]", response.getStatus(), response.getContent());
    }
}
Also used : Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ISE(org.apache.druid.java.util.common.ISE) URL(java.net.URL)

Aggregations

Request (org.apache.druid.java.util.http.client.Request)148 URL (java.net.URL)129 Test (org.junit.Test)84 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)42 ISE (org.apache.druid.java.util.common.ISE)29 StringFullResponseHolder (org.apache.druid.java.util.http.client.response.StringFullResponseHolder)28 ObjectOrErrorResponseHandler (org.apache.druid.java.util.http.client.response.ObjectOrErrorResponseHandler)24 IOException (java.io.IOException)23 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)22 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)14 Map (java.util.Map)14 ExecutionException (java.util.concurrent.ExecutionException)14 InputStream (java.io.InputStream)12 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)11 RE (org.apache.druid.java.util.common.RE)10 InputStreamResponseHandler (org.apache.druid.java.util.http.client.response.InputStreamResponseHandler)10 BigEndianHeapChannelBuffer (org.jboss.netty.buffer.BigEndianHeapChannelBuffer)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 HttpResponseHandler (org.apache.druid.java.util.http.client.response.HttpResponseHandler)8