use of org.apache.druid.metadata.EntryExistsException in project druid by druid-io.
the class OverlordResource method taskPost.
/**
* Warning, magic: {@link org.apache.druid.client.indexing.HttpIndexingServiceClient#runTask} may call this method
* remotely with {@link ClientTaskQuery} objects, but we deserialize {@link Task} objects. See the comment for {@link
* ClientTaskQuery} for details.
*/
@POST
@Path("/task")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response taskPost(final Task task, @Context final HttpServletRequest req) {
final String dataSource = task.getDataSource();
final ResourceAction resourceAction = new ResourceAction(new Resource(dataSource, ResourceType.DATASOURCE), Action.WRITE);
Access authResult = AuthorizationUtils.authorizeResourceAction(req, resourceAction, authorizerMapper);
if (!authResult.isAllowed()) {
throw new ForbiddenException(authResult.getMessage());
}
return asLeaderWith(taskMaster.getTaskQueue(), new Function<TaskQueue, Response>() {
@Override
public Response apply(TaskQueue taskQueue) {
try {
taskQueue.add(task);
return Response.ok(ImmutableMap.of("task", task.getId())).build();
} catch (EntryExistsException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(ImmutableMap.of("error", StringUtils.format("Task[%s] already exists!", task.getId()))).build();
}
}
});
}
use of org.apache.druid.metadata.EntryExistsException in project druid by druid-io.
the class AppenderatorDriverRealtimeIndexTaskTest method runTask.
private ListenableFuture<TaskStatus> runTask(final Task task) {
try {
taskStorage.insert(task, TaskStatus.running(task.getId()));
} catch (EntryExistsException e) {
// suppress
}
taskLockbox.syncFromStorage();
final TaskToolbox toolbox = taskToolboxFactory.build(task);
return taskExec.submit(() -> {
try {
if (task.isReady(toolbox.getTaskActionClient())) {
return task.run(toolbox);
} else {
throw new ISE("Task is not ready");
}
} catch (Exception e) {
log.warn(e, "Task failed");
throw e;
}
});
}
use of org.apache.druid.metadata.EntryExistsException in project druid by druid-io.
the class TaskLockboxTest method testRevokedLockSyncFromStorage.
@Test
public void testRevokedLockSyncFromStorage() throws EntryExistsException {
final TaskLockbox originalBox = new TaskLockbox(taskStorage, metadataStorageCoordinator);
final Task task1 = NoopTask.create("task1", 10);
taskStorage.insert(task1, TaskStatus.running(task1.getId()));
originalBox.add(task1);
Assert.assertTrue(originalBox.tryLock(task1, new TimeChunkLockRequest(TaskLockType.EXCLUSIVE, task1, Intervals.of("2017/2018"), null)).isOk());
// task2 revokes task1
final Task task2 = NoopTask.create("task2", 100);
taskStorage.insert(task2, TaskStatus.running(task2.getId()));
originalBox.add(task2);
Assert.assertTrue(originalBox.tryLock(task2, new TimeChunkLockRequest(TaskLockType.EXCLUSIVE, task2, Intervals.of("2017/2018"), null)).isOk());
final Map<String, List<TaskLock>> beforeLocksInStorage = taskStorage.getActiveTasks().stream().collect(Collectors.toMap(Task::getId, task -> taskStorage.getLocks(task.getId())));
final List<TaskLock> task1Locks = beforeLocksInStorage.get("task1");
Assert.assertEquals(1, task1Locks.size());
Assert.assertTrue(task1Locks.get(0).isRevoked());
final List<TaskLock> task2Locks = beforeLocksInStorage.get("task1");
Assert.assertEquals(1, task2Locks.size());
Assert.assertTrue(task2Locks.get(0).isRevoked());
final TaskLockbox newBox = new TaskLockbox(taskStorage, metadataStorageCoordinator);
newBox.syncFromStorage();
final Set<TaskLock> afterLocksInStorage = taskStorage.getActiveTasks().stream().flatMap(task -> taskStorage.getLocks(task.getId()).stream()).collect(Collectors.toSet());
Assert.assertEquals(beforeLocksInStorage.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()), afterLocksInStorage);
}
use of org.apache.druid.metadata.EntryExistsException in project druid by druid-io.
the class TaskLockboxTest method testSyncFromStorageWithMissingTaskPriority.
@Test
public void testSyncFromStorageWithMissingTaskPriority() throws EntryExistsException {
final Task task = NoopTask.create();
taskStorage.insert(task, TaskStatus.running(task.getId()));
taskStorage.addLock(task.getId(), new TimeChunkLock(TaskLockType.EXCLUSIVE, task.getGroupId(), task.getDataSource(), Intervals.of("2017/2018"), "v1", task.getPriority()));
final List<TaskLock> beforeLocksInStorage = taskStorage.getActiveTasks().stream().flatMap(t -> taskStorage.getLocks(t.getId()).stream()).collect(Collectors.toList());
final TaskLockbox lockbox = new TaskLockbox(taskStorage, metadataStorageCoordinator);
lockbox.syncFromStorage();
final List<TaskLock> afterLocksInStorage = taskStorage.getActiveTasks().stream().flatMap(t -> taskStorage.getLocks(t.getId()).stream()).collect(Collectors.toList());
Assert.assertEquals(beforeLocksInStorage, afterLocksInStorage);
}
use of org.apache.druid.metadata.EntryExistsException in project druid by druid-io.
the class MaterializedViewSupervisor method submitTasks.
private void submitTasks(SortedMap<Interval, String> sortedToBuildVersion, Map<Interval, List<DataSegment>> baseSegments) {
for (Map.Entry<Interval, String> entry : sortedToBuildVersion.entrySet()) {
if (runningTasks.size() < maxTaskCount) {
HadoopIndexTask task = spec.createTask(entry.getKey(), entry.getValue(), baseSegments.get(entry.getKey()));
try {
if (taskMaster.getTaskQueue().isPresent()) {
taskMaster.getTaskQueue().get().add(task);
runningVersion.put(entry.getKey(), entry.getValue());
runningTasks.put(entry.getKey(), task);
}
} catch (EntryExistsException e) {
log.error("task %s already exsits", task);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
Aggregations