Search in sources :

Example 11 with PrivateModule

use of com.google.inject.PrivateModule in project cdap by caskdata.

the class DataSetServiceModules method getStandaloneModules.

@Override
public Module getStandaloneModules() {
    return new AbstractModule() {

        @Override
        protected void configure() {
            // Add the system dataset runtime module as public binding so that adding bindings could be added
            install(new SystemDatasetRuntimeModule().getStandaloneModules());
            install(new PrivateModule() {

                @Override
                protected void configure() {
                    install(new FactoryModuleBuilder().implement(DatasetDefinitionRegistry.class, DefaultDatasetDefinitionRegistry.class).build(DatasetDefinitionRegistryFactory.class));
                    bind(DatasetFramework.class).annotatedWith(Names.named("datasetMDS")).toProvider(DatasetMdsProvider.class).in(Singleton.class);
                    expose(DatasetFramework.class).annotatedWith(Names.named("datasetMDS"));
                    Multibinder.newSetBinder(binder(), DatasetMetricsReporter.class).addBinding().to(LevelDBDatasetMetricsReporter.class);
                    bind(DatasetService.class);
                    expose(DatasetService.class);
                    Named datasetUserName = Names.named(Constants.Service.DATASET_EXECUTOR);
                    Multibinder<HttpHandler> handlerBinder = Multibinder.newSetBinder(binder(), HttpHandler.class, datasetUserName);
                    CommonHandlers.add(handlerBinder);
                    handlerBinder.addBinding().to(DatasetAdminOpHTTPHandler.class);
                    bind(DatasetOpExecutorService.class).in(Scopes.SINGLETON);
                    expose(DatasetOpExecutorService.class);
                    bind(DatasetOpExecutor.class).to(LocalDatasetOpExecutor.class);
                    expose(DatasetOpExecutor.class);
                }
            });
        }
    };
}
Also used : Named(com.google.inject.name.Named) HttpHandler(co.cask.http.HttpHandler) DatasetAdminOpHTTPHandler(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetAdminOpHTTPHandler) Multibinder(com.google.inject.multibindings.Multibinder) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) DefaultDatasetDefinitionRegistry(co.cask.cdap.data2.dataset2.DefaultDatasetDefinitionRegistry) DatasetDefinitionRegistry(co.cask.cdap.api.dataset.module.DatasetDefinitionRegistry) LocalDatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.LocalDatasetOpExecutor) DatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor) YarnDatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.YarnDatasetOpExecutor) AbstractModule(com.google.inject.AbstractModule) DefaultDatasetDefinitionRegistry(co.cask.cdap.data2.dataset2.DefaultDatasetDefinitionRegistry) Singleton(com.google.inject.Singleton) DatasetOpExecutorService(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) LevelDBDatasetMetricsReporter(co.cask.cdap.data2.metrics.LevelDBDatasetMetricsReporter) DatasetMetricsReporter(co.cask.cdap.data2.metrics.DatasetMetricsReporter) HBaseDatasetMetricsReporter(co.cask.cdap.data2.metrics.HBaseDatasetMetricsReporter) LevelDBDatasetMetricsReporter(co.cask.cdap.data2.metrics.LevelDBDatasetMetricsReporter) LocalDatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.LocalDatasetOpExecutor) PrivateModule(com.google.inject.PrivateModule)

Example 12 with PrivateModule

use of com.google.inject.PrivateModule in project cdap by caskdata.

the class DataSetServiceModules method getDistributedModules.

@Override
public Module getDistributedModules() {
    return new AbstractModule() {

        @Override
        protected void configure() {
            // Add the system dataset runtime module as public binding so that adding bindings could be added
            install(new SystemDatasetRuntimeModule().getDistributedModules());
            install(new PrivateModule() {

                @Override
                protected void configure() {
                    install(new FactoryModuleBuilder().implement(DatasetDefinitionRegistry.class, DefaultDatasetDefinitionRegistry.class).build(DatasetDefinitionRegistryFactory.class));
                    bind(DatasetFramework.class).annotatedWith(Names.named("datasetMDS")).toProvider(DatasetMdsProvider.class).in(Singleton.class);
                    expose(DatasetFramework.class).annotatedWith(Names.named("datasetMDS"));
                    Multibinder.newSetBinder(binder(), DatasetMetricsReporter.class).addBinding().to(HBaseDatasetMetricsReporter.class);
                    // NOTE: this cannot be a singleton, because MasterServiceMain needs to obtain a new instance
                    //       every time it becomes leader and starts a dataset service.
                    bind(DatasetService.class);
                    expose(DatasetService.class);
                    Named datasetUserName = Names.named(Constants.Service.DATASET_EXECUTOR);
                    Multibinder<HttpHandler> handlerBinder = Multibinder.newSetBinder(binder(), HttpHandler.class, datasetUserName);
                    CommonHandlers.add(handlerBinder);
                    handlerBinder.addBinding().to(DatasetAdminOpHTTPHandler.class);
                    bind(DatasetOpExecutorService.class).in(Scopes.SINGLETON);
                    expose(DatasetOpExecutorService.class);
                    bind(DatasetOpExecutor.class).to(YarnDatasetOpExecutor.class);
                    expose(DatasetOpExecutor.class);
                }
            });
        }
    };
}
Also used : Named(com.google.inject.name.Named) HttpHandler(co.cask.http.HttpHandler) DatasetAdminOpHTTPHandler(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetAdminOpHTTPHandler) Multibinder(com.google.inject.multibindings.Multibinder) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) DefaultDatasetDefinitionRegistry(co.cask.cdap.data2.dataset2.DefaultDatasetDefinitionRegistry) DatasetDefinitionRegistry(co.cask.cdap.api.dataset.module.DatasetDefinitionRegistry) LocalDatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.LocalDatasetOpExecutor) DatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor) YarnDatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.YarnDatasetOpExecutor) AbstractModule(com.google.inject.AbstractModule) DefaultDatasetDefinitionRegistry(co.cask.cdap.data2.dataset2.DefaultDatasetDefinitionRegistry) Singleton(com.google.inject.Singleton) DatasetOpExecutorService(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) HBaseDatasetMetricsReporter(co.cask.cdap.data2.metrics.HBaseDatasetMetricsReporter) LevelDBDatasetMetricsReporter(co.cask.cdap.data2.metrics.LevelDBDatasetMetricsReporter) DatasetMetricsReporter(co.cask.cdap.data2.metrics.DatasetMetricsReporter) HBaseDatasetMetricsReporter(co.cask.cdap.data2.metrics.HBaseDatasetMetricsReporter) YarnDatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.YarnDatasetOpExecutor) PrivateModule(com.google.inject.PrivateModule)

Example 13 with PrivateModule

use of com.google.inject.PrivateModule in project cdap by caskdata.

the class DataSetsModules method getInMemoryModules.

@Override
public Module getInMemoryModules() {
    return new PrivateModule() {

        @Override
        protected void configure() {
            install(new FactoryModuleBuilder().implement(DatasetDefinitionRegistry.class, DefaultDatasetDefinitionRegistry.class).build(DatasetDefinitionRegistryFactory.class));
            bind(MetadataStore.class).to(NoOpMetadataStore.class);
            expose(MetadataStore.class);
            bind(DatasetFramework.class).annotatedWith(Names.named(BASE_DATASET_FRAMEWORK)).to(InMemoryDatasetFramework.class).in(Scopes.SINGLETON);
            bind(LineageStoreReader.class).to(LineageStore.class);
            bind(LineageStoreWriter.class).to(LineageStore.class);
            // Need to expose LineageStoreReader as it's being used by the LineageHandler (through LineageAdmin)
            expose(LineageStoreReader.class);
            bind(LineageWriter.class).to(BasicLineageWriter.class);
            expose(LineageWriter.class);
            bind(UsageRegistry.class).to(DefaultUsageRegistry.class).in(Scopes.SINGLETON);
            expose(UsageRegistry.class);
            bind(RuntimeUsageRegistry.class).to(DefaultUsageRegistry.class).in(Scopes.SINGLETON);
            expose(RuntimeUsageRegistry.class);
            bind(DefaultUsageRegistry.class).in(Scopes.SINGLETON);
            bind(DatasetFramework.class).to(LineageWriterDatasetFramework.class);
            expose(DatasetFramework.class);
            bind(DefaultOwnerStore.class).in(Scopes.SINGLETON);
            bind(OwnerStore.class).to(DefaultOwnerStore.class);
            expose(OwnerStore.class);
        }
    };
}
Also used : DefaultMetadataStore(co.cask.cdap.data2.metadata.store.DefaultMetadataStore) NoOpMetadataStore(co.cask.cdap.data2.metadata.store.NoOpMetadataStore) MetadataStore(co.cask.cdap.data2.metadata.store.MetadataStore) DatasetFramework(co.cask.cdap.data2.dataset2.DatasetFramework) RemoteDatasetFramework(co.cask.cdap.data2.datafabric.dataset.RemoteDatasetFramework) LineageWriterDatasetFramework(co.cask.cdap.data2.metadata.writer.LineageWriterDatasetFramework) InMemoryDatasetFramework(co.cask.cdap.data2.dataset2.InMemoryDatasetFramework) DatasetDefinitionRegistryFactory(co.cask.cdap.data2.dataset2.DatasetDefinitionRegistryFactory) LineageWriter(co.cask.cdap.data2.metadata.writer.LineageWriter) BasicLineageWriter(co.cask.cdap.data2.metadata.writer.BasicLineageWriter) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) LineageStoreReader(co.cask.cdap.data2.metadata.lineage.LineageStoreReader) DefaultOwnerStore(co.cask.cdap.store.DefaultOwnerStore) LineageStoreWriter(co.cask.cdap.data2.metadata.lineage.LineageStoreWriter) DefaultUsageRegistry(co.cask.cdap.data2.registry.DefaultUsageRegistry) PrivateModule(com.google.inject.PrivateModule) OwnerStore(co.cask.cdap.security.impersonation.OwnerStore) DefaultOwnerStore(co.cask.cdap.store.DefaultOwnerStore) InMemoryDatasetFramework(co.cask.cdap.data2.dataset2.InMemoryDatasetFramework)

Example 14 with PrivateModule

use of com.google.inject.PrivateModule in project cdap by caskdata.

the class InMemoryMetricsTableTest method setup.

@BeforeClass
public static void setup() throws Exception {
    Injector injector = Guice.createInjector(new ConfigModule(), new NonCustomLocationUnitTestModule().getModule(), new DiscoveryRuntimeModule().getInMemoryModules(), new DataFabricModules().getInMemoryModules(), new TransactionMetricsModule(), new SystemDatasetRuntimeModule().getInMemoryModules(), new PrivateModule() {

        @Override
        protected void configure() {
            install(new FactoryModuleBuilder().implement(DatasetDefinitionRegistry.class, DefaultDatasetDefinitionRegistry.class).build(DatasetDefinitionRegistryFactory.class));
            bind(DatasetFramework.class).to(InMemoryDatasetFramework.class);
            expose(DatasetFramework.class);
        }
    });
    dsFramework = injector.getInstance(DatasetFramework.class);
}
Also used : ConfigModule(co.cask.cdap.common.guice.ConfigModule) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) DefaultDatasetDefinitionRegistry(co.cask.cdap.data2.dataset2.DefaultDatasetDefinitionRegistry) DatasetDefinitionRegistry(co.cask.cdap.api.dataset.module.DatasetDefinitionRegistry) NonCustomLocationUnitTestModule(co.cask.cdap.common.guice.NonCustomLocationUnitTestModule) TransactionMetricsModule(co.cask.cdap.data.runtime.TransactionMetricsModule) DatasetFramework(co.cask.cdap.data2.dataset2.DatasetFramework) InMemoryDatasetFramework(co.cask.cdap.data2.dataset2.InMemoryDatasetFramework) DefaultDatasetDefinitionRegistry(co.cask.cdap.data2.dataset2.DefaultDatasetDefinitionRegistry) Injector(com.google.inject.Injector) SystemDatasetRuntimeModule(co.cask.cdap.data.runtime.SystemDatasetRuntimeModule) DiscoveryRuntimeModule(co.cask.cdap.common.guice.DiscoveryRuntimeModule) DataFabricModules(co.cask.cdap.data.runtime.DataFabricModules) PrivateModule(com.google.inject.PrivateModule) InMemoryDatasetFramework(co.cask.cdap.data2.dataset2.InMemoryDatasetFramework) BeforeClass(org.junit.BeforeClass)

Example 15 with PrivateModule

use of com.google.inject.PrivateModule in project guice by google.

the class ModuleAnnotatedMethodScannerTest method testPrivateModuleWithinPrivateModule.

public void testPrivateModuleWithinPrivateModule() {
    Injector injector = Guice.createInjector(NamedMunger.module(), new PrivateModule() {

        @Override
        protected void configure() {
            expose(Key.get(String.class, named("foo-munged")));
            install(new PrivateModule() {

                @Override
                protected void configure() {
                }

                @Exposed
                @TestProvides
                @Named("foo")
                String foo() {
                    return "foo";
                }
            });
        }
    });
    assertMungedBinding(injector, String.class, "foo", "foo");
}
Also used : Injector(com.google.inject.Injector) PrivateModule(com.google.inject.PrivateModule)

Aggregations

PrivateModule (com.google.inject.PrivateModule)28 Injector (com.google.inject.Injector)17 AbstractModule (com.google.inject.AbstractModule)16 Module (com.google.inject.Module)10 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)10 Guice.createInjector (com.google.inject.Guice.createInjector)6 DatasetDefinitionRegistry (co.cask.cdap.api.dataset.module.DatasetDefinitionRegistry)5 ConfigModule (co.cask.cdap.common.guice.ConfigModule)5 DefaultDatasetDefinitionRegistry (co.cask.cdap.data2.dataset2.DefaultDatasetDefinitionRegistry)5 DatasetFramework (co.cask.cdap.data2.dataset2.DatasetFramework)4 Binding (com.google.inject.Binding)4 Key (com.google.inject.Key)4 Singleton (com.google.inject.Singleton)4 Named (com.google.inject.name.Named)4 Element (com.google.inject.spi.Element)4 NonCustomLocationUnitTestModule (co.cask.cdap.common.guice.NonCustomLocationUnitTestModule)3 RemoteDatasetFramework (co.cask.cdap.data2.datafabric.dataset.RemoteDatasetFramework)3 DatasetDefinitionRegistryFactory (co.cask.cdap.data2.dataset2.DatasetDefinitionRegistryFactory)3 LineageStoreReader (co.cask.cdap.data2.metadata.lineage.LineageStoreReader)3 LineageStoreWriter (co.cask.cdap.data2.metadata.lineage.LineageStoreWriter)3