Search in sources :

Example 1 with EntryExistsException

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();
            }
        }
    });
}
Also used : Response(javax.ws.rs.core.Response) ForbiddenException(org.apache.druid.server.security.ForbiddenException) Resource(org.apache.druid.server.security.Resource) Access(org.apache.druid.server.security.Access) TaskQueue(org.apache.druid.indexing.overlord.TaskQueue) EntryExistsException(org.apache.druid.metadata.EntryExistsException) ResourceAction(org.apache.druid.server.security.ResourceAction) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 2 with EntryExistsException

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;
        }
    });
}
Also used : TaskToolbox(org.apache.druid.indexing.common.TaskToolbox) EntryExistsException(org.apache.druid.metadata.EntryExistsException) ISE(org.apache.druid.java.util.common.ISE) ParseException(org.apache.druid.java.util.common.parsers.ParseException) EntryExistsException(org.apache.druid.metadata.EntryExistsException) IOException(java.io.IOException) ExpectedException(org.junit.rules.ExpectedException)

Example 3 with EntryExistsException

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);
}
Also used : TaskToolbox(org.apache.druid.indexing.common.TaskToolbox) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Arrays(java.util.Arrays) TaskConfig(org.apache.druid.indexing.common.config.TaskConfig) AbstractTask(org.apache.druid.indexing.common.task.AbstractTask) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) TaskActionClient(org.apache.druid.indexing.common.actions.TaskActionClient) Task(org.apache.druid.indexing.common.task.Task) Map(java.util.Map) TaskLock(org.apache.druid.indexing.common.TaskLock) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) DerbyMetadataStorageActionHandlerFactory(org.apache.druid.metadata.DerbyMetadataStorageActionHandlerFactory) HashBasedNumberedPartialShardSpec(org.apache.druid.timeline.partition.HashBasedNumberedPartialShardSpec) DateTimes(org.apache.druid.java.util.common.DateTimes) MetadataStorageTablesConfig(org.apache.druid.metadata.MetadataStorageTablesConfig) TaskLockPosse(org.apache.druid.indexing.overlord.TaskLockbox.TaskLockPosse) NumberedShardSpec(org.apache.druid.timeline.partition.NumberedShardSpec) Collection(java.util.Collection) StringUtils(org.apache.druid.java.util.common.StringUtils) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) Collectors(java.util.stream.Collectors) LockGranularity(org.apache.druid.indexing.common.LockGranularity) IndexerSQLMetadataStorageCoordinator(org.apache.druid.metadata.IndexerSQLMetadataStorageCoordinator) NoopTask(org.apache.druid.indexing.common.task.NoopTask) List(java.util.List) TaskLockType(org.apache.druid.indexing.common.TaskLockType) PartitionIds(org.apache.druid.timeline.partition.PartitionIds) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) TestDerbyConnector(org.apache.druid.metadata.TestDerbyConnector) PartialShardSpec(org.apache.druid.timeline.partition.PartialShardSpec) NumberedPartialShardSpec(org.apache.druid.timeline.partition.NumberedPartialShardSpec) Iterables(com.google.common.collect.Iterables) Intervals(org.apache.druid.java.util.common.Intervals) TaskStorageConfig(org.apache.druid.indexing.common.config.TaskStorageConfig) HashBasedNumberedShardSpec(org.apache.druid.timeline.partition.HashBasedNumberedShardSpec) HashMap(java.util.HashMap) TaskStatus(org.apache.druid.indexer.TaskStatus) ArrayList(java.util.ArrayList) EntryExistsException(org.apache.druid.metadata.EntryExistsException) HashSet(java.util.HashSet) Interval(org.joda.time.Interval) TimeChunkLock(org.apache.druid.indexing.common.TimeChunkLock) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) EmittingLogger(org.apache.druid.java.util.emitter.EmittingLogger) NumberedOverwritePartialShardSpec(org.apache.druid.timeline.partition.NumberedOverwritePartialShardSpec) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SegmentIdWithShardSpec(org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) TestHelper(org.apache.druid.segment.TestHelper) Rule(org.junit.Rule) SegmentLock(org.apache.druid.indexing.common.SegmentLock) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) Assert(org.junit.Assert) Collections(java.util.Collections) AbstractTask(org.apache.druid.indexing.common.task.AbstractTask) Task(org.apache.druid.indexing.common.task.Task) NoopTask(org.apache.druid.indexing.common.task.NoopTask) TaskLock(org.apache.druid.indexing.common.TaskLock) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with EntryExistsException

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);
}
Also used : TaskToolbox(org.apache.druid.indexing.common.TaskToolbox) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Arrays(java.util.Arrays) TaskConfig(org.apache.druid.indexing.common.config.TaskConfig) AbstractTask(org.apache.druid.indexing.common.task.AbstractTask) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) TaskActionClient(org.apache.druid.indexing.common.actions.TaskActionClient) Task(org.apache.druid.indexing.common.task.Task) Map(java.util.Map) TaskLock(org.apache.druid.indexing.common.TaskLock) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) DerbyMetadataStorageActionHandlerFactory(org.apache.druid.metadata.DerbyMetadataStorageActionHandlerFactory) HashBasedNumberedPartialShardSpec(org.apache.druid.timeline.partition.HashBasedNumberedPartialShardSpec) DateTimes(org.apache.druid.java.util.common.DateTimes) MetadataStorageTablesConfig(org.apache.druid.metadata.MetadataStorageTablesConfig) TaskLockPosse(org.apache.druid.indexing.overlord.TaskLockbox.TaskLockPosse) NumberedShardSpec(org.apache.druid.timeline.partition.NumberedShardSpec) Collection(java.util.Collection) StringUtils(org.apache.druid.java.util.common.StringUtils) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) Collectors(java.util.stream.Collectors) LockGranularity(org.apache.druid.indexing.common.LockGranularity) IndexerSQLMetadataStorageCoordinator(org.apache.druid.metadata.IndexerSQLMetadataStorageCoordinator) NoopTask(org.apache.druid.indexing.common.task.NoopTask) List(java.util.List) TaskLockType(org.apache.druid.indexing.common.TaskLockType) PartitionIds(org.apache.druid.timeline.partition.PartitionIds) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) TestDerbyConnector(org.apache.druid.metadata.TestDerbyConnector) PartialShardSpec(org.apache.druid.timeline.partition.PartialShardSpec) NumberedPartialShardSpec(org.apache.druid.timeline.partition.NumberedPartialShardSpec) Iterables(com.google.common.collect.Iterables) Intervals(org.apache.druid.java.util.common.Intervals) TaskStorageConfig(org.apache.druid.indexing.common.config.TaskStorageConfig) HashBasedNumberedShardSpec(org.apache.druid.timeline.partition.HashBasedNumberedShardSpec) HashMap(java.util.HashMap) TaskStatus(org.apache.druid.indexer.TaskStatus) ArrayList(java.util.ArrayList) EntryExistsException(org.apache.druid.metadata.EntryExistsException) HashSet(java.util.HashSet) Interval(org.joda.time.Interval) TimeChunkLock(org.apache.druid.indexing.common.TimeChunkLock) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) EmittingLogger(org.apache.druid.java.util.emitter.EmittingLogger) NumberedOverwritePartialShardSpec(org.apache.druid.timeline.partition.NumberedOverwritePartialShardSpec) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SegmentIdWithShardSpec(org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) TestHelper(org.apache.druid.segment.TestHelper) Rule(org.junit.Rule) SegmentLock(org.apache.druid.indexing.common.SegmentLock) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) Assert(org.junit.Assert) Collections(java.util.Collections) AbstractTask(org.apache.druid.indexing.common.task.AbstractTask) Task(org.apache.druid.indexing.common.task.Task) NoopTask(org.apache.druid.indexing.common.task.NoopTask) TaskLock(org.apache.druid.indexing.common.TaskLock) TimeChunkLock(org.apache.druid.indexing.common.TimeChunkLock) Test(org.junit.Test)

Example 5 with EntryExistsException

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);
            }
        }
    }
}
Also used : EntryExistsException(org.apache.druid.metadata.EntryExistsException) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) HadoopIndexTask(org.apache.druid.indexing.common.task.HadoopIndexTask) EntryExistsException(org.apache.druid.metadata.EntryExistsException) IOException(java.io.IOException) Interval(org.joda.time.Interval)

Aggregations

EntryExistsException (org.apache.druid.metadata.EntryExistsException)10 HashMap (java.util.HashMap)6 TaskToolbox (org.apache.druid.indexing.common.TaskToolbox)6 ISE (org.apache.druid.java.util.common.ISE)6 Map (java.util.Map)5 TaskConfig (org.apache.druid.indexing.common.config.TaskConfig)5 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)4 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)4 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)4 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)4 Iterables (com.google.common.collect.Iterables)4 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4