Search in sources :

Example 6 with Lifecycle

use of org.apache.druid.java.util.common.lifecycle.Lifecycle in project druid by druid-io.

the class ITTLSTest method makeCertlessClient.

private HttpClient makeCertlessClient() {
    SSLContext certlessClientSSLContext = new TLSUtils.ClientSSLContextBuilder().setProtocol(sslClientConfig.getProtocol()).setTrustStoreType(sslClientConfig.getTrustStoreType()).setTrustStorePath(sslClientConfig.getTrustStorePath()).setTrustStoreAlgorithm(sslClientConfig.getTrustStoreAlgorithm()).setTrustStorePasswordProvider(sslClientConfig.getTrustStorePasswordProvider()).setCertificateChecker(certificateChecker).build();
    final HttpClientConfig.Builder builder = getHttpClientConfigBuilder(certlessClientSSLContext);
    final Lifecycle lifecycle = new Lifecycle();
    HttpClient client = HttpClientInit.createClient(builder.build(), lifecycle);
    HttpClient adminClient = new CredentialedHttpClient(new BasicCredentials("admin", "priest"), client);
    return adminClient;
}
Also used : CredentialedHttpClient(org.apache.druid.java.util.http.client.CredentialedHttpClient) HttpClientConfig(org.apache.druid.java.util.http.client.HttpClientConfig) DruidHttpClientConfig(org.apache.druid.guice.http.DruidHttpClientConfig) TLSUtils(org.apache.druid.server.security.TLSUtils) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) HttpClient(org.apache.druid.java.util.http.client.HttpClient) CredentialedHttpClient(org.apache.druid.java.util.http.client.CredentialedHttpClient) SSLContext(javax.net.ssl.SSLContext) BasicCredentials(org.apache.druid.java.util.http.client.auth.BasicCredentials)

Example 7 with Lifecycle

use of org.apache.druid.java.util.common.lifecycle.Lifecycle in project druid by druid-io.

the class ITTLSTest method makeCustomHttpClient.

private HttpClient makeCustomHttpClient(String keystorePath, String certAlias, TLSCertificateChecker certificateChecker) {
    SSLContext intermediateClientSSLContext = new TLSUtils.ClientSSLContextBuilder().setProtocol(sslClientConfig.getProtocol()).setTrustStoreType(sslClientConfig.getTrustStoreType()).setTrustStorePath(sslClientConfig.getTrustStorePath()).setTrustStoreAlgorithm(sslClientConfig.getTrustStoreAlgorithm()).setTrustStorePasswordProvider(sslClientConfig.getTrustStorePasswordProvider()).setKeyStoreType(sslClientConfig.getKeyStoreType()).setKeyStorePath(keystorePath).setKeyStoreAlgorithm(sslClientConfig.getKeyManagerFactoryAlgorithm()).setCertAlias(certAlias).setKeyStorePasswordProvider(sslClientConfig.getKeyStorePasswordProvider()).setKeyManagerFactoryPasswordProvider(sslClientConfig.getKeyManagerPasswordProvider()).setCertificateChecker(certificateChecker).build();
    final HttpClientConfig.Builder builder = getHttpClientConfigBuilder(intermediateClientSSLContext);
    final Lifecycle lifecycle = new Lifecycle();
    HttpClient client = HttpClientInit.createClient(builder.build(), lifecycle);
    HttpClient adminClient = new CredentialedHttpClient(new BasicCredentials("admin", "priest"), client);
    return adminClient;
}
Also used : CredentialedHttpClient(org.apache.druid.java.util.http.client.CredentialedHttpClient) HttpClientConfig(org.apache.druid.java.util.http.client.HttpClientConfig) DruidHttpClientConfig(org.apache.druid.guice.http.DruidHttpClientConfig) TLSUtils(org.apache.druid.server.security.TLSUtils) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) HttpClient(org.apache.druid.java.util.http.client.HttpClient) CredentialedHttpClient(org.apache.druid.java.util.http.client.CredentialedHttpClient) SSLContext(javax.net.ssl.SSLContext) BasicCredentials(org.apache.druid.java.util.http.client.auth.BasicCredentials)

Example 8 with Lifecycle

use of org.apache.druid.java.util.common.lifecycle.Lifecycle in project druid by druid-io.

the class PrioritizedListenableFutureTask method create.

public static PrioritizedExecutorService create(Lifecycle lifecycle, DruidProcessingConfig config) {
    final PrioritizedExecutorService service = new PrioritizedExecutorService(new ThreadPoolExecutor(config.getNumThreads(), config.getNumThreads(), 0L, TimeUnit.MILLISECONDS, new PriorityBlockingQueue<Runnable>(), new ThreadFactoryBuilder().setDaemon(true).setNameFormat(config.getFormatString()).build()), config);
    lifecycle.addHandler(new Lifecycle.Handler() {

        @Override
        public void start() {
        }

        @Override
        public void stop() {
            service.shutdownNow();
        }
    });
    return service;
}
Also used : Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) PriorityBlockingQueue(java.util.concurrent.PriorityBlockingQueue)

Example 9 with Lifecycle

use of org.apache.druid.java.util.common.lifecycle.Lifecycle in project druid by druid-io.

the class LifecycleScopeTest method testAnnotation.

@Test
public void testAnnotation() throws Exception {
    final Injector injector = Guice.createInjector(new DruidGuiceExtensions(), new LifecycleModule(), new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(TestInterface.class).to(AnnotatedClass.class);
        }
    });
    final Lifecycle lifecycle = injector.getInstance(Lifecycle.class);
    final TestInterface instance = injector.getInstance(TestInterface.class);
    testIt(injector, lifecycle, instance);
}
Also used : Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) Module(com.google.inject.Module) Test(org.junit.Test)

Example 10 with Lifecycle

use of org.apache.druid.java.util.common.lifecycle.Lifecycle in project druid by druid-io.

the class LifecycleScopeTest method testExplicit.

@Test
public void testExplicit() throws Exception {
    final Injector injector = Guice.createInjector(new DruidGuiceExtensions(), new LifecycleModule(), new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(TestInterface.class).to(ExplicitClass.class).in(ManageLifecycle.class);
        }
    });
    final Lifecycle lifecycle = injector.getInstance(Lifecycle.class);
    final TestInterface instance = injector.getInstance(TestInterface.class);
    testIt(injector, lifecycle, instance);
}
Also used : Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) Module(com.google.inject.Module) Test(org.junit.Test)

Aggregations

Lifecycle (org.apache.druid.java.util.common.lifecycle.Lifecycle)46 Test (org.junit.Test)21 Injector (com.google.inject.Injector)12 URL (java.net.URL)12 ExecutionException (java.util.concurrent.ExecutionException)12 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)10 Before (org.junit.Before)10 ExecutorService (java.util.concurrent.ExecutorService)6 Binder (com.google.inject.Binder)5 Module (com.google.inject.Module)5 OutputStream (java.io.OutputStream)5 Properties (java.util.Properties)5 ManageLifecycle (org.apache.druid.guice.ManageLifecycle)5 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)5 ChannelException (org.jboss.netty.channel.ChannelException)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)4 IOException (java.io.IOException)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Provides (com.google.inject.Provides)3