Search in sources :

Example 36 with TaskStatus

use of org.apache.druid.indexer.TaskStatus in project druid by druid-io.

the class TaskLifecycleTest method testRealtimeIndexTaskFailure.

@Test(timeout = 60_000L)
public void testRealtimeIndexTaskFailure() throws Exception {
    dataSegmentPusher = new DataSegmentPusher() {

        @Deprecated
        @Override
        public String getPathForHadoop(String s) {
            return getPathForHadoop();
        }

        @Override
        public String getPathForHadoop() {
            throw new UnsupportedOperationException();
        }

        @Override
        public DataSegment push(File file, DataSegment dataSegment, boolean useUniquePath) {
            throw new RuntimeException("FAILURE");
        }

        @Override
        public Map<String, Object> makeLoadSpec(URI uri) {
            throw new UnsupportedOperationException();
        }
    };
    tb = setUpTaskToolboxFactory(dataSegmentPusher, handoffNotifierFactory, mdc);
    taskRunner = setUpThreadPoolTaskRunner(tb);
    taskQueue = setUpTaskQueue(taskStorage, taskRunner);
    monitorScheduler.addMonitor(EasyMock.anyObject(Monitor.class));
    EasyMock.expectLastCall().atLeastOnce();
    monitorScheduler.removeMonitor(EasyMock.anyObject(Monitor.class));
    EasyMock.expectLastCall().anyTimes();
    EasyMock.replay(monitorScheduler, queryRunnerFactoryConglomerate);
    RealtimeIndexTask realtimeIndexTask = newRealtimeIndexTask();
    final String taskId = realtimeIndexTask.getId();
    taskQueue.start();
    taskQueue.add(realtimeIndexTask);
    // Wait for realtime index task to fail
    while (tsqa.getStatus(taskId).get().isRunnable()) {
        Thread.sleep(10);
    }
    TaskStatus status = tsqa.getStatus(taskId).get();
    Assert.assertTrue("Task should be in Failure state", status.isFailure());
    Assert.assertEquals(taskLocation, status.getLocation());
    EasyMock.verify(monitorScheduler, queryRunnerFactoryConglomerate);
}
Also used : DataSegmentPusher(org.apache.druid.segment.loading.DataSegmentPusher) RealtimeIndexTask(org.apache.druid.indexing.common.task.RealtimeIndexTask) TaskStatus(org.apache.druid.indexer.TaskStatus) DataSegment(org.apache.druid.timeline.DataSegment) URI(java.net.URI) Monitor(org.apache.druid.java.util.metrics.Monitor) File(java.io.File) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FireDepartmentTest(org.apache.druid.segment.realtime.FireDepartmentTest) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 37 with TaskStatus

use of org.apache.druid.indexer.TaskStatus in project druid by druid-io.

the class TaskLifecycleTest method testLockRevoked.

@Test
public void testLockRevoked() throws Exception {
    final Task task = new AbstractFixedIntervalTask("id1", "id1", new TaskResource("id1", 1), "ds", Intervals.of("2012-01-01/P1D"), null) {

        @Override
        public String getType() {
            return "test";
        }

        @Override
        public void stopGracefully(TaskConfig taskConfig) {
        }

        @Override
        public TaskStatus run(TaskToolbox toolbox) throws Exception {
            final Interval interval = Intervals.of("2012-01-01/P1D");
            final TimeChunkLockTryAcquireAction action = new TimeChunkLockTryAcquireAction(TaskLockType.EXCLUSIVE, interval);
            final TaskLock lock = toolbox.getTaskActionClient().submit(action);
            if (lock == null) {
                throw new ISE("Failed to get a lock");
            }
            final TaskLock lockBeforeRevoke = toolbox.getTaskActionClient().submit(action);
            Assert.assertFalse(lockBeforeRevoke.isRevoked());
            taskLockbox.revokeLock(getId(), lock);
            final TaskLock lockAfterRevoke = toolbox.getTaskActionClient().submit(action);
            Assert.assertTrue(lockAfterRevoke.isRevoked());
            return TaskStatus.failure(getId(), "lock revoked test");
        }
    };
    final TaskStatus status = runTask(task);
    Assert.assertEquals(taskLocation, status.getLocation());
    Assert.assertEquals("statusCode", TaskState.FAILED, status.getStatusCode());
    Assert.assertEquals("segments published", 0, mdc.getPublished().size());
    Assert.assertEquals("segments nuked", 0, mdc.getNuked().size());
}
Also used : TaskToolbox(org.apache.druid.indexing.common.TaskToolbox) IndexTask(org.apache.druid.indexing.common.task.IndexTask) KillUnusedSegmentsTask(org.apache.druid.indexing.common.task.KillUnusedSegmentsTask) Task(org.apache.druid.indexing.common.task.Task) AbstractFixedIntervalTask(org.apache.druid.indexing.common.task.AbstractFixedIntervalTask) RealtimeIndexTask(org.apache.druid.indexing.common.task.RealtimeIndexTask) TaskResource(org.apache.druid.indexing.common.task.TaskResource) TaskLock(org.apache.druid.indexing.common.TaskLock) TimeChunkLockTryAcquireAction(org.apache.druid.indexing.common.actions.TimeChunkLockTryAcquireAction) TaskConfig(org.apache.druid.indexing.common.config.TaskConfig) DefaultTaskConfig(org.apache.druid.indexing.overlord.config.DefaultTaskConfig) ISE(org.apache.druid.java.util.common.ISE) TaskStatus(org.apache.druid.indexer.TaskStatus) AbstractFixedIntervalTask(org.apache.druid.indexing.common.task.AbstractFixedIntervalTask) Interval(org.joda.time.Interval) FireDepartmentTest(org.apache.druid.segment.realtime.FireDepartmentTest) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 38 with TaskStatus

use of org.apache.druid.indexer.TaskStatus in project druid by druid-io.

the class TaskLifecycleTest method testRealtimeishTask.

@Test
public void testRealtimeishTask() throws Exception {
    final Task rtishTask = new RealtimeishTask();
    final TaskStatus status = runTask(rtishTask);
    Assert.assertEquals("statusCode", TaskState.SUCCESS, status.getStatusCode());
    Assert.assertEquals(taskLocation, status.getLocation());
    Assert.assertEquals("num segments published", 2, mdc.getPublished().size());
    Assert.assertEquals("num segments nuked", 0, mdc.getNuked().size());
}
Also used : IndexTask(org.apache.druid.indexing.common.task.IndexTask) KillUnusedSegmentsTask(org.apache.druid.indexing.common.task.KillUnusedSegmentsTask) Task(org.apache.druid.indexing.common.task.Task) AbstractFixedIntervalTask(org.apache.druid.indexing.common.task.AbstractFixedIntervalTask) RealtimeIndexTask(org.apache.druid.indexing.common.task.RealtimeIndexTask) TaskStatus(org.apache.druid.indexer.TaskStatus) FireDepartmentTest(org.apache.druid.segment.realtime.FireDepartmentTest) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 39 with TaskStatus

use of org.apache.druid.indexer.TaskStatus in project druid by druid-io.

the class TaskQueueTest method testShutdownReleasesTaskLock.

@Test
public void testShutdownReleasesTaskLock() throws Exception {
    final TaskActionClientFactory actionClientFactory = createActionClientFactory();
    final TaskQueue taskQueue = new TaskQueue(new TaskLockConfig(), new TaskQueueConfig(null, null, null, null), new DefaultTaskConfig(), getTaskStorage(), new SimpleTaskRunner(actionClientFactory), actionClientFactory, getLockbox(), new NoopServiceEmitter());
    taskQueue.setActive(true);
    // Create a Task and add it to the TaskQueue
    final TestTask task = new TestTask("t1", Intervals.of("2021-01/P1M"));
    taskQueue.add(task);
    // Acquire a lock for the Task
    getLockbox().lock(task, new TimeChunkLockRequest(TaskLockType.EXCLUSIVE, task, task.interval, null));
    final List<TaskLock> locksForTask = getLockbox().findLocksForTask(task);
    Assert.assertEquals(1, locksForTask.size());
    Assert.assertEquals(task.interval, locksForTask.get(0).getInterval());
    // Verify that locks are removed on calling shutdown
    taskQueue.shutdown(task.getId(), "Shutdown Task test");
    Assert.assertTrue(getLockbox().findLocksForTask(task).isEmpty());
    Optional<TaskStatus> statusOptional = getTaskStorage().getStatus(task.getId());
    Assert.assertTrue(statusOptional.isPresent());
    Assert.assertEquals(TaskState.FAILED, statusOptional.get().getStatusCode());
    Assert.assertNotNull(statusOptional.get().getErrorMsg());
    Assert.assertEquals("Shutdown Task test", statusOptional.get().getErrorMsg());
}
Also used : TaskActionClientFactory(org.apache.druid.indexing.common.actions.TaskActionClientFactory) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) DefaultTaskConfig(org.apache.druid.indexing.overlord.config.DefaultTaskConfig) TaskStatus(org.apache.druid.indexer.TaskStatus) TaskLockConfig(org.apache.druid.indexing.overlord.config.TaskLockConfig) TaskLock(org.apache.druid.indexing.common.TaskLock) TaskQueueConfig(org.apache.druid.indexing.overlord.config.TaskQueueConfig) Test(org.junit.Test)

Example 40 with TaskStatus

use of org.apache.druid.indexer.TaskStatus in project druid by druid-io.

the class TaskQueueTest method testTaskStatusWhenExceptionIsThrownInIsReady.

@Test
public void testTaskStatusWhenExceptionIsThrownInIsReady() throws EntryExistsException {
    final TaskActionClientFactory actionClientFactory = createActionClientFactory();
    final TaskQueue taskQueue = new TaskQueue(new TaskLockConfig(), new TaskQueueConfig(null, null, null, null), new DefaultTaskConfig(), getTaskStorage(), new SimpleTaskRunner(actionClientFactory), actionClientFactory, getLockbox(), new NoopServiceEmitter());
    taskQueue.setActive(true);
    final Task task = new TestTask("t1", Intervals.of("2021-01-01/P1D")) {

        @Override
        public boolean isReady(TaskActionClient taskActionClient) {
            throw new RuntimeException("isReady failure test");
        }
    };
    taskQueue.add(task);
    taskQueue.manageInternal();
    Optional<TaskStatus> statusOptional = getTaskStorage().getStatus(task.getId());
    Assert.assertTrue(statusOptional.isPresent());
    Assert.assertEquals(TaskState.FAILED, statusOptional.get().getStatusCode());
    Assert.assertNotNull(statusOptional.get().getErrorMsg());
    Assert.assertTrue(StringUtils.format("Actual message is: %s", statusOptional.get().getErrorMsg()), statusOptional.get().getErrorMsg().startsWith("Failed while waiting for the task to be ready to run"));
}
Also used : Task(org.apache.druid.indexing.common.task.Task) AbstractBatchIndexTask(org.apache.druid.indexing.common.task.AbstractBatchIndexTask) TaskActionClientFactory(org.apache.druid.indexing.common.actions.TaskActionClientFactory) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) DefaultTaskConfig(org.apache.druid.indexing.overlord.config.DefaultTaskConfig) TaskStatus(org.apache.druid.indexer.TaskStatus) TaskLockConfig(org.apache.druid.indexing.overlord.config.TaskLockConfig) TaskActionClient(org.apache.druid.indexing.common.actions.TaskActionClient) TaskQueueConfig(org.apache.druid.indexing.overlord.config.TaskQueueConfig) Test(org.junit.Test)

Aggregations

TaskStatus (org.apache.druid.indexer.TaskStatus)135 Test (org.junit.Test)103 DataSegment (org.apache.druid.timeline.DataSegment)55 List (java.util.List)50 ImmutableList (com.google.common.collect.ImmutableList)44 ArrayList (java.util.ArrayList)41 TaskToolbox (org.apache.druid.indexing.common.TaskToolbox)40 Task (org.apache.druid.indexing.common.task.Task)39 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)37 Map (java.util.Map)34 File (java.io.File)32 IOException (java.io.IOException)26 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)25 ImmutableMap (com.google.common.collect.ImmutableMap)25 SegmentDescriptor (org.apache.druid.query.SegmentDescriptor)25 DataSchema (org.apache.druid.segment.indexing.DataSchema)25 ISE (org.apache.druid.java.util.common.ISE)24 HashMap (java.util.HashMap)23 Executor (java.util.concurrent.Executor)23 Pair (org.apache.druid.java.util.common.Pair)23