use of org.apache.druid.indexer.TaskStatusPlus in project druid by druid-io.
the class OverlordResource method securedTaskStatusPlus.
private List<TaskStatusPlus> securedTaskStatusPlus(List<TaskStatusPlus> collectionToFilter, @Nullable String dataSource, @Nullable String type, HttpServletRequest req) {
Function<TaskStatusPlus, Iterable<ResourceAction>> raGenerator = taskStatusPlus -> {
final String taskId = taskStatusPlus.getId();
final String taskDatasource = taskStatusPlus.getDataSource();
if (taskDatasource == null) {
throw new WebApplicationException(Response.serverError().entity(StringUtils.format("No task information found for task with id: [%s]", taskId)).build());
}
return Collections.singletonList(new ResourceAction(new Resource(taskDatasource, ResourceType.DATASOURCE), Action.READ));
};
List<TaskStatusPlus> optionalTypeFilteredList = collectionToFilter;
if (type != null) {
optionalTypeFilteredList = collectionToFilter.stream().filter(task -> type.equals(task.getType())).collect(Collectors.toList());
}
if (dataSource != null) {
// skip auth check here, as it's already done in getTasks
return optionalTypeFilteredList;
}
return Lists.newArrayList(AuthorizationUtils.filterAuthorizedResources(req, optionalTypeFilteredList, raGenerator, authorizerMapper));
}
use of org.apache.druid.indexer.TaskStatusPlus in project druid by druid-io.
the class OverlordResourceTest method testGetTaskStatus.
@Test
public void testGetTaskStatus() throws Exception {
// This is disabled since OverlordResource.getTaskStatus() is annotated with TaskResourceFilter which is supposed to
// set authorization token properly, but isn't called in this test.
// This should be fixed in https://github.com/apache/druid/issues/6685.
// expectAuthorizationTokenCheck();
final Task task = NoopTask.create("mytask", 0);
final TaskStatus status = TaskStatus.running("mytask");
EasyMock.expect(taskStorageQueryAdapter.getTaskInfo("mytask")).andReturn(new TaskInfo(task.getId(), DateTimes.of("2018-01-01"), status, task.getDataSource(), task));
EasyMock.expect(taskStorageQueryAdapter.getTaskInfo("othertask")).andReturn(null);
EasyMock.<Collection<? extends TaskRunnerWorkItem>>expect(taskRunner.getKnownTasks()).andReturn(ImmutableList.of());
EasyMock.replay(taskRunner, taskMaster, taskStorageQueryAdapter, indexerMetadataStorageAdapter, req, workerTaskRunnerQueryAdapter);
final Response response1 = overlordResource.getTaskStatus("mytask");
final TaskStatusResponse taskStatusResponse1 = TestHelper.makeJsonMapper().readValue(TestHelper.makeJsonMapper().writeValueAsString(response1.getEntity()), TaskStatusResponse.class);
TaskStatusPlus tsp = taskStatusResponse1.getStatus();
Assert.assertEquals(tsp.getStatusCode(), tsp.getStatus());
Assert.assertEquals(new TaskStatusResponse("mytask", new TaskStatusPlus("mytask", "mytask", "noop", DateTimes.of("2018-01-01"), DateTimes.EPOCH, TaskState.RUNNING, RunnerTaskState.RUNNING, -1L, TaskLocation.unknown(), task.getDataSource(), null)), taskStatusResponse1);
final Response response2 = overlordResource.getTaskStatus("othertask");
final TaskStatusResponse taskStatusResponse2 = TestHelper.makeJsonMapper().readValue(TestHelper.makeJsonMapper().writeValueAsString(response2.getEntity()), TaskStatusResponse.class);
Assert.assertEquals(new TaskStatusResponse("othertask", null), taskStatusResponse2);
}
use of org.apache.druid.indexer.TaskStatusPlus in project druid by druid-io.
the class OverlordResourceTest method testGetNullCompleteTask.
@Test
public void testGetNullCompleteTask() {
expectAuthorizationTokenCheck();
EasyMock.expect(taskStorageQueryAdapter.getCompletedTaskInfoByCreatedTimeDuration(null, null, null)).andStubReturn(ImmutableList.of(new TaskInfo("id_1", DateTime.now(ISOChronology.getInstanceUTC()), TaskStatus.success("id_1"), "allow", null), new TaskInfo("id_2", DateTime.now(ISOChronology.getInstanceUTC()), TaskStatus.success("id_2"), "deny", getTaskWithIdAndDatasource("id_2", "deny")), new TaskInfo("id_3", DateTime.now(ISOChronology.getInstanceUTC()), TaskStatus.success("id_3"), "allow", getTaskWithIdAndDatasource("id_3", "allow"))));
EasyMock.replay(taskRunner, taskMaster, taskStorageQueryAdapter, indexerMetadataStorageAdapter, req, workerTaskRunnerQueryAdapter);
List<TaskStatusPlus> responseObjects = (List<TaskStatusPlus>) overlordResource.getTasks("complete", null, null, null, null, req).getEntity();
Assert.assertEquals(2, responseObjects.size());
Assert.assertEquals("id_1", responseObjects.get(0).getId());
TaskStatusPlus tsp = responseObjects.get(0);
Assert.assertEquals(null, tsp.getType());
Assert.assertTrue("DataSource Check", "allow".equals(responseObjects.get(0).getDataSource()));
}
use of org.apache.druid.indexer.TaskStatusPlus in project druid by druid-io.
the class OverlordResourceTest method testGetTasksFilterCompleteStateWithInterval.
@Test
public void testGetTasksFilterCompleteStateWithInterval() {
expectAuthorizationTokenCheck();
List<String> tasksIds = ImmutableList.of("id_1", "id_2", "id_3");
Duration duration = new Period("PT86400S").toStandardDuration();
EasyMock.expect(taskStorageQueryAdapter.getCompletedTaskInfoByCreatedTimeDuration(null, duration, null)).andStubReturn(ImmutableList.of(new TaskInfo("id_1", DateTime.now(ISOChronology.getInstanceUTC()), TaskStatus.success("id_1"), "deny", getTaskWithIdAndDatasource("id_1", "deny")), new TaskInfo("id_2", DateTime.now(ISOChronology.getInstanceUTC()), TaskStatus.success("id_2"), "allow", getTaskWithIdAndDatasource("id_2", "allow")), new TaskInfo("id_3", DateTime.now(ISOChronology.getInstanceUTC()), TaskStatus.success("id_3"), "allow", getTaskWithIdAndDatasource("id_3", "allow"))));
EasyMock.replay(taskRunner, taskMaster, taskStorageQueryAdapter, indexerMetadataStorageAdapter, req, workerTaskRunnerQueryAdapter);
String interval = "2010-01-01_P1D";
List<TaskStatusPlus> responseObjects = (List<TaskStatusPlus>) overlordResource.getTasks("complete", null, interval, null, null, req).getEntity();
Assert.assertEquals(2, responseObjects.size());
Assert.assertEquals("id_2", responseObjects.get(0).getId());
Assert.assertTrue("DataSource Check", "allow".equals(responseObjects.get(0).getDataSource()));
}
use of org.apache.druid.indexer.TaskStatusPlus in project druid by druid-io.
the class KillStalePendingSegments method run.
@Override
public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams params) {
final List<DateTime> createdTimes = new ArrayList<>();
createdTimes.add(indexingServiceClient.getActiveTasks().stream().map(TaskStatusPlus::getCreatedTime).min(Comparators.naturalNullsFirst()).orElse(// If there are no active tasks, this returns the current time.
DateTimes.nowUtc()));
final TaskStatusPlus completeTaskStatus = indexingServiceClient.getLastCompleteTask();
if (completeTaskStatus != null) {
createdTimes.add(completeTaskStatus.getCreatedTime());
}
createdTimes.sort(Comparators.naturalNullsFirst());
// There should be at least one createdTime because the current time is added to the 'createdTimes' list if there
// is no running/pending/waiting tasks.
Preconditions.checkState(!createdTimes.isEmpty(), "Failed to gather createdTimes of tasks");
// If there is no running/pending/waiting/complete tasks, stalePendingSegmentsCutoffCreationTime is
// (DateTimes.nowUtc() - KEEP_PENDING_SEGMENTS_OFFSET).
final DateTime stalePendingSegmentsCutoffCreationTime = createdTimes.get(0).minus(KEEP_PENDING_SEGMENTS_OFFSET);
for (String dataSource : params.getUsedSegmentsTimelinesPerDataSource().keySet()) {
if (!params.getCoordinatorDynamicConfig().getDataSourcesToNotKillStalePendingSegmentsIn().contains(dataSource)) {
log.info("Killed [%d] pendingSegments created until [%s] for dataSource[%s]", indexingServiceClient.killPendingSegments(dataSource, stalePendingSegmentsCutoffCreationTime), stalePendingSegmentsCutoffCreationTime, dataSource);
}
}
return params;
}
Aggregations