Search in sources :

Example 21 with RemoteTaskRunnerConfig

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

the class PendingTaskBasedProvisioningStrategyTest method testProvisionWithPendingTaskAndWorkerCapacityHintSetButEmptyCurrentlyRunningWorkerShouldUseCapcityFromHintConfig.

@Test
public void testProvisionWithPendingTaskAndWorkerCapacityHintSetButEmptyCurrentlyRunningWorkerShouldUseCapcityFromHintConfig() {
    PendingTaskBasedWorkerProvisioningConfig config = new PendingTaskBasedWorkerProvisioningConfig().setMaxScalingDuration(new Period(1000)).setNumEventsToTrack(10).setPendingTaskTimeout(new Period(0)).setWorkerVersion(MIN_VERSION).setMaxScalingStep(2).setWorkerCapacityHint(30);
    strategy = new PendingTaskBasedWorkerProvisioningStrategy(config, DSuppliers.of(workerConfig), new ProvisioningSchedulerConfig(), new Supplier<ScheduledExecutorService>() {

        @Override
        public ScheduledExecutorService get() {
            return executorService;
        }
    });
    EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(0).times(3);
    EasyMock.expect(autoScaler.getMaxNumWorkers()).andReturn(3).times(1);
    EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.anyObject())).andReturn(new ArrayList<String>()).times(2);
    EasyMock.expect(autoScaler.provision()).andReturn(new AutoScalingData(Collections.singletonList("fake"))).times(1);
    RemoteTaskRunner runner = EasyMock.createMock(RemoteTaskRunner.class);
    // two pending tasks
    EasyMock.expect(runner.getPendingTaskPayloads()).andReturn(ImmutableList.of(NoopTask.create(), NoopTask.create())).times(2);
    // No currently running worker node
    EasyMock.expect(runner.getWorkers()).andReturn(Collections.emptyList()).times(2);
    EasyMock.expect(runner.getConfig()).andReturn(new RemoteTaskRunnerConfig()).times(1);
    EasyMock.replay(runner);
    EasyMock.replay(autoScaler);
    Provisioner provisioner = strategy.makeProvisioner(runner);
    boolean provisionedSomething = provisioner.doProvision();
    // Expect to use capacity from workerCapacityHint config (which is 30)
    // and since there are two pending tasks, we will need one more worker
    Assert.assertTrue(provisionedSomething);
    Assert.assertEquals(1, provisioner.getStats().toList().size());
    DateTime createdTime = provisioner.getStats().toList().get(0).getTimestamp();
    Assert.assertEquals(ScalingStats.EVENT.PROVISION, provisioner.getStats().toList().get(0).getEvent());
    provisionedSomething = provisioner.doProvision();
    Assert.assertFalse(provisionedSomething);
    Assert.assertTrue(provisioner.getStats().toList().get(0).getEvent() == ScalingStats.EVENT.PROVISION);
    DateTime anotherCreatedTime = provisioner.getStats().toList().get(0).getTimestamp();
    Assert.assertTrue(createdTime.equals(anotherCreatedTime));
    EasyMock.verify(autoScaler);
    EasyMock.verify(runner);
}
Also used : RemoteTaskRunner(org.apache.druid.indexing.overlord.RemoteTaskRunner) ArrayList(java.util.ArrayList) Period(org.joda.time.Period) Supplier(com.google.common.base.Supplier) RemoteTaskRunnerConfig(org.apache.druid.indexing.overlord.config.RemoteTaskRunnerConfig) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 22 with RemoteTaskRunnerConfig

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

the class PendingTaskBasedProvisioningStrategyTest method testSuccessfulInitialMinWorkersProvision.

@Test
public void testSuccessfulInitialMinWorkersProvision() {
    EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(3).times(2);
    EasyMock.expect(autoScaler.getMaxNumWorkers()).andReturn(5);
    EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.anyObject())).andReturn(new ArrayList<String>());
    RemoteTaskRunner runner = EasyMock.createMock(RemoteTaskRunner.class);
    // No pending tasks
    EasyMock.expect(runner.getPendingTaskPayloads()).andReturn(new ArrayList<>());
    EasyMock.expect(runner.getWorkers()).andReturn(Collections.emptyList());
    EasyMock.expect(runner.getConfig()).andReturn(new RemoteTaskRunnerConfig());
    EasyMock.expect(autoScaler.provision()).andReturn(new AutoScalingData(Collections.singletonList("aNode"))).times(3);
    EasyMock.replay(runner, autoScaler);
    Provisioner provisioner = strategy.makeProvisioner(runner);
    boolean provisionedSomething = provisioner.doProvision();
    Assert.assertTrue(provisionedSomething);
    Assert.assertTrue(provisioner.getStats().toList().size() == 3);
    for (ScalingStats.ScalingEvent event : provisioner.getStats().toList()) {
        Assert.assertTrue(event.getEvent() == ScalingStats.EVENT.PROVISION);
    }
}
Also used : RemoteTaskRunner(org.apache.druid.indexing.overlord.RemoteTaskRunner) RemoteTaskRunnerConfig(org.apache.druid.indexing.overlord.config.RemoteTaskRunnerConfig) Test(org.junit.Test)

Example 23 with RemoteTaskRunnerConfig

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

the class PendingTaskBasedProvisioningStrategyTest method testProvisionAlert.

@Test
public void testProvisionAlert() throws Exception {
    ServiceEmitter emitter = EasyMock.createMock(ServiceEmitter.class);
    EmittingLogger.registerEmitter(emitter);
    emitter.emit(EasyMock.<ServiceEventBuilder>anyObject());
    EasyMock.expectLastCall();
    EasyMock.replay(emitter);
    EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(1).times(3);
    EasyMock.expect(autoScaler.getMaxNumWorkers()).andReturn(2).times(1);
    EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.anyObject())).andReturn(new ArrayList<String>()).times(2);
    EasyMock.expect(autoScaler.terminateWithIds(EasyMock.anyObject())).andReturn(null);
    EasyMock.expect(autoScaler.provision()).andReturn(new AutoScalingData(Collections.singletonList("fake")));
    EasyMock.replay(autoScaler);
    RemoteTaskRunner runner = EasyMock.createMock(RemoteTaskRunner.class);
    EasyMock.expect(runner.getPendingTaskPayloads()).andReturn(Collections.singletonList(NoopTask.create())).times(2);
    EasyMock.expect(runner.getWorkers()).andReturn(Arrays.asList(new TestZkWorker(testTask, "http", "hi", "lo", MIN_VERSION, 1).toImmutable(), // Invalid version node
    new TestZkWorker(testTask, "http", "h1", "n1", INVALID_VERSION).toImmutable(), // Invalid version node
    new TestZkWorker(testTask, "http", "h2", "n1", INVALID_VERSION).toImmutable())).times(2);
    EasyMock.expect(runner.getConfig()).andReturn(new RemoteTaskRunnerConfig());
    EasyMock.replay(runner);
    Provisioner provisioner = strategy.makeProvisioner(runner);
    boolean provisionedSomething = provisioner.doProvision();
    Assert.assertTrue(provisionedSomething);
    Assert.assertTrue(provisioner.getStats().toList().size() == 1);
    DateTime createdTime = provisioner.getStats().toList().get(0).getTimestamp();
    Assert.assertTrue(provisioner.getStats().toList().get(0).getEvent() == ScalingStats.EVENT.PROVISION);
    Thread.sleep(2000);
    provisionedSomething = provisioner.doProvision();
    Assert.assertFalse(provisionedSomething);
    Assert.assertTrue(provisioner.getStats().toList().get(0).getEvent() == ScalingStats.EVENT.PROVISION);
    DateTime anotherCreatedTime = provisioner.getStats().toList().get(0).getTimestamp();
    Assert.assertTrue(createdTime.equals(anotherCreatedTime));
    EasyMock.verify(autoScaler);
    EasyMock.verify(emitter);
    EasyMock.verify(runner);
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) RemoteTaskRunner(org.apache.druid.indexing.overlord.RemoteTaskRunner) ArrayList(java.util.ArrayList) RemoteTaskRunnerConfig(org.apache.druid.indexing.overlord.config.RemoteTaskRunnerConfig) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 24 with RemoteTaskRunnerConfig

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

the class PendingTaskBasedProvisioningStrategyTest method testProvisionWithPendingTaskAndWorkerCapacityHintSetButNonEmptyCurrentlyRunningWorkerShouldUseCapcityFromRunningWorker.

@Test
public void testProvisionWithPendingTaskAndWorkerCapacityHintSetButNonEmptyCurrentlyRunningWorkerShouldUseCapcityFromRunningWorker() {
    PendingTaskBasedWorkerProvisioningConfig config = new PendingTaskBasedWorkerProvisioningConfig().setMaxScalingDuration(new Period(1000)).setNumEventsToTrack(10).setPendingTaskTimeout(new Period(0)).setWorkerVersion(MIN_VERSION).setMaxScalingStep(2).setWorkerCapacityHint(30);
    strategy = new PendingTaskBasedWorkerProvisioningStrategy(config, DSuppliers.of(workerConfig), new ProvisioningSchedulerConfig(), new Supplier<ScheduledExecutorService>() {

        @Override
        public ScheduledExecutorService get() {
            return executorService;
        }
    });
    EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(0).times(3);
    EasyMock.expect(autoScaler.getMaxNumWorkers()).andReturn(3).times(1);
    EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.anyObject())).andReturn(new ArrayList<String>()).times(2);
    EasyMock.expect(autoScaler.provision()).andReturn(new AutoScalingData(Collections.singletonList("fake"))).times(2);
    RemoteTaskRunner runner = EasyMock.createMock(RemoteTaskRunner.class);
    // two pending tasks
    EasyMock.expect(runner.getPendingTaskPayloads()).andReturn(ImmutableList.of(NoopTask.create(), NoopTask.create())).times(2);
    // Capacity for current worker is 1
    EasyMock.expect(runner.getWorkers()).andReturn(Arrays.asList(new TestZkWorker(testTask).toImmutable(), // Invalid version node
    new TestZkWorker(testTask, "http", "h1", "n1", INVALID_VERSION).toImmutable())).times(2);
    EasyMock.expect(runner.getConfig()).andReturn(new RemoteTaskRunnerConfig()).times(1);
    EasyMock.replay(runner);
    EasyMock.replay(autoScaler);
    Provisioner provisioner = strategy.makeProvisioner(runner);
    boolean provisionedSomething = provisioner.doProvision();
    // Expect to use capacity from current worker (which is 1)
    // and since there are two pending tasks, we will need two more workers
    Assert.assertTrue(provisionedSomething);
    Assert.assertEquals(2, provisioner.getStats().toList().size());
    DateTime createdTime = provisioner.getStats().toList().get(0).getTimestamp();
    Assert.assertEquals(ScalingStats.EVENT.PROVISION, provisioner.getStats().toList().get(0).getEvent());
    Assert.assertEquals(ScalingStats.EVENT.PROVISION, provisioner.getStats().toList().get(1).getEvent());
    provisionedSomething = provisioner.doProvision();
    Assert.assertFalse(provisionedSomething);
    Assert.assertTrue(provisioner.getStats().toList().get(0).getEvent() == ScalingStats.EVENT.PROVISION);
    DateTime anotherCreatedTime = provisioner.getStats().toList().get(0).getTimestamp();
    Assert.assertTrue(createdTime.equals(anotherCreatedTime));
    EasyMock.verify(autoScaler);
    EasyMock.verify(runner);
}
Also used : RemoteTaskRunner(org.apache.druid.indexing.overlord.RemoteTaskRunner) ArrayList(java.util.ArrayList) Period(org.joda.time.Period) DateTime(org.joda.time.DateTime) Supplier(com.google.common.base.Supplier) RemoteTaskRunnerConfig(org.apache.druid.indexing.overlord.config.RemoteTaskRunnerConfig) Test(org.junit.Test)

Example 25 with RemoteTaskRunnerConfig

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

the class PendingTaskBasedProvisioningStrategyTest method testProvisionNoCurrentlyRunningWorkerWithCapacityHintSetAndNoPendingTaskShouldNotProvisionAsMinimumIsZero.

@Test
public void testProvisionNoCurrentlyRunningWorkerWithCapacityHintSetAndNoPendingTaskShouldNotProvisionAsMinimumIsZero() {
    PendingTaskBasedWorkerProvisioningConfig config = new PendingTaskBasedWorkerProvisioningConfig().setMaxScalingDuration(new Period(1000)).setNumEventsToTrack(10).setPendingTaskTimeout(new Period(0)).setWorkerVersion(MIN_VERSION).setMaxScalingStep(2).setWorkerCapacityHint(30);
    strategy = new PendingTaskBasedWorkerProvisioningStrategy(config, DSuppliers.of(workerConfig), new ProvisioningSchedulerConfig(), new Supplier<ScheduledExecutorService>() {

        @Override
        public ScheduledExecutorService get() {
            return executorService;
        }
    });
    // minWorkerCount is 0
    EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(0).times(2);
    EasyMock.expect(autoScaler.getMaxNumWorkers()).andReturn(5);
    EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.anyObject())).andReturn(new ArrayList<String>());
    RemoteTaskRunner runner = EasyMock.createMock(RemoteTaskRunner.class);
    // No pending tasks
    EasyMock.expect(runner.getPendingTaskPayloads()).andReturn(new ArrayList<>());
    EasyMock.expect(runner.getWorkers()).andReturn(Collections.emptyList());
    EasyMock.expect(runner.getConfig()).andReturn(new RemoteTaskRunnerConfig());
    EasyMock.replay(runner, autoScaler);
    Provisioner provisioner = strategy.makeProvisioner(runner);
    boolean provisionedSomething = provisioner.doProvision();
    Assert.assertFalse(provisionedSomething);
    Assert.assertEquals(0, provisioner.getStats().toList().size());
}
Also used : RemoteTaskRunner(org.apache.druid.indexing.overlord.RemoteTaskRunner) Period(org.joda.time.Period) Supplier(com.google.common.base.Supplier) RemoteTaskRunnerConfig(org.apache.druid.indexing.overlord.config.RemoteTaskRunnerConfig) Test(org.junit.Test)

Aggregations

RemoteTaskRunnerConfig (org.apache.druid.indexing.overlord.config.RemoteTaskRunnerConfig)32 Test (org.junit.Test)29 ImmutableWorkerInfo (org.apache.druid.indexing.overlord.ImmutableWorkerInfo)14 NoopTask (org.apache.druid.indexing.common.task.NoopTask)12 RemoteTaskRunner (org.apache.druid.indexing.overlord.RemoteTaskRunner)11 Worker (org.apache.druid.indexing.worker.Worker)11 TaskStatus (org.apache.druid.indexer.TaskStatus)5 TestRealtimeTask (org.apache.druid.indexing.common.TestRealtimeTask)5 TaskResource (org.apache.druid.indexing.common.task.TaskResource)5 Supplier (com.google.common.base.Supplier)4 ArrayList (java.util.ArrayList)4 DateTime (org.joda.time.DateTime)4 Period (org.joda.time.Period)4 Function (com.google.common.base.Function)1 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)1 TestingCluster (org.apache.curator.test.TestingCluster)1 PotentiallyGzippedCompressionProvider (org.apache.druid.curator.PotentiallyGzippedCompressionProvider)1 IndexingServiceCondition (org.apache.druid.indexing.common.IndexingServiceCondition)1 WorkerCuratorCoordinator (org.apache.druid.indexing.worker.WorkerCuratorCoordinator)1 ServiceEmitter (org.apache.druid.java.util.emitter.service.ServiceEmitter)1