Search in sources :

Example 51 with DruidNode

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

the class DruidLeaderClientTest method testServerFailureAndRedirect.

@Test
public void testServerFailureAndRedirect() throws Exception {
    DruidNodeDiscovery druidNodeDiscovery = EasyMock.createMock(DruidNodeDiscovery.class);
    DiscoveryDruidNode dummyNode = new DiscoveryDruidNode(new DruidNode("test", "dummyhost", false, 64231, null, true, false), NodeRole.PEON, ImmutableMap.of());
    EasyMock.expect(druidNodeDiscovery.getAllNodes()).andReturn(ImmutableList.of(dummyNode));
    EasyMock.expect(druidNodeDiscovery.getAllNodes()).andReturn(ImmutableList.of(discoveryDruidNode));
    DruidNodeDiscoveryProvider druidNodeDiscoveryProvider = EasyMock.createMock(DruidNodeDiscoveryProvider.class);
    EasyMock.expect(druidNodeDiscoveryProvider.getForNodeRole(NodeRole.PEON)).andReturn(druidNodeDiscovery).anyTimes();
    EasyMock.replay(druidNodeDiscovery, druidNodeDiscoveryProvider);
    DruidLeaderClient druidLeaderClient = new DruidLeaderClient(httpClient, druidNodeDiscoveryProvider, NodeRole.PEON, "/simple/leader");
    druidLeaderClient.start();
    Request request = druidLeaderClient.makeRequest(HttpMethod.POST, "/simple/redirect");
    request.setContent("hello".getBytes(StandardCharsets.UTF_8));
    Assert.assertEquals("hello", druidLeaderClient.go(request).getContent());
}
Also used : Request(org.apache.druid.java.util.http.client.Request) DruidNode(org.apache.druid.server.DruidNode) BaseJettyTest(org.apache.druid.server.initialization.BaseJettyTest) Test(org.junit.Test)

Example 52 with DruidNode

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

the class DruidLeaderClientTest method setupInjector.

@Override
protected Injector setupInjector() {
    final DruidNode node = new DruidNode("test", "localhost", false, null, null, true, false);
    discoveryDruidNode = new DiscoveryDruidNode(node, NodeRole.PEON, ImmutableMap.of());
    Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(new Module() {

        @Override
        public void configure(Binder binder) {
            JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), node);
            binder.bind(Integer.class).annotatedWith(Names.named("port")).toInstance(node.getPlaintextPort());
            binder.bind(JettyServerInitializer.class).to(TestJettyServerInitializer.class).in(LazySingleton.class);
            Jerseys.addResource(binder, SimpleResource.class);
            LifecycleModule.register(binder, Server.class);
        }
    }));
    httpClient = injector.getInstance(ClientHolder.class).getClient();
    return 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.google.inject.Module) LifecycleModule(org.apache.druid.guice.LifecycleModule)

Example 53 with DruidNode

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

the class InitializationTest method testCreateInjectorWithNodeRoles.

@Test
public void testCreateInjectorWithNodeRoles() {
    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(binder -> JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), expected)));
    Assert.assertNotNull(injector);
    Assert.assertEquals(expected, injector.getInstance(Key.get(DruidNode.class, Self.class)));
}
Also used : Module(com.fasterxml.jackson.databind.Module) MethodSorters(org.junit.runners.MethodSorters) Arrays(java.util.Arrays) Self(org.apache.druid.guice.annotations.Self) URL(java.net.URL) Inject(com.google.inject.Inject) Key(com.google.inject.Key) Collections2(com.google.common.collect.Collections2) HashSet(java.util.HashSet) URLClassLoader(java.net.URLClassLoader) ImmutableList(com.google.common.collect.ImmutableList) Binder(com.google.inject.Binder) ExtensionsConfig(org.apache.druid.guice.ExtensionsConfig) Nullable(javax.annotation.Nullable) LinkedHashSet(java.util.LinkedHashSet) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) JsonConfigProvider(org.apache.druid.guice.JsonConfigProvider) LoadScope(org.apache.druid.guice.annotations.LoadScope) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigurationException(com.google.inject.ConfigurationException) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) Test(org.junit.Test) IOException(java.io.IOException) Names(com.google.inject.name.Names) Multibinder(com.google.inject.multibindings.Multibinder) Sets(com.google.common.collect.Sets) GuiceInjectors(org.apache.druid.guice.GuiceInjectors) File(java.io.File) Injector(com.google.inject.Injector) List(java.util.List) Rule(org.junit.Rule) DruidNode(org.apache.druid.server.DruidNode) NodeRole(org.apache.druid.discovery.NodeRole) Assert(org.junit.Assert) FixMethodOrder(org.junit.FixMethodOrder) Comparator(java.util.Comparator) TemporaryFolder(org.junit.rules.TemporaryFolder) NodeRole(org.apache.druid.discovery.NodeRole) Injector(com.google.inject.Injector) DruidNode(org.apache.druid.server.DruidNode) Self(org.apache.druid.guice.annotations.Self) Test(org.junit.Test)

Example 54 with DruidNode

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

the class CalciteTests method createMockSystemSchema.

public static SystemSchema createMockSystemSchema(final DruidSchema druidSchema, final SpecificSegmentsQuerySegmentWalker walker, final PlannerConfig plannerConfig, final AuthorizerMapper authorizerMapper) {
    final DruidNode coordinatorNode = new DruidNode("test-coordinator", "dummy", false, 8081, null, true, false);
    FakeDruidNodeDiscoveryProvider provider = new FakeDruidNodeDiscoveryProvider(ImmutableMap.of(NodeRole.COORDINATOR, new FakeDruidNodeDiscovery(ImmutableMap.of(NodeRole.COORDINATOR, coordinatorNode))));
    final DruidNode overlordNode = new DruidNode("test-overlord", "dummy", false, 8090, null, true, false);
    FakeDruidNodeDiscoveryProvider overlordProvider = new FakeDruidNodeDiscoveryProvider(ImmutableMap.of(NodeRole.OVERLORD, new FakeDruidNodeDiscovery(ImmutableMap.of(NodeRole.OVERLORD, coordinatorNode))));
    final DruidLeaderClient druidLeaderClient = new DruidLeaderClient(new FakeHttpClient(), provider, NodeRole.COORDINATOR, "/simple/leader") {

        @Override
        public String findCurrentLeader() {
            return coordinatorNode.getHostAndPortToUse();
        }
    };
    final DruidLeaderClient overlordLeaderClient = new DruidLeaderClient(new FakeHttpClient(), overlordProvider, NodeRole.OVERLORD, "/simple/leader") {

        @Override
        public String findCurrentLeader() {
            return overlordNode.getHostAndPortToUse();
        }
    };
    return new SystemSchema(druidSchema, new MetadataSegmentView(druidLeaderClient, getJsonMapper(), new BrokerSegmentWatcherConfig(), plannerConfig), new TestServerInventoryView(walker.getSegments()), new FakeServerInventoryView(), authorizerMapper, druidLeaderClient, overlordLeaderClient, provider, getJsonMapper());
}
Also used : SystemSchema(org.apache.druid.sql.calcite.schema.SystemSchema) NamedSystemSchema(org.apache.druid.sql.calcite.schema.NamedSystemSchema) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) DruidNode(org.apache.druid.server.DruidNode) DruidLeaderClient(org.apache.druid.discovery.DruidLeaderClient) BrokerSegmentWatcherConfig(org.apache.druid.client.BrokerSegmentWatcherConfig) MetadataSegmentView(org.apache.druid.sql.calcite.schema.MetadataSegmentView)

Example 55 with DruidNode

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

the class InitializationTest method testCreateInjectorWithNodeRoleFilterUsingInject_moduleLoaded.

@Test
public void testCreateInjectorWithNodeRoleFilterUsingInject_moduleLoaded() {
    final Set<NodeRole> nodeRoles = ImmutableSet.of(new NodeRole("role1"), new NodeRole("druid"));
    final DruidNode expected = new DruidNode("test-inject", null, false, null, null, true, false);
    Injector startupInjector = GuiceInjectors.makeStartupInjectorWithModules(ImmutableList.of(binder -> {
        Multibinder<NodeRole> selfBinder = Multibinder.newSetBinder(binder, NodeRole.class, Self.class);
        nodeRoles.forEach(nodeRole -> selfBinder.addBinding().toInstance(nodeRole));
    }));
    Injector injector = Initialization.makeInjectorWithModules(nodeRoles, startupInjector, ImmutableList.of((com.google.inject.Module) binder -> JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), expected), new NodeRolesInjectTestModule()));
    Assert.assertNotNull(injector);
    Assert.assertEquals(expected, injector.getInstance(Key.get(DruidNode.class, Self.class)));
    Assert.assertEquals("I am Druid", injector.getInstance(Key.get(String.class, Names.named("emperor"))));
}
Also used : Module(com.fasterxml.jackson.databind.Module) MethodSorters(org.junit.runners.MethodSorters) Arrays(java.util.Arrays) Self(org.apache.druid.guice.annotations.Self) URL(java.net.URL) Inject(com.google.inject.Inject) Key(com.google.inject.Key) Collections2(com.google.common.collect.Collections2) HashSet(java.util.HashSet) URLClassLoader(java.net.URLClassLoader) ImmutableList(com.google.common.collect.ImmutableList) Binder(com.google.inject.Binder) ExtensionsConfig(org.apache.druid.guice.ExtensionsConfig) Nullable(javax.annotation.Nullable) LinkedHashSet(java.util.LinkedHashSet) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) JsonConfigProvider(org.apache.druid.guice.JsonConfigProvider) LoadScope(org.apache.druid.guice.annotations.LoadScope) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigurationException(com.google.inject.ConfigurationException) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) Test(org.junit.Test) IOException(java.io.IOException) Names(com.google.inject.name.Names) Multibinder(com.google.inject.multibindings.Multibinder) Sets(com.google.common.collect.Sets) GuiceInjectors(org.apache.druid.guice.GuiceInjectors) File(java.io.File) Injector(com.google.inject.Injector) List(java.util.List) Rule(org.junit.Rule) DruidNode(org.apache.druid.server.DruidNode) NodeRole(org.apache.druid.discovery.NodeRole) Assert(org.junit.Assert) FixMethodOrder(org.junit.FixMethodOrder) Comparator(java.util.Comparator) TemporaryFolder(org.junit.rules.TemporaryFolder) NodeRole(org.apache.druid.discovery.NodeRole) Multibinder(com.google.inject.multibindings.Multibinder) 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)

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