Search in sources :

Example 6 with StringFullResponseHolder

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

the class HttpIndexingServiceClientTest method testGetTotalWorkerCapacityWithAutoScale.

@Test
public void testGetTotalWorkerCapacityWithAutoScale() throws Exception {
    int currentClusterCapacity = 5;
    int maximumCapacityWithAutoScale = 10;
    // Mock response for /druid/indexer/v1/totalWorkerCapacity
    HttpResponse totalWorkerCapacityResponse = EasyMock.createMock(HttpResponse.class);
    EasyMock.expect(totalWorkerCapacityResponse.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
    EasyMock.expect(totalWorkerCapacityResponse.getContent()).andReturn(new BigEndianHeapChannelBuffer(0));
    EasyMock.replay(totalWorkerCapacityResponse);
    IndexingTotalWorkerCapacityInfo indexingTotalWorkerCapacityInfo = new IndexingTotalWorkerCapacityInfo(currentClusterCapacity, maximumCapacityWithAutoScale);
    StringFullResponseHolder autoScaleResponseHolder = new StringFullResponseHolder(totalWorkerCapacityResponse, StandardCharsets.UTF_8).addChunk(jsonMapper.writeValueAsString(indexingTotalWorkerCapacityInfo));
    EasyMock.expect(druidLeaderClient.go(EasyMock.anyObject(Request.class))).andReturn(autoScaleResponseHolder).once();
    EasyMock.expect(druidLeaderClient.makeRequest(HttpMethod.GET, "/druid/indexer/v1/totalWorkerCapacity")).andReturn(new Request(HttpMethod.GET, new URL("http://localhost:8090/druid/indexer/v1/totalWorkerCapacity"))).once();
    EasyMock.replay(druidLeaderClient);
    final int actualResponse = httpIndexingServiceClient.getTotalWorkerCapacityWithAutoScale();
    Assert.assertEquals(maximumCapacityWithAutoScale, actualResponse);
    EasyMock.verify(druidLeaderClient);
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) Request(org.apache.druid.java.util.http.client.Request) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer) URL(java.net.URL) Test(org.junit.Test)

Example 7 with StringFullResponseHolder

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

the class HttpIndexingServiceClientTest method testCompact.

@Test
public void testCompact() throws Exception {
    DataSegment segment = new DataSegment("test", Intervals.of("2015-04-12/2015-04-13"), "1", ImmutableMap.of("bucket", "bucket", "path", "test/2015-04-12T00:00:00.000Z_2015-04-13T00:00:00.000Z/1/0/index.zip"), null, null, NoneShardSpec.instance(), 0, 1);
    Capture captureTask = EasyMock.newCapture();
    HttpResponse response = EasyMock.createMock(HttpResponse.class);
    EasyMock.expect(response.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
    EasyMock.expect(response.getContent()).andReturn(new BigEndianHeapChannelBuffer(0));
    EasyMock.replay(response);
    StringFullResponseHolder responseHolder = new StringFullResponseHolder(response, StandardCharsets.UTF_8).addChunk(jsonMapper.writeValueAsString(ImmutableMap.of("task", "aaa")));
    EasyMock.expect(druidLeaderClient.makeRequest(HttpMethod.POST, "/druid/indexer/v1/task")).andReturn(new Request(HttpMethod.POST, new URL("http://localhost:8090/druid/indexer/v1/task"))).anyTimes();
    EasyMock.expect(druidLeaderClient.go(EasyMock.anyObject(Request.class))).andReturn(responseHolder).anyTimes();
    EasyMock.expect(mockMapper.writeValueAsBytes(EasyMock.capture(captureTask))).andReturn(new byte[] { 1, 2, 3 }).anyTimes();
    EasyMock.expect(mockMapper.readValue(EasyMock.anyString(), EasyMock.eq(JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT))).andReturn(ImmutableMap.of()).anyTimes();
    EasyMock.replay(druidLeaderClient, mockMapper);
    HttpIndexingServiceClient httpIndexingServiceClient = new HttpIndexingServiceClient(mockMapper, druidLeaderClient);
    try {
        httpIndexingServiceClient.compactSegments("test-compact", ImmutableList.of(segment), 50, null, null, null, null, null, null, null);
    } catch (Exception e) {
        // Ignore IllegalStateException as taskId is internally generated and returned task id will failed check
        Assert.assertEquals(IllegalStateException.class.getName(), e.getCause().getClass().getName());
    }
    ClientCompactionTaskQuery taskQuery = (ClientCompactionTaskQuery) captureTask.getValue();
    Assert.assertNull(taskQuery.getIoConfig().getInputSpec().getSha256OfSortedSegmentIds());
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) Request(org.apache.druid.java.util.http.client.Request) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer) DataSegment(org.apache.druid.timeline.DataSegment) Capture(org.easymock.Capture) URL(java.net.URL) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 8 with StringFullResponseHolder

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

the class HttpIndexingServiceClientTest method testGetTaskReportStatusNotFound.

@Test
public void testGetTaskReportStatusNotFound() throws Exception {
    String taskId = "testTaskId";
    HttpResponse response = EasyMock.createMock(HttpResponse.class);
    String errorMsg = "No task reports were found for this task. " + "The task may not exist, or it may not have completed yet.";
    ChannelBuffer buf = ChannelBuffers.buffer(errorMsg.length());
    buf.writeBytes(errorMsg.getBytes(StandardCharsets.UTF_8));
    EasyMock.expect(response.getStatus()).andReturn(HttpResponseStatus.NOT_FOUND).anyTimes();
    EasyMock.expect(response.getContent()).andReturn(buf);
    EasyMock.replay(response);
    StringFullResponseHolder responseHolder = new StringFullResponseHolder(response, StandardCharsets.UTF_8).addChunk("");
    EasyMock.expect(druidLeaderClient.go(EasyMock.anyObject(Request.class))).andReturn(responseHolder).anyTimes();
    EasyMock.expect(druidLeaderClient.makeRequest(HttpMethod.GET, "/druid/indexer/v1/task/testTaskId/reports")).andReturn(new Request(HttpMethod.GET, new URL("http://localhost:8090/druid/indexer/v1/task/testTaskId/reports"))).anyTimes();
    EasyMock.replay(druidLeaderClient);
    final Map<String, Object> actualResponse = httpIndexingServiceClient.getTaskReport(taskId);
    Assert.assertNull(actualResponse);
    EasyMock.verify(druidLeaderClient, response);
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) Request(org.apache.druid.java.util.http.client.Request) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) URL(java.net.URL) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer) Test(org.junit.Test)

Example 9 with StringFullResponseHolder

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

the class HttpIndexingServiceClient method getTotalWorkerCapacity.

@Override
public int getTotalWorkerCapacity() {
    try {
        final StringFullResponseHolder response = druidLeaderClient.go(druidLeaderClient.makeRequest(HttpMethod.GET, "/druid/indexer/v1/workers").setHeader("Content-Type", MediaType.APPLICATION_JSON));
        if (!response.getStatus().equals(HttpResponseStatus.OK)) {
            throw new ISE("Error while getting available cluster capacity. status[%s] content[%s]", response.getStatus(), response.getContent());
        }
        final Collection<IndexingWorkerInfo> workers = jsonMapper.readValue(response.getContent(), new TypeReference<Collection<IndexingWorkerInfo>>() {
        });
        return workers.stream().mapToInt(workerInfo -> workerInfo.getWorker().getCapacity()).sum();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Logger(org.apache.druid.java.util.common.logger.Logger) Iterables(com.google.common.collect.Iterables) Inject(com.google.inject.Inject) HttpMethod(org.jboss.netty.handler.codec.http.HttpMethod) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) Interval(org.joda.time.Interval) MediaType(javax.ws.rs.core.MediaType) IdUtils(org.apache.druid.common.utils.IdUtils) Map(java.util.Map) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Nullable(javax.annotation.Nullable) DateTimes(org.apache.druid.java.util.common.DateTimes) JacksonUtils(org.apache.druid.java.util.common.jackson.JacksonUtils) AggregatorFactory(org.apache.druid.query.aggregation.AggregatorFactory) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) StringUtils(org.apache.druid.java.util.common.StringUtils) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) IOException(java.io.IOException) TaskStatusPlus(org.apache.druid.indexer.TaskStatusPlus) HttpResponseStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus) List(java.util.List) DataSegment(org.apache.druid.timeline.DataSegment) Preconditions(com.google.common.base.Preconditions) StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) Collections(java.util.Collections) DruidLeaderClient(org.apache.druid.discovery.DruidLeaderClient) StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) Collection(java.util.Collection) ISE(org.apache.druid.java.util.common.ISE) IOException(java.io.IOException)

Example 10 with StringFullResponseHolder

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

the class HttpIndexingServiceClient method killPendingSegments.

@Override
public int killPendingSegments(String dataSource, DateTime end) {
    final String endPoint = StringUtils.format("/druid/indexer/v1/pendingSegments/%s?interval=%s", StringUtils.urlEncode(dataSource), new Interval(DateTimes.MIN, end));
    try {
        final StringFullResponseHolder responseHolder = druidLeaderClient.go(druidLeaderClient.makeRequest(HttpMethod.DELETE, endPoint));
        if (!responseHolder.getStatus().equals(HttpResponseStatus.OK)) {
            throw new ISE("Error while killing pendingSegments of dataSource[%s] created until [%s]", dataSource, end);
        }
        final Map<String, Object> resultMap = jsonMapper.readValue(responseHolder.getContent(), JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT);
        final Object numDeletedObject = resultMap.get("numDeleted");
        return (Integer) Preconditions.checkNotNull(numDeletedObject, "numDeletedObject");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) ISE(org.apache.druid.java.util.common.ISE) IOException(java.io.IOException) Interval(org.joda.time.Interval)

Aggregations

StringFullResponseHolder (org.apache.druid.java.util.http.client.response.StringFullResponseHolder)86 Test (org.junit.Test)56 URL (java.net.URL)50 Request (org.apache.druid.java.util.http.client.Request)49 HashMap (java.util.HashMap)32 IOException (java.io.IOException)31 BigEndianHeapChannelBuffer (org.jboss.netty.buffer.BigEndianHeapChannelBuffer)18 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)18 ISE (org.apache.druid.java.util.common.ISE)16 HttpClient (org.apache.druid.java.util.http.client.HttpClient)12 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)12 ArrayList (java.util.ArrayList)8 List (java.util.List)8 ChannelException (org.jboss.netty.channel.ChannelException)8 MalformedURLException (java.net.MalformedURLException)7 ExecutionException (java.util.concurrent.ExecutionException)7 HttpResponseStatus (org.jboss.netty.handler.codec.http.HttpResponseStatus)6 Duration (org.joda.time.Duration)6 Interval (org.joda.time.Interval)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4