Search in sources :

Example 11 with DruidNode

use of io.druid.server.DruidNode in project druid by druid-io.

the class OverlordTest method setUp.

@Before
public void setUp() throws Exception {
    req = EasyMock.createStrictMock(HttpServletRequest.class);
    supervisorManager = EasyMock.createMock(SupervisorManager.class);
    taskLockbox = EasyMock.createStrictMock(TaskLockbox.class);
    taskLockbox.syncFromStorage();
    EasyMock.expectLastCall().atLeastOnce();
    taskLockbox.add(EasyMock.<Task>anyObject());
    EasyMock.expectLastCall().atLeastOnce();
    taskLockbox.remove(EasyMock.<Task>anyObject());
    EasyMock.expectLastCall().atLeastOnce();
    // for second Noop Task directly added to deep storage.
    taskLockbox.add(EasyMock.<Task>anyObject());
    EasyMock.expectLastCall().atLeastOnce();
    taskLockbox.remove(EasyMock.<Task>anyObject());
    EasyMock.expectLastCall().atLeastOnce();
    taskActionClientFactory = EasyMock.createStrictMock(TaskActionClientFactory.class);
    EasyMock.expect(taskActionClientFactory.create(EasyMock.<Task>anyObject())).andReturn(null).anyTimes();
    EasyMock.replay(taskLockbox, taskActionClientFactory);
    taskStorage = new HeapMemoryTaskStorage(new TaskStorageConfig(null));
    runTaskCountDownLatches = new CountDownLatch[2];
    runTaskCountDownLatches[0] = new CountDownLatch(1);
    runTaskCountDownLatches[1] = new CountDownLatch(1);
    taskCompletionCountDownLatches = new CountDownLatch[2];
    taskCompletionCountDownLatches[0] = new CountDownLatch(1);
    taskCompletionCountDownLatches[1] = new CountDownLatch(1);
    announcementLatch = new CountDownLatch(1);
    IndexerZkConfig indexerZkConfig = new IndexerZkConfig(new ZkPathsConfig(), null, null, null, null, null);
    setupServerAndCurator();
    curator.start();
    curator.blockUntilConnected();
    curator.create().creatingParentsIfNeeded().forPath(indexerZkConfig.getLeaderLatchPath());
    druidNode = new DruidNode("hey", "what", 1234);
    ServiceEmitter serviceEmitter = new NoopServiceEmitter();
    taskMaster = new TaskMaster(new TaskQueueConfig(null, new Period(1), null, new Period(10)), taskLockbox, taskStorage, taskActionClientFactory, druidNode, indexerZkConfig, new TaskRunnerFactory<MockTaskRunner>() {

        @Override
        public MockTaskRunner build() {
            return new MockTaskRunner(runTaskCountDownLatches, taskCompletionCountDownLatches);
        }
    }, curator, new NoopServiceAnnouncer() {

        @Override
        public void announce(DruidNode node) {
            announcementLatch.countDown();
        }
    }, new CoordinatorOverlordServiceConfig(null, null), serviceEmitter, supervisorManager, EasyMock.createNiceMock(OverlordHelperManager.class));
    EmittingLogger.registerEmitter(serviceEmitter);
}
Also used : IndexerZkConfig(io.druid.server.initialization.IndexerZkConfig) NoopServiceEmitter(io.druid.server.metrics.NoopServiceEmitter) ServiceEmitter(com.metamx.emitter.service.ServiceEmitter) Task(io.druid.indexing.common.task.Task) NoopTask(io.druid.indexing.common.task.NoopTask) CoordinatorOverlordServiceConfig(io.druid.server.coordinator.CoordinatorOverlordServiceConfig) TaskStorageConfig(io.druid.indexing.common.config.TaskStorageConfig) HeapMemoryTaskStorage(io.druid.indexing.overlord.HeapMemoryTaskStorage) TaskActionClientFactory(io.druid.indexing.common.actions.TaskActionClientFactory) Period(org.joda.time.Period) NoopServiceEmitter(io.druid.server.metrics.NoopServiceEmitter) CountDownLatch(java.util.concurrent.CountDownLatch) HttpServletRequest(javax.servlet.http.HttpServletRequest) SupervisorManager(io.druid.indexing.overlord.supervisor.SupervisorManager) ZkPathsConfig(io.druid.server.initialization.ZkPathsConfig) TaskLockbox(io.druid.indexing.overlord.TaskLockbox) TaskQueueConfig(io.druid.indexing.overlord.config.TaskQueueConfig) DruidNode(io.druid.server.DruidNode) TaskMaster(io.druid.indexing.overlord.TaskMaster) NoopServiceAnnouncer(io.druid.curator.discovery.NoopServiceAnnouncer) TaskRunnerFactory(io.druid.indexing.overlord.TaskRunnerFactory) Before(org.junit.Before)

Example 12 with DruidNode

use of io.druid.server.DruidNode in project druid by druid-io.

the class DatasourcePathSpecTest method testSerde.

@Test
public void testSerde() throws Exception {
    final UsedSegmentLister segmentList = EasyMock.createMock(UsedSegmentLister.class);
    Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(UsedSegmentLister.class).toInstance(segmentList);
            JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("dummy-node", null, null));
        }
    }));
    ObjectMapper jsonMapper = injector.getInstance(ObjectMapper.class);
    DatasourcePathSpec expected = new DatasourcePathSpec(jsonMapper, null, ingestionSpec, Long.valueOf(10));
    PathSpec actual = jsonMapper.readValue(jsonMapper.writeValueAsString(expected), PathSpec.class);
    Assert.assertEquals(expected, actual);
    expected = new DatasourcePathSpec(jsonMapper, null, ingestionSpec, null);
    actual = jsonMapper.readValue(jsonMapper.writeValueAsString(expected), PathSpec.class);
    Assert.assertEquals(expected, actual);
    expected = new DatasourcePathSpec(jsonMapper, segments, ingestionSpec, null);
    actual = jsonMapper.readValue(jsonMapper.writeValueAsString(expected), PathSpec.class);
    Assert.assertEquals(expected, actual);
}
Also used : Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) DruidNode(io.druid.server.DruidNode) Self(io.druid.guice.annotations.Self) Module(com.google.inject.Module) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 13 with DruidNode

use of io.druid.server.DruidNode in project druid by druid-io.

the class DruidCoordinatorTest method setUp.

@Before
public void setUp() throws Exception {
    taskMaster = EasyMock.createMock(LoadQueueTaskMaster.class);
    druidServer = EasyMock.createMock(DruidServer.class);
    serverInventoryView = EasyMock.createMock(SingleServerInventoryView.class);
    databaseSegmentManager = EasyMock.createNiceMock(MetadataSegmentManager.class);
    metadataRuleManager = EasyMock.createNiceMock(MetadataRuleManager.class);
    configManager = EasyMock.createNiceMock(JacksonConfigManager.class);
    EasyMock.expect(configManager.watch(EasyMock.anyString(), EasyMock.anyObject(Class.class), EasyMock.anyObject())).andReturn(new AtomicReference(new CoordinatorDynamicConfig.Builder().build())).anyTimes();
    EasyMock.replay(configManager);
    setupServerAndCurator();
    curator.start();
    curator.blockUntilConnected();
    curator.create().creatingParentsIfNeeded().forPath(LOADPATH);
    objectMapper = new DefaultObjectMapper();
    druidCoordinatorConfig = new TestDruidCoordinatorConfig(new Duration(COORDINATOR_START_DELAY), new Duration(COORDINATOR_PERIOD), null, null, new Duration(COORDINATOR_PERIOD), null, 10, null, false, false, new Duration("PT0s"));
    pathChildrenCache = new PathChildrenCache(curator, LOADPATH, true, true, Execs.singleThreaded("coordinator_test_path_children_cache-%d"));
    loadQueuePeon = new LoadQueuePeon(curator, LOADPATH, objectMapper, Execs.scheduledSingleThreaded("coordinator_test_load_queue_peon_scheduled-%d"), Execs.singleThreaded("coordinator_test_load_queue_peon-%d"), druidCoordinatorConfig);
    loadQueuePeon.start();
    druidNode = new DruidNode("hey", "what", 1234);
    loadManagementPeons = new MapMaker().makeMap();
    scheduledExecutorFactory = new ScheduledExecutorFactory() {

        @Override
        public ScheduledExecutorService create(int corePoolSize, final String nameFormat) {
            return Executors.newSingleThreadScheduledExecutor();
        }
    };
    leaderAnnouncerLatch = new CountDownLatch(1);
    leaderUnannouncerLatch = new CountDownLatch(1);
    coordinator = new DruidCoordinator(druidCoordinatorConfig, new ZkPathsConfig() {

        @Override
        public String getBase() {
            return "druid";
        }
    }, configManager, databaseSegmentManager, serverInventoryView, metadataRuleManager, curator, new NoopServiceEmitter(), scheduledExecutorFactory, null, taskMaster, new NoopServiceAnnouncer() {

        @Override
        public void announce(DruidNode node) {
            // count down when this coordinator becomes the leader
            leaderAnnouncerLatch.countDown();
        }

        @Override
        public void unannounce(DruidNode node) {
            leaderUnannouncerLatch.countDown();
        }
    }, druidNode, loadManagementPeons, null, new CostBalancerStrategyFactory());
}
Also used : MetadataSegmentManager(io.druid.metadata.MetadataSegmentManager) MetadataRuleManager(io.druid.metadata.MetadataRuleManager) ZkPathsConfig(io.druid.server.initialization.ZkPathsConfig) SingleServerInventoryView(io.druid.client.SingleServerInventoryView) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) JacksonConfigManager(io.druid.common.config.JacksonConfigManager) MapMaker(com.google.common.collect.MapMaker) ImmutableDruidServer(io.druid.client.ImmutableDruidServer) DruidServer(io.druid.client.DruidServer) AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(org.joda.time.Duration) NoopServiceEmitter(io.druid.server.metrics.NoopServiceEmitter) CountDownLatch(java.util.concurrent.CountDownLatch) ScheduledExecutorFactory(io.druid.java.util.common.concurrent.ScheduledExecutorFactory) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DruidNode(io.druid.server.DruidNode) NoopServiceAnnouncer(io.druid.curator.discovery.NoopServiceAnnouncer) Before(org.junit.Before)

Example 14 with DruidNode

use of io.druid.server.DruidNode in project druid by druid-io.

the class EmitterModule method getServiceEmitter.

@Provides
@ManageLifecycle
public ServiceEmitter getServiceEmitter(@Self Supplier<DruidNode> configSupplier, Emitter emitter) {
    final DruidNode config = configSupplier.get();
    String version = getClass().getPackage().getImplementationVersion();
    final ImmutableMap<String, String> otherServiceDimensions = ImmutableMap.of("version", // Version is null during `mvn test`.
    Strings.nullToEmpty(version));
    final ServiceEmitter retVal = new ServiceEmitter(config.getServiceName(), config.getHostAndPort(), emitter, otherServiceDimensions);
    EmittingLogger.registerEmitter(retVal);
    return retVal;
}
Also used : ServiceEmitter(com.metamx.emitter.service.ServiceEmitter) DruidNode(io.druid.server.DruidNode) ManageLifecycle(io.druid.guice.ManageLifecycle) Provides(com.google.inject.Provides)

Example 15 with DruidNode

use of io.druid.server.DruidNode in project druid by druid-io.

the class NamespaceLookupExtractorFactoryTest method testSerDe.

// Note this does NOT catch problems with returning factories as failed in error messages.
@Test
public void testSerDe() throws Exception {
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {

        @Override
        public void configure(Binder binder) {
            JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null));
        }
    }));
    final ObjectMapper mapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class));
    mapper.registerSubtypes(NamespaceLookupExtractorFactory.class);
    final String str = "{ \"type\": \"cachedNamespace\", \"extractionNamespace\": { \"type\": \"uri\", \"uriPrefix\": \"s3://bucket/prefix/\", \"fileRegex\": \"foo.*\\\\.gz\", \"namespaceParseSpec\": { \"format\": \"customJson\", \"keyFieldName\": \"someKey\", \"valueFieldName\": \"someVal\" }, \"pollPeriod\": \"PT5M\" } } }";
    final LookupExtractorFactory factory = mapper.readValue(str, LookupExtractorFactory.class);
    Assert.assertTrue(factory instanceof NamespaceLookupExtractorFactory);
    final NamespaceLookupExtractorFactory namespaceLookupExtractorFactory = (NamespaceLookupExtractorFactory) factory;
    Assert.assertNotNull(mapper.writeValueAsString(factory));
    Assert.assertFalse(factory.replaces(mapper.readValue(mapper.writeValueAsString(factory), LookupExtractorFactory.class)));
    Assert.assertEquals(URIExtractionNamespace.class, namespaceLookupExtractorFactory.getExtractionNamespace().getClass());
    Assert.assertFalse(namespaceLookupExtractorFactory.replaces(mapper.readValue(str, LookupExtractorFactory.class)));
    final Map<String, Object> map = new HashMap<>(mapper.<Map<String, Object>>readValue(str, new TypeReference<Map<String, Object>>() {
    }));
    map.put("firstCacheTimeout", "1");
    Assert.assertTrue(namespaceLookupExtractorFactory.replaces(mapper.convertValue(map, LookupExtractorFactory.class)));
}
Also used : HashMap(java.util.HashMap) Self(io.druid.guice.annotations.Self) Json(io.druid.guice.annotations.Json) Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) DruidNode(io.druid.server.DruidNode) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Module(com.google.inject.Module) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

DruidNode (io.druid.server.DruidNode)19 Self (io.druid.guice.annotations.Self)13 Binder (com.google.inject.Binder)12 Injector (com.google.inject.Injector)11 Module (com.google.inject.Module)11 Test (org.junit.Test)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)4 Before (org.junit.Before)4 Properties (java.util.Properties)3 ServiceEmitter (com.metamx.emitter.service.ServiceEmitter)2 NoopServiceAnnouncer (io.druid.curator.discovery.NoopServiceAnnouncer)2 LifecycleModule (io.druid.guice.LifecycleModule)2 Json (io.druid.guice.annotations.Json)2 ZkPathsConfig (io.druid.server.initialization.ZkPathsConfig)2 NamespaceExtractionModule (io.druid.server.lookup.namespace.NamespaceExtractionModule)2 NoopServiceEmitter (io.druid.server.metrics.NoopServiceEmitter)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Server (org.eclipse.jetty.server.Server)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1