Search in sources :

Example 21 with StringFullResponseHolder

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

the class HttpIndexingServiceClient method getTotalWorkerCapacityWithAutoScale.

@Override
public int getTotalWorkerCapacityWithAutoScale() {
    try {
        final StringFullResponseHolder response = druidLeaderClient.go(druidLeaderClient.makeRequest(HttpMethod.GET, "/druid/indexer/v1/totalWorkerCapacity").setHeader("Content-Type", MediaType.APPLICATION_JSON));
        if (!response.getStatus().equals(HttpResponseStatus.OK)) {
            throw new ISE("Error while getting total worker capacity. status[%s] content[%s]", response.getStatus(), response.getContent());
        }
        final IndexingTotalWorkerCapacityInfo indexingTotalWorkerCapacityInfo = jsonMapper.readValue(response.getContent(), new TypeReference<IndexingTotalWorkerCapacityInfo>() {
        });
        return indexingTotalWorkerCapacityInfo.getMaximumCapacityWithAutoScale();
    } 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)

Example 22 with StringFullResponseHolder

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

the class DruidLeaderClient method findCurrentLeader.

public String findCurrentLeader() {
    Preconditions.checkState(lifecycleLock.awaitStarted(1, TimeUnit.MILLISECONDS));
    final StringFullResponseHolder responseHolder;
    try {
        responseHolder = go(makeRequest(HttpMethod.GET, leaderRequestPath));
    } catch (Exception ex) {
        throw new ISE(ex, "Couldn't find leader.");
    }
    if (responseHolder.getStatus().getCode() == 200) {
        String leaderUrl = responseHolder.getContent();
        // verify this is valid url
        try {
            URL validatedUrl = new URL(leaderUrl);
            currentKnownLeader.set(leaderUrl);
            // the rule of ignoring new URL(leaderUrl) object.
            return validatedUrl.toString();
        } catch (MalformedURLException ex) {
            log.error(ex, "Received malformed leader url[%s].", leaderUrl);
        }
    }
    throw new ISE("Couldn't find leader, failed response status is [%s] and content [%s].", responseHolder.getStatus().getCode(), responseHolder.getContent());
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) MalformedURLException(java.net.MalformedURLException) ISE(org.apache.druid.java.util.common.ISE) MalformedURLException(java.net.MalformedURLException) ChannelException(org.jboss.netty.channel.ChannelException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL)

Example 23 with StringFullResponseHolder

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

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 24 with StringFullResponseHolder

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

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 25 with StringFullResponseHolder

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

the class RemoteTaskActionClientTest method testSubmitSimple.

@Test
public void testSubmitSimple() throws Exception {
    Request request = new Request(HttpMethod.POST, new URL("http://localhost:1234/xx"));
    EasyMock.expect(druidLeaderClient.makeRequest(HttpMethod.POST, "/druid/indexer/v1/action")).andReturn(request);
    // return status code 200 and a list with size equals 1
    Map<String, Object> responseBody = new HashMap<>();
    final List<TaskLock> expectedLocks = Collections.singletonList(new TimeChunkLock(TaskLockType.SHARED, "groupId", "dataSource", Intervals.of("2019/2020"), "version", 0));
    responseBody.put("result", expectedLocks);
    String strResult = objectMapper.writeValueAsString(responseBody);
    final HttpResponse response = EasyMock.createNiceMock(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(strResult);
    // set up mocks
    EasyMock.expect(druidLeaderClient.go(request)).andReturn(responseHolder);
    EasyMock.replay(druidLeaderClient);
    Task task = NoopTask.create("id", 0);
    RemoteTaskActionClient client = new RemoteTaskActionClient(task, druidLeaderClient, new RetryPolicyFactory(new RetryPolicyConfig()), objectMapper);
    final List<TaskLock> locks = client.submit(new LockListAction());
    Assert.assertEquals(expectedLocks, locks);
    EasyMock.verify(druidLeaderClient);
}
Also used : Task(org.apache.druid.indexing.common.task.Task) NoopTask(org.apache.druid.indexing.common.task.NoopTask) RetryPolicyConfig(org.apache.druid.indexing.common.RetryPolicyConfig) HashMap(java.util.HashMap) TimeChunkLock(org.apache.druid.indexing.common.TimeChunkLock) Request(org.apache.druid.java.util.http.client.Request) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer) RetryPolicyFactory(org.apache.druid.indexing.common.RetryPolicyFactory) URL(java.net.URL) StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) TaskLock(org.apache.druid.indexing.common.TaskLock) Test(org.junit.Test)

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