Search in sources :

Example 1 with TaskRunner

use of org.apache.druid.indexing.overlord.TaskRunner in project druid by druid-io.

the class OverlordResource method getTotalWorkerCapacity.

/**
 * Gets the total worker capacity of varies states of the cluster.
 */
@GET
@Path("/totalWorkerCapacity")
@Produces(MediaType.APPLICATION_JSON)
@ResourceFilters(ConfigResourceFilter.class)
public Response getTotalWorkerCapacity() {
    // Calculate current cluster capacity
    int currentCapacity;
    Optional<TaskRunner> taskRunnerOptional = taskMaster.getTaskRunner();
    if (!taskRunnerOptional.isPresent()) {
        // Cannot serve call as not leader
        return Response.status(Response.Status.SERVICE_UNAVAILABLE).build();
    }
    TaskRunner taskRunner = taskRunnerOptional.get();
    Collection<ImmutableWorkerInfo> workers;
    if (taskRunner instanceof WorkerTaskRunner) {
        workers = ((WorkerTaskRunner) taskRunner).getWorkers();
        currentCapacity = workers.stream().mapToInt(workerInfo -> workerInfo.getWorker().getCapacity()).sum();
    } else {
        log.debug("Cannot calculate capacity as task runner [%s] of type [%s] does not support listing workers", taskRunner, taskRunner.getClass().getName());
        workers = ImmutableList.of();
        currentCapacity = -1;
    }
    // Calculate maximum capacity with auto scale
    int maximumCapacity;
    if (workerConfigRef == null) {
        workerConfigRef = configManager.watch(WorkerBehaviorConfig.CONFIG_KEY, WorkerBehaviorConfig.class);
    }
    WorkerBehaviorConfig workerBehaviorConfig = workerConfigRef.get();
    if (workerBehaviorConfig == null) {
        // Auto scale not setup
        log.debug("Cannot calculate maximum worker capacity as worker behavior config is not configured");
        maximumCapacity = -1;
    } else if (workerBehaviorConfig instanceof DefaultWorkerBehaviorConfig) {
        DefaultWorkerBehaviorConfig defaultWorkerBehaviorConfig = (DefaultWorkerBehaviorConfig) workerBehaviorConfig;
        if (defaultWorkerBehaviorConfig.getAutoScaler() == null) {
            // Auto scale not setup
            log.debug("Cannot calculate maximum worker capacity as auto scaler not configured");
            maximumCapacity = -1;
        } else {
            int maxWorker = defaultWorkerBehaviorConfig.getAutoScaler().getMaxNumWorkers();
            int expectedWorkerCapacity = provisioningStrategy.getExpectedWorkerCapacity(workers);
            maximumCapacity = expectedWorkerCapacity == -1 ? -1 : maxWorker * expectedWorkerCapacity;
        }
    } else {
        // Auto scale is not using DefaultWorkerBehaviorConfig
        log.debug("Cannot calculate maximum worker capacity as WorkerBehaviorConfig [%s] of type [%s] does not support getting max capacity", workerBehaviorConfig, workerBehaviorConfig.getClass().getSimpleName());
        maximumCapacity = -1;
    }
    return Response.ok(new TotalWorkerCapacityResponse(currentCapacity, maximumCapacity)).build();
}
Also used : WorkerBehaviorConfig(org.apache.druid.indexing.overlord.setup.WorkerBehaviorConfig) DefaultWorkerBehaviorConfig(org.apache.druid.indexing.overlord.setup.DefaultWorkerBehaviorConfig) WorkerTaskRunner(org.apache.druid.indexing.overlord.WorkerTaskRunner) DefaultWorkerBehaviorConfig(org.apache.druid.indexing.overlord.setup.DefaultWorkerBehaviorConfig) ImmutableWorkerInfo(org.apache.druid.indexing.overlord.ImmutableWorkerInfo) TaskRunner(org.apache.druid.indexing.overlord.TaskRunner) WorkerTaskRunner(org.apache.druid.indexing.overlord.WorkerTaskRunner) Path(javax.ws.rs.Path) ResourceFilters(com.sun.jersey.spi.container.ResourceFilters) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with TaskRunner

use of org.apache.druid.indexing.overlord.TaskRunner in project druid by druid-io.

the class KafkaSupervisorTest method setupTest.

@Before
public void setupTest() {
    taskStorage = createMock(TaskStorage.class);
    taskMaster = createMock(TaskMaster.class);
    taskRunner = createMock(TaskRunner.class);
    indexerMetadataStorageCoordinator = createMock(IndexerMetadataStorageCoordinator.class);
    taskClient = createMock(KafkaIndexTaskClient.class);
    taskQueue = createMock(TaskQueue.class);
    topic = getTopic();
    rowIngestionMetersFactory = new TestUtils().getRowIngestionMetersFactory();
    serviceEmitter = new ExceptionCapturingServiceEmitter();
    EmittingLogger.registerEmitter(serviceEmitter);
    supervisorConfig = new SupervisorStateManagerConfig();
    ingestionSchema = EasyMock.createMock(KafkaSupervisorIngestionSpec.class);
}
Also used : IndexerMetadataStorageCoordinator(org.apache.druid.indexing.overlord.IndexerMetadataStorageCoordinator) TestUtils(org.apache.druid.indexing.common.TestUtils) TaskStorage(org.apache.druid.indexing.overlord.TaskStorage) SupervisorStateManagerConfig(org.apache.druid.indexing.overlord.supervisor.SupervisorStateManagerConfig) KafkaIndexTaskClient(org.apache.druid.indexing.kafka.KafkaIndexTaskClient) TaskQueue(org.apache.druid.indexing.overlord.TaskQueue) TaskMaster(org.apache.druid.indexing.overlord.TaskMaster) ExceptionCapturingServiceEmitter(org.apache.druid.server.metrics.ExceptionCapturingServiceEmitter) TaskRunner(org.apache.druid.indexing.overlord.TaskRunner) Before(org.junit.Before)

Example 3 with TaskRunner

use of org.apache.druid.indexing.overlord.TaskRunner in project druid by druid-io.

the class KinesisSupervisorTest method setupTest.

@Before
public void setupTest() {
    taskStorage = createMock(TaskStorage.class);
    taskMaster = createMock(TaskMaster.class);
    taskRunner = createMock(TaskRunner.class);
    indexerMetadataStorageCoordinator = createMock(IndexerMetadataStorageCoordinator.class);
    taskClient = createMock(KinesisIndexTaskClient.class);
    taskQueue = createMock(TaskQueue.class);
    supervisorRecordSupplier = createMock(KinesisRecordSupplier.class);
    tuningConfig = new KinesisSupervisorTuningConfig(null, 1000, null, null, 50000, null, new Period("P1Y"), new File("/test"), null, null, null, false, null, null, null, null, numThreads, TEST_CHAT_THREADS, TEST_CHAT_RETRIES, TEST_HTTP_TIMEOUT, TEST_SHUTDOWN_TIMEOUT, null, null, null, 5000, null, null, null, null, null, null, null, null, null);
    rowIngestionMetersFactory = new TestUtils().getRowIngestionMetersFactory();
    serviceEmitter = new ExceptionCapturingServiceEmitter();
    EmittingLogger.registerEmitter(serviceEmitter);
    supervisorConfig = new SupervisorStateManagerConfig();
}
Also used : IndexerMetadataStorageCoordinator(org.apache.druid.indexing.overlord.IndexerMetadataStorageCoordinator) KinesisRecordSupplier(org.apache.druid.indexing.kinesis.KinesisRecordSupplier) KinesisIndexTaskClient(org.apache.druid.indexing.kinesis.KinesisIndexTaskClient) Period(org.joda.time.Period) TaskRunner(org.apache.druid.indexing.overlord.TaskRunner) SeekableStreamIndexTaskRunner(org.apache.druid.indexing.seekablestream.SeekableStreamIndexTaskRunner) TestUtils(org.apache.druid.indexing.common.TestUtils) TaskStorage(org.apache.druid.indexing.overlord.TaskStorage) SupervisorStateManagerConfig(org.apache.druid.indexing.overlord.supervisor.SupervisorStateManagerConfig) TaskQueue(org.apache.druid.indexing.overlord.TaskQueue) TaskMaster(org.apache.druid.indexing.overlord.TaskMaster) File(java.io.File) ExceptionCapturingServiceEmitter(org.apache.druid.server.metrics.ExceptionCapturingServiceEmitter) Before(org.junit.Before)

Example 4 with TaskRunner

use of org.apache.druid.indexing.overlord.TaskRunner in project druid by druid-io.

the class SeekableStreamSupervisor method possiblyRegisterListener.

private void possiblyRegisterListener() {
    if (listenerRegistered) {
        return;
    }
    Optional<TaskRunner> taskRunner = taskMaster.getTaskRunner();
    if (taskRunner.isPresent()) {
        taskRunner.get().registerListener(new TaskRunnerListener() {

            @Override
            public String getListenerId() {
                return supervisorId;
            }

            @Override
            public void locationChanged(final String taskId, final TaskLocation newLocation) {
            // do nothing
            }

            @Override
            public void statusChanged(String taskId, TaskStatus status) {
                addNotice(new RunNotice());
            }
        }, Execs.directExecutor());
        listenerRegistered = true;
    }
}
Also used : TaskRunnerListener(org.apache.druid.indexing.overlord.TaskRunnerListener) TaskStatus(org.apache.druid.indexer.TaskStatus) TaskLocation(org.apache.druid.indexer.TaskLocation) TaskRunner(org.apache.druid.indexing.overlord.TaskRunner) SeekableStreamIndexTaskRunner(org.apache.druid.indexing.seekablestream.SeekableStreamIndexTaskRunner)

Example 5 with TaskRunner

use of org.apache.druid.indexing.overlord.TaskRunner in project druid by druid-io.

the class OverlordResource method filterActiveTasks.

private List<AnyTask> filterActiveTasks(RunnerTaskState state, List<AnyTask> allTasks) {
    // divide active tasks into 3 lists : running, pending, waiting
    Optional<TaskRunner> taskRunnerOpt = taskMaster.getTaskRunner();
    if (!taskRunnerOpt.isPresent()) {
        throw new WebApplicationException(Response.serverError().entity("No task runner found").build());
    }
    TaskRunner runner = taskRunnerOpt.get();
    // counted twice but never skipped
    if (RunnerTaskState.WAITING.equals(state)) {
        Collection<? extends TaskRunnerWorkItem> runnersKnownTasks = runner.getKnownTasks();
        Set<String> runnerKnownTaskIds = runnersKnownTasks.stream().map(TaskRunnerWorkItem::getTaskId).collect(Collectors.toSet());
        final List<AnyTask> waitingTasks = new ArrayList<>();
        for (TaskRunnerWorkItem task : allTasks) {
            if (!runnerKnownTaskIds.contains(task.getTaskId())) {
                waitingTasks.add(((AnyTask) task).withTaskState(TaskState.RUNNING, RunnerTaskState.WAITING, task.getCreatedTime(), task.getQueueInsertionTime(), task.getLocation()));
            }
        }
        return waitingTasks;
    }
    if (RunnerTaskState.PENDING.equals(state)) {
        Collection<? extends TaskRunnerWorkItem> knownPendingTasks = runner.getPendingTasks();
        Set<String> pendingTaskIds = knownPendingTasks.stream().map(TaskRunnerWorkItem::getTaskId).collect(Collectors.toSet());
        Map<String, TaskRunnerWorkItem> workItemIdMap = knownPendingTasks.stream().collect(Collectors.toMap(TaskRunnerWorkItem::getTaskId, java.util.function.Function.identity(), (previousWorkItem, newWorkItem) -> newWorkItem));
        final List<AnyTask> pendingTasks = new ArrayList<>();
        for (TaskRunnerWorkItem task : allTasks) {
            if (pendingTaskIds.contains(task.getTaskId())) {
                pendingTasks.add(((AnyTask) task).withTaskState(TaskState.RUNNING, RunnerTaskState.PENDING, workItemIdMap.get(task.getTaskId()).getCreatedTime(), workItemIdMap.get(task.getTaskId()).getQueueInsertionTime(), workItemIdMap.get(task.getTaskId()).getLocation()));
            }
        }
        return pendingTasks;
    }
    if (RunnerTaskState.RUNNING.equals(state)) {
        Collection<? extends TaskRunnerWorkItem> knownRunningTasks = runner.getRunningTasks();
        Set<String> runningTaskIds = knownRunningTasks.stream().map(TaskRunnerWorkItem::getTaskId).collect(Collectors.toSet());
        Map<String, TaskRunnerWorkItem> workItemIdMap = knownRunningTasks.stream().collect(Collectors.toMap(TaskRunnerWorkItem::getTaskId, java.util.function.Function.identity(), (previousWorkItem, newWorkItem) -> newWorkItem));
        final List<AnyTask> runningTasks = new ArrayList<>();
        for (TaskRunnerWorkItem task : allTasks) {
            if (runningTaskIds.contains(task.getTaskId())) {
                runningTasks.add(((AnyTask) task).withTaskState(TaskState.RUNNING, RunnerTaskState.RUNNING, workItemIdMap.get(task.getTaskId()).getCreatedTime(), workItemIdMap.get(task.getTaskId()).getQueueInsertionTime(), workItemIdMap.get(task.getTaskId()).getLocation()));
            }
        }
        return runningTasks;
    }
    return allTasks;
}
Also used : Produces(javax.ws.rs.Produces) AuthorizerMapper(org.apache.druid.server.security.AuthorizerMapper) TaskLogStreamer(org.apache.druid.tasklogs.TaskLogStreamer) Inject(com.google.inject.Inject) Path(javax.ws.rs.Path) ResourceFilters(com.sun.jersey.spi.container.ResourceFilters) JacksonConfigManager(org.apache.druid.common.config.JacksonConfigManager) SettableFuture(com.google.common.util.concurrent.SettableFuture) TaskStorageQueryAdapter(org.apache.druid.indexing.overlord.TaskStorageQueryAdapter) HttpMediaType(org.apache.druid.server.http.HttpMediaType) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) TaskActionClient(org.apache.druid.indexing.common.actions.TaskActionClient) Consumes(javax.ws.rs.Consumes) TaskQueue(org.apache.druid.indexing.overlord.TaskQueue) Optional(com.google.common.base.Optional) Task(org.apache.druid.indexing.common.task.Task) TaskRunner(org.apache.druid.indexing.overlord.TaskRunner) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) ForbiddenException(org.apache.druid.server.security.ForbiddenException) TaskResourceFilter(org.apache.druid.indexing.overlord.http.security.TaskResourceFilter) DELETE(javax.ws.rs.DELETE) WorkerBehaviorConfig(org.apache.druid.indexing.overlord.setup.WorkerBehaviorConfig) DateTimes(org.apache.druid.java.util.common.DateTimes) Function(com.google.common.base.Function) Context(javax.ws.rs.core.Context) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) StringUtils(org.apache.druid.java.util.common.StringUtils) Set(java.util.Set) Action(org.apache.druid.server.security.Action) IndexerMetadataStorageAdapter(org.apache.druid.indexing.overlord.IndexerMetadataStorageAdapter) Collectors(java.util.stream.Collectors) AuditManager(org.apache.druid.audit.AuditManager) TaskStatusPlus(org.apache.druid.indexer.TaskStatusPlus) DatasourceResourceFilter(org.apache.druid.server.http.security.DatasourceResourceFilter) TaskState(org.apache.druid.indexer.TaskState) List(java.util.List) Response(javax.ws.rs.core.Response) ClientTaskQuery(org.apache.druid.client.indexing.ClientTaskQuery) AuditEntry(org.apache.druid.audit.AuditEntry) DataSegment(org.apache.druid.timeline.DataSegment) WebApplicationException(javax.ws.rs.WebApplicationException) TaskMaster(org.apache.druid.indexing.overlord.TaskMaster) Logger(org.apache.druid.java.util.common.logger.Logger) SetResult(org.apache.druid.common.config.ConfigManager.SetResult) TaskActionHolder(org.apache.druid.indexing.common.actions.TaskActionHolder) AuditInfo(org.apache.druid.audit.AuditInfo) PathParam(javax.ws.rs.PathParam) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Intervals(org.apache.druid.java.util.common.Intervals) GET(javax.ws.rs.GET) Duration(org.joda.time.Duration) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) TaskStatus(org.apache.druid.indexer.TaskStatus) WorkerTaskRunnerQueryAdapter(org.apache.druid.indexing.overlord.WorkerTaskRunnerQueryAdapter) ScalingStats(org.apache.druid.indexing.overlord.autoscaling.ScalingStats) ArrayList(java.util.ArrayList) EntryExistsException(org.apache.druid.metadata.EntryExistsException) Interval(org.joda.time.Interval) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) DefaultWorkerBehaviorConfig(org.apache.druid.indexing.overlord.setup.DefaultWorkerBehaviorConfig) ByteSource(com.google.common.io.ByteSource) Status(javax.ws.rs.core.Response.Status) StateResourceFilter(org.apache.druid.server.http.security.StateResourceFilter) Nullable(javax.annotation.Nullable) ImmutableWorkerInfo(org.apache.druid.indexing.overlord.ImmutableWorkerInfo) Access(org.apache.druid.server.security.Access) POST(javax.ws.rs.POST) TaskInfo(org.apache.druid.indexer.TaskInfo) ResourceType(org.apache.druid.server.security.ResourceType) DateTime(org.joda.time.DateTime) TaskLocation(org.apache.druid.indexer.TaskLocation) WorkerTaskRunner(org.apache.druid.indexing.overlord.WorkerTaskRunner) ConfigResourceFilter(org.apache.druid.server.http.security.ConfigResourceFilter) AuthorizationUtils(org.apache.druid.server.security.AuthorizationUtils) Maps(com.google.common.collect.Maps) RunnerTaskState(org.apache.druid.indexer.RunnerTaskState) ProvisioningStrategy(org.apache.druid.indexing.overlord.autoscaling.ProvisioningStrategy) Resource(org.apache.druid.server.security.Resource) ResourceAction(org.apache.druid.server.security.ResourceAction) TaskRunnerWorkItem(org.apache.druid.indexing.overlord.TaskRunnerWorkItem) Collections(java.util.Collections) TaskRunnerWorkItem(org.apache.druid.indexing.overlord.TaskRunnerWorkItem) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) TaskRunner(org.apache.druid.indexing.overlord.TaskRunner) WorkerTaskRunner(org.apache.druid.indexing.overlord.WorkerTaskRunner)

Aggregations

TaskRunner (org.apache.druid.indexing.overlord.TaskRunner)8 TaskMaster (org.apache.druid.indexing.overlord.TaskMaster)5 TaskQueue (org.apache.druid.indexing.overlord.TaskQueue)4 WorkerTaskRunner (org.apache.druid.indexing.overlord.WorkerTaskRunner)4 Before (org.junit.Before)4 ResourceFilters (com.sun.jersey.spi.container.ResourceFilters)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 TaskStatus (org.apache.druid.indexer.TaskStatus)3 TestUtils (org.apache.druid.indexing.common.TestUtils)3 IndexerMetadataStorageCoordinator (org.apache.druid.indexing.overlord.IndexerMetadataStorageCoordinator)3 TaskStorage (org.apache.druid.indexing.overlord.TaskStorage)3 SupervisorStateManagerConfig (org.apache.druid.indexing.overlord.supervisor.SupervisorStateManagerConfig)3 SeekableStreamIndexTaskRunner (org.apache.druid.indexing.seekablestream.SeekableStreamIndexTaskRunner)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Response (javax.ws.rs.core.Response)2 Status (javax.ws.rs.core.Response.Status)2 JacksonConfigManager (org.apache.druid.common.config.JacksonConfigManager)2 TaskLocation (org.apache.druid.indexer.TaskLocation)2