Search in sources :

Example 1 with AppFabricTestModule

use of io.cdap.cdap.internal.guice.AppFabricTestModule in project cdap by caskdata.

the class RouterResource method before.

@Override
protected void before() {
    CConfiguration cConf = CConfiguration.create();
    Injector injector = Guice.createInjector(new CoreSecurityRuntimeModule().getStandaloneModules(), new ExternalAuthenticationModule(), new InMemoryDiscoveryModule(), new AppFabricTestModule(cConf));
    DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
    TokenValidator mockValidator = new MockTokenValidator("failme");
    UserIdentityExtractor extractor = new MockAccessTokenIdentityExtractor(mockValidator);
    SConfiguration sConf = injector.getInstance(SConfiguration.class);
    cConf.set(Constants.Router.ADDRESS, hostname);
    cConf.setInt(Constants.Router.ROUTER_PORT, 0);
    for (Map.Entry<String, String> entry : additionalConfig.entrySet()) {
        cConf.set(entry.getKey(), entry.getValue());
    }
    router = new NettyRouter(cConf, sConf, InetAddresses.forString(hostname), new RouterServiceLookup(cConf, (DiscoveryServiceClient) discoveryService, new RouterPathLookup()), mockValidator, extractor, discoveryServiceClient);
    router.startAndWait();
}
Also used : InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) ExternalAuthenticationModule(io.cdap.cdap.security.guice.ExternalAuthenticationModule) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) TokenValidator(io.cdap.cdap.security.auth.TokenValidator) CoreSecurityRuntimeModule(io.cdap.cdap.security.guice.CoreSecurityRuntimeModule) Injector(com.google.inject.Injector) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) AppFabricTestModule(io.cdap.cdap.internal.guice.AppFabricTestModule) UserIdentityExtractor(io.cdap.cdap.security.auth.UserIdentityExtractor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AppFabricTestModule

use of io.cdap.cdap.internal.guice.AppFabricTestModule in project cdap by caskdata.

the class ProvisioningServiceTest method setupClass.

@BeforeClass
public static void setupClass() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    Injector injector = Guice.createInjector(new AppFabricTestModule(cConf));
    txManager = injector.getInstance(TransactionManager.class);
    txManager.startAndWait();
    // Define all StructuredTable before starting any services that need StructuredTable
    StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
    datasetService = injector.getInstance(DatasetService.class);
    datasetService.startAndWait();
    messagingService = injector.getInstance(MessagingService.class);
    provisionerStore = injector.getInstance(ProvisionerStore.class);
    if (messagingService instanceof Service) {
        ((Service) messagingService).startAndWait();
    }
    provisioningService = injector.getInstance(ProvisioningService.class);
    provisioningService.startAndWait();
    transactionRunner = injector.getInstance(TransactionRunner.class);
}
Also used : Injector(com.google.inject.Injector) TransactionManager(org.apache.tephra.TransactionManager) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) MessagingService(io.cdap.cdap.messaging.MessagingService) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) Service(com.google.common.util.concurrent.Service) AppFabricTestModule(io.cdap.cdap.internal.guice.AppFabricTestModule) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) MessagingService(io.cdap.cdap.messaging.MessagingService) BeforeClass(org.junit.BeforeClass)

Example 3 with AppFabricTestModule

use of io.cdap.cdap.internal.guice.AppFabricTestModule in project cdap by caskdata.

the class LocalMRJobInfoFetcherTest method startMetricsService.

public static Injector startMetricsService(CConfiguration conf) throws Exception {
    Injector injector = Guice.createInjector(new AppFabricTestModule(conf));
    injector.getInstance(TransactionManager.class).startAndWait();
    StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
    injector.getInstance(DatasetOpExecutorService.class).startAndWait();
    injector.getInstance(DatasetService.class).startAndWait();
    return injector;
}
Also used : Injector(com.google.inject.Injector) TransactionManager(org.apache.tephra.TransactionManager) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) DatasetOpExecutorService(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) AppFabricTestModule(io.cdap.cdap.internal.guice.AppFabricTestModule) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService)

Example 4 with AppFabricTestModule

use of io.cdap.cdap.internal.guice.AppFabricTestModule in project cdap by caskdata.

the class AppFabricTestHelper method getInjector.

public static synchronized Injector getInjector(CConfiguration conf, @Nullable SConfiguration sConf, Module overrides) {
    if (injector == null) {
        services = new ArrayList<>();
        configuration = conf;
        if (!CConfigurationUtil.isOverridden(configuration, Constants.CFG_LOCAL_DATA_DIR)) {
            configuration.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder("data").getAbsolutePath());
        }
        configuration.set(Constants.AppFabric.REST_PORT, Integer.toString(Networks.getRandomPort()));
        configuration.setBoolean(Constants.Dangerous.UNRECOVERABLE_RESET, true);
        // Speed up tests
        configuration.setLong(Constants.Scheduler.EVENT_POLL_DELAY_MILLIS, 100L);
        configuration.setLong(Constants.AppFabric.STATUS_EVENT_POLL_DELAY_MILLIS, 100L);
        injector = Guice.createInjector(Modules.override(new AppFabricTestModule(configuration, sConf)).with(overrides));
        startService(injector, MessagingService.class);
        startService(injector, TransactionManager.class);
        metadataStorage = injector.getInstance(MetadataStorage.class);
        try {
            metadataStorage.createIndex();
        } catch (IOException e) {
            throw new RuntimeException("Unable to create the metadata tables.", e);
        }
        startService(injector, MetadataService.class);
        // Register the tables before services will need to use them
        try {
            StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
        } catch (IOException e) {
            throw new RuntimeException("Failed to create the system tables", e);
        }
        startService(injector, DatasetOpExecutorService.class);
        startService(injector, DatasetService.class);
        startService(injector, MetricsCollectionService.class);
        startService(injector, MetadataSubscriberService.class);
        startService(injector, ProgramNotificationSubscriberService.class);
        Scheduler programScheduler = startService(injector, Scheduler.class);
        // Wait for the scheduler to be functional.
        if (programScheduler instanceof CoreSchedulerService) {
            try {
                ((CoreSchedulerService) programScheduler).waitUntilFunctional(10, TimeUnit.SECONDS);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    return injector;
}
Also used : StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) Scheduler(io.cdap.cdap.scheduler.Scheduler) CoreSchedulerService(io.cdap.cdap.scheduler.CoreSchedulerService) MetadataStorage(io.cdap.cdap.spi.metadata.MetadataStorage) AppFabricTestModule(io.cdap.cdap.internal.guice.AppFabricTestModule) IOException(java.io.IOException) TableAlreadyExistsException(io.cdap.cdap.spi.data.TableAlreadyExistsException) NamespaceAlreadyExistsException(io.cdap.cdap.common.NamespaceAlreadyExistsException) IOException(java.io.IOException)

Example 5 with AppFabricTestModule

use of io.cdap.cdap.internal.guice.AppFabricTestModule in project cdap by caskdata.

the class StorageProviderNamespaceAdminTest method setup.

@BeforeClass
public static void setup() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    cConf.setBoolean(Constants.Explore.EXPLORE_ENABLED, true);
    Injector injector = Guice.createInjector(Modules.override(new AppFabricTestModule(cConf)).with(new AbstractModule() {

        @Override
        protected void configure() {
            // use the DefaultNamespacePathLocator here to test proper namespace creation in storage handler and
            // not the NamespacedLocationFactoryTestClient
            bind(NamespacePathLocator.class).to(DefaultNamespacePathLocator.class);
        }
    }));
    namespacePathLocator = injector.getInstance(NamespacePathLocator.class);
    storageProviderNamespaceAdmin = injector.getInstance(StorageProviderNamespaceAdmin.class);
    // start the dataset service for namespace store to work
    transactionManager = injector.getInstance(TransactionManager.class);
    transactionManager.startAndWait();
    // Define all StructuredTable before starting any services that need StructuredTable
    StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
    datasetService = injector.getInstance(DatasetService.class);
    datasetService.startAndWait();
    // we don't use namespace admin here but the store because namespaceadmin will try to create the
    // home directory for namespace which we don't want. We just want to store the namespace meta in store
    // to look up during the delete.
    namespaceStore = injector.getInstance(NamespaceStore.class);
}
Also used : Injector(com.google.inject.Injector) TransactionManager(org.apache.tephra.TransactionManager) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) NamespaceStore(io.cdap.cdap.store.NamespaceStore) AppFabricTestModule(io.cdap.cdap.internal.guice.AppFabricTestModule) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) DefaultNamespacePathLocator(io.cdap.cdap.common.namespace.DefaultNamespacePathLocator) NamespacePathLocator(io.cdap.cdap.common.namespace.NamespacePathLocator) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) AbstractModule(com.google.inject.AbstractModule) BeforeClass(org.junit.BeforeClass)

Aggregations

AppFabricTestModule (io.cdap.cdap.internal.guice.AppFabricTestModule)9 StructuredTableAdmin (io.cdap.cdap.spi.data.StructuredTableAdmin)7 DatasetService (io.cdap.cdap.data2.datafabric.dataset.service.DatasetService)6 TransactionManager (org.apache.tephra.TransactionManager)6 Injector (com.google.inject.Injector)5 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)5 Service (com.google.common.util.concurrent.Service)4 DatasetOpExecutorService (io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService)4 MessagingService (io.cdap.cdap.messaging.MessagingService)4 MetadataStorage (io.cdap.cdap.spi.metadata.MetadataStorage)4 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)4 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)3 AppFabricServer (io.cdap.cdap.internal.app.services.AppFabricServer)3 LogQueryService (io.cdap.cdap.logging.service.LogQueryService)3 MetadataService (io.cdap.cdap.metadata.MetadataService)3 CoreSchedulerService (io.cdap.cdap.scheduler.CoreSchedulerService)3 Scheduler (io.cdap.cdap.scheduler.Scheduler)3 CoreSecurityRuntimeModule (io.cdap.cdap.security.guice.CoreSecurityRuntimeModule)3 ExternalAuthenticationModule (io.cdap.cdap.security.guice.ExternalAuthenticationModule)3 IOException (java.io.IOException)3