use of io.cdap.cdap.common.guice.ZKDiscoveryModule 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);
}
use of io.cdap.cdap.common.guice.ZKDiscoveryModule in project cdap by cdapio.
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);
}
});
}
use of io.cdap.cdap.common.guice.ZKDiscoveryModule in project cdap by cdapio.
the class SystemWorkerTwillRunnable method createInjector.
@VisibleForTesting
static Injector createInjector(CConfiguration cConf, Configuration hConf, SConfiguration sConf) {
List<Module> modules = new ArrayList<>();
ExecutorService cleanupExecutorService = Executors.newFixedThreadPool(cConf.getInt(Constants.SystemWorker.CLEANUP_THREADS));
CoreSecurityModule coreSecurityModule = new FileBasedCoreSecurityModule() {
@Override
protected void bindKeyManager(Binder binder) {
super.bindKeyManager(binder);
expose(KeyManager.class);
}
};
modules.add(new RemoteTwillModule());
modules.add(new ConfigModule(cConf, hConf, sConf));
modules.add(RemoteAuthenticatorModules.getDefaultModule());
modules.add(new IOModule());
modules.add(new AuthenticationContextModules().getMasterModule());
modules.add(coreSecurityModule);
modules.add(new MetricsClientRuntimeModule().getDistributedModules());
modules.addAll(Arrays.asList(// In K8s, there won't be HBase and the cdap-site should be set to use SQL store for StructuredTable.
new DataSetServiceModules().getStandaloneModules(), new AbstractModule() {
@Override
protected void configure() {
bind(ExecutorService.class).annotatedWith(Names.named(Constants.SystemWorker.CLEANUP_EXECUTOR_SERVICE_BINDING)).toInstance(cleanupExecutorService);
}
}, // The Dataset set modules are only needed to satisfy dependency injection
new DataSetsModules().getStandaloneModules(), new MessagingClientModule(), new ExploreClientModule(), new AuthorizationModule(), new AuthorizationEnforcementModule().getDistributedModules(), Modules.override(new AppFabricServiceRuntimeModule(cConf).getDistributedModules()).with(new AbstractModule() {
@Override
protected void configure() {
bind(StorageProviderNamespaceAdmin.class).to(LocalStorageProviderNamespaceAdmin.class);
}
}, new DistributedArtifactManagerModule()), Modules.override(new ProgramRunnerRuntimeModule().getDistributedModules(true)).with(new AbstractModule() {
@Override
protected void configure() {
bind(RemoteExecutionTwillRunnerService.class).to(FireAndForgetTwillRunnerService.class).in(Scopes.SINGLETON);
}
}), new SecureStoreClientModule(), new AbstractModule() {
@Override
protected void configure() {
install(new StorageModule());
install(new TransactionExecutorModule());
bind(TransactionSystemClientService.class).to(DelegatingTransactionSystemClientService.class);
bind(TransactionSystemClient.class).to(ConstantTransactionSystemClient.class);
}
}, new DFSLocationModule(), new AbstractModule() {
@Override
protected void configure() {
bind(MetadataPublisher.class).to(MessagingMetadataPublisher.class);
bind(MetadataServiceClient.class).to(DefaultMetadataServiceClient.class);
}
}));
// 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());
} else {
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(DiscoveryService.class).toProvider(new SupplierProviderBridge<>(masterEnv.getDiscoveryServiceSupplier()));
bind(DiscoveryServiceClient.class).toProvider(new SupplierProviderBridge<>(masterEnv.getDiscoveryServiceClientSupplier()));
}
});
modules.add(new RemoteLogAppenderModule());
if (coreSecurityModule.requiresZKClient()) {
modules.add(new ZKClientModule());
}
}
return Guice.createInjector(modules);
}
use of io.cdap.cdap.common.guice.ZKDiscoveryModule in project cdap by cdapio.
the class HBaseMetricsTableTest method setup.
@BeforeClass
public static void setup() throws Exception {
CConfiguration cConf = CConfiguration.create();
cConf.set(Constants.CFG_HDFS_USER, System.getProperty("user.name"));
Injector injector = Guice.createInjector(new DataFabricModules().getDistributedModules(), new ConfigModule(cConf, TEST_HBASE.getConfiguration()), new ZKClientModule(), new ZKDiscoveryModule(), new TransactionMetricsModule(), new DFSLocationModule(), new NamespaceAdminTestModule(), new SystemDatasetRuntimeModule().getDistributedModules(), new DataSetsModules().getInMemoryModules(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getNoOpModule(), new AbstractModule() {
@Override
protected void configure() {
bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
}
});
dsFramework = injector.getInstance(DatasetFramework.class);
tableUtil = injector.getInstance(HBaseTableUtil.class);
ddlExecutor = new HBaseDDLExecutorFactory(cConf, TEST_HBASE.getHBaseAdmin().getConfiguration()).get();
ddlExecutor.createNamespaceIfNotExists(tableUtil.getHBaseNamespace(NamespaceId.SYSTEM));
}
use of io.cdap.cdap.common.guice.ZKDiscoveryModule in project cdap by cdapio.
the class TransactionServiceClientTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
HBaseTestingUtility hBaseTestingUtility = new HBaseTestingUtility();
hBaseTestingUtility.startMiniDFSCluster(1);
Configuration hConf = hBaseTestingUtility.getConfiguration();
hConf.setBoolean("fs.hdfs.impl.disable.cache", true);
zkServer = InMemoryZKServer.builder().build();
zkServer.startAndWait();
CConfiguration cConf = CConfiguration.create();
// tests should use the current user for HDFS
cConf.set(Constants.CFG_HDFS_USER, System.getProperty("user.name"));
cConf.set(Constants.Zookeeper.QUORUM, zkServer.getConnectionStr());
cConf.set(Constants.CFG_LOCAL_DATA_DIR, tmpFolder.newFolder().getAbsolutePath());
cConf.setBoolean(TxConstants.TransactionPruning.PRUNE_ENABLE, false);
// we want persisting for this test
cConf.setBoolean(TxConstants.Manager.CFG_DO_PERSIST, true);
// getCommonConfiguration() sets up an hConf with tx service configuration.
// however, createTxService() will override these with defaults from the CConf.
// hence, we must pass in these settings when creating the tx service.
Configuration extraCConf = new Configuration();
extraCConf.clear();
extraCConf = getCommonConfiguration(extraCConf);
for (Map.Entry<String, String> entry : extraCConf) {
cConf.set(entry.getKey(), entry.getValue());
}
server = TransactionServiceTest.createTxService(zkServer.getConnectionStr(), Networks.getRandomPort(), hConf, tmpFolder.newFolder(), cConf);
server.startAndWait();
injector = Guice.createInjector(new ConfigModule(cConf, hConf), RemoteAuthenticatorModules.getNoOpModule(), new ZKClientModule(), new ZKDiscoveryModule(), new NonCustomLocationUnitTestModule(), new TransactionMetricsModule(), new DataFabricModules().getDistributedModules(), new AbstractModule() {
@Override
protected void configure() {
bind(NamespaceQueryAdmin.class).to(SimpleNamespaceQueryAdmin.class);
bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
}
}, Modules.override(new DataSetsModules().getDistributedModules()).with(new AbstractModule() {
@Override
protected void configure() {
bind(MetadataStorage.class).to(NoopMetadataStorage.class);
}
}), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getNoOpModule());
zkClient = injector.getInstance(ZKClientService.class);
zkClient.startAndWait();
txStateStorage = injector.getInstance(TransactionStateStorage.class);
txStateStorage.startAndWait();
}
Aggregations