Search in sources :

Example 11 with RE

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);
    }
}
Also used : HttpResponseStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus) StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) RE(org.apache.druid.java.util.common.RE) HttpResponseStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus) Duration(org.joda.time.Duration) ISE(org.apache.druid.java.util.common.ISE) IOException(java.io.IOException) RetryPolicy(org.apache.druid.indexing.common.RetryPolicy)

Example 12 with RE

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;
}
Also used : DerbyMetadataStorageActionHandlerFactory(org.apache.druid.metadata.DerbyMetadataStorageActionHandlerFactory) RE(org.apache.druid.java.util.common.RE) TaskStorageConfig(org.apache.druid.indexing.common.config.TaskStorageConfig) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) TestDerbyConnector(org.apache.druid.metadata.TestDerbyConnector)

Example 13 with RE

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);
        }
    }
}
Also used : Task(org.apache.druid.indexing.common.task.Task) TaskStatus(org.apache.druid.indexer.TaskStatus) RE(org.apache.druid.java.util.common.RE) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Interval(org.joda.time.Interval)

Example 14 with RE

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());
}
Also used : RE(org.apache.druid.java.util.common.RE) Request(org.apache.druid.java.util.http.client.Request) URL(java.net.URL) Test(org.junit.Test)

Example 15 with RE

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());
}
Also used : Response(javax.ws.rs.core.Response) RE(org.apache.druid.java.util.common.RE) Test(org.junit.Test)

Aggregations

RE (org.apache.druid.java.util.common.RE)46 IOException (java.io.IOException)11 Request (org.apache.druid.java.util.http.client.Request)10 URL (java.net.URL)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 InputStream (java.io.InputStream)5 ExecutionException (java.util.concurrent.ExecutionException)5 ISE (org.apache.druid.java.util.common.ISE)5 Map (java.util.Map)4 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)4 JavaType (com.fasterxml.jackson.databind.JavaType)3 HashMap (java.util.HashMap)3 DataSegment (org.apache.druid.timeline.DataSegment)3 OSSException (com.aliyun.oss.OSSException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ApiException (io.kubernetes.client.openapi.ApiException)2 File (java.io.File)2