@Override protected List<? extends com.google.inject.Module> getModules() { return ImmutableList.of( // It's unknown if those modules are required in DruidJsonValidator. // Maybe some of those modules could be removed. // See https://github.com/apache/incubator-druid/pull/4429#discussion_r123603498 new DruidProcessingModule(), new QueryableModule(), new QueryRunnerFactoryModule(), binder -> { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/validator"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1); } ); }
/** @see Binder#bindConstant() */ protected AnnotatedConstantBindingBuilder bindConstant() { return binder().bindConstant(); }
@Override public void configure(Binder binder) binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/tool"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(9999); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1); binder.bind(DruidProcessingConfig.class).toInstance( new DruidProcessingConfig()
@Override protected List<? extends Module> getModules() { return ImmutableList.of( binder -> { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/internal-hadoop-indexer"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1); // bind metadata storage config based on HadoopIOConfig MetadataStorageUpdaterJobSpec metadataSpec = getHadoopDruidIndexerConfig().getSchema() .getIOConfig() .getMetadataUpdateSpec(); binder.bind(new TypeLiteral<Supplier<MetadataStorageConnectorConfig>>() {}) .toInstance(metadataSpec); binder.bind(MetadataStorageTablesConfig.class).toInstance(metadataSpec.getMetadataStorageTablesConfig()); binder.bind(IndexerMetadataStorageCoordinator.class).to(IndexerSQLMetadataStorageCoordinator.class).in( LazySingleton.class ); } ); }
/** Bind classes that are specific to the cluster connection @param binder @param config */ private void bindCassandraClient(Binder binder, ClusterConfiguration config) { binder.bind(ClusterConfiguration.class).toInstance(config); binder.bind(CassandraClient.class).to(CassandraClientImpl.class); binder.bindConstant().annotatedWith(Names.named("request_retry_count")).to(config.getRequestRetryCount()); binder.bindConstant().annotatedWith(Names.named("cluster_name")).to(config.getClusterName()); binder.bind(KairosRetryPolicy.class); }
@Override protected List<? extends Module> getModules() { return ImmutableList.of( new DruidProcessingModule(), new QueryableModule(), new QueryRunnerFactoryModule(), new RealtimeModule(), binder -> { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/realtime"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(8084); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(8284); binder.bind(DataSegmentPusher.class).to(NoopDataSegmentPusher.class).in(LazySingleton.class); binder.bind(DataSegmentAnnouncer.class).to(NoopDataSegmentAnnouncer.class).in(LazySingleton.class); binder.bind(InventoryView.class).to(NoopInventoryView.class).in(LazySingleton.class); binder.bind(ServerView.class).to(NoopServerView.class).in(LazySingleton.class); }, new ChatHandlerServerModule(properties), new LookupModule() ); }
@Override protected List<? extends Module> getModules() { return ImmutableList.of( new DruidProcessingModule(), new QueryableModule(), new QueryRunnerFactoryModule(), new RealtimeModule(), binder -> { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/realtime"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(8084); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(8284); }, new ChatHandlerServerModule(properties), new LookupModule() ); } }
@Override public void configure(Binder binder) { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test/memcached"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1); binder.bind(MemcachedCacheConfig.class).toInstance(config); binder.bind(Cache.class).toProvider(MemcachedProviderWithConfig.class).in(ManageLifecycle.class); } }
@Override public void configure(Binder binder) { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1); JsonConfigProvider.bind(binder, configPrefix, clazz); } };
@Override public void configure(Binder binder) { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test/memcached"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1); binder.bind(Cache.class).toProvider(CacheProvider.class); JsonConfigProvider.bind(binder, uuid, CacheProvider.class); } }
@Override public void configure(Binder binder) { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1); // See IndexingServiceModuleHelper JsonConfigProvider.bind(binder, indexerPropertyString, IndexerZkConfig.class); JsonConfigProvider.bind(binder, zkServiceConfigString, ZkPathsConfig.class); } };
@Override public void configure(Binder binder) { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("hybridTest"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1); binder.install(new CacheModule(prefix)); } }
@Override public void configure(Binder binder) { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/router"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(8888); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(9088); JsonConfigProvider.bind(binder, "druid.router", TieredBrokerConfig.class); JsonConfigProvider.bind(binder, "druid.router.avatica.balancer", AvaticaConnectionBalancer.class); JsonConfigProvider.bind(binder, "druid.router.managementProxy", ManagementProxyConfig.class); binder.bind(CoordinatorRuleManager.class); LifecycleModule.register(binder, CoordinatorRuleManager.class); binder.bind(TieredBrokerHostSelector.class).in(ManageLifecycle.class); binder.bind(QueryHostFinder.class).in(LazySingleton.class); binder.bind(new TypeLiteral<List<TieredBrokerSelectorStrategy>>() { }) .toProvider(TieredBrokerSelectorStrategiesProvider.class) .in(LazySingleton.class); binder.bind(QueryCountStatsProvider.class).to(AsyncQueryForwardingServlet.class).in(LazySingleton.class); binder.bind(JettyServerInitializer.class).to(RouterJettyServerInitializer.class).in(LazySingleton.class); Jerseys.addResource(binder, RouterResource.class); LifecycleModule.register(binder, RouterResource.class); LifecycleModule.register(binder, Server.class); DiscoveryModule.register(binder, Self.class); bindAnnouncer( binder, DiscoverySideEffectsProvider.builder(NodeType.ROUTER).build() ); } },
@Override public void configure(Binder binder) { binder.bind(FlowConfigsResourceHandler.class).annotatedWith(Names.named("flowConfigsV2ResourceHandler")).toInstance(new FlowConfigV2ResourceLocalHandler(flowCatalog)); // indicate that we are in unit testing since the resource is being blocked until flow catalog changes have // been made binder.bindConstant().annotatedWith(Names.named("readyToUse")).to(Boolean.TRUE); } });
@Override public void configure(Binder binder) { binder.bind(FlowConfigsResourceHandler.class) .annotatedWith(Names.named(FlowConfigsResource.INJECT_FLOW_CONFIG_RESOURCE_HANDLER)) .toInstance(new FlowConfigResourceLocalHandler(flowCatalog)); // indicate that we are in unit testing since the resource is being blocked until flow catalog changes have // been made binder.bindConstant().annotatedWith(Names.named(FlowConfigsResource.INJECT_READY_TO_USE)).to(Boolean.TRUE); binder.bind(RequesterService.class) .annotatedWith(Names.named(FlowConfigsResource.INJECT_REQUESTER_SERVICE)).toInstance(new NoopRequesterService(config)); } });
@Test public void testSimpleInjection() { final String uuid = UUID.randomUUID().toString(); System.setProperty(uuid + ".type", "caffeine"); final Injector injector = Initialization.makeInjectorWithModules( GuiceInjectors.makeStartupInjector(), ImmutableList.of( binder -> { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test/redis"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1); binder.bind(Cache.class).toProvider(CacheProvider.class); JsonConfigProvider.bind(binder, uuid, CacheProvider.class); } ) ); final CacheProvider cacheProvider = injector.getInstance(CacheProvider.class); Assert.assertNotNull(cacheProvider); Assert.assertEquals(CaffeineCacheProvider.class, cacheProvider.getClass()); }
@Test public void testBasicInjection() throws Exception { final CaffeineCacheConfig config = new CaffeineCacheConfig(); Injector injector = Initialization.makeInjectorWithModules( GuiceInjectors.makeStartupInjector(), ImmutableList.of( binder -> { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test/redis"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1); binder.bind(CaffeineCacheConfig.class).toInstance(config); binder.bind(Cache.class).toProvider(CaffeineCacheProviderWithConfig.class).in(ManageLifecycle.class); } ) ); final Lifecycle lifecycle = injector.getInstance(Lifecycle.class); lifecycle.start(); try { Cache cache = injector.getInstance(Cache.class); Assert.assertEquals(CaffeineCache.class, cache.getClass()); } finally { lifecycle.stop(); } }
@Test public void testFromProperties() { final String keyPrefix = "cache.config.prefix"; final Properties properties = new Properties(); properties.put(keyPrefix + ".expireAfter", "10"); properties.put(keyPrefix + ".sizeInBytes", "100"); properties.put(keyPrefix + ".cacheExecutorFactory", "single_thread"); final Injector injector = Initialization.makeInjectorWithModules( GuiceInjectors.makeStartupInjector(), ImmutableList.of( binder -> { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1); JsonConfigProvider.bind(binder, keyPrefix, CaffeineCacheConfig.class); } ) ); final JsonConfigurator configurator = injector.getInstance(JsonConfigurator.class); final JsonConfigProvider<CaffeineCacheConfig> caffeineCacheConfigJsonConfigProvider = JsonConfigProvider.of( keyPrefix, CaffeineCacheConfig.class ); caffeineCacheConfigJsonConfigProvider.inject(properties, configurator); final CaffeineCacheConfig config = caffeineCacheConfigJsonConfigProvider.get().get(); Assert.assertEquals(10, config.getExpireAfter()); Assert.assertEquals(100, config.getSizeInBytes()); Assert.assertNotNull(config.createExecutor()); }
@Test public void testMixedCaseFromProperties() { final String keyPrefix = "cache.config.prefix"; final Properties properties = new Properties(); properties.put(keyPrefix + ".expireAfter", "10"); properties.put(keyPrefix + ".sizeInBytes", "100"); properties.put(keyPrefix + ".cacheExecutorFactory", "CoMmON_FjP"); final Injector injector = Initialization.makeInjectorWithModules( GuiceInjectors.makeStartupInjector(), ImmutableList.of( binder -> { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1); JsonConfigProvider.bind(binder, keyPrefix, CaffeineCacheConfig.class); } ) ); final JsonConfigurator configurator = injector.getInstance(JsonConfigurator.class); final JsonConfigProvider<CaffeineCacheConfig> caffeineCacheConfigJsonConfigProvider = JsonConfigProvider.of( keyPrefix, CaffeineCacheConfig.class ); caffeineCacheConfigJsonConfigProvider.inject(properties, configurator); final CaffeineCacheConfig config = caffeineCacheConfigJsonConfigProvider.get().get(); Assert.assertEquals(10, config.getExpireAfter()); Assert.assertEquals(100, config.getSizeInBytes()); Assert.assertEquals(ForkJoinPool.commonPool(), config.createExecutor()); }
@Test public void testDefaultFromProperties() { final String keyPrefix = "cache.config.prefix"; final Properties properties = new Properties(); final Injector injector = Initialization.makeInjectorWithModules( GuiceInjectors.makeStartupInjector(), ImmutableList.of( binder -> { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0); binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1); JsonConfigProvider.bind(binder, keyPrefix, CaffeineCacheConfig.class); } ) ); final JsonConfigurator configurator = injector.getInstance(JsonConfigurator.class); final JsonConfigProvider<CaffeineCacheConfig> caffeineCacheConfigJsonConfigProvider = JsonConfigProvider.of( keyPrefix, CaffeineCacheConfig.class ); caffeineCacheConfigJsonConfigProvider.inject(properties, configurator); final CaffeineCacheConfig config = caffeineCacheConfigJsonConfigProvider.get().get(); Assert.assertEquals(-1, config.getExpireAfter()); Assert.assertEquals(-1L, config.getSizeInBytes()); Assert.assertEquals(ForkJoinPool.commonPool(), config.createExecutor()); }