Search in sources :

Example 41 with DruidNode

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

the class DiscoveryDruidNodeTest method testDeserializeWithDataNodeServiceWithAWrongPropertyOrder.

@Test
public void testDeserializeWithDataNodeServiceWithAWrongPropertyOrder() throws JsonProcessingException {
    final ObjectMapper mapper = createObjectMapper(ImmutableList.of());
    final String json = "{\n" + "  \"druidNode\" : {\n" + "    \"service\" : \"druid/broker\",\n" + "    \"host\" : \"druid-broker\",\n" + "    \"bindOnHost\" : false,\n" + "    \"plaintextPort\" : 8082,\n" + "    \"port\" : -1,\n" + "    \"tlsPort\" : 8282,\n" + "    \"enablePlaintextPort\" : true,\n" + "    \"enableTlsPort\" : true\n" + "  },\n" + "  \"nodeType\" : \"broker\",\n" + "  \"services\" : {\n" + "    \"dataNodeService\" : {\n" + // In normal case, this proprty must appear after another "type" below.
    "      \"type\" : \"broker\",\n" + "      \"type\" : \"dataNodeService\",\n" + "      \"tier\" : \"_default_tier\",\n" + "      \"maxSize\" : 1000000000,\n" + "      \"serverType\" : \"broker\",\n" + "      \"priority\" : 0\n" + "    }\n" + "  }\n" + "}";
    Assert.assertEquals(new DiscoveryDruidNode(new DruidNode("druid/broker", "druid-broker", false, 8082, -1, 8282, true, true), NodeRole.BROKER, ImmutableMap.of("dataNodeService", new DataNodeService("_default_tier", 1000000000, ServerType.BROKER, 0))), mapper.readValue(json, DiscoveryDruidNode.class));
}
Also used : DruidNode(org.apache.druid.server.DruidNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 42 with DruidNode

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

the class DiscoveryDruidNodeTest method testDeserialize_duplicateProperties_shouldSucceedToDeserialize.

@Test
public void testDeserialize_duplicateProperties_shouldSucceedToDeserialize() throws JsonProcessingException {
    final ObjectMapper mapper = createObjectMapper(ImmutableList.of());
    final String json = "{\n" + "  \"druidNode\" : {\n" + "    \"service\" : \"druid/broker\",\n" + "    \"host\" : \"druid-broker\",\n" + "    \"bindOnHost\" : false,\n" + "    \"plaintextPort\" : 8082,\n" + "    \"port\" : -1,\n" + "    \"tlsPort\" : 8282,\n" + "    \"enablePlaintextPort\" : true,\n" + "    \"enableTlsPort\" : true\n" + "  },\n" + "  \"nodeType\" : \"broker\",\n" + "  \"services\" : {\n" + "    \"dataNodeService\" : {\n" + "      \"type\" : \"dataNodeService\",\n" + "      \"tier\" : \"_default_tier\",\n" + "      \"maxSize\" : 1000000000,\n" + "      \"maxSize\" : 1000000000,\n" + "      \"serverType\" : \"broker\",\n" + "      \"priority\" : 0\n" + "    }\n" + "  }\n" + "}";
    Assert.assertEquals(new DiscoveryDruidNode(new DruidNode("druid/broker", "druid-broker", false, 8082, -1, 8282, true, true), NodeRole.BROKER, ImmutableMap.of("dataNodeService", new DataNodeService("_default_tier", 1000000000, ServerType.BROKER, 0))), mapper.readValue(json, DiscoveryDruidNode.class));
}
Also used : DruidNode(org.apache.druid.server.DruidNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 43 with DruidNode

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

the class DruidNodeDiscoveryProviderTest method testGetForService.

@Test
public void testGetForService() {
    TestDruidNodeDiscoveryProvider provider = new TestDruidNodeDiscoveryProvider();
    DruidNodeDiscovery dataNodeDiscovery = provider.getForService(DataNodeService.DISCOVERY_SERVICE_KEY);
    Set<DiscoveryDruidNode> dataNodes = new HashSet<>();
    dataNodeDiscovery.registerListener(new DruidNodeDiscovery.Listener() {

        @Override
        public void nodesAdded(Collection<DiscoveryDruidNode> nodes) {
            dataNodes.addAll(nodes);
        }

        @Override
        public void nodesRemoved(Collection<DiscoveryDruidNode> nodes) {
            dataNodes.removeAll(nodes);
        }
    });
    DruidNodeDiscovery lookupNodeDiscovery = provider.getForService(LookupNodeService.DISCOVERY_SERVICE_KEY);
    Set<DiscoveryDruidNode> lookupNodes = new HashSet<>();
    lookupNodeDiscovery.registerListener(new DruidNodeDiscovery.Listener() {

        @Override
        public void nodesAdded(Collection<DiscoveryDruidNode> nodes) {
            lookupNodes.addAll(nodes);
        }

        @Override
        public void nodesRemoved(Collection<DiscoveryDruidNode> nodes) {
            lookupNodes.removeAll(nodes);
        }
    });
    Assert.assertTrue(dataNodes.isEmpty());
    Assert.assertTrue(dataNodes.isEmpty());
    Assert.assertTrue(dataNodeDiscovery.getAllNodes().isEmpty());
    Assert.assertTrue(lookupNodes.isEmpty());
    Assert.assertTrue(lookupNodeDiscovery.getAllNodes().isEmpty());
    DiscoveryDruidNode node1 = new DiscoveryDruidNode(new DruidNode("s1", "h1", false, 8080, null, true, false), NodeRole.HISTORICAL, ImmutableMap.of(DataNodeService.DISCOVERY_SERVICE_KEY, new DataNodeService("tier", 1000, ServerType.HISTORICAL, 0), LookupNodeService.DISCOVERY_SERVICE_KEY, new LookupNodeService("tier")));
    DiscoveryDruidNode node2 = new DiscoveryDruidNode(new DruidNode("s2", "h2", false, 8080, null, true, false), NodeRole.HISTORICAL, ImmutableMap.of(DataNodeService.DISCOVERY_SERVICE_KEY, new DataNodeService("tier", 1000, ServerType.HISTORICAL, 0)));
    DiscoveryDruidNode node3 = new DiscoveryDruidNode(new DruidNode("s3", "h3", false, 8080, null, true, false), NodeRole.HISTORICAL, ImmutableMap.of(LookupNodeService.DISCOVERY_SERVICE_KEY, new LookupNodeService("tier")));
    DiscoveryDruidNode node4 = new DiscoveryDruidNode(new DruidNode("s4", "h4", false, 8080, null, true, false), NodeRole.PEON, ImmutableMap.of(DataNodeService.DISCOVERY_SERVICE_KEY, new DataNodeService("tier", 1000, ServerType.HISTORICAL, 0), LookupNodeService.DISCOVERY_SERVICE_KEY, new LookupNodeService("tier")));
    DiscoveryDruidNode node5 = new DiscoveryDruidNode(new DruidNode("s5", "h5", false, 8080, null, true, false), NodeRole.PEON, ImmutableMap.of(DataNodeService.DISCOVERY_SERVICE_KEY, new DataNodeService("tier", 1000, ServerType.HISTORICAL, 0)));
    DiscoveryDruidNode node6 = new DiscoveryDruidNode(new DruidNode("s6", "h6", false, 8080, null, true, false), NodeRole.PEON, ImmutableMap.of(LookupNodeService.DISCOVERY_SERVICE_KEY, new LookupNodeService("tier")));
    DiscoveryDruidNode node7 = new DiscoveryDruidNode(new DruidNode("s7", "h7", false, 8080, null, true, false), NodeRole.BROKER, ImmutableMap.of(LookupNodeService.DISCOVERY_SERVICE_KEY, new LookupNodeService("tier")));
    DiscoveryDruidNode node7Clone = new DiscoveryDruidNode(new DruidNode("s7", "h7", false, 8080, null, true, false), NodeRole.BROKER, ImmutableMap.of(LookupNodeService.DISCOVERY_SERVICE_KEY, new LookupNodeService("tier")));
    DiscoveryDruidNode node8 = new DiscoveryDruidNode(new DruidNode("s8", "h8", false, 8080, null, true, false), NodeRole.COORDINATOR, ImmutableMap.of());
    provider.add(node1);
    provider.add(node2);
    provider.add(node3);
    provider.add(node4);
    provider.add(node5);
    provider.add(node6);
    provider.add(node7);
    provider.add(node7Clone);
    provider.add(node8);
    Assert.assertEquals(ImmutableSet.of(node1, node2, node4, node5), ImmutableSet.copyOf(dataNodeDiscovery.getAllNodes()));
    Assert.assertEquals(ImmutableSet.of(node1, node2, node4, node5), dataNodes);
    Assert.assertEquals(ImmutableSet.of(node1, node3, node4, node6, node7), ImmutableSet.copyOf(lookupNodeDiscovery.getAllNodes()));
    Assert.assertEquals(ImmutableSet.of(node1, node3, node4, node6, node7), lookupNodes);
    provider.remove(node8);
    provider.remove(node7Clone);
    provider.remove(node6);
    provider.remove(node5);
    provider.remove(node4);
    Assert.assertEquals(ImmutableSet.of(node1, node2), ImmutableSet.copyOf(dataNodeDiscovery.getAllNodes()));
    Assert.assertEquals(ImmutableSet.of(node1, node2), dataNodes);
    Assert.assertEquals(ImmutableSet.of(node1, node3), ImmutableSet.copyOf(lookupNodeDiscovery.getAllNodes()));
    Assert.assertEquals(ImmutableSet.of(node1, node3), lookupNodes);
}
Also used : DruidNode(org.apache.druid.server.DruidNode) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 44 with DruidNode

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

the class CacheMonitorTest method testInject.

@Test
public void testInject() {
    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));
            binder.bind(Cache.class).toInstance(MapCache.create(0));
        }
    }));
    CacheMonitor monitor = injector.getInstance(CacheMonitor.class);
    Assert.assertNotNull(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)

Example 45 with DruidNode

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

the class JettyQosTest method setupInjector.

@Override
protected Injector setupInjector() {
    return Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(new Module() {

        @Override
        public void configure(Binder binder) {
            JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test", "localhost", false, null, null, true, false));
            binder.bind(JettyServerInitializer.class).to(JettyServerInit.class).in(LazySingleton.class);
            Jerseys.addResource(binder, SlowResource.class);
            Jerseys.addResource(binder, ExceptionResource.class);
            Jerseys.addResource(binder, DefaultResource.class);
            binder.bind(AuthorizerMapper.class).toInstance(AuthTestUtils.TEST_AUTHORIZER_MAPPER);
            JettyBindings.addQosFilter(binder, "/slow/*", 2);
            final ServerConfig serverConfig = new ObjectMapper().convertValue(ImmutableMap.of("numThreads", "2"), ServerConfig.class);
            binder.bind(ServerConfig.class).toInstance(serverConfig);
            LifecycleModule.register(binder, Server.class);
        }
    }));
}
Also used : Binder(com.google.inject.Binder) AuthorizerMapper(org.apache.druid.server.security.AuthorizerMapper) DruidNode(org.apache.druid.server.DruidNode) Self(org.apache.druid.guice.annotations.Self) Module(com.google.inject.Module) LifecycleModule(org.apache.druid.guice.LifecycleModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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