use of io.cdap.cdap.common.guice.ConfigModule in project cdap by caskdata.
the class DatasetServiceTestBase method initializeAndStartService.
protected static void initializeAndStartService(CConfiguration cConf) throws Exception {
// TODO: this whole method is a mess. Streamline it!
injector = Guice.createInjector(new ConfigModule(cConf), RemoteAuthenticatorModules.getNoOpModule(), new InMemoryDiscoveryModule(), new NonCustomLocationUnitTestModule(), new NamespaceAdminTestModule(), new SystemDatasetRuntimeModule().getInMemoryModules(), new TransactionInMemoryModule(), new AuthorizationTestModule(), new StorageModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule(), new AbstractModule() {
@Override
protected void configure() {
bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class).in(Singleton.class);
bind(DatasetDefinitionRegistryFactory.class).to(DefaultDatasetDefinitionRegistryFactory.class).in(Scopes.SINGLETON);
// through the injector, we only need RemoteDatasetFramework in these tests
bind(RemoteDatasetFramework.class);
bind(OwnerStore.class).to(InMemoryOwnerStore.class);
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
}
});
AccessEnforcer authEnforcer = injector.getInstance(AccessEnforcer.class);
AuthenticationContext authenticationContext = injector.getInstance(AuthenticationContext.class);
transactionRunner = injector.getInstance(TransactionRunner.class);
DiscoveryService discoveryService = injector.getInstance(DiscoveryService.class);
discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
dsFramework = injector.getInstance(RemoteDatasetFramework.class);
// Tx Manager to support working with datasets
txManager = injector.getInstance(TransactionManager.class);
txManager.startAndWait();
StructuredTableAdmin structuredTableAdmin = injector.getInstance(StructuredTableAdmin.class);
StoreDefinition.createAllTables(structuredTableAdmin);
TransactionSystemClient txSystemClient = injector.getInstance(TransactionSystemClient.class);
TransactionSystemClientService txSystemClientService = new DelegatingTransactionSystemClientService(txSystemClient);
NamespacePathLocator namespacePathLocator = injector.getInstance(NamespacePathLocator.class);
SystemDatasetInstantiatorFactory datasetInstantiatorFactory = new SystemDatasetInstantiatorFactory(locationFactory, dsFramework, cConf);
// ok to pass null, since the impersonator won't actually be called, if kerberos security is not enabled
Impersonator impersonator = new DefaultImpersonator(cConf, null);
DatasetAdminService datasetAdminService = new DatasetAdminService(dsFramework, cConf, locationFactory, datasetInstantiatorFactory, impersonator);
ImmutableSet<HttpHandler> handlers = ImmutableSet.<HttpHandler>of(new DatasetAdminOpHTTPHandler(datasetAdminService));
MetricsCollectionService metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
opExecutorService = new DatasetOpExecutorService(cConf, SConfiguration.create(), discoveryService, metricsCollectionService, handlers);
opExecutorService.startAndWait();
Map<String, DatasetModule> defaultModules = injector.getInstance(Key.get(new TypeLiteral<Map<String, DatasetModule>>() {
}, Constants.Dataset.Manager.DefaultDatasetModules.class));
ImmutableMap<String, DatasetModule> modules = ImmutableMap.<String, DatasetModule>builder().putAll(defaultModules).build();
registryFactory = injector.getInstance(DatasetDefinitionRegistryFactory.class);
inMemoryDatasetFramework = new InMemoryDatasetFramework(registryFactory, modules);
DiscoveryExploreClient exploreClient = new DiscoveryExploreClient(discoveryServiceClient, authenticationContext);
ExploreFacade exploreFacade = new ExploreFacade(exploreClient, cConf);
namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
namespaceAdmin.create(NamespaceMeta.DEFAULT);
ownerAdmin = injector.getInstance(OwnerAdmin.class);
NamespaceQueryAdmin namespaceQueryAdmin = injector.getInstance(NamespaceQueryAdmin.class);
DatasetTypeManager typeManager = new DatasetTypeManager(cConf, locationFactory, impersonator, transactionRunner);
DatasetOpExecutor opExecutor = new InMemoryDatasetOpExecutor(dsFramework);
DatasetInstanceManager instanceManager = new DatasetInstanceManager(transactionRunner);
DatasetTypeService noAuthTypeService = new DefaultDatasetTypeService(typeManager, namespaceAdmin, namespacePathLocator, cConf, impersonator, txSystemClientService, transactionRunner, defaultModules);
DatasetTypeService typeService = new AuthorizationDatasetTypeService(noAuthTypeService, authEnforcer, authenticationContext);
instanceService = new DatasetInstanceService(typeService, noAuthTypeService, instanceManager, opExecutor, exploreFacade, namespaceQueryAdmin, ownerAdmin, authEnforcer, authenticationContext, new NoOpMetadataServiceClient());
service = new DatasetService(cConf, SConfiguration.create(), discoveryService, discoveryServiceClient, metricsCollectionService, new HashSet<>(), typeService, instanceService);
// Start dataset service, wait for it to be discoverable
service.startAndWait();
waitForService(Constants.Service.DATASET_EXECUTOR);
waitForService(Constants.Service.DATASET_MANAGER);
// this usually happens while creating a namespace, however not doing that in data fabric tests
Locations.mkdirsIfNotExists(namespacePathLocator.get(NamespaceId.DEFAULT));
}
use of io.cdap.cdap.common.guice.ConfigModule in project cdap by caskdata.
the class DatasetOpExecutorServiceTest method setUp.
@Before
public void setUp() throws Exception {
Configuration hConf = new Configuration();
CConfiguration cConf = CConfiguration.create();
File datasetDir = new File(TMP_FOLDER.newFolder(), "datasetUser");
Assert.assertTrue(datasetDir.mkdirs());
cConf.set(Constants.Dataset.Manager.OUTPUT_DIR, datasetDir.getAbsolutePath());
cConf.set(Constants.Service.MASTER_SERVICES_BIND_ADDRESS, "localhost");
cConf.set(Constants.Dataset.Executor.ADDRESS, "localhost");
cConf.setInt(Constants.Dataset.Executor.PORT, Networks.getRandomPort());
Injector injector = Guice.createInjector(new ConfigModule(cConf, hConf), RemoteAuthenticatorModules.getNoOpModule(), new IOModule(), new ZKClientModule(), new KafkaClientModule(), new InMemoryDiscoveryModule(), new NonCustomLocationUnitTestModule(), new DataFabricModules().getInMemoryModules(), new DataSetsModules().getStandaloneModules(), new DataSetServiceModules().getInMemoryModules(), new TransactionMetricsModule(), new ExploreClientModule(), new NamespaceAdminTestModule(), new AuthenticationContextModules().getMasterModule(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AbstractModule() {
@Override
protected void configure() {
bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
bind(MetadataServiceClient.class).to(NoOpMetadataServiceClient.class);
}
});
txManager = injector.getInstance(TransactionManager.class);
txManager.startAndWait();
StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
dsOpExecService = injector.getInstance(DatasetOpExecutorService.class);
dsOpExecService.startAndWait();
managerService = injector.getInstance(DatasetService.class);
managerService.startAndWait();
dsFramework = injector.getInstance(DatasetFramework.class);
// find host
DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class);
endpointStrategy = new RandomEndpointStrategy(() -> discoveryClient.discover(Constants.Service.DATASET_MANAGER));
namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
namespaceAdmin.create(NamespaceMeta.DEFAULT);
namespaceAdmin.create(new NamespaceMeta.Builder().setName(bob.getParent()).build());
}
use of io.cdap.cdap.common.guice.ConfigModule in project cdap by caskdata.
the class AbstractDatasetFrameworkTest method setup.
@BeforeClass
public static void setup() throws Exception {
cConf = CConfiguration.create();
File dataDir = new File(TMP_FOLDER.newFolder(), "data");
cConf.set(Constants.CFG_LOCAL_DATA_DIR, dataDir.getAbsolutePath());
final Injector injector = Guice.createInjector(new ConfigModule(cConf), new NonCustomLocationUnitTestModule(), new TransactionInMemoryModule(), new NamespaceAdminTestModule(), new AuditTestModule(), new AbstractModule() {
@Override
protected void configure() {
bind(OwnerStore.class).to(InMemoryOwnerStore.class).in(Scopes.SINGLETON);
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
}
});
locationFactory = injector.getInstance(LocationFactory.class);
namespacePathLocator = injector.getInstance(NamespacePathLocator.class);
txExecutorFactory = injector.getInstance(TransactionExecutorFactory.class);
registryFactory = new DatasetDefinitionRegistryFactory() {
@Override
public DatasetDefinitionRegistry create() {
DefaultDatasetDefinitionRegistry registry = new DefaultDatasetDefinitionRegistry();
injector.injectMembers(registry);
return registry;
}
};
namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
namespaceQueryAdmin = injector.getInstance(NamespaceQueryAdmin.class);
ownerAdmin = injector.getInstance(OwnerAdmin.class);
inMemoryAuditPublisher = injector.getInstance(InMemoryAuditPublisher.class);
}
use of io.cdap.cdap.common.guice.ConfigModule in project cdap by caskdata.
the class TwillAppLifecycleEventHandler method initialize.
@Override
public void initialize(EventHandlerContext context) {
super.initialize(context);
this.runningPublished = new AtomicBoolean();
this.twillRunId = context.getRunId();
Map<String, String> configs = context.getSpecification().getConfigs();
this.programRunId = GSON.fromJson(configs.get("programRunId"), ProgramRunId.class);
this.clusterMode = ClusterMode.valueOf(configs.get("clusterMode"));
this.runtimeMonitorType = RuntimeMonitorType.valueOf(configs.get("monitorType"));
// Fetch cConf and hConf from resources jar
File cConfFile = new File("resources.jar/resources/" + CDAP_CONF_FILE_NAME);
File hConfFile = new File("resources.jar/resources/" + HADOOP_CONF_FILE_NAME);
if (!cConfFile.exists()) {
// This shouldn't happen, unless CDAP is misconfigured
throw new IllegalArgumentException("Missing cConf file " + cConfFile.getAbsolutePath());
}
try {
// Load the configuration from the XML files serialized from the cdap master.
CConfiguration cConf = CConfiguration.create();
cConf.clear();
cConf.addResource(cConfFile.toURI().toURL());
Configuration hConf = new Configuration();
if (hConfFile.exists()) {
hConf.clear();
hConf.addResource(hConfFile.toURI().toURL());
}
// Create the injector to create a program state writer
List<Module> modules = new ArrayList<>(Arrays.asList(new ConfigModule(cConf, hConf), RemoteAuthenticatorModules.getDefaultModule(), new MessagingClientModule(), new AbstractModule() {
@Override
protected void configure() {
bind(ProgramStateWriter.class).to(MessagingProgramStateWriter.class);
}
}));
switch(clusterMode) {
case ON_PREMISE:
modules.add(new AuthenticationContextModules().getProgramContainerModule(cConf));
modules.add(new ZKClientModule());
modules.add(new ZKDiscoveryModule());
modules.add(new KafkaClientModule());
break;
case ISOLATED:
modules.add(new AuthenticationContextModules().getProgramContainerModule(cConf));
modules.add(new RemoteExecutionDiscoveryModule());
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(RuntimeMonitorType.class).toInstance(runtimeMonitorType);
}
});
break;
}
Injector injector = Guice.createInjector(modules);
if (clusterMode == ClusterMode.ON_PREMISE) {
zkClientService = injector.getInstance(ZKClientService.class);
zkClientService.startAndWait();
}
ProgramStateWriter programStateWriter = injector.getInstance(ProgramStateWriter.class);
MessagingService messagingService = injector.getInstance(MessagingService.class);
programStateWriterWithHeartBeat = new ProgramStateWriterWithHeartBeat(programRunId, programStateWriter, messagingService, cConf);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of io.cdap.cdap.common.guice.ConfigModule in project cdap by caskdata.
the class TetheringRuntimeJobManagerTest method setUp.
@BeforeClass
public static void setUp() throws IOException, TopicAlreadyExistsException {
CConfiguration cConf = CConfiguration.create();
cConf.set(Constants.Tethering.TOPIC_PREFIX, "prefix-");
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
Injector injector = Guice.createInjector(new ConfigModule(cConf), new InMemoryDiscoveryModule(), new LocalLocationModule(), new MessagingServerRuntimeModule().getInMemoryModules(), new AbstractModule() {
@Override
protected void configure() {
bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class).in(Scopes.SINGLETON);
}
});
messagingService = injector.getInstance(MessagingService.class);
if (messagingService instanceof Service) {
((Service) messagingService).startAndWait();
}
TetheringConf conf = TetheringConf.fromProperties(PROPERTIES);
topicId = new TopicId(NamespaceId.SYSTEM.getNamespace(), cConf.get(Constants.Tethering.TOPIC_PREFIX) + TETHERED_INSTANCE_NAME);
messagingService.createTopic(new TopicMetadata(topicId, Collections.emptyMap()));
messageFetcher = new MultiThreadMessagingContext(messagingService).getMessageFetcher();
runtimeJobManager = new TetheringRuntimeJobManager(conf, cConf, messagingService);
}
Aggregations