use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class SeekableStreamIndexTaskClient method pause.
public Map<PartitionIdType, SequenceOffsetType> pause(final String id) {
log.debug("Pause task[%s]", id);
try {
final StringFullResponseHolder response = submitRequestWithEmptyContent(id, HttpMethod.POST, "pause", null, true);
final HttpResponseStatus responseStatus = response.getStatus();
final String responseContent = response.getContent();
if (responseStatus.equals(HttpResponseStatus.OK)) {
log.info("Task [%s] paused successfully", id);
return deserializeMap(responseContent, Map.class, getPartitionType(), getSequenceType());
} else if (responseStatus.equals(HttpResponseStatus.ACCEPTED)) {
// The task received the pause request, but its status hasn't been changed yet.
final RetryPolicy retryPolicy = newRetryPolicy();
while (true) {
final SeekableStreamIndexTaskRunner.Status status = getStatus(id);
if (status == SeekableStreamIndexTaskRunner.Status.PAUSED) {
return getCurrentOffsets(id, true);
}
final Duration delay = retryPolicy.getAndIncrementRetryDelay();
if (delay == null) {
throw new ISE("Task [%s] failed to change its status from [%s] to [%s], aborting", id, status, SeekableStreamIndexTaskRunner.Status.PAUSED);
} else {
final long sleepTime = delay.getMillis();
log.info("Still waiting for task [%s] to change its status to [%s]; will try again in [%s]", id, SeekableStreamIndexTaskRunner.Status.PAUSED, new Duration(sleepTime).toString());
Thread.sleep(sleepTime);
}
}
} else {
throw new ISE("Pause request for task [%s] failed with response [%s] : [%s]", id, responseStatus, responseContent);
}
} catch (NoTaskLocationException e) {
log.error("Exception [%s] while pausing Task [%s]", e.getMessage(), id);
return ImmutableMap.of();
} catch (IOException | InterruptedException e) {
throw new RE(e, "Exception [%s] while pausing Task [%s]", e.getMessage(), id);
}
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class TaskLifecycleTest method setUpTaskStorage.
private TaskStorage setUpTaskStorage() {
Preconditions.checkNotNull(mapper);
Preconditions.checkNotNull(derbyConnectorRule);
TaskStorage taskStorage;
switch(taskStorageType) {
case HEAP_TASK_STORAGE:
{
taskStorage = new HeapMemoryTaskStorage(new TaskStorageConfig(null) {
});
break;
}
case METADATA_TASK_STORAGE:
{
TestDerbyConnector testDerbyConnector = derbyConnectorRule.getConnector();
mapper.registerSubtypes(new NamedType(MockFirehoseFactory.class, "mockFirehoseFactory"), new NamedType(MockInputSource.class, "mockInputSource"), new NamedType(NoopInputFormat.class, "noopInputFormat"));
testDerbyConnector.createTaskTables();
testDerbyConnector.createSegmentTable();
taskStorage = new MetadataTaskStorage(testDerbyConnector, new TaskStorageConfig(null), new DerbyMetadataStorageActionHandlerFactory(testDerbyConnector, derbyConnectorRule.metadataTablesConfigSupplier().get(), mapper));
break;
}
default:
{
throw new RE("Unknown task storage type [%s]", taskStorageType);
}
}
tsqa = new TaskStorageQueryAdapter(taskStorage, taskLockbox);
return taskStorage;
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class TestTaskRunner method stop.
@Override
public void stop() {
stopping = true;
for (Map.Entry<Integer, ListeningExecutorService> entry : exec.entrySet()) {
try {
entry.getValue().shutdown();
} catch (SecurityException ex) {
throw new RuntimeException("I can't control my own threads!", ex);
}
}
for (TestTaskRunnerWorkItem item : runningItems) {
final Task task = item.getTask();
final long start = System.currentTimeMillis();
if (taskConfig.isRestoreTasksOnRestart() && task.canRestore()) {
// Attempt graceful shutdown.
log.info("Starting graceful shutdown of task[%s].", task.getId());
try {
task.stopGracefully(taskConfig);
final TaskStatus taskStatus = item.getResult().get(new Interval(DateTimes.utc(start), taskConfig.getGracefulShutdownTimeout()).toDurationMillis(), TimeUnit.MILLISECONDS);
// Ignore status, it doesn't matter for graceful shutdowns.
log.info("Graceful shutdown of task[%s] finished in %,dms.", task.getId(), System.currentTimeMillis() - start);
TaskRunnerUtils.notifyStatusChanged(listeners, task.getId(), taskStatus);
} catch (Exception e) {
String errMsg = "Graceful shutdown of task aborted with exception, see task logs for more information";
TaskRunnerUtils.notifyStatusChanged(listeners, task.getId(), TaskStatus.failure(task.getId(), errMsg));
throw new RE(e, "Graceful shutdown of task[%s] aborted with exception", task.getId());
}
} else {
TaskRunnerUtils.notifyStatusChanged(listeners, task.getId(), TaskStatus.failure(task.getId(), "Task failure while shutting down gracefully"));
}
}
// Ok, now interrupt everything.
for (Map.Entry<Integer, ListeningExecutorService> entry : exec.entrySet()) {
try {
entry.getValue().shutdownNow();
} catch (SecurityException ex) {
throw new RuntimeException("I can't control my own threads!", ex);
}
}
}
use of org.apache.druid.java.util.common.RE 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.common.RE in project druid by druid-io.
the class OverlordResourceTest method testEnableWorkerWhenWorkerAPIRaisesError.
@Test
public void testEnableWorkerWhenWorkerAPIRaisesError() {
final String host = "worker-host";
workerTaskRunnerQueryAdapter.enableWorker(host);
EasyMock.expectLastCall().andThrow(new RE("Worker API returns error!")).once();
EasyMock.replay(taskRunner, taskMaster, taskStorageQueryAdapter, indexerMetadataStorageAdapter, req, workerTaskRunnerQueryAdapter);
final Response response = overlordResource.enableWorker(host);
Assert.assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR.getCode(), response.getStatus());
Assert.assertEquals(ImmutableMap.of("error", "Worker API returns error!"), response.getEntity());
}
Aggregations