Search in sources :

Example 16 with ZKClientModule

use of io.cdap.cdap.common.guice.ZKClientModule in project cdap by caskdata.

the class LeaderElectionMessagingServiceTest method createInjector.

private Injector createInjector(int instanceId) {
    CConfiguration cConf = CConfiguration.copy(LeaderElectionMessagingServiceTest.cConf);
    cConf.setInt(Constants.MessagingSystem.CONTAINER_INSTANCE_ID, instanceId);
    return Guice.createInjector(new ConfigModule(cConf), new ZKClientModule(), new ZKDiscoveryModule(), new AuthorizationEnforcementModule().getNoOpModules(), new DFSLocationModule(), new AbstractModule() {

        @Override
        protected void configure() {
            // Bindings to services for testing only
            bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class);
            // Use the same in memory client across all injectors.
            bind(NamespaceQueryAdmin.class).toInstance(namespaceQueryAdmin);
        }
    }, new PrivateModule() {

        @Override
        protected void configure() {
            // This is very similar to bindings in distributed mode, except we bind to level db instead of HBase
            // Also the level DB has to be one instance since unit-test runs in the same process.
            bind(TableFactory.class).annotatedWith(Names.named(CachingTableFactory.DELEGATE_TABLE_FACTORY)).toInstance(levelDBTableFactory);
            // The cache must be in singleton scope
            bind(MessageTableCacheProvider.class).to(DefaultMessageTableCacheProvider.class).in(Scopes.SINGLETON);
            bind(TableFactory.class).to(CachingTableFactory.class);
            // Bind http handlers
            MessagingServerRuntimeModule.bindHandlers(binder(), Constants.MessagingSystem.HANDLER_BINDING_NAME);
            bind(MessagingService.class).to(LeaderElectionMessagingService.class).in(Scopes.SINGLETON);
            expose(MessagingService.class);
        }
    });
}
Also used : MessageTableCacheProvider(io.cdap.cdap.messaging.store.cache.MessageTableCacheProvider) DefaultMessageTableCacheProvider(io.cdap.cdap.messaging.store.cache.DefaultMessageTableCacheProvider) ZKDiscoveryModule(io.cdap.cdap.common.guice.ZKDiscoveryModule) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) CachingTableFactory(io.cdap.cdap.messaging.store.cache.CachingTableFactory) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) AbstractModule(com.google.inject.AbstractModule) MessagingService(io.cdap.cdap.messaging.MessagingService) ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) DFSLocationModule(io.cdap.cdap.common.guice.DFSLocationModule) CachingTableFactory(io.cdap.cdap.messaging.store.cache.CachingTableFactory) TableFactory(io.cdap.cdap.messaging.store.TableFactory) LevelDBTableFactory(io.cdap.cdap.messaging.store.leveldb.LevelDBTableFactory) AuthorizationEnforcementModule(io.cdap.cdap.security.authorization.AuthorizationEnforcementModule) PrivateModule(com.google.inject.PrivateModule)

Example 17 with ZKClientModule

use of io.cdap.cdap.common.guice.ZKClientModule in project cdap by caskdata.

the class DistributedLogFrameworkTest method createInjector.

private Injector createInjector() throws IOException {
    CConfiguration cConf = CConfiguration.copy(KAFKA_TESTER.getCConf());
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    // The event delay cannot be too small, otherwise the events will be out of order, especially on slow machine
    cConf.setLong(Constants.Logging.PIPELINE_EVENT_DELAY_MS, 2000);
    cConf.setLong("log.process.pipeline.checkpoint.interval.ms", 2000);
    MockTwillContext mockTwillContext = new MockTwillContext();
    return Guice.createInjector(new ConfigModule(cConf), new ZKClientModule(), new InMemoryDiscoveryModule(), new KafkaClientModule(), new LocalLocationModule(), new DistributedLogFrameworkModule(mockTwillContext.getInstanceId(), mockTwillContext.getInstanceCount()), new DataSetsModules().getInMemoryModules(), new TransactionModules().getInMemoryModules(), new TransactionExecutorModule(), new SystemDatasetRuntimeModule().getInMemoryModules(), new NamespaceAdminTestModule(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getNoOpModule(), new StorageModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class);
            bind(UGIProvider.class).to(CurrentUGIProvider.class);
            bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
        }
    });
}
Also used : MockTwillContext(io.cdap.cdap.common.test.MockTwillContext) InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) StorageModule(io.cdap.cdap.data.runtime.StorageModule) NamespaceAdminTestModule(io.cdap.cdap.common.guice.NamespaceAdminTestModule) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) DataSetsModules(io.cdap.cdap.data.runtime.DataSetsModules) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) DefaultOwnerAdmin(io.cdap.cdap.security.impersonation.DefaultOwnerAdmin) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) AuthorizationTestModule(io.cdap.cdap.security.authorization.AuthorizationTestModule) AbstractModule(com.google.inject.AbstractModule) TransactionModules(org.apache.tephra.runtime.TransactionModules) ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) TransactionExecutorModule(io.cdap.cdap.data.runtime.TransactionExecutorModule) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) KafkaClientModule(io.cdap.cdap.common.guice.KafkaClientModule) DistributedLogFrameworkModule(io.cdap.cdap.logging.guice.DistributedLogFrameworkModule) CurrentUGIProvider(io.cdap.cdap.security.impersonation.CurrentUGIProvider) SystemDatasetRuntimeModule(io.cdap.cdap.data.runtime.SystemDatasetRuntimeModule) AuthorizationEnforcementModule(io.cdap.cdap.security.authorization.AuthorizationEnforcementModule)

Example 18 with ZKClientModule

use of io.cdap.cdap.common.guice.ZKClientModule in project cdap by cdapio.

the class UpgradeTool method createInjector.

@VisibleForTesting
Injector createInjector() {
    return Guice.createInjector(new ConfigModule(cConf, hConf), RemoteAuthenticatorModules.getDefaultModule(), new DFSLocationModule(), new ZKClientModule(), new ZKDiscoveryModule(), new MessagingClientModule(), Modules.override(new DataSetsModules().getDistributedModules()).with(new AbstractModule() {

        @Override
        protected void configure() {
            bind(DatasetFramework.class).to(InMemoryDatasetFramework.class).in(Scopes.SINGLETON);
            // the DataSetsModules().getDistributedModules() binds to RemoteDatasetFramework so override that to
            // the same InMemoryDatasetFramework
            bind(DatasetFramework.class).annotatedWith(Names.named(DataSetsModules.BASE_DATASET_FRAMEWORK)).to(DatasetFramework.class);
            bind(DatasetDefinitionRegistryFactory.class).to(DefaultDatasetDefinitionRegistryFactory.class).in(Scopes.SINGLETON);
            // CDAP-5954 Upgrade tool does not need to record lineage and metadata changes for now.
            bind(LineageWriter.class).to(NoOpLineageWriter.class);
            bind(FieldLineageWriter.class).to(NoOpLineageWriter.class);
        }
    }), new TwillModule(), new ExploreClientModule(), new ProgramRunnerRuntimeModule().getDistributedModules(), new SystemDatasetRuntimeModule().getDistributedModules(), new KafkaClientModule(), new IOModule(), CoreSecurityRuntimeModule.getDistributedModule(cConf), new AuthenticationContextModules().getMasterModule(), new AuthorizationModule(), new AuthorizationEnforcementModule().getMasterModule(), new SecureStoreServerModule(), new DataFabricModules(UpgradeTool.class.getName()).getDistributedModules(), new AppFabricServiceRuntimeModule(cConf).getDistributedModules(), new KafkaLogAppenderModule(), // the DataFabricDistributedModule needs MetricsCollectionService binding
    new AbstractModule() {

        @Override
        protected void configure() {
            // Since Upgrade tool does not do anything with Metrics we just bind it to no-op implementations
            bind(MetricsCollectionService.class).toInstance(new NoOpMetricsCollectionService());
            bind(MetricsSystemClient.class).toInstance(new NoOpMetricsSystemClient());
        }

        @Provides
        @Singleton
        @Named("datasetInstanceManager")
        @SuppressWarnings("unused")
        public DatasetInstanceManager getDatasetInstanceManager(TransactionRunner transactionRunner) {
            return new DatasetInstanceManager(transactionRunner);
        }

        // This is needed because the LocalApplicationManager
        // expects a dsframework injection named datasetMDS
        @Provides
        @Singleton
        @Named("datasetMDS")
        @SuppressWarnings("unused")
        public DatasetFramework getInDsFramework(DatasetFramework dsFramework) {
            return dsFramework;
        }
    }, new AbstractModule() {

        @Override
        protected void configure() {
            // TODO (CDAP-14677): find a better way to inject metadata publisher
            bind(MetadataServiceClient.class).to(NoOpMetadataServiceClient.class);
        }
    });
}
Also used : MessagingClientModule(io.cdap.cdap.messaging.guice.MessagingClientModule) IOModule(io.cdap.cdap.common.guice.IOModule) NoOpMetricsSystemClient(io.cdap.cdap.common.metrics.NoOpMetricsSystemClient) ZKDiscoveryModule(io.cdap.cdap.common.guice.ZKDiscoveryModule) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) DatasetFramework(io.cdap.cdap.data2.dataset2.DatasetFramework) InMemoryDatasetFramework(io.cdap.cdap.data2.dataset2.InMemoryDatasetFramework) ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) KafkaClientModule(io.cdap.cdap.common.guice.KafkaClientModule) DefaultDatasetDefinitionRegistryFactory(io.cdap.cdap.data2.dataset2.DefaultDatasetDefinitionRegistryFactory) SystemDatasetRuntimeModule(io.cdap.cdap.data.runtime.SystemDatasetRuntimeModule) AuthorizationModule(io.cdap.cdap.app.guice.AuthorizationModule) InMemoryDatasetFramework(io.cdap.cdap.data2.dataset2.InMemoryDatasetFramework) Named(com.google.inject.name.Named) TwillModule(io.cdap.cdap.app.guice.TwillModule) DatasetInstanceManager(io.cdap.cdap.data2.datafabric.dataset.instance.DatasetInstanceManager) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) DataSetsModules(io.cdap.cdap.data.runtime.DataSetsModules) Provides(com.google.inject.Provides) AbstractModule(com.google.inject.AbstractModule) KafkaLogAppenderModule(io.cdap.cdap.logging.guice.KafkaLogAppenderModule) DFSLocationModule(io.cdap.cdap.common.guice.DFSLocationModule) ProgramRunnerRuntimeModule(io.cdap.cdap.app.guice.ProgramRunnerRuntimeModule) FieldLineageWriter(io.cdap.cdap.data2.metadata.writer.FieldLineageWriter) LineageWriter(io.cdap.cdap.data2.metadata.writer.LineageWriter) NoOpLineageWriter(io.cdap.cdap.data2.metadata.writer.NoOpLineageWriter) ExploreClientModule(io.cdap.cdap.explore.guice.ExploreClientModule) Singleton(com.google.inject.Singleton) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) NoOpMetadataServiceClient(io.cdap.cdap.data2.metadata.writer.NoOpMetadataServiceClient) DataFabricModules(io.cdap.cdap.data.runtime.DataFabricModules) AuthorizationEnforcementModule(io.cdap.cdap.security.authorization.AuthorizationEnforcementModule) SecureStoreServerModule(io.cdap.cdap.security.guice.SecureStoreServerModule) AppFabricServiceRuntimeModule(io.cdap.cdap.app.guice.AppFabricServiceRuntimeModule) FieldLineageWriter(io.cdap.cdap.data2.metadata.writer.FieldLineageWriter) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 19 with ZKClientModule

use of io.cdap.cdap.common.guice.ZKClientModule in project cdap by cdapio.

the class DistributedProgramContainerModule method addOnPremiseModules.

private void addOnPremiseModules(List<Module> modules) {
    CoreSecurityModule coreSecurityModule = CoreSecurityRuntimeModule.getDistributedModule(cConf);
    modules.add(new AuthenticationContextModules().getMasterModule());
    modules.add(coreSecurityModule);
    // If MasterEnvironment is not available, assuming it is the old hadoop stack with ZK, Kafka
    MasterEnvironment masterEnv = MasterEnvironments.getMasterEnvironment();
    if (masterEnv == null) {
        modules.add(new ZKClientModule());
        modules.add(new ZKDiscoveryModule());
        modules.add(new KafkaClientModule());
        modules.add(new KafkaLogAppenderModule());
        return;
    }
    if (coreSecurityModule.requiresZKClient()) {
        modules.add(new ZKClientModule());
    }
    modules.add(new AbstractModule() {

        @Override
        protected void configure() {
            bind(DiscoveryService.class).toProvider(new SupplierProviderBridge<>(masterEnv.getDiscoveryServiceSupplier()));
            bind(DiscoveryServiceClient.class).toProvider(new SupplierProviderBridge<>(masterEnv.getDiscoveryServiceClientSupplier()));
            bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
        }
    });
    modules.add(new RemoteLogAppenderModule());
}
Also used : ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) CoreSecurityModule(io.cdap.cdap.security.guice.CoreSecurityModule) MasterEnvironment(io.cdap.cdap.master.spi.environment.MasterEnvironment) ZKDiscoveryModule(io.cdap.cdap.common.guice.ZKDiscoveryModule) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) KafkaClientModule(io.cdap.cdap.common.guice.KafkaClientModule) RemoteLogAppenderModule(io.cdap.cdap.logging.guice.RemoteLogAppenderModule) SupplierProviderBridge(io.cdap.cdap.common.guice.SupplierProviderBridge) DefaultOwnerAdmin(io.cdap.cdap.security.impersonation.DefaultOwnerAdmin) KafkaLogAppenderModule(io.cdap.cdap.logging.guice.KafkaLogAppenderModule) AbstractModule(com.google.inject.AbstractModule)

Example 20 with ZKClientModule

use of io.cdap.cdap.common.guice.ZKClientModule in project cdap by cdapio.

the class DistributedKeyManagerTest method setup.

@BeforeClass
public static void setup() throws Exception {
    HBaseTestingUtility testUtil = new HBaseTestingUtility();
    zkCluster = testUtil.startMiniZKCluster();
    String zkConnectString = testUtil.getConfiguration().get(HConstants.ZOOKEEPER_QUORUM) + ":" + zkCluster.getClientPort();
    LOG.info("Running ZK cluster at " + zkConnectString);
    CConfiguration cConf1 = CConfiguration.create();
    cConf1.setBoolean(Constants.Security.ENABLED, true);
    cConf1.set(Constants.Zookeeper.QUORUM, zkConnectString);
    CConfiguration cConf2 = CConfiguration.create();
    cConf2.setBoolean(Constants.Security.ENABLED, true);
    cConf2.set(Constants.Zookeeper.QUORUM, zkConnectString);
    List<Module> modules = new ArrayList<>();
    modules.add(new ConfigModule(cConf1, testUtil.getConfiguration()));
    modules.add(new IOModule());
    CoreSecurityModule coreSecurityModule = CoreSecurityRuntimeModule.getDistributedModule(cConf1);
    modules.add(coreSecurityModule);
    if (coreSecurityModule.requiresZKClient()) {
        modules.add(new ZKClientModule());
        modules.add(new ZKDiscoveryModule());
    }
    injector1 = Guice.createInjector(modules);
    modules.clear();
    modules.add(new ConfigModule(cConf2, testUtil.getConfiguration()));
    modules.add(new IOModule());
    coreSecurityModule = CoreSecurityRuntimeModule.getDistributedModule(cConf2);
    modules.add(coreSecurityModule);
    if (coreSecurityModule.requiresZKClient()) {
        modules.add(new ZKClientModule());
        modules.add(new ZKDiscoveryModule());
    }
    injector2 = Guice.createInjector(modules);
}
Also used : IOModule(io.cdap.cdap.common.guice.IOModule) ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) CoreSecurityModule(io.cdap.cdap.security.guice.CoreSecurityModule) ZKDiscoveryModule(io.cdap.cdap.common.guice.ZKDiscoveryModule) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) ArrayList(java.util.ArrayList) Module(com.google.inject.Module) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) CoreSecurityRuntimeModule(io.cdap.cdap.security.guice.CoreSecurityRuntimeModule) ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) CoreSecurityModule(io.cdap.cdap.security.guice.CoreSecurityModule) IOModule(io.cdap.cdap.common.guice.IOModule) ZKDiscoveryModule(io.cdap.cdap.common.guice.ZKDiscoveryModule) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) BeforeClass(org.junit.BeforeClass)

Aggregations

ZKClientModule (io.cdap.cdap.common.guice.ZKClientModule)48 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)46 AbstractModule (com.google.inject.AbstractModule)40 AuthenticationContextModules (io.cdap.cdap.security.auth.context.AuthenticationContextModules)38 ZKDiscoveryModule (io.cdap.cdap.common.guice.ZKDiscoveryModule)34 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)32 IOModule (io.cdap.cdap.common.guice.IOModule)28 KafkaClientModule (io.cdap.cdap.common.guice.KafkaClientModule)26 AuthorizationEnforcementModule (io.cdap.cdap.security.authorization.AuthorizationEnforcementModule)26 DataSetsModules (io.cdap.cdap.data.runtime.DataSetsModules)24 Injector (com.google.inject.Injector)18 Module (com.google.inject.Module)18 DataFabricModules (io.cdap.cdap.data.runtime.DataFabricModules)18 ArrayList (java.util.ArrayList)18 DFSLocationModule (io.cdap.cdap.common.guice.DFSLocationModule)16 KafkaLogAppenderModule (io.cdap.cdap.logging.guice.KafkaLogAppenderModule)16 MessagingClientModule (io.cdap.cdap.messaging.guice.MessagingClientModule)16 CoreSecurityModule (io.cdap.cdap.security.guice.CoreSecurityModule)16 CoreSecurityRuntimeModule (io.cdap.cdap.security.guice.CoreSecurityRuntimeModule)16 VisibleForTesting (com.google.common.annotations.VisibleForTesting)14