Search in sources :

Example 31 with ImmutableWorkerInfo

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

the class HttpRemoteTaskRunner method getIdleTaskSlotCount.

@Override
public Map<String, Long> getIdleTaskSlotCount() {
    Map<String, Long> totalIdlePeons = new HashMap<>();
    for (ImmutableWorkerInfo worker : getWorkersEligibleToRunTasks().values()) {
        String workerCategory = worker.getWorker().getCategory();
        int workerAvailableCapacity = worker.getAvailableCapacity();
        totalIdlePeons.compute(workerCategory, (category, availableCapacity) -> availableCapacity == null ? workerAvailableCapacity : availableCapacity + workerAvailableCapacity);
    }
    return totalIdlePeons;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ImmutableWorkerInfo(org.apache.druid.indexing.overlord.ImmutableWorkerInfo)

Example 32 with ImmutableWorkerInfo

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

the class HttpRemoteTaskRunner method getBlacklistedTaskSlotCount.

@Override
public Map<String, Long> getBlacklistedTaskSlotCount() {
    Map<String, Long> totalBlacklistedPeons = new HashMap<>();
    for (ImmutableWorkerInfo worker : getBlackListedWorkers()) {
        String workerCategory = worker.getWorker().getCategory();
        int workerBlacklistedPeons = worker.getWorker().getCapacity();
        totalBlacklistedPeons.compute(workerCategory, (category, blacklistedPeons) -> blacklistedPeons == null ? workerBlacklistedPeons : blacklistedPeons + workerBlacklistedPeons);
    }
    return totalBlacklistedPeons;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ImmutableWorkerInfo(org.apache.druid.indexing.overlord.ImmutableWorkerInfo)

Example 33 with ImmutableWorkerInfo

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

the class HttpRemoteTaskRunner method getUsedTaskSlotCount.

@Override
public Map<String, Long> getUsedTaskSlotCount() {
    Map<String, Long> totalUsedPeons = new HashMap<>();
    for (ImmutableWorkerInfo worker : getWorkers()) {
        String workerCategory = worker.getWorker().getCategory();
        int workerUsedCapacity = worker.getCurrCapacityUsed();
        totalUsedPeons.compute(workerCategory, (category, usedCapacity) -> usedCapacity == null ? workerUsedCapacity : usedCapacity + workerUsedCapacity);
    }
    return totalUsedPeons;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ImmutableWorkerInfo(org.apache.druid.indexing.overlord.ImmutableWorkerInfo)

Example 34 with ImmutableWorkerInfo

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

the class WorkerSelectUtils method selectWorker.

/**
 * Helper for {@link WorkerSelectStrategy} implementations.
 *
 * @param allWorkers     map of all workers, in the style provided to {@link WorkerSelectStrategy}
 * @param affinityConfig affinity config, or null
 * @param workerSelector function that receives a list of eligible workers: version is high enough, worker can run
 *                       the task, and worker satisfies the affinity config. may return null.
 *
 * @return selected worker from "allWorkers", or null.
 */
@Nullable
public static ImmutableWorkerInfo selectWorker(final Task task, final Map<String, ImmutableWorkerInfo> allWorkers, final WorkerTaskRunnerConfig workerTaskRunnerConfig, @Nullable final AffinityConfig affinityConfig, final Function<ImmutableMap<String, ImmutableWorkerInfo>, ImmutableWorkerInfo> workerSelector) {
    final Map<String, ImmutableWorkerInfo> runnableWorkers = getRunnableWorkers(task, allWorkers, workerTaskRunnerConfig);
    if (affinityConfig == null) {
        // All runnable workers are valid.
        return workerSelector.apply(ImmutableMap.copyOf(runnableWorkers));
    } else {
        // Workers assigned to the affinity pool for our task.
        final Set<String> dataSourceWorkers = affinityConfig.getAffinity().get(task.getDataSource());
        if (dataSourceWorkers == null) {
            // No affinity config for this dataSource; use non-affinity workers.
            return workerSelector.apply(getNonAffinityWorkers(affinityConfig, runnableWorkers));
        } else {
            // Get runnable, affinity workers.
            final ImmutableMap<String, ImmutableWorkerInfo> dataSourceWorkerMap = ImmutableMap.copyOf(Maps.filterKeys(runnableWorkers, dataSourceWorkers::contains));
            final ImmutableWorkerInfo selected = workerSelector.apply(dataSourceWorkerMap);
            if (selected != null) {
                return selected;
            } else if (affinityConfig.isStrong()) {
                return null;
            } else {
                // are available.
                return workerSelector.apply(getNonAffinityWorkers(affinityConfig, runnableWorkers));
            }
        }
    }
}
Also used : ImmutableWorkerInfo(org.apache.druid.indexing.overlord.ImmutableWorkerInfo) Nullable(javax.annotation.Nullable)

Example 35 with ImmutableWorkerInfo

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

the class OverlordResourceTest method testGetTotalWorkerCapacityWithAutoScaleConfiguredAndProvisioningStrategyNotSupportExpectedWorkerCapacity.

@Test
public void testGetTotalWorkerCapacityWithAutoScaleConfiguredAndProvisioningStrategyNotSupportExpectedWorkerCapacity() {
    int invalidExpectedCapacity = -1;
    int maxNumWorkers = 2;
    WorkerTaskRunner workerTaskRunner = EasyMock.createMock(WorkerTaskRunner.class);
    Collection<ImmutableWorkerInfo> workerInfos = ImmutableList.of(new ImmutableWorkerInfo(new Worker("http", "testWorker", "192.0.0.1", 3, "v1", WorkerConfig.DEFAULT_CATEGORY), 2, ImmutableSet.of("grp1", "grp2"), ImmutableSet.of("task1", "task2"), DateTimes.of("2015-01-01T01:01:01Z")));
    EasyMock.expect(workerTaskRunner.getWorkers()).andReturn(workerInfos);
    EasyMock.reset(taskMaster);
    EasyMock.expect(taskMaster.getTaskRunner()).andReturn(Optional.of(workerTaskRunner)).anyTimes();
    EasyMock.expect(provisioningStrategy.getExpectedWorkerCapacity(workerInfos)).andReturn(invalidExpectedCapacity).anyTimes();
    AutoScaler autoScaler = EasyMock.createMock(AutoScaler.class);
    EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(0);
    EasyMock.expect(autoScaler.getMaxNumWorkers()).andReturn(maxNumWorkers);
    DefaultWorkerBehaviorConfig workerBehaviorConfig = new DefaultWorkerBehaviorConfig(null, autoScaler);
    AtomicReference<WorkerBehaviorConfig> workerBehaviorConfigAtomicReference = new AtomicReference<>(workerBehaviorConfig);
    EasyMock.expect(configManager.watch(WorkerBehaviorConfig.CONFIG_KEY, WorkerBehaviorConfig.class)).andReturn(workerBehaviorConfigAtomicReference);
    EasyMock.replay(workerTaskRunner, autoScaler, taskRunner, taskMaster, taskStorageQueryAdapter, indexerMetadataStorageAdapter, req, workerTaskRunnerQueryAdapter, configManager, provisioningStrategy);
    final Response response = overlordResource.getTotalWorkerCapacity();
    Assert.assertEquals(HttpResponseStatus.OK.getCode(), response.getStatus());
    Assert.assertEquals(workerInfos.stream().findFirst().get().getWorker().getCapacity(), ((TotalWorkerCapacityResponse) response.getEntity()).getCurrentClusterCapacity());
    Assert.assertEquals(invalidExpectedCapacity, ((TotalWorkerCapacityResponse) response.getEntity()).getMaximumCapacityWithAutoScale());
}
Also used : Response(javax.ws.rs.core.Response) 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) Worker(org.apache.druid.indexing.worker.Worker) AtomicReference(java.util.concurrent.atomic.AtomicReference) AutoScaler(org.apache.druid.indexing.overlord.autoscaling.AutoScaler) ImmutableWorkerInfo(org.apache.druid.indexing.overlord.ImmutableWorkerInfo) Test(org.junit.Test)

Aggregations

ImmutableWorkerInfo (org.apache.druid.indexing.overlord.ImmutableWorkerInfo)42 Test (org.junit.Test)31 RemoteTaskRunnerConfig (org.apache.druid.indexing.overlord.config.RemoteTaskRunnerConfig)14 Worker (org.apache.druid.indexing.worker.Worker)14 NoopTask (org.apache.druid.indexing.common.task.NoopTask)12 TestRemoteTaskRunnerConfig (org.apache.druid.indexing.overlord.TestRemoteTaskRunnerConfig)5 Period (org.joda.time.Period)5 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 WorkerTaskRunner (org.apache.druid.indexing.overlord.WorkerTaskRunner)3 DefaultWorkerBehaviorConfig (org.apache.druid.indexing.overlord.setup.DefaultWorkerBehaviorConfig)3 WorkerBehaviorConfig (org.apache.druid.indexing.overlord.setup.WorkerBehaviorConfig)3 HashSet (java.util.HashSet)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Nullable (javax.annotation.Nullable)2 Response (javax.ws.rs.core.Response)2 ZkWorker (org.apache.druid.indexing.overlord.ZkWorker)2 AutoScaler (org.apache.druid.indexing.overlord.autoscaling.AutoScaler)2 ResourceFilters (com.sun.jersey.spi.container.ResourceFilters)1 GET (javax.ws.rs.GET)1