Search in sources :

Example 11 with DruidNode

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

the class CuratorDruidNodeAnnouncerAndDiscoveryTest method testAnnouncementAndDiscovery.

@Test(timeout = 60_000L)
public void testAnnouncementAndDiscovery() throws Exception {
    ObjectMapper objectMapper = new DefaultObjectMapper();
    // additional setup to serde DruidNode
    objectMapper.setInjectableValues(new InjectableValues.Std().addValue(ServerConfig.class, new ServerConfig()).addValue("java.lang.String", "dummy").addValue("java.lang.Integer", 1234).addValue(ObjectMapper.class, objectMapper));
    curator.start();
    curator.blockUntilConnected();
    Announcer announcer = new Announcer(curator, Execs.directExecutor());
    announcer.start();
    CuratorDruidNodeAnnouncer druidNodeAnnouncer = new CuratorDruidNodeAnnouncer(announcer, new ZkPathsConfig(), objectMapper);
    DiscoveryDruidNode coordinatorNode1 = new DiscoveryDruidNode(new DruidNode("s1", "h1", false, 8080, null, true, false), NodeRole.COORDINATOR, ImmutableMap.of());
    DiscoveryDruidNode coordinatorNode2 = new DiscoveryDruidNode(new DruidNode("s2", "h2", false, 8080, null, true, false), NodeRole.COORDINATOR, ImmutableMap.of());
    DiscoveryDruidNode overlordNode1 = new DiscoveryDruidNode(new DruidNode("s3", "h3", false, 8080, null, true, false), NodeRole.OVERLORD, ImmutableMap.of());
    DiscoveryDruidNode overlordNode2 = new DiscoveryDruidNode(new DruidNode("s4", "h4", false, 8080, null, true, false), NodeRole.OVERLORD, ImmutableMap.of());
    druidNodeAnnouncer.announce(coordinatorNode1);
    druidNodeAnnouncer.announce(overlordNode1);
    CuratorDruidNodeDiscoveryProvider druidNodeDiscoveryProvider = new CuratorDruidNodeDiscoveryProvider(curator, new ZkPathsConfig(), objectMapper);
    druidNodeDiscoveryProvider.start();
    DruidNodeDiscovery coordDiscovery = druidNodeDiscoveryProvider.getForNodeRole(NodeRole.COORDINATOR);
    BooleanSupplier coord1NodeDiscovery = druidNodeDiscoveryProvider.getForNode(coordinatorNode1.getDruidNode(), NodeRole.COORDINATOR);
    DruidNodeDiscovery overlordDiscovery = druidNodeDiscoveryProvider.getForNodeRole(NodeRole.OVERLORD);
    BooleanSupplier overlord1NodeDiscovery = druidNodeDiscoveryProvider.getForNode(overlordNode1.getDruidNode(), NodeRole.OVERLORD);
    while (!checkNodes(ImmutableSet.of(coordinatorNode1), coordDiscovery.getAllNodes()) && !coord1NodeDiscovery.getAsBoolean()) {
        Thread.sleep(100);
    }
    while (!checkNodes(ImmutableSet.of(overlordNode1), overlordDiscovery.getAllNodes()) && !overlord1NodeDiscovery.getAsBoolean()) {
        Thread.sleep(100);
    }
    HashSet<DiscoveryDruidNode> coordNodes = new HashSet<>();
    coordDiscovery.registerListener(createSetAggregatingListener(coordNodes));
    HashSet<DiscoveryDruidNode> overlordNodes = new HashSet<>();
    overlordDiscovery.registerListener(createSetAggregatingListener(overlordNodes));
    while (!checkNodes(ImmutableSet.of(coordinatorNode1), coordNodes)) {
        Thread.sleep(100);
    }
    while (!checkNodes(ImmutableSet.of(overlordNode1), overlordNodes)) {
        Thread.sleep(100);
    }
    druidNodeAnnouncer.announce(coordinatorNode2);
    druidNodeAnnouncer.announce(overlordNode2);
    while (!checkNodes(ImmutableSet.of(coordinatorNode1, coordinatorNode2), coordDiscovery.getAllNodes())) {
        Thread.sleep(100);
    }
    while (!checkNodes(ImmutableSet.of(overlordNode1, overlordNode2), overlordDiscovery.getAllNodes())) {
        Thread.sleep(100);
    }
    while (!checkNodes(ImmutableSet.of(coordinatorNode1, coordinatorNode2), coordNodes)) {
        Thread.sleep(100);
    }
    while (!checkNodes(ImmutableSet.of(overlordNode1, overlordNode2), overlordNodes)) {
        Thread.sleep(100);
    }
    druidNodeAnnouncer.unannounce(coordinatorNode1);
    druidNodeAnnouncer.unannounce(coordinatorNode2);
    druidNodeAnnouncer.unannounce(overlordNode1);
    druidNodeAnnouncer.unannounce(overlordNode2);
    while (!checkNodes(ImmutableSet.of(), coordDiscovery.getAllNodes())) {
        Thread.sleep(100);
    }
    while (!checkNodes(ImmutableSet.of(), overlordDiscovery.getAllNodes())) {
        Thread.sleep(100);
    }
    while (!coordNodes.isEmpty()) {
        Thread.sleep(100);
    }
    while (!overlordNodes.isEmpty()) {
        Thread.sleep(100);
    }
    druidNodeDiscoveryProvider.stop();
    announcer.stop();
}
Also used : DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) ServerConfig(org.apache.druid.server.initialization.ServerConfig) Announcer(org.apache.druid.curator.announcement.Announcer) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) ZkPathsConfig(org.apache.druid.server.initialization.ZkPathsConfig) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) DruidNode(org.apache.druid.server.DruidNode) BooleanSupplier(java.util.function.BooleanSupplier) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with DruidNode

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

the class BaseNodeRoleWatcherTest method testGeneralUseSimulation.

@Test(timeout = 60_000L)
public void testGeneralUseSimulation() {
    BaseNodeRoleWatcher nodeRoleWatcher = new BaseNodeRoleWatcher(Execs.directExecutor(), NodeRole.BROKER);
    DiscoveryDruidNode broker1 = buildDiscoveryDruidNode(NodeRole.BROKER, "broker1");
    DiscoveryDruidNode broker2 = buildDiscoveryDruidNode(NodeRole.BROKER, "broker2");
    DiscoveryDruidNode broker3 = buildDiscoveryDruidNode(NodeRole.BROKER, "broker3");
    DiscoveryDruidNode notBroker = new DiscoveryDruidNode(new DruidNode("s3", "h3", false, 8080, null, true, false), NodeRole.COORDINATOR, ImmutableMap.of());
    TestListener listener1 = new TestListener();
    TestListener listener2 = new TestListener();
    TestListener listener3 = new TestListener();
    nodeRoleWatcher.registerListener(listener1);
    nodeRoleWatcher.childAdded(broker1);
    nodeRoleWatcher.childAdded(broker2);
    nodeRoleWatcher.childAdded(notBroker);
    nodeRoleWatcher.childAdded(broker3);
    nodeRoleWatcher.registerListener(listener2);
    nodeRoleWatcher.childRemoved(broker2);
    assertListener(listener1, false, Collections.emptyList(), Collections.emptyList());
    assertListener(listener2, false, Collections.emptyList(), Collections.emptyList());
    nodeRoleWatcher.cacheInitialized();
    nodeRoleWatcher.registerListener(listener3);
    List<DiscoveryDruidNode> presentNodes = new ArrayList<>(nodeRoleWatcher.getAllNodes());
    Assert.assertEquals(2, presentNodes.size());
    Assert.assertTrue(presentNodes.contains(broker1));
    Assert.assertTrue(presentNodes.contains(broker3));
    assertListener(listener1, true, presentNodes, Collections.emptyList());
    assertListener(listener2, true, presentNodes, Collections.emptyList());
    assertListener(listener3, true, presentNodes, Collections.emptyList());
    nodeRoleWatcher.childRemoved(notBroker);
    nodeRoleWatcher.childRemoved(broker2);
    nodeRoleWatcher.childAdded(broker2);
    nodeRoleWatcher.childRemoved(broker3);
    nodeRoleWatcher.childAdded(broker1);
    Assert.assertEquals(ImmutableSet.of(broker2, broker1), new HashSet<>(nodeRoleWatcher.getAllNodes()));
    List<DiscoveryDruidNode> nodesAdded = new ArrayList<>(presentNodes);
    nodesAdded.add(broker2);
    List<DiscoveryDruidNode> nodesRemoved = new ArrayList<>();
    nodesRemoved.add(broker3);
    assertListener(listener1, true, nodesAdded, nodesRemoved);
    assertListener(listener2, true, nodesAdded, nodesRemoved);
    assertListener(listener3, true, nodesAdded, nodesRemoved);
    LinkedHashMap<String, DiscoveryDruidNode> resetNodes = new LinkedHashMap<>();
    resetNodes.put(broker2.getDruidNode().getHostAndPortToUse(), broker2);
    resetNodes.put(broker3.getDruidNode().getHostAndPortToUse(), broker3);
    nodeRoleWatcher.resetNodes(resetNodes);
    Assert.assertEquals(ImmutableSet.of(broker2, broker3), new HashSet<>(nodeRoleWatcher.getAllNodes()));
    nodesAdded.add(broker3);
    nodesRemoved.add(broker1);
    assertListener(listener1, true, nodesAdded, nodesRemoved);
    assertListener(listener2, true, nodesAdded, nodesRemoved);
    assertListener(listener3, true, nodesAdded, nodesRemoved);
}
Also used : ArrayList(java.util.ArrayList) DruidNode(org.apache.druid.server.DruidNode) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 13 with DruidNode

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

the class InitializationTest method testCreateInjectorWithNodeRoleFilter_moduleNotLoaded.

@Test
public void testCreateInjectorWithNodeRoleFilter_moduleNotLoaded() {
    final DruidNode expected = new DruidNode("test-inject", null, false, null, null, true, false);
    Injector startupInjector = GuiceInjectors.makeStartupInjector();
    Injector injector = Initialization.makeInjectorWithModules(ImmutableSet.of(new NodeRole("role1"), new NodeRole("role2")), startupInjector, ImmutableList.of((com.google.inject.Module) binder -> JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), expected), new LoadOnAnnotationTestModule()));
    Assert.assertNotNull(injector);
    Assert.assertEquals(expected, injector.getInstance(Key.get(DruidNode.class, Self.class)));
    Assert.assertThrows("Guice configuration errors", ConfigurationException.class, () -> injector.getInstance(Key.get(String.class, Names.named("emperor"))));
}
Also used : NodeRole(org.apache.druid.discovery.NodeRole) Injector(com.google.inject.Injector) DruidNode(org.apache.druid.server.DruidNode) Module(com.fasterxml.jackson.databind.Module) Test(org.junit.Test)

Example 14 with DruidNode

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

the class InitializationTest method test05MakeInjectorWithModules.

@Test
public void test05MakeInjectorWithModules() {
    Injector startupInjector = GuiceInjectors.makeStartupInjector();
    Injector injector = Initialization.makeInjectorWithModules(startupInjector, ImmutableList.<com.google.inject.Module>of(new com.google.inject.Module() {

        @Override
        public void configure(Binder binder) {
            JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, false, null, null, true, false));
        }
    }));
    Assert.assertNotNull(injector);
}
Also used : Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) DruidNode(org.apache.druid.server.DruidNode) Self(org.apache.druid.guice.annotations.Self) Module(com.fasterxml.jackson.databind.Module) Test(org.junit.Test)

Example 15 with DruidNode

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

the class CacheMonitorTest method testOptionalInject.

@Test
public void testOptionalInject() {
    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, false, null, null, true, false));
        }
    }));
    CacheMonitor monitor = injector.getInstance(CacheMonitor.class);
    Assert.assertNull(monitor.cache);
}
Also used : Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) DruidNode(org.apache.druid.server.DruidNode) Self(org.apache.druid.guice.annotations.Self) Module(com.google.inject.Module) Test(org.junit.Test)

Aggregations

DruidNode (org.apache.druid.server.DruidNode)61 Test (org.junit.Test)41 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)25 Self (org.apache.druid.guice.annotations.Self)19 ImmutableList (com.google.common.collect.ImmutableList)18 List (java.util.List)18 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)16 ZkPathsConfig (org.apache.druid.server.initialization.ZkPathsConfig)16 Binder (com.google.inject.Binder)15 Injector (com.google.inject.Injector)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)15 DiscoveryDruidNode (org.apache.druid.discovery.DiscoveryDruidNode)14 HashSet (java.util.HashSet)12 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)12 DruidNodeDiscoveryProvider (org.apache.druid.discovery.DruidNodeDiscoveryProvider)12 TaskStatus (org.apache.druid.indexer.TaskStatus)12 Module (com.google.inject.Module)11 CuratorFramework (org.apache.curator.framework.CuratorFramework)11 NoopTask (org.apache.druid.indexing.common.task.NoopTask)11 Task (org.apache.druid.indexing.common.task.Task)11