Search in sources :

Example 1 with DruidNode

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

the class JettyBindOnHostTest 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", true, null, null, true, false));
            binder.bind(JettyServerInitializer.class).to(JettyServerInit.class).in(LazySingleton.class);
            Jerseys.addResource(binder, DefaultResource.class);
            binder.bind(AuthorizerMapper.class).toInstance(AuthTestUtils.TEST_AUTHORIZER_MAPPER);
            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)

Example 2 with DruidNode

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

the class JettyTest method setupInjector.

@Override
protected Injector setupInjector() {
    TLSServerConfig tlsConfig;
    try {
        File keyStore = new File(JettyTest.class.getClassLoader().getResource("server.jks").getFile());
        Path tmpKeyStore = Files.copy(keyStore.toPath(), new File(folder.newFolder(), "server.jks").toPath());
        File trustStore = new File(JettyTest.class.getClassLoader().getResource("truststore.jks").getFile());
        Path tmpTrustStore = Files.copy(trustStore.toPath(), new File(folder.newFolder(), "truststore.jks").toPath());
        PasswordProvider pp = () -> "druid123";
        tlsConfig = new TLSServerConfig() {

            @Override
            public String getKeyStorePath() {
                return tmpKeyStore.toString();
            }

            @Override
            public String getKeyStoreType() {
                return "jks";
            }

            @Override
            public PasswordProvider getKeyStorePasswordProvider() {
                return pp;
            }

            @Override
            public PasswordProvider getKeyManagerPasswordProvider() {
                return pp;
            }

            @Override
            public String getTrustStorePath() {
                return tmpTrustStore.toString();
            }

            @Override
            public String getTrustStoreAlgorithm() {
                return "PKIX";
            }

            @Override
            public PasswordProvider getTrustStorePasswordProvider() {
                return pp;
            }

            @Override
            public String getCertAlias() {
                return "druid";
            }

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

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

            @Override
            public boolean isValidateHostnames() {
                return false;
            }
        };
        sslConfig = HttpClientConfig.builder().withSslContext(HttpClientInit.sslContextWithTrustedKeyStore(tmpTrustStore.toString(), pp.getPassword())).withWorkerCount(1).withReadTimeout(Duration.ZERO).build();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    final int ephemeralPort = ThreadLocalRandom.current().nextInt(49152, 65535);
    latchedRequestState = new LatchedRequestStateHolder();
    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), new DruidNode("test", "localhost", false, ephemeralPort, ephemeralPort + 1, true, true));
            binder.bind(TLSServerConfig.class).toInstance(tlsConfig);
            binder.bind(JettyServerInitializer.class).to(JettyServerInit.class).in(LazySingleton.class);
            binder.bind(LatchedRequestStateHolder.class).toInstance(latchedRequestState);
            Multibinder<ServletFilterHolder> multibinder = Multibinder.newSetBinder(binder, ServletFilterHolder.class);
            multibinder.addBinding().toInstance(new ServletFilterHolder() {

                @Override
                public String getPath() {
                    return "/*";
                }

                @Override
                public Map<String, String> getInitParameters() {
                    return null;
                }

                @Override
                public Class<? extends Filter> getFilterClass() {
                    return DummyAuthFilter.class;
                }

                @Override
                public Filter getFilter() {
                    return null;
                }

                @Override
                public EnumSet<DispatcherType> getDispatcherType() {
                    return null;
                }
            });
            Jerseys.addResource(binder, SlowResource.class);
            Jerseys.addResource(binder, LatchedResource.class);
            Jerseys.addResource(binder, ExceptionResource.class);
            Jerseys.addResource(binder, DefaultResource.class);
            Jerseys.addResource(binder, DirectlyReturnResource.class);
            binder.bind(AuthorizerMapper.class).toInstance(AuthTestUtils.TEST_AUTHORIZER_MAPPER);
            LifecycleModule.register(binder, Server.class);
        }
    }));
    return injector;
}
Also used : Server(org.eclipse.jetty.server.Server) ServletFilterHolder(org.apache.druid.server.initialization.jetty.ServletFilterHolder) Binder(com.google.inject.Binder) LazySingleton(org.apache.druid.guice.LazySingleton) JettyServerInitializer(org.apache.druid.server.initialization.jetty.JettyServerInitializer) DispatcherType(javax.servlet.DispatcherType) Path(java.nio.file.Path) Multibinder(com.google.inject.multibindings.Multibinder) IOException(java.io.IOException) PasswordProvider(org.apache.druid.metadata.PasswordProvider) DruidNode(org.apache.druid.server.DruidNode) Module(com.google.inject.Module) LifecycleModule(org.apache.druid.guice.LifecycleModule) JettyServerModule(org.apache.druid.server.initialization.jetty.JettyServerModule) File(java.io.File)

Example 3 with DruidNode

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

the class ExportMetadata method getModules.

@Override
protected List<? extends Module> getModules() {
    return ImmutableList.of(// See https://github.com/apache/druid/pull/4429#discussion_r123602930
    new DruidProcessingModule(), new QueryableModule(), new QueryRunnerFactoryModule(), binder -> {
        JsonConfigProvider.bindInstance(binder, Key.get(MetadataStorageConnectorConfig.class), new MetadataStorageConnectorConfig() {

            @Override
            public String getConnectURI() {
                return connectURI;
            }

            @Override
            public String getUser() {
                return user;
            }

            @Override
            public String getPassword() {
                return password;
            }
        });
        JsonConfigProvider.bindInstance(binder, Key.get(MetadataStorageTablesConfig.class), MetadataStorageTablesConfig.fromBase(base));
        JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("tools", "localhost", false, -1, null, true, false));
    });
}
Also used : MetadataStorageTablesConfig(org.apache.druid.metadata.MetadataStorageTablesConfig) MetadataStorageConnectorConfig(org.apache.druid.metadata.MetadataStorageConnectorConfig) QueryableModule(org.apache.druid.guice.QueryableModule) DruidProcessingModule(org.apache.druid.guice.DruidProcessingModule) QueryRunnerFactoryModule(org.apache.druid.guice.QueryRunnerFactoryModule) DruidNode(org.apache.druid.server.DruidNode) Self(org.apache.druid.guice.annotations.Self)

Example 4 with DruidNode

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

the class ResetCluster method getModules.

@Override
protected List<? extends Module> getModules() {
    return ImmutableList.of(// See https://github.com/apache/druid/pull/4429#discussion_r123603498
    new DruidProcessingModule(), new QueryableModule(), new QueryRunnerFactoryModule(), binder -> {
        JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("tools", "localhost", false, -1, null, true, false));
        JsonConfigProvider.bind(binder, "druid.indexer.task", TaskConfig.class);
    }, new IndexingServiceTaskLogsModule());
}
Also used : QueryableModule(org.apache.druid.guice.QueryableModule) DruidProcessingModule(org.apache.druid.guice.DruidProcessingModule) QueryRunnerFactoryModule(org.apache.druid.guice.QueryRunnerFactoryModule) DruidNode(org.apache.druid.server.DruidNode) Self(org.apache.druid.guice.annotations.Self) IndexingServiceTaskLogsModule(org.apache.druid.guice.IndexingServiceTaskLogsModule)

Example 5 with DruidNode

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

the class ServiceAnnouncingChatHandlerProviderTest method testRegistrationWithAnnounce.

private void testRegistrationWithAnnounce(boolean useThreeArgConstructor) {
    ChatHandler testChatHandler = new TestChatHandler();
    Capture<DruidNode> captured = Capture.newInstance();
    EasyMock.expect(node.getHost()).andReturn(TEST_HOST);
    EasyMock.expect(node.isBindOnHost()).andReturn(false);
    EasyMock.expect(node.getPlaintextPort()).andReturn(TEST_PORT);
    EasyMock.expect(node.isEnablePlaintextPort()).andReturn(true);
    EasyMock.expect(node.isEnableTlsPort()).andReturn(false);
    EasyMock.expect(node.getTlsPort()).andReturn(-1);
    serviceAnnouncer.announce(EasyMock.capture(captured));
    replayAll();
    Assert.assertFalse("bad initial state", chatHandlerProvider.get(TEST_SERVICE_NAME).isPresent());
    if (useThreeArgConstructor) {
        chatHandlerProvider.register(TEST_SERVICE_NAME, testChatHandler, true);
    } else {
        chatHandlerProvider.register(TEST_SERVICE_NAME, testChatHandler);
    }
    verifyAll();
    DruidNode param = captured.getValues().get(0);
    Assert.assertEquals(TEST_SERVICE_NAME, param.getServiceName());
    Assert.assertEquals(TEST_HOST, param.getHost());
    Assert.assertEquals(TEST_PORT, param.getPlaintextPort());
    Assert.assertEquals(-1, param.getTlsPort());
    Assert.assertEquals(null, param.getHostAndTlsPort());
    Assert.assertTrue("chatHandler did not register", chatHandlerProvider.get(TEST_SERVICE_NAME).isPresent());
    Assert.assertEquals(testChatHandler, chatHandlerProvider.get(TEST_SERVICE_NAME).get());
    captured.reset();
    resetAll();
    EasyMock.expect(node.getHost()).andReturn(TEST_HOST);
    EasyMock.expect(node.isBindOnHost()).andReturn(false);
    EasyMock.expect(node.getPlaintextPort()).andReturn(TEST_PORT);
    EasyMock.expect(node.isEnablePlaintextPort()).andReturn(true);
    EasyMock.expect(node.getTlsPort()).andReturn(-1);
    EasyMock.expect(node.isEnableTlsPort()).andReturn(false);
    serviceAnnouncer.unannounce(EasyMock.capture(captured));
    replayAll();
    chatHandlerProvider.unregister(TEST_SERVICE_NAME);
    verifyAll();
    param = captured.getValues().get(0);
    Assert.assertEquals(TEST_SERVICE_NAME, param.getServiceName());
    Assert.assertEquals(TEST_HOST, param.getHost());
    Assert.assertEquals(TEST_PORT, param.getPlaintextPort());
    Assert.assertEquals(-1, param.getTlsPort());
    Assert.assertEquals(null, param.getHostAndTlsPort());
    Assert.assertFalse("chatHandler did not deregister", chatHandlerProvider.get(TEST_SERVICE_NAME).isPresent());
}
Also used : DruidNode(org.apache.druid.server.DruidNode)

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