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);
}
}
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());
}
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);
}
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);
}
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);
}
Aggregations