Search in sources :

Example 1 with EntryExistsException

use of io.druid.metadata.EntryExistsException in project druid by druid-io.

the class KafkaIndexTaskTest 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 = toolboxFactory.build(task);
    synchronized (runningTasks) {
        runningTasks.add(task);
    }
    return taskExec.submit(new Callable<TaskStatus>() {

        @Override
        public TaskStatus call() throws Exception {
            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");
                return TaskStatus.failure(task.getId());
            }
        }
    });
}
Also used : TaskToolbox(io.druid.indexing.common.TaskToolbox) EntryExistsException(io.druid.metadata.EntryExistsException) ISE(io.druid.java.util.common.ISE) TaskStatus(io.druid.indexing.common.TaskStatus) EntryExistsException(io.druid.metadata.EntryExistsException) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with EntryExistsException

use of io.druid.metadata.EntryExistsException in project druid by druid-io.

the class OverlordResource method taskPost.

@POST
@Path("/task")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response taskPost(final Task task, @Context final HttpServletRequest req) {
    if (authConfig.isEnabled()) {
        // This is an experimental feature, see - https://github.com/druid-io/druid/pull/2424
        final String dataSource = task.getDataSource();
        final AuthorizationInfo authorizationInfo = (AuthorizationInfo) req.getAttribute(AuthConfig.DRUID_AUTH_TOKEN);
        Preconditions.checkNotNull(authorizationInfo, "Security is enabled but no authorization info found in the request");
        Access authResult = authorizationInfo.isAuthorized(new Resource(dataSource, ResourceType.DATASOURCE), Action.WRITE);
        if (!authResult.isAllowed()) {
            return Response.status(Response.Status.FORBIDDEN).header("Access-Check-Result", authResult).build();
        }
    }
    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", String.format("Task[%s] already exists!", task.getId()))).build();
            }
        }
    });
}
Also used : Response(javax.ws.rs.core.Response) Access(io.druid.server.security.Access) Resource(io.druid.server.security.Resource) TaskQueue(io.druid.indexing.overlord.TaskQueue) EntryExistsException(io.druid.metadata.EntryExistsException) AuthorizationInfo(io.druid.server.security.AuthorizationInfo) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 3 with EntryExistsException

use of io.druid.metadata.EntryExistsException in project druid by druid-io.

the class RealtimeIndexTaskTest method makeToolbox.

private TaskToolbox makeToolbox(final Task task, final TaskStorage taskStorage, final IndexerMetadataStorageCoordinator mdc, final File directory) {
    final TaskConfig taskConfig = new TaskConfig(directory.getPath(), null, null, 50000, null, false, null, null);
    final TaskLockbox taskLockbox = new TaskLockbox(taskStorage);
    try {
        taskStorage.insert(task, TaskStatus.running(task.getId()));
    } catch (EntryExistsException e) {
    // suppress
    }
    taskLockbox.syncFromStorage();
    final TaskActionToolbox taskActionToolbox = new TaskActionToolbox(taskLockbox, mdc, emitter, EasyMock.createMock(SupervisorManager.class));
    final TaskActionClientFactory taskActionClientFactory = new LocalTaskActionClientFactory(taskStorage, taskActionToolbox);
    final QueryRunnerFactoryConglomerate conglomerate = new DefaultQueryRunnerFactoryConglomerate(ImmutableMap.<Class<? extends Query>, QueryRunnerFactory>of(TimeseriesQuery.class, new TimeseriesQueryRunnerFactory(new TimeseriesQueryQueryToolChest(new IntervalChunkingQueryRunnerDecorator(null, null, null) {

        @Override
        public <T> QueryRunner<T> decorate(QueryRunner<T> delegate, QueryToolChest<T, ? extends Query<T>> toolChest) {
            return delegate;
        }
    }), new TimeseriesQueryEngine(), new QueryWatcher() {

        @Override
        public void registerQuery(Query query, ListenableFuture future) {
        // do nothing
        }
    })));
    handOffCallbacks = Maps.newConcurrentMap();
    final SegmentHandoffNotifierFactory handoffNotifierFactory = new SegmentHandoffNotifierFactory() {

        @Override
        public SegmentHandoffNotifier createSegmentHandoffNotifier(String dataSource) {
            return new SegmentHandoffNotifier() {

                @Override
                public boolean registerSegmentHandoffCallback(SegmentDescriptor descriptor, Executor exec, Runnable handOffRunnable) {
                    handOffCallbacks.put(descriptor, new Pair<>(exec, handOffRunnable));
                    return true;
                }

                @Override
                public void start() {
                //Noop
                }

                @Override
                public void close() {
                //Noop
                }

                Map<SegmentDescriptor, Pair<Executor, Runnable>> getHandOffCallbacks() {
                    return handOffCallbacks;
                }
            };
        }
    };
    final TestUtils testUtils = new TestUtils();
    final TaskToolboxFactory toolboxFactory = new TaskToolboxFactory(taskConfig, taskActionClientFactory, emitter, new TestDataSegmentPusher(), new TestDataSegmentKiller(), // DataSegmentMover
    null, // DataSegmentArchiver
    null, new TestDataSegmentAnnouncer(), handoffNotifierFactory, conglomerate, // queryExecutorService
    MoreExecutors.sameThreadExecutor(), EasyMock.createMock(MonitorScheduler.class), new SegmentLoaderFactory(new SegmentLoaderLocalCacheManager(null, new SegmentLoaderConfig() {

        @Override
        public List<StorageLocationConfig> getLocations() {
            return Lists.newArrayList();
        }
    }, testUtils.getTestObjectMapper())), testUtils.getTestObjectMapper(), testUtils.getTestIndexMerger(), testUtils.getTestIndexIO(), MapCache.create(1024), new CacheConfig(), testUtils.getTestIndexMergerV9());
    return toolboxFactory.build(task);
}
Also used : TimeseriesQuery(io.druid.query.timeseries.TimeseriesQuery) Query(io.druid.query.Query) QueryWatcher(io.druid.query.QueryWatcher) LocalTaskActionClientFactory(io.druid.indexing.common.actions.LocalTaskActionClientFactory) TaskActionClientFactory(io.druid.indexing.common.actions.TaskActionClientFactory) TestDataSegmentAnnouncer(io.druid.indexing.test.TestDataSegmentAnnouncer) TaskConfig(io.druid.indexing.common.config.TaskConfig) TimeseriesQueryQueryToolChest(io.druid.query.timeseries.TimeseriesQueryQueryToolChest) QueryToolChest(io.druid.query.QueryToolChest) TimeseriesQueryQueryToolChest(io.druid.query.timeseries.TimeseriesQueryQueryToolChest) TestUtils(io.druid.indexing.common.TestUtils) DefaultQueryRunnerFactoryConglomerate(io.druid.query.DefaultQueryRunnerFactoryConglomerate) QueryRunnerFactoryConglomerate(io.druid.query.QueryRunnerFactoryConglomerate) TimeseriesQueryEngine(io.druid.query.timeseries.TimeseriesQueryEngine) Executor(java.util.concurrent.Executor) TaskToolboxFactory(io.druid.indexing.common.TaskToolboxFactory) SegmentDescriptor(io.druid.query.SegmentDescriptor) TaskActionToolbox(io.druid.indexing.common.actions.TaskActionToolbox) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LocalTaskActionClientFactory(io.druid.indexing.common.actions.LocalTaskActionClientFactory) IntervalChunkingQueryRunnerDecorator(io.druid.query.IntervalChunkingQueryRunnerDecorator) SegmentLoaderConfig(io.druid.segment.loading.SegmentLoaderConfig) SegmentLoaderFactory(io.druid.indexing.common.SegmentLoaderFactory) SegmentLoaderLocalCacheManager(io.druid.segment.loading.SegmentLoaderLocalCacheManager) CacheConfig(io.druid.client.cache.CacheConfig) TestDataSegmentPusher(io.druid.indexing.test.TestDataSegmentPusher) Pair(io.druid.java.util.common.Pair) TimeseriesQuery(io.druid.query.timeseries.TimeseriesQuery) MonitorScheduler(com.metamx.metrics.MonitorScheduler) SegmentHandoffNotifier(io.druid.segment.realtime.plumber.SegmentHandoffNotifier) DefaultQueryRunnerFactoryConglomerate(io.druid.query.DefaultQueryRunnerFactoryConglomerate) EntryExistsException(io.druid.metadata.EntryExistsException) QueryRunner(io.druid.query.QueryRunner) TestDataSegmentKiller(io.druid.indexing.test.TestDataSegmentKiller) SegmentHandoffNotifierFactory(io.druid.segment.realtime.plumber.SegmentHandoffNotifierFactory) SupervisorManager(io.druid.indexing.overlord.supervisor.SupervisorManager) TimeseriesQueryRunnerFactory(io.druid.query.timeseries.TimeseriesQueryRunnerFactory) TaskLockbox(io.druid.indexing.overlord.TaskLockbox) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 4 with EntryExistsException

use of io.druid.metadata.EntryExistsException in project druid by druid-io.

the class MetadataTaskStorage method insert.

@Override
public void insert(final Task task, final TaskStatus status) throws EntryExistsException {
    Preconditions.checkNotNull(task, "task");
    Preconditions.checkNotNull(status, "status");
    Preconditions.checkArgument(task.getId().equals(status.getId()), "Task/Status ID mismatch[%s/%s]", task.getId(), status.getId());
    log.info("Inserting task %s with status: %s", task.getId(), status);
    try {
        handler.insert(task.getId(), new DateTime(), task.getDataSource(), task, status.isRunnable(), status);
    } catch (Exception e) {
        if (e instanceof EntryExistsException) {
            throw (EntryExistsException) e;
        } else {
            Throwables.propagate(e);
        }
    }
}
Also used : EntryExistsException(io.druid.metadata.EntryExistsException) DateTime(org.joda.time.DateTime) EntryExistsException(io.druid.metadata.EntryExistsException)

Example 5 with EntryExistsException

use of io.druid.metadata.EntryExistsException in project druid by druid-io.

the class KafkaSupervisor method createKafkaTasksForGroup.

private void createKafkaTasksForGroup(int groupId, int replicas) {
    Map<Integer, Long> startPartitions = taskGroups.get(groupId).partitionOffsets;
    Map<Integer, Long> endPartitions = new HashMap<>();
    for (Integer partition : startPartitions.keySet()) {
        endPartitions.put(partition, Long.MAX_VALUE);
    }
    String sequenceName = generateSequenceName(groupId);
    Map<String, String> consumerProperties = Maps.newHashMap(ioConfig.getConsumerProperties());
    DateTime minimumMessageTime = taskGroups.get(groupId).minimumMessageTime.orNull();
    KafkaIOConfig kafkaIOConfig = new KafkaIOConfig(sequenceName, new KafkaPartitions(ioConfig.getTopic(), startPartitions), new KafkaPartitions(ioConfig.getTopic(), endPartitions), consumerProperties, true, false, minimumMessageTime);
    for (int i = 0; i < replicas; i++) {
        String taskId = Joiner.on("_").join(sequenceName, getRandomId());
        KafkaIndexTask indexTask = new KafkaIndexTask(taskId, new TaskResource(sequenceName, 1), spec.getDataSchema(), taskTuningConfig, kafkaIOConfig, spec.getContext(), null);
        Optional<TaskQueue> taskQueue = taskMaster.getTaskQueue();
        if (taskQueue.isPresent()) {
            try {
                taskQueue.get().add(indexTask);
            } catch (EntryExistsException e) {
                log.error("Tried to add task [%s] but it already exists", indexTask.getId());
            }
        } else {
            log.error("Failed to get task queue because I'm not the leader!");
        }
    }
}
Also used : TaskResource(io.druid.indexing.common.task.TaskResource) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) KafkaPartitions(io.druid.indexing.kafka.KafkaPartitions) EntryExistsException(io.druid.metadata.EntryExistsException) DateTime(org.joda.time.DateTime) KafkaIndexTask(io.druid.indexing.kafka.KafkaIndexTask) KafkaIOConfig(io.druid.indexing.kafka.KafkaIOConfig) TaskQueue(io.druid.indexing.overlord.TaskQueue)

Aggregations

EntryExistsException (io.druid.metadata.EntryExistsException)5 TaskQueue (io.druid.indexing.overlord.TaskQueue)2 DateTime (org.joda.time.DateTime)2 ImmutableList (com.google.common.collect.ImmutableList)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MonitorScheduler (com.metamx.metrics.MonitorScheduler)1 CacheConfig (io.druid.client.cache.CacheConfig)1 SegmentLoaderFactory (io.druid.indexing.common.SegmentLoaderFactory)1 TaskStatus (io.druid.indexing.common.TaskStatus)1 TaskToolbox (io.druid.indexing.common.TaskToolbox)1 TaskToolboxFactory (io.druid.indexing.common.TaskToolboxFactory)1 TestUtils (io.druid.indexing.common.TestUtils)1 LocalTaskActionClientFactory (io.druid.indexing.common.actions.LocalTaskActionClientFactory)1 TaskActionClientFactory (io.druid.indexing.common.actions.TaskActionClientFactory)1 TaskActionToolbox (io.druid.indexing.common.actions.TaskActionToolbox)1 TaskConfig (io.druid.indexing.common.config.TaskConfig)1 TaskResource (io.druid.indexing.common.task.TaskResource)1 KafkaIOConfig (io.druid.indexing.kafka.KafkaIOConfig)1 KafkaIndexTask (io.druid.indexing.kafka.KafkaIndexTask)1 KafkaPartitions (io.druid.indexing.kafka.KafkaPartitions)1