Search in sources :

Example 1 with TaskResource

use of org.apache.druid.indexing.common.task.TaskResource 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 2 with TaskResource

use of org.apache.druid.indexing.common.task.TaskResource in project druid by druid-io.

the class TaskLifecycleTest method newRealtimeIndexTask.

private RealtimeIndexTask newRealtimeIndexTask() {
    String taskId = StringUtils.format("rt_task_%s", System.currentTimeMillis());
    DataSchema dataSchema = new DataSchema("test_ds", TestHelper.makeJsonMapper().convertValue(new MapInputRowParser(new TimeAndDimsParseSpec(new TimestampSpec(null, null, null), DimensionsSpec.EMPTY)), JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT), new AggregatorFactory[] { new LongSumAggregatorFactory("count", "rows") }, new UniformGranularitySpec(Granularities.DAY, Granularities.NONE, null), null, mapper);
    RealtimeIOConfig realtimeIOConfig = new RealtimeIOConfig(new MockFirehoseFactory(), null);
    RealtimeTuningConfig realtimeTuningConfig = new RealtimeTuningConfig(null, 1000, null, null, new Period("P1Y"), // default window period of 10 minutes
    null, // base persist dir ignored by Realtime Index task
    null, null, null, null, null, null, null, 0, 0, null, null, null, null, null);
    FireDepartment fireDepartment = new FireDepartment(dataSchema, realtimeIOConfig, realtimeTuningConfig);
    return new RealtimeIndexTask(taskId, new TaskResource(taskId, 1), fireDepartment, null);
}
Also used : RealtimeIOConfig(org.apache.druid.segment.indexing.RealtimeIOConfig) RealtimeIndexTask(org.apache.druid.indexing.common.task.RealtimeIndexTask) TaskResource(org.apache.druid.indexing.common.task.TaskResource) MapInputRowParser(org.apache.druid.data.input.impl.MapInputRowParser) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) Period(org.joda.time.Period) RealtimeTuningConfig(org.apache.druid.segment.indexing.RealtimeTuningConfig) DataSchema(org.apache.druid.segment.indexing.DataSchema) TimeAndDimsParseSpec(org.apache.druid.data.input.impl.TimeAndDimsParseSpec) UniformGranularitySpec(org.apache.druid.segment.indexing.granularity.UniformGranularitySpec) FireDepartment(org.apache.druid.segment.realtime.FireDepartment) TimestampSpec(org.apache.druid.data.input.impl.TimestampSpec)

Example 3 with TaskResource

use of org.apache.druid.indexing.common.task.TaskResource in project druid by druid-io.

the class RemoteTaskRunnerTest method testRunSameAvailabilityGroup.

@Test
public void testRunSameAvailabilityGroup() throws Exception {
    doSetup();
    TestRealtimeTask task1 = new TestRealtimeTask("rt1", new TaskResource("rt1", 1), "foo", TaskStatus.running("rt1"), jsonMapper);
    remoteTaskRunner.run(task1);
    Assert.assertTrue(taskAnnounced(task1.getId()));
    mockWorkerRunningTask(task1);
    TestRealtimeTask task2 = new TestRealtimeTask("rt2", new TaskResource("rt1", 1), "foo", TaskStatus.running("rt2"), jsonMapper);
    remoteTaskRunner.run(task2);
    TestRealtimeTask task3 = new TestRealtimeTask("rt3", new TaskResource("rt2", 1), "foo", TaskStatus.running("rt3"), jsonMapper);
    remoteTaskRunner.run(task3);
    Assert.assertTrue(TestUtils.conditionValid(new IndexingServiceCondition() {

        @Override
        public boolean isValid() {
            return remoteTaskRunner.getRunningTasks().size() == 2;
        }
    }));
    Assert.assertTrue(TestUtils.conditionValid(new IndexingServiceCondition() {

        @Override
        public boolean isValid() {
            return remoteTaskRunner.getPendingTasks().size() == 1;
        }
    }));
    Assert.assertTrue(remoteTaskRunner.getPendingTasks().iterator().next().getTaskId().equals("rt2"));
}
Also used : TestRealtimeTask(org.apache.druid.indexing.common.TestRealtimeTask) TaskResource(org.apache.druid.indexing.common.task.TaskResource) IndexingServiceCondition(org.apache.druid.indexing.common.IndexingServiceCondition) Test(org.junit.Test)

Example 4 with TaskResource

use of org.apache.druid.indexing.common.task.TaskResource in project druid by druid-io.

the class RemoteTaskRunnerTest method testRunWithTaskComplete.

@Test
public void testRunWithTaskComplete() throws Exception {
    doSetup();
    TestRealtimeTask task1 = new TestRealtimeTask("testTask", new TaskResource("testTask", 2), "foo", TaskStatus.success("testTask"), jsonMapper);
    remoteTaskRunner.run(task1);
    Assert.assertTrue(taskAnnounced(task1.getId()));
    mockWorkerRunningTask(task1);
    mockWorkerCompleteSuccessfulTask(task1);
    Assert.assertEquals(TaskState.SUCCESS, remoteTaskRunner.run(task1).get().getStatusCode());
}
Also used : TestRealtimeTask(org.apache.druid.indexing.common.TestRealtimeTask) TaskResource(org.apache.druid.indexing.common.task.TaskResource) Test(org.junit.Test)

Example 5 with TaskResource

use of org.apache.druid.indexing.common.task.TaskResource in project druid by druid-io.

the class RemoteTaskRunnerTest method testBootstrap.

@Test
public void testBootstrap() throws Exception {
    makeWorker();
    RemoteTaskRunnerConfig rtrConfig = new TestRemoteTaskRunnerConfig(TIMEOUT_PERIOD);
    rtrConfig.setMaxPercentageBlacklistWorkers(100);
    makeRemoteTaskRunner(rtrConfig);
    TestRealtimeTask task1 = new TestRealtimeTask("first", new TaskResource("first", 1), "foo", TaskStatus.running("first"), jsonMapper);
    remoteTaskRunner.run(task1);
    Assert.assertTrue(taskAnnounced(task1.getId()));
    mockWorkerRunningTask(task1);
    TestRealtimeTask task = new TestRealtimeTask("second", new TaskResource("task", 2), "foo", TaskStatus.running("task"), jsonMapper);
    remoteTaskRunner.run(task);
    TestRealtimeTask task2 = new TestRealtimeTask("second", new TaskResource("second", 2), "foo", TaskStatus.running("second"), jsonMapper);
    remoteTaskRunner.run(task2);
    Assert.assertTrue(taskAnnounced(task2.getId()));
    mockWorkerRunningTask(task2);
    final Set<String> runningTasks = Sets.newHashSet(Iterables.transform(remoteTaskRunner.getRunningTasks(), new Function<RemoteTaskRunnerWorkItem, String>() {

        @Override
        public String apply(RemoteTaskRunnerWorkItem input) {
            return input.getTaskId();
        }
    }));
    Assert.assertEquals("runningTasks", ImmutableSet.of("first", "second"), runningTasks);
}
Also used : Function(com.google.common.base.Function) TestRealtimeTask(org.apache.druid.indexing.common.TestRealtimeTask) TaskResource(org.apache.druid.indexing.common.task.TaskResource) RemoteTaskRunnerConfig(org.apache.druid.indexing.overlord.config.RemoteTaskRunnerConfig) Test(org.junit.Test)

Aggregations

TaskResource (org.apache.druid.indexing.common.task.TaskResource)16 Test (org.junit.Test)13 TestRealtimeTask (org.apache.druid.indexing.common.TestRealtimeTask)8 TaskStatus (org.apache.druid.indexer.TaskStatus)7 RealtimeIndexTask (org.apache.druid.indexing.common.task.RealtimeIndexTask)5 RemoteTaskRunnerConfig (org.apache.druid.indexing.overlord.config.RemoteTaskRunnerConfig)5 Task (org.apache.druid.indexing.common.task.Task)4 IndexTask (org.apache.druid.indexing.common.task.IndexTask)3 DataSchema (org.apache.druid.segment.indexing.DataSchema)3 RealtimeIOConfig (org.apache.druid.segment.indexing.RealtimeIOConfig)3 FireDepartment (org.apache.druid.segment.realtime.FireDepartment)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 IndexingServiceCondition (org.apache.druid.indexing.common.IndexingServiceCondition)2 TaskLock (org.apache.druid.indexing.common.TaskLock)2 TaskToolbox (org.apache.druid.indexing.common.TaskToolbox)2 TimeChunkLockTryAcquireAction (org.apache.druid.indexing.common.actions.TimeChunkLockTryAcquireAction)2 TaskConfig (org.apache.druid.indexing.common.config.TaskConfig)2 AbstractFixedIntervalTask (org.apache.druid.indexing.common.task.AbstractFixedIntervalTask)2 KillUnusedSegmentsTask (org.apache.druid.indexing.common.task.KillUnusedSegmentsTask)2