use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class IndexTaskClient method createRequest.
private Request createRequest(String taskId, TaskLocation location, String path, @Nullable String encodedQueryString, HttpMethod method, @Nullable String mediaType, byte[] content) throws MalformedURLException {
// The below line can throw a MalformedURLException, and this method should return immediately without rety.
final URL serviceUrl = location.makeURL(encodedQueryString == null ? path : StringUtils.format("%s?%s", path, encodedQueryString));
final Request request = new Request(method, serviceUrl);
// used to validate that we are talking to the correct worker
request.addHeader(ChatHandlerResource.TASK_ID_HEADER, StringUtils.urlEncode(taskId));
if (content.length > 0) {
request.setContent(Preconditions.checkNotNull(mediaType, "mediaType"), content);
}
return request;
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class HttpRemoteTaskRunner method streamTaskReports.
@Override
public Optional<ByteSource> streamTaskReports(String taskId) {
// Read on tasks is safe
@SuppressWarnings("GuardedBy") HttpRemoteTaskRunnerWorkItem taskRunnerWorkItem = tasks.get(taskId);
Worker worker = null;
if (taskRunnerWorkItem != null && taskRunnerWorkItem.getState() != HttpRemoteTaskRunnerWorkItem.State.COMPLETE) {
worker = taskRunnerWorkItem.getWorker();
}
if (worker == null || !workers.containsKey(worker.getHost())) {
// Worker is not running this task, it might be available in deep storage
return Optional.absent();
} else {
// Worker is still running this task
TaskLocation taskLocation = taskRunnerWorkItem.getLocation();
final URL url = TaskRunnerUtils.makeTaskLocationURL(taskLocation, "/druid/worker/v1/chat/%s/liveReports", taskId);
return Optional.of(new ByteSource() {
@Override
public InputStream openStream() throws IOException {
try {
return httpClient.go(new Request(HttpMethod.GET, url), new InputStreamResponseHandler()).get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
// Unwrap if possible
Throwables.propagateIfPossible(e.getCause(), IOException.class);
throw new RuntimeException(e);
}
}
});
}
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class HttpRemoteTaskRunner method streamTaskLog.
@Override
public Optional<ByteSource> streamTaskLog(String taskId, long offset) {
// Read on tasks is safe
@SuppressWarnings("GuardedBy") HttpRemoteTaskRunnerWorkItem taskRunnerWorkItem = tasks.get(taskId);
Worker worker = null;
if (taskRunnerWorkItem != null && taskRunnerWorkItem.getState() != HttpRemoteTaskRunnerWorkItem.State.COMPLETE) {
worker = taskRunnerWorkItem.getWorker();
}
if (worker == null || !workers.containsKey(worker.getHost())) {
// Worker is not running this task, it might be available in deep storage
return Optional.absent();
} else {
// Worker is still running this task
final URL url = TaskRunnerUtils.makeWorkerURL(worker, "/druid/worker/v1/task/%s/log?offset=%s", taskId, Long.toString(offset));
return Optional.of(new ByteSource() {
@Override
public InputStream openStream() throws IOException {
try {
return httpClient.go(new Request(HttpMethod.GET, url), new InputStreamResponseHandler()).get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
// Unwrap if possible
Throwables.propagateIfPossible(e.getCause(), IOException.class);
throw new RuntimeException(e);
}
}
});
}
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class WorkerTaskRunnerQueryAdpaterTest method testEnableWorkerWhenWorkerRaisesError.
@Test
public void testEnableWorkerWhenWorkerRaisesError() throws Exception {
final URL workerUrl = new URL("https://worker-host2/druid/worker/v1/enable");
Capture<Request> capturedRequest = getHttpClientRequestCapture(HttpResponseStatus.INTERNAL_SERVER_ERROR, "");
EasyMock.replay(workerTaskRunner, taskMaster, httpClient);
try {
workerTaskRunnerQueryAdapter.enableWorker("worker-host2");
Assert.fail("Should raise RE exception!");
} catch (RE re) {
}
Assert.assertEquals(HttpMethod.POST, capturedRequest.getValue().getMethod());
Assert.assertEquals(workerUrl, capturedRequest.getValue().getUrl());
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class WorkerTaskRunnerQueryAdpaterTest method getHttpClientRequestCapture.
private Capture<Request> getHttpClientRequestCapture(HttpResponseStatus httpStatus, String responseContent) {
SettableFuture<StatusResponseHolder> futureResult = SettableFuture.create();
futureResult.set(new StatusResponseHolder(httpStatus, new StringBuilder(responseContent)));
Capture<Request> capturedRequest = EasyMock.newCapture();
EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject())).andReturn(futureResult).once();
return capturedRequest;
}
Aggregations