Search in sources :

Example 1 with Supervisor

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

the class OverlordSecurityResourceFilterTest method setUp.

@Before
public void setUp() {
    if (resourceFilter instanceof TaskResourceFilter && !mockedOnceTsqa) {
        // Since we are creating the mocked tsqa object only once and getting that object from Guice here therefore
        // if the mockedOnce check is not done then we will call EasyMock.expect and EasyMock.replay on the mocked object
        // multiple times and it will throw exceptions
        tsqa = injector.getInstance(TaskStorageQueryAdapter.class);
        EasyMock.expect(tsqa.getTask(EasyMock.anyString())).andReturn(Optional.of(noopTask)).anyTimes();
        EasyMock.replay(tsqa);
        mockedOnceTsqa = true;
    }
    if (resourceFilter instanceof SupervisorResourceFilter && !mockedOnceSM) {
        supervisorManager = injector.getInstance(SupervisorManager.class);
        SupervisorSpec supervisorSpec = new SupervisorSpec() {

            @Override
            public String getId() {
                return "id";
            }

            @Override
            public Supervisor createSupervisor() {
                return null;
            }

            @Override
            public SupervisorTaskAutoScaler createAutoscaler(Supervisor supervisor) {
                return new NoopTaskAutoScaler();
            }

            @Override
            public List<String> getDataSources() {
                return ImmutableList.of("test");
            }

            @Override
            public SupervisorSpec createSuspendedSpec() {
                return null;
            }

            @Override
            public SupervisorSpec createRunningSpec() {
                return null;
            }

            @Override
            public boolean isSuspended() {
                return false;
            }

            @Override
            public String getType() {
                return null;
            }

            @Override
            public String getSource() {
                return null;
            }
        };
        EasyMock.expect(supervisorManager.getSupervisorSpec(EasyMock.anyString())).andReturn(Optional.of(supervisorSpec)).anyTimes();
        EasyMock.replay(supervisorManager);
        mockedOnceSM = true;
    }
    setUp(resourceFilter);
}
Also used : Supervisor(org.apache.druid.indexing.overlord.supervisor.Supervisor) SupervisorManager(org.apache.druid.indexing.overlord.supervisor.SupervisorManager) NoopTaskAutoScaler(org.apache.druid.indexing.seekablestream.supervisor.autoscaler.NoopTaskAutoScaler) TaskStorageQueryAdapter(org.apache.druid.indexing.overlord.TaskStorageQueryAdapter) SupervisorSpec(org.apache.druid.indexing.overlord.supervisor.SupervisorSpec) Before(org.junit.Before)

Example 2 with Supervisor

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

the class NoopSupervisorSpecTest method testNoopSupervisorSpecWithAutoscaler.

@Test
public void testNoopSupervisorSpecWithAutoscaler() {
    Exception e = null;
    try {
        NoopSupervisorSpec noopSupervisorSpec = new NoopSupervisorSpec(null, Collections.singletonList("datasource1"));
        Supervisor supervisor = noopSupervisorSpec.createSupervisor();
        SupervisorTaskAutoScaler autoscaler = noopSupervisorSpec.createAutoscaler(supervisor);
        Assert.assertNull(autoscaler);
        Callable<Integer> noop = new Callable<Integer>() {

            @Override
            public Integer call() {
                return -1;
            }
        };
        int count = supervisor.getActiveTaskGroupsCount();
        Assert.assertEquals(count, -1);
        LagStats lagStats = supervisor.computeLagStats();
        long totalLag = lagStats.getTotalLag();
        long avgLag = lagStats.getAvgLag();
        long maxLag = lagStats.getMaxLag();
        Assert.assertEquals(totalLag, 0);
        Assert.assertEquals(avgLag, 0);
        Assert.assertEquals(maxLag, 0);
    } catch (Exception ex) {
        e = ex;
    }
    Assert.assertNull(e);
}
Also used : Supervisor(org.apache.druid.indexing.overlord.supervisor.Supervisor) NoopSupervisorSpec(org.apache.druid.indexing.overlord.supervisor.NoopSupervisorSpec) SupervisorTaskAutoScaler(org.apache.druid.indexing.overlord.supervisor.autoscaler.SupervisorTaskAutoScaler) LagStats(org.apache.druid.indexing.overlord.supervisor.autoscaler.LagStats) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 3 with Supervisor

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

the class MaterializedViewSupervisorSpecTest method testMaterializedViewSupervisorSpecCreated.

@Test
public void testMaterializedViewSupervisorSpecCreated() {
    Exception ex = null;
    try {
        MaterializedViewSupervisorSpec spec = new MaterializedViewSupervisorSpec("wikiticker", new DimensionsSpec(Lists.newArrayList(new StringDimensionSchema("isUnpatrolled"), new StringDimensionSchema("metroCode"), new StringDimensionSchema("namespace"), new StringDimensionSchema("page"), new StringDimensionSchema("regionIsoCode"), new StringDimensionSchema("regionName"), new StringDimensionSchema("user"))), new AggregatorFactory[] { new CountAggregatorFactory("count"), new LongSumAggregatorFactory("added", "added") }, HadoopTuningConfig.makeDefaultTuningConfig(), null, null, null, null, null, false, objectMapper, null, null, null, null, null, new MaterializedViewTaskConfig(), EasyMock.createMock(AuthorizerMapper.class), new NoopChatHandlerProvider(), new SupervisorStateManagerConfig());
        Supervisor supervisor = spec.createSupervisor();
        Assert.assertTrue(supervisor instanceof MaterializedViewSupervisor);
        SupervisorTaskAutoScaler autoscaler = spec.createAutoscaler(supervisor);
        Assert.assertNull(autoscaler);
        try {
            supervisor.computeLagStats();
        } catch (Exception e) {
            Assert.assertTrue(e instanceof UnsupportedOperationException);
        }
        try {
            int count = supervisor.getActiveTaskGroupsCount();
        } catch (Exception e) {
            Assert.assertTrue(e instanceof UnsupportedOperationException);
        }
        Callable<Integer> noop = new Callable<Integer>() {

            @Override
            public Integer call() {
                return -1;
            }
        };
    } catch (Exception e) {
        ex = e;
    }
    Assert.assertNull(ex);
}
Also used : Supervisor(org.apache.druid.indexing.overlord.supervisor.Supervisor) NoopChatHandlerProvider(org.apache.druid.segment.realtime.firehose.NoopChatHandlerProvider) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) StringDimensionSchema(org.apache.druid.data.input.impl.StringDimensionSchema) SupervisorTaskAutoScaler(org.apache.druid.indexing.overlord.supervisor.autoscaler.SupervisorTaskAutoScaler) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) SupervisorStateManagerConfig(org.apache.druid.indexing.overlord.supervisor.SupervisorStateManagerConfig) DimensionsSpec(org.apache.druid.data.input.impl.DimensionsSpec) AuthorizerMapper(org.apache.druid.server.security.AuthorizerMapper) Test(org.junit.Test)

Aggregations

Supervisor (org.apache.druid.indexing.overlord.supervisor.Supervisor)3 Callable (java.util.concurrent.Callable)2 SupervisorTaskAutoScaler (org.apache.druid.indexing.overlord.supervisor.autoscaler.SupervisorTaskAutoScaler)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 DimensionsSpec (org.apache.druid.data.input.impl.DimensionsSpec)1 StringDimensionSchema (org.apache.druid.data.input.impl.StringDimensionSchema)1 TaskStorageQueryAdapter (org.apache.druid.indexing.overlord.TaskStorageQueryAdapter)1 NoopSupervisorSpec (org.apache.druid.indexing.overlord.supervisor.NoopSupervisorSpec)1 SupervisorManager (org.apache.druid.indexing.overlord.supervisor.SupervisorManager)1 SupervisorSpec (org.apache.druid.indexing.overlord.supervisor.SupervisorSpec)1 SupervisorStateManagerConfig (org.apache.druid.indexing.overlord.supervisor.SupervisorStateManagerConfig)1 LagStats (org.apache.druid.indexing.overlord.supervisor.autoscaler.LagStats)1 NoopTaskAutoScaler (org.apache.druid.indexing.seekablestream.supervisor.autoscaler.NoopTaskAutoScaler)1 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)1 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)1 NoopChatHandlerProvider (org.apache.druid.segment.realtime.firehose.NoopChatHandlerProvider)1 AuthorizerMapper (org.apache.druid.server.security.AuthorizerMapper)1 Before (org.junit.Before)1 ExpectedException (org.junit.rules.ExpectedException)1