Search in sources :

Example 6 with Provides

use of com.google.inject.Provides in project druid by druid-io.

the class JettyServerModule method getJacksonJsonProvider.

@Provides
@Singleton
public JacksonJsonProvider getJacksonJsonProvider(@Json ObjectMapper objectMapper) {
    final JacksonJsonProvider provider = new JacksonJsonProvider();
    provider.setMapper(objectMapper);
    return provider;
}
Also used : JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) LazySingleton(io.druid.guice.LazySingleton) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 7 with Provides

use of com.google.inject.Provides in project druid by druid-io.

the class CliCoordinator method getModules.

@Override
protected List<? extends Module> getModules() {
    List<Module> modules = new ArrayList<>();
    modules.add(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bindConstant().annotatedWith(Names.named("serviceName")).to(TieredBrokerConfig.DEFAULT_COORDINATOR_SERVICE_NAME);
            binder.bindConstant().annotatedWith(Names.named("servicePort")).to(8081);
            ConfigProvider.bind(binder, DruidCoordinatorConfig.class);
            binder.bind(MetadataStorage.class).toProvider(MetadataStorageProvider.class);
            JsonConfigProvider.bind(binder, "druid.manager.segments", MetadataSegmentManagerConfig.class);
            JsonConfigProvider.bind(binder, "druid.manager.rules", MetadataRuleManagerConfig.class);
            JsonConfigProvider.bind(binder, "druid.manager.lookups", LookupCoordinatorManagerConfig.class);
            JsonConfigProvider.bind(binder, "druid.coordinator.balancer", BalancerStrategyFactory.class);
            binder.bind(RedirectFilter.class).in(LazySingleton.class);
            if (beOverlord) {
                binder.bind(RedirectInfo.class).to(CoordinatorOverlordRedirectInfo.class).in(LazySingleton.class);
            } else {
                binder.bind(RedirectInfo.class).to(CoordinatorRedirectInfo.class).in(LazySingleton.class);
            }
            binder.bind(MetadataSegmentManager.class).toProvider(MetadataSegmentManagerProvider.class).in(ManageLifecycle.class);
            binder.bind(MetadataRuleManager.class).toProvider(MetadataRuleManagerProvider.class).in(ManageLifecycle.class);
            binder.bind(AuditManager.class).toProvider(AuditManagerProvider.class).in(ManageLifecycle.class);
            binder.bind(IndexingServiceClient.class).in(LazySingleton.class);
            binder.bind(CoordinatorServerView.class).in(LazySingleton.class);
            binder.bind(DruidCoordinator.class);
            binder.bind(LookupCoordinatorManager.class).in(ManageLifecycle.class);
            binder.bind(ListenerDiscoverer.class).in(ManageLifecycle.class);
            LifecycleModule.register(binder, ListenerDiscoverer.class);
            LifecycleModule.register(binder, MetadataStorage.class);
            LifecycleModule.register(binder, DruidCoordinator.class);
            LifecycleModule.register(binder, LookupCoordinatorManager.class);
            binder.bind(JettyServerInitializer.class).to(CoordinatorJettyServerInitializer.class);
            Jerseys.addResource(binder, CoordinatorResource.class);
            Jerseys.addResource(binder, CoordinatorDynamicConfigsResource.class);
            Jerseys.addResource(binder, TiersResource.class);
            Jerseys.addResource(binder, RulesResource.class);
            Jerseys.addResource(binder, ServersResource.class);
            Jerseys.addResource(binder, DatasourcesResource.class);
            Jerseys.addResource(binder, MetadataResource.class);
            Jerseys.addResource(binder, IntervalsResource.class);
            Jerseys.addResource(binder, LookupCoordinatorResource.class);
            LifecycleModule.register(binder, Server.class);
            LifecycleModule.register(binder, DatasourcesResource.class);
            ConditionalMultibind.create(properties, binder, DruidCoordinatorHelper.class, CoordinatorIndexingServiceHelper.class).addConditionBinding("druid.coordinator.merge.on", Predicates.equalTo("true"), DruidCoordinatorSegmentMerger.class).addConditionBinding("druid.coordinator.conversion.on", Predicates.equalTo("true"), DruidCoordinatorVersionConverter.class).addConditionBinding("druid.coordinator.kill.on", Predicates.equalTo("true"), DruidCoordinatorSegmentKiller.class);
        }

        @Provides
        @LazySingleton
        public LoadQueueTaskMaster getLoadQueueTaskMaster(CuratorFramework curator, ObjectMapper jsonMapper, ScheduledExecutorFactory factory, DruidCoordinatorConfig config) {
            return new LoadQueueTaskMaster(curator, jsonMapper, factory.create(1, "Master-PeonExec--%d"), Executors.newSingleThreadExecutor(), config);
        }
    });
    if (beOverlord) {
        modules.addAll(new CliOverlord().getModules(false));
    }
    return modules;
}
Also used : MetadataSegmentManager(io.druid.metadata.MetadataSegmentManager) MetadataRuleManager(io.druid.metadata.MetadataRuleManager) Server(org.eclipse.jetty.server.Server) ArrayList(java.util.ArrayList) CoordinatorResource(io.druid.server.http.CoordinatorResource) LookupCoordinatorResource(io.druid.server.http.LookupCoordinatorResource) ServersResource(io.druid.server.http.ServersResource) ListenerDiscoverer(io.druid.server.listener.announcer.ListenerDiscoverer) Binder(com.google.inject.Binder) LazySingleton(io.druid.guice.LazySingleton) LookupCoordinatorManager(io.druid.server.lookup.cache.LookupCoordinatorManager) TiersResource(io.druid.server.http.TiersResource) CuratorFramework(org.apache.curator.framework.CuratorFramework) DruidCoordinatorConfig(io.druid.server.coordinator.DruidCoordinatorConfig) LookupCoordinatorManagerConfig(io.druid.server.lookup.cache.LookupCoordinatorManagerConfig) AuditManager(io.druid.audit.AuditManager) DruidCoordinator(io.druid.server.coordinator.DruidCoordinator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MetadataStorageProvider(io.druid.metadata.MetadataStorageProvider) MetadataResource(io.druid.server.http.MetadataResource) DruidCoordinatorSegmentMerger(io.druid.server.coordinator.helper.DruidCoordinatorSegmentMerger) RulesResource(io.druid.server.http.RulesResource) BalancerStrategyFactory(io.druid.server.coordinator.BalancerStrategyFactory) ManageLifecycle(io.druid.guice.ManageLifecycle) Provides(com.google.inject.Provides) MetadataSegmentManagerConfig(io.druid.metadata.MetadataSegmentManagerConfig) CoordinatorDynamicConfigsResource(io.druid.server.http.CoordinatorDynamicConfigsResource) IntervalsResource(io.druid.server.http.IntervalsResource) DatasourcesResource(io.druid.server.http.DatasourcesResource) MetadataRuleManagerConfig(io.druid.metadata.MetadataRuleManagerConfig) LookupCoordinatorResource(io.druid.server.http.LookupCoordinatorResource) ScheduledExecutorFactory(io.druid.java.util.common.concurrent.ScheduledExecutorFactory) MetadataStorage(io.druid.metadata.MetadataStorage) DruidCoordinatorSegmentKiller(io.druid.server.coordinator.helper.DruidCoordinatorSegmentKiller) RedirectInfo(io.druid.server.http.RedirectInfo) CoordinatorRedirectInfo(io.druid.server.http.CoordinatorRedirectInfo) Module(com.google.inject.Module) LifecycleModule(io.druid.guice.LifecycleModule) LoadQueueTaskMaster(io.druid.server.coordinator.LoadQueueTaskMaster)

Example 8 with Provides

use of com.google.inject.Provides in project druid by druid-io.

the class MetadataStorageTablesConfigTest method testSerdeMetadataStorageTablesConfig.

@Test
public void testSerdeMetadataStorageTablesConfig() throws Exception {
    Injector injector = Guice.createInjector(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.install(new PropertiesModule(Arrays.asList("test.runtime.properties")));
            binder.install(new ConfigModule());
            binder.install(new DruidGuiceExtensions());
            JsonConfigProvider.bind(binder, "druid.metadata.storage.tables", MetadataStorageTablesConfig.class);
        }

        @Provides
        @LazySingleton
        public ObjectMapper jsonMapper() {
            return new DefaultObjectMapper();
        }
    });
    Properties props = injector.getInstance(Properties.class);
    MetadataStorageTablesConfig config = injector.getInstance(MetadataStorageTablesConfig.class);
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.base"), config.getBase());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.segments"), config.getSegmentsTable());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.rules"), config.getRulesTable());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.config"), config.getConfigTable());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.tasks"), config.getEntryTable(MetadataStorageTablesConfig.TASK_ENTRY_TYPE));
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.taskLog"), config.getLogTable(MetadataStorageTablesConfig.TASK_ENTRY_TYPE));
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.taskLock"), config.getLockTable(MetadataStorageTablesConfig.TASK_ENTRY_TYPE));
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.dataSource"), config.getDataSourceTable());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.supervisors"), config.getSupervisorTable());
}
Also used : Provides(com.google.inject.Provides) Properties(java.util.Properties) Binder(com.google.inject.Binder) MetadataStorageTablesConfig(io.druid.metadata.MetadataStorageTablesConfig) Injector(com.google.inject.Injector) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Module(com.google.inject.Module) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 9 with Provides

use of com.google.inject.Provides in project druid by druid-io.

the class LifecycleModule method getLifecycle.

@Provides
@LazySingleton
public Lifecycle getLifecycle(final Injector injector) {
    final Key<Set<KeyHolder>> keyHolderKey = Key.get(new TypeLiteral<Set<KeyHolder>>() {
    }, Names.named("lifecycle"));
    final Set<KeyHolder> eagerClasses = injector.getInstance(keyHolderKey);
    Lifecycle lifecycle = new Lifecycle() {

        @Override
        public void start() throws Exception {
            for (KeyHolder<?> holder : eagerClasses) {
                // Pull the key so as to "eagerly" load up the class.
                injector.getInstance(holder.getKey());
            }
            super.start();
        }
    };
    scope.setLifecycle(lifecycle);
    lastScope.setLifecycle(lifecycle);
    return lifecycle;
}
Also used : Set(java.util.Set) Lifecycle(io.druid.java.util.common.lifecycle.Lifecycle) Provides(com.google.inject.Provides)

Example 10 with Provides

use of com.google.inject.Provides in project druid by druid-io.

the class AuthenticationKerberosConfigTest method testserde.

@Test
public void testserde() {
    Injector injector = Guice.createInjector(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.install(new PropertiesModule(Arrays.asList("test.runtime.properties")));
            binder.install(new ConfigModule());
            binder.install(new DruidGuiceExtensions());
            JsonConfigProvider.bind(binder, "druid.hadoop.security.kerberos", AuthenticationKerberosConfig.class);
        }

        @Provides
        @LazySingleton
        public ObjectMapper jsonMapper() {
            return new DefaultObjectMapper();
        }
    });
    Properties props = injector.getInstance(Properties.class);
    AuthenticationKerberosConfig config = injector.getInstance(AuthenticationKerberosConfig.class);
    Assert.assertEquals(props.getProperty("druid.hadoop.security.kerberos.principal"), config.getPrincipal());
    Assert.assertEquals(props.getProperty("druid.hadoop.security.kerberos.keytab"), config.getKeytab());
}
Also used : DruidGuiceExtensions(io.druid.guice.DruidGuiceExtensions) ConfigModule(io.druid.guice.ConfigModule) Provides(com.google.inject.Provides) Properties(java.util.Properties) Binder(com.google.inject.Binder) LazySingleton(io.druid.guice.LazySingleton) Injector(com.google.inject.Injector) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Module(com.google.inject.Module) PropertiesModule(io.druid.guice.PropertiesModule) ConfigModule(io.druid.guice.ConfigModule) PropertiesModule(io.druid.guice.PropertiesModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Aggregations

Provides (com.google.inject.Provides)111 AbstractModule (com.google.inject.AbstractModule)26 Singleton (com.google.inject.Singleton)23 Singleton (javax.inject.Singleton)23 Injector (com.google.inject.Injector)22 LazySingleton (io.druid.guice.LazySingleton)12 Named (javax.inject.Named)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 Named (com.google.inject.name.Named)8 File (java.io.File)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 Inject (javax.inject.Inject)6 Properties (java.util.Properties)5 Test (org.junit.Test)5 Key (com.google.inject.Key)4 ExecutorService (java.util.concurrent.ExecutorService)4 ConfigModule (co.cask.cdap.common.guice.ConfigModule)3 DB (com.codecademy.eventhub.base.DB)3 Binder (com.google.inject.Binder)3