Search in sources :

Example 1 with LazySingleton

use of org.apache.druid.guice.LazySingleton in project druid by druid-io.

the class CuratorModule method makeCurator.

@Provides
@LazySingleton
@SuppressForbidden(reason = "System#err")
public CuratorFramework makeCurator(ZkEnablementConfig zkEnablementConfig, CuratorConfig config, EnsembleProvider ensembleProvider, Lifecycle lifecycle) {
    if (!zkEnablementConfig.isEnabled()) {
        throw new RuntimeException("Zookeeper is disabled, Can't create CuratorFramework.");
    }
    final CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
    if (!Strings.isNullOrEmpty(config.getZkUser()) && !Strings.isNullOrEmpty(config.getZkPwd())) {
        builder.authorization(config.getAuthScheme(), StringUtils.format("%s:%s", config.getZkUser(), config.getZkPwd()).getBytes(StandardCharsets.UTF_8));
    }
    RetryPolicy retryPolicy = new BoundedExponentialBackoffRetry(BASE_SLEEP_TIME_MS, MAX_SLEEP_TIME_MS, MAX_RETRIES);
    final CuratorFramework framework = builder.ensembleProvider(ensembleProvider).sessionTimeoutMs(config.getZkSessionTimeoutMs()).connectionTimeoutMs(config.getZkConnectionTimeoutMs()).retryPolicy(retryPolicy).compressionProvider(new PotentiallyGzippedCompressionProvider(config.getEnableCompression())).aclProvider(config.getEnableAcl() ? new SecuredACLProvider() : new DefaultACLProvider()).build();
    framework.getUnhandledErrorListenable().addListener((message, e) -> {
        log.error(e, "Unhandled error in Curator, stopping server.");
        shutdown(lifecycle);
    });
    lifecycle.addHandler(new Lifecycle.Handler() {

        @Override
        public void start() {
            log.debug("Starting Curator");
            framework.start();
        }

        @Override
        public void stop() {
            log.debug("Stopping Curator");
            framework.close();
        }
    });
    return framework;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) DefaultACLProvider(org.apache.curator.framework.imps.DefaultACLProvider) RetryPolicy(org.apache.curator.RetryPolicy) BoundedExponentialBackoffRetry(org.apache.curator.retry.BoundedExponentialBackoffRetry) LazySingleton(org.apache.druid.guice.LazySingleton) SuppressForbidden(io.netty.util.SuppressForbidden) Provides(com.google.inject.Provides)

Example 2 with LazySingleton

use of org.apache.druid.guice.LazySingleton in project druid by druid-io.

the class JacksonModule method smileMapper.

@Provides
@LazySingleton
@Smile
public ObjectMapper smileMapper() {
    final SmileFactory smileFactory = new SmileFactory();
    smileFactory.configure(SmileGenerator.Feature.ENCODE_BINARY_AS_7BIT, false);
    smileFactory.delegateToTextual(true);
    final ObjectMapper retVal = new DefaultObjectMapper(smileFactory);
    retVal.getFactory().setCodec(retVal);
    return retVal;
}
Also used : SmileFactory(com.fasterxml.jackson.dataformat.smile.SmileFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LazySingleton(org.apache.druid.guice.LazySingleton) Provides(com.google.inject.Provides) Smile(org.apache.druid.guice.annotations.Smile)

Example 3 with LazySingleton

use of org.apache.druid.guice.LazySingleton in project druid by druid-io.

the class CloudFilesStorageDruidModule method getCloudFilesApi.

@Provides
@LazySingleton
public CloudFilesApi getCloudFilesApi(final CloudFilesAccountConfig config) {
    log.info("Building Cloud Files Api...");
    Iterable<com.google.inject.Module> modules;
    if (config.getUseServiceNet()) {
        log.info("Configuring Cloud Files Api to use the internal service network...");
        modules = ImmutableSet.of(new SLF4JLoggingModule(), new InternalUrlModule());
    } else {
        log.info("Configuring Cloud Files Api to use the public network...");
        modules = ImmutableSet.of(new SLF4JLoggingModule());
    }
    ProviderRegistry.registerProvider(CloudFilesUSProviderMetadata.builder().build());
    ProviderRegistry.registerProvider(CloudFilesUKProviderMetadata.builder().build());
    ContextBuilder cb = ContextBuilder.newBuilder(config.getProvider()).credentials(config.getUserName(), config.getApiKey()).modules(modules);
    CloudFilesApi cfa = cb.buildApi(CloudFilesApi.class);
    log.info("Cloud Files Api built.");
    return cfa;
}
Also used : InternalUrlModule(org.jclouds.openstack.v2_0.config.InternalUrlModule) SLF4JLoggingModule(org.jclouds.logging.slf4j.config.SLF4JLoggingModule) ContextBuilder(org.jclouds.ContextBuilder) CloudFilesApi(org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi) Module(com.fasterxml.jackson.databind.Module) SLF4JLoggingModule(org.jclouds.logging.slf4j.config.SLF4JLoggingModule) InternalUrlModule(org.jclouds.openstack.v2_0.config.InternalUrlModule) DruidModule(org.apache.druid.initialization.DruidModule) LazySingleton(org.apache.druid.guice.LazySingleton) Provides(com.google.inject.Provides)

Example 4 with LazySingleton

use of org.apache.druid.guice.LazySingleton in project druid by druid-io.

the class CuratorModule method makeEnsembleProvider.

@Provides
@LazySingleton
public EnsembleProvider makeEnsembleProvider(CuratorConfig config, ExhibitorConfig exConfig) {
    if (exConfig.getHosts().isEmpty()) {
        return new FixedEnsembleProvider(config.getZkHosts());
    }
    RetryPolicy retryPolicy = new BoundedExponentialBackoffRetry(BASE_SLEEP_TIME_MS, MAX_SLEEP_TIME_MS, MAX_RETRIES);
    return new ExhibitorEnsembleProvider(new Exhibitors(exConfig.getHosts(), exConfig.getRestPort(), newBackupProvider(config.getZkHosts())), new DefaultExhibitorRestClient(exConfig.getUseSsl()), exConfig.getRestUriPath(), exConfig.getPollingMs(), retryPolicy) {

        @Override
        public void start() throws Exception {
            log.debug("Polling the list of ZooKeeper servers for the initial ensemble");
            this.pollForInitialEnsemble();
            super.start();
        }
    };
}
Also used : Exhibitors(org.apache.curator.ensemble.exhibitor.Exhibitors) DefaultExhibitorRestClient(org.apache.curator.ensemble.exhibitor.DefaultExhibitorRestClient) ExhibitorEnsembleProvider(org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider) RetryPolicy(org.apache.curator.RetryPolicy) FixedEnsembleProvider(org.apache.curator.ensemble.fixed.FixedEnsembleProvider) BoundedExponentialBackoffRetry(org.apache.curator.retry.BoundedExponentialBackoffRetry) LazySingleton(org.apache.druid.guice.LazySingleton) Provides(com.google.inject.Provides)

Example 5 with LazySingleton

use of org.apache.druid.guice.LazySingleton in project druid by druid-io.

the class BrokerInternalQueryConfigTest method testDefaultBehavior.

/**
 * Test the behavior if the operator does not specify anything for druid.broker.internal.query.config.context in runtime.properties
 */
@Test
public void testDefaultBehavior() {
    Injector injector = Guice.createInjector(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.install(new ConfigModule());
            binder.install(new DruidGuiceExtensions());
            JsonConfigProvider.bind(binder, "druid.broker.internal.query.config", BrokerInternalQueryConfig.class);
        }

        @Provides
        @LazySingleton
        public ObjectMapper jsonMapper() {
            return new DefaultObjectMapper();
        }
    });
    BrokerInternalQueryConfig config = injector.getInstance(BrokerInternalQueryConfig.class);
    Assert.assertEquals(ImmutableMap.of(), config.getContext());
}
Also used : Binder(com.google.inject.Binder) LazySingleton(org.apache.druid.guice.LazySingleton) DruidGuiceExtensions(org.apache.druid.guice.DruidGuiceExtensions) Injector(com.google.inject.Injector) ConfigModule(org.apache.druid.guice.ConfigModule) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Module(com.google.inject.Module) ConfigModule(org.apache.druid.guice.ConfigModule) Provides(com.google.inject.Provides) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Aggregations

Provides (com.google.inject.Provides)6 LazySingleton (org.apache.druid.guice.LazySingleton)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Binder (com.google.inject.Binder)2 Module (com.google.inject.Module)2 RetryPolicy (org.apache.curator.RetryPolicy)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 BoundedExponentialBackoffRetry (org.apache.curator.retry.BoundedExponentialBackoffRetry)2 Lifecycle (org.apache.druid.java.util.common.lifecycle.Lifecycle)2 Module (com.fasterxml.jackson.databind.Module)1 SmileFactory (com.fasterxml.jackson.dataformat.smile.SmileFactory)1 Injector (com.google.inject.Injector)1 SuppressForbidden (io.netty.util.SuppressForbidden)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 DefaultExhibitorRestClient (org.apache.curator.ensemble.exhibitor.DefaultExhibitorRestClient)1 ExhibitorEnsembleProvider (org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider)1 Exhibitors (org.apache.curator.ensemble.exhibitor.Exhibitors)1 FixedEnsembleProvider (org.apache.curator.ensemble.fixed.FixedEnsembleProvider)1 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)1