Search in sources :

Example 61 with Request

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

the class KafkaIndexTaskClientTest method testPause.

@Test
public void testPause() throws Exception {
    Capture<Request> captured = Capture.newInstance();
    EasyMock.expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.OK);
    EasyMock.expect(responseHolder.getContent()).andReturn("{\"0\":1, \"1\":10}").anyTimes();
    EasyMock.expect(httpClient.go(EasyMock.capture(captured), EasyMock.anyObject(ObjectOrErrorResponseHandler.class), EasyMock.eq(TEST_HTTP_TIMEOUT))).andReturn(okResponseHolder());
    replayAll();
    Map<Integer, Long> results = client.pause(TEST_ID);
    verifyAll();
    Request request = captured.getValue();
    Assert.assertEquals(HttpMethod.POST, request.getMethod());
    Assert.assertEquals(new URL("http://test-host:1234/druid/worker/v1/chat/test-id/pause"), request.getUrl());
    Assert.assertTrue(request.getHeaders().get("X-Druid-Task-Id").contains("test-id"));
    Assert.assertEquals(2, results.size());
    Assert.assertEquals(1, (long) results.get(0));
    Assert.assertEquals(10, (long) results.get(1));
}
Also used : Request(org.apache.druid.java.util.http.client.Request) ObjectOrErrorResponseHandler(org.apache.druid.java.util.http.client.response.ObjectOrErrorResponseHandler) URL(java.net.URL) Test(org.junit.Test)

Example 62 with Request

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

the class KafkaIndexTaskClientTest method testStop.

@Test
public void testStop() throws Exception {
    Capture<Request> captured = Capture.newInstance();
    EasyMock.expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
    EasyMock.expect(httpClient.go(EasyMock.capture(captured), EasyMock.anyObject(ObjectOrErrorResponseHandler.class), EasyMock.eq(TEST_HTTP_TIMEOUT))).andReturn(okResponseHolder());
    replayAll();
    client.stop(TEST_ID, false);
    verifyAll();
    Request request = captured.getValue();
    Assert.assertEquals(HttpMethod.POST, request.getMethod());
    Assert.assertEquals(new URL("http://test-host:1234/druid/worker/v1/chat/test-id/stop"), request.getUrl());
    Assert.assertTrue(request.getHeaders().get("X-Druid-Task-Id").contains("test-id"));
}
Also used : Request(org.apache.druid.java.util.http.client.Request) ObjectOrErrorResponseHandler(org.apache.druid.java.util.http.client.response.ObjectOrErrorResponseHandler) URL(java.net.URL) Test(org.junit.Test)

Example 63 with Request

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

the class KafkaIndexTaskClientTest method testGetCurrentOffsets.

@Test
public void testGetCurrentOffsets() throws Exception {
    Capture<Request> captured = Capture.newInstance();
    EasyMock.expect(responseHolder.getContent()).andReturn("{\"0\":1, \"1\":10}");
    EasyMock.expect(httpClient.go(EasyMock.capture(captured), EasyMock.anyObject(ObjectOrErrorResponseHandler.class), EasyMock.eq(TEST_HTTP_TIMEOUT))).andReturn(okResponseHolder());
    replayAll();
    Map<Integer, Long> results = client.getCurrentOffsets(TEST_ID, true);
    verifyAll();
    Request request = captured.getValue();
    Assert.assertEquals(HttpMethod.GET, request.getMethod());
    Assert.assertEquals(new URL("http://test-host:1234/druid/worker/v1/chat/test-id/offsets/current"), request.getUrl());
    Assert.assertTrue(request.getHeaders().get("X-Druid-Task-Id").contains("test-id"));
    Assert.assertEquals(2, results.size());
    Assert.assertEquals(1, (long) results.get(0));
    Assert.assertEquals(10, (long) results.get(1));
}
Also used : Request(org.apache.druid.java.util.http.client.Request) ObjectOrErrorResponseHandler(org.apache.druid.java.util.http.client.response.ObjectOrErrorResponseHandler) URL(java.net.URL) Test(org.junit.Test)

Example 64 with Request

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

the class KafkaIndexTaskClientTest method testGetEndOffsetsAsync.

@Test
public void testGetEndOffsetsAsync() throws Exception {
    final int numRequests = TEST_IDS.size();
    Capture<Request> captured = Capture.newInstance(CaptureType.ALL);
    EasyMock.expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
    EasyMock.expect(responseHolder.getContent()).andReturn("{\"0\":\"1\"}").anyTimes();
    EasyMock.expect(httpClient.go(EasyMock.capture(captured), EasyMock.anyObject(ObjectOrErrorResponseHandler.class), EasyMock.eq(TEST_HTTP_TIMEOUT))).andReturn(okResponseHolder()).times(numRequests);
    replayAll();
    List<URL> expectedUrls = new ArrayList<>();
    List<ListenableFuture<Map<Integer, Long>>> futures = new ArrayList<>();
    for (String testId : TEST_IDS) {
        expectedUrls.add(new URL(StringUtils.format(URL_FORMATTER, TEST_HOST, TEST_PORT, testId, "offsets/end")));
        futures.add(client.getEndOffsetsAsync(testId));
    }
    List<Map<Integer, Long>> responses = Futures.allAsList(futures).get();
    verifyAll();
    List<Request> requests = captured.getValues();
    Assert.assertEquals(numRequests, requests.size());
    Assert.assertEquals(numRequests, responses.size());
    for (int i = 0; i < numRequests; i++) {
        Assert.assertEquals(HttpMethod.GET, requests.get(i).getMethod());
        Assert.assertTrue("unexpectedURL", expectedUrls.contains(requests.get(i).getUrl()));
        Assert.assertEquals(Maps.newLinkedHashMap(ImmutableMap.of(0, 1L)), responses.get(i));
    }
}
Also used : Request(org.apache.druid.java.util.http.client.Request) ArrayList(java.util.ArrayList) URL(java.net.URL) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 65 with Request

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

the class DruidKafkaUtils method updateKafkaIngestionSpec.

static void updateKafkaIngestionSpec(String overlordAddress, KafkaSupervisorSpec spec) {
    try {
        String task = JSON_MAPPER.writeValueAsString(spec);
        CONSOLE.printInfo("submitting kafka Spec {}", task);
        LOG.info("submitting kafka Supervisor Spec {}", task);
        StringFullResponseHolder response = DruidStorageHandlerUtils.getResponseFromCurrentLeader(DruidStorageHandler.getHttpClient(), new Request(HttpMethod.POST, new URL(String.format("http://%s/druid/indexer/v1/supervisor", overlordAddress))).setContent("application/json", JSON_MAPPER.writeValueAsBytes(spec)), new StringFullResponseHandler(Charset.forName("UTF-8")));
        if (response.getStatus().equals(HttpResponseStatus.OK)) {
            String msg = String.format("Kafka Supervisor for [%s] Submitted Successfully to druid.", spec.getDataSchema().getDataSource());
            LOG.info(msg);
            CONSOLE.printInfo(msg);
        } else {
            throw new IOException(String.format("Unable to update Kafka Ingestion for Druid status [%d] full response [%s]", response.getStatus().getCode(), response.getContent()));
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) StringFullResponseHandler(org.apache.druid.java.util.http.client.response.StringFullResponseHandler) Request(org.apache.druid.java.util.http.client.Request) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException)

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