Search in sources :

Example 1 with AppFabricTestModule

use of co.cask.cdap.internal.guice.AppFabricTestModule in project cdap by caskdata.

the class AuthorizationBootstrapperTest method setup.

@BeforeClass
public static void setup() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TMP_FOLDER.newFolder().getAbsolutePath());
    cConf.setBoolean(Constants.Security.ENABLED, true);
    cConf.setBoolean(Constants.Security.KERBEROS_ENABLED, false);
    cConf.setBoolean(Constants.Security.Authorization.ENABLED, true);
    Location deploymentJar = AppJarHelper.createDeploymentJar(new LocalLocationFactory(TMP_FOLDER.newFolder()), InMemoryAuthorizer.class);
    cConf.set(Constants.Security.Authorization.EXTENSION_JAR_PATH, deploymentJar.toURI().getPath());
    // make Alice an admin user, so she can create namespaces
    cConf.set(Constants.Security.Authorization.ADMIN_USERS, ADMIN_USER.getName());
    instanceId = new InstanceId(cConf.get(Constants.INSTANCE_NAME));
    // setup a system artifact
    File systemArtifactsDir = TMP_FOLDER.newFolder();
    cConf.set(Constants.AppFabric.SYSTEM_ARTIFACTS_DIR, systemArtifactsDir.getAbsolutePath());
    createSystemArtifact(systemArtifactsDir);
    Injector injector = Guice.createInjector(new AppFabricTestModule(cConf));
    namespaceQueryAdmin = injector.getInstance(NamespaceQueryAdmin.class);
    namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
    defaultNamespaceEnsurer = new DefaultNamespaceEnsurer(namespaceAdmin);
    discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
    txManager = injector.getInstance(TransactionManager.class);
    datasetService = injector.getInstance(DatasetService.class);
    systemArtifactLoader = injector.getInstance(SystemArtifactLoader.class);
    authorizationBootstrapper = injector.getInstance(AuthorizationBootstrapper.class);
    artifactRepository = injector.getInstance(ArtifactRepository.class);
    dsFramework = injector.getInstance(DatasetFramework.class);
    authorizationEnforcer = injector.getInstance(AuthorizationEnforcer.class);
}
Also used : DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) InstanceId(co.cask.cdap.proto.id.InstanceId) NamespaceAdmin(co.cask.cdap.common.namespace.NamespaceAdmin) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) ArtifactRepository(co.cask.cdap.internal.app.runtime.artifact.ArtifactRepository) AuthorizationEnforcer(co.cask.cdap.security.spi.authorization.AuthorizationEnforcer) DefaultNamespaceEnsurer(co.cask.cdap.internal.app.namespace.DefaultNamespaceEnsurer) CConfiguration(co.cask.cdap.common.conf.CConfiguration) DatasetFramework(co.cask.cdap.data2.dataset2.DatasetFramework) AuthorizationBootstrapper(co.cask.cdap.security.authorization.AuthorizationBootstrapper) Injector(com.google.inject.Injector) TransactionManager(org.apache.tephra.TransactionManager) SystemArtifactLoader(co.cask.cdap.internal.app.runtime.artifact.SystemArtifactLoader) NamespaceQueryAdmin(co.cask.cdap.common.namespace.NamespaceQueryAdmin) AppFabricTestModule(co.cask.cdap.internal.guice.AppFabricTestModule) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) File(java.io.File) Location(org.apache.twill.filesystem.Location) BeforeClass(org.junit.BeforeClass)

Example 2 with AppFabricTestModule

use of co.cask.cdap.internal.guice.AppFabricTestModule in project cdap by caskdata.

the class GatewayTestBase method startGateway.

public static Injector startGateway(final CConfiguration conf) throws Exception {
    // Set up our Guice injections
    injector = Guice.createInjector(Modules.override(new AbstractModule() {

        @Override
        protected void configure() {
        }

        @SuppressWarnings("unused")
        @Provides
        @Named(Constants.Router.ADDRESS)
        public final InetAddress providesHostname(CConfiguration cConf) {
            return Networks.resolve(cConf.get(Constants.Router.ADDRESS), new InetSocketAddress("localhost", 0).getAddress());
        }
    }, new SecurityModules().getInMemoryModules(), new NotificationServiceRuntimeModule().getInMemoryModules(), new AppFabricTestModule(conf)).with(new AbstractModule() {

        @Override
        protected void configure() {
            install(new StreamServiceRuntimeModule().getStandaloneModules());
            // It's a bit hacky to add it here. Need to refactor these
            // bindings out as it overlaps with
            // AppFabricServiceModule
            bind(LogReader.class).to(MockLogReader.class).in(Scopes.SINGLETON);
            bind(StreamConsumerStateStoreFactory.class).to(LevelDBStreamConsumerStateStoreFactory.class).in(Singleton.class);
            bind(StreamAdmin.class).to(FileStreamAdmin.class).in(Singleton.class);
            bind(StreamConsumerFactory.class).to(LevelDBStreamFileConsumerFactory.class).in(Singleton.class);
            bind(StreamFileWriterFactory.class).to(LocationStreamFileWriterFactory.class).in(Singleton.class);
            bind(PrivilegesManager.class).to(NoOpAuthorizer.class);
            bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
        }
    }));
    messagingService = injector.getInstance(MessagingService.class);
    if (messagingService instanceof Service) {
        ((Service) messagingService).startAndWait();
    }
    txService = injector.getInstance(TransactionManager.class);
    txService.startAndWait();
    dsOpService = injector.getInstance(DatasetOpExecutor.class);
    dsOpService.startAndWait();
    datasetService = injector.getInstance(DatasetService.class);
    datasetService.startAndWait();
    appFabricServer = injector.getInstance(AppFabricServer.class);
    appFabricServer.startAndWait();
    metricsQueryService = injector.getInstance(MetricsQueryService.class);
    metricsQueryService.startAndWait();
    metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
    metricsCollectionService.startAndWait();
    notificationService = injector.getInstance(NotificationService.class);
    notificationService.startAndWait();
    streamService = injector.getInstance(StreamService.class);
    streamService.startAndWait();
    namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
    namespaceAdmin.create(TEST_NAMESPACE_META1);
    namespaceAdmin.create(TEST_NAMESPACE_META2);
    // Restart handlers to check if they are resilient across restarts.
    router = injector.getInstance(NettyRouter.class);
    router.startAndWait();
    Map<String, Integer> serviceMap = Maps.newHashMap();
    for (Map.Entry<Integer, String> entry : router.getServiceLookup().getServiceMap().entrySet()) {
        serviceMap.put(entry.getValue(), entry.getKey());
    }
    port = serviceMap.get(Constants.Service.GATEWAY);
    return injector;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) AppFabricServer(co.cask.cdap.internal.app.services.AppFabricServer) NoOpAuthorizer(co.cask.cdap.security.spi.authorization.NoOpAuthorizer) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) NotificationServiceRuntimeModule(co.cask.cdap.notifications.guice.NotificationServiceRuntimeModule) StreamConsumerFactory(co.cask.cdap.data2.transaction.stream.StreamConsumerFactory) SecurityModules(co.cask.cdap.security.guice.SecurityModules) StreamServiceRuntimeModule(co.cask.cdap.data.stream.service.StreamServiceRuntimeModule) StreamService(co.cask.cdap.data.stream.service.StreamService) MetricsQueryService(co.cask.cdap.metrics.query.MetricsQueryService) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) NamespaceAdmin(co.cask.cdap.common.namespace.NamespaceAdmin) MessagingService(co.cask.cdap.messaging.MessagingService) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) MetricsQueryService(co.cask.cdap.metrics.query.MetricsQueryService) StreamService(co.cask.cdap.data.stream.service.StreamService) NotificationService(co.cask.cdap.notifications.service.NotificationService) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) Service(com.google.common.util.concurrent.Service) NotificationService(co.cask.cdap.notifications.service.NotificationService) DatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor) DefaultOwnerAdmin(co.cask.cdap.security.impersonation.DefaultOwnerAdmin) CConfiguration(co.cask.cdap.common.conf.CConfiguration) NettyRouter(co.cask.cdap.gateway.router.NettyRouter) AbstractModule(com.google.inject.AbstractModule) MessagingService(co.cask.cdap.messaging.MessagingService) StreamAdmin(co.cask.cdap.data2.transaction.stream.StreamAdmin) FileStreamAdmin(co.cask.cdap.data2.transaction.stream.FileStreamAdmin) StreamFileWriterFactory(co.cask.cdap.data.stream.StreamFileWriterFactory) LocationStreamFileWriterFactory(co.cask.cdap.data.runtime.LocationStreamFileWriterFactory) Singleton(com.google.inject.Singleton) TransactionManager(org.apache.tephra.TransactionManager) MockLogReader(co.cask.cdap.gateway.handlers.log.MockLogReader) LogReader(co.cask.cdap.logging.read.LogReader) AppFabricTestModule(co.cask.cdap.internal.guice.AppFabricTestModule) Map(java.util.Map) StreamConsumerStateStoreFactory(co.cask.cdap.data2.transaction.stream.StreamConsumerStateStoreFactory) LevelDBStreamConsumerStateStoreFactory(co.cask.cdap.data2.transaction.stream.leveldb.LevelDBStreamConsumerStateStoreFactory)

Example 3 with AppFabricTestModule

use of co.cask.cdap.internal.guice.AppFabricTestModule in project cdap by caskdata.

the class AppFabricTestBase method initializeAndStartServices.

protected static void initializeAndStartServices(CConfiguration cConf, @Nullable SConfiguration sConf) throws Exception {
    injector = Guice.createInjector(Modules.override(new AppFabricTestModule(cConf, sConf)).with(new AbstractModule() {

        @Override
        protected void configure() {
            // needed because we set Kerberos to true in DefaultNamespaceAdminTest
            bind(UGIProvider.class).to(CurrentUGIProvider.class);
        }
    }));
    messagingService = injector.getInstance(MessagingService.class);
    if (messagingService instanceof Service) {
        ((Service) messagingService).startAndWait();
    }
    txManager = injector.getInstance(TransactionManager.class);
    txManager.startAndWait();
    dsOpService = injector.getInstance(DatasetOpExecutor.class);
    dsOpService.startAndWait();
    remoteSysOpService = injector.getInstance(RemoteSystemOperationsService.class);
    remoteSysOpService.startAndWait();
    datasetService = injector.getInstance(DatasetService.class);
    datasetService.startAndWait();
    appFabricServer = injector.getInstance(AppFabricServer.class);
    appFabricServer.startAndWait();
    DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class);
    ServiceDiscovered appFabricHttpDiscovered = discoveryClient.discover(Constants.Service.APP_FABRIC_HTTP);
    EndpointStrategy endpointStrategy = new RandomEndpointStrategy(appFabricHttpDiscovered);
    port = endpointStrategy.pick(1, TimeUnit.SECONDS).getSocketAddress().getPort();
    txClient = injector.getInstance(TransactionSystemClient.class);
    metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
    metricsCollectionService.startAndWait();
    metricsService = injector.getInstance(MetricsQueryService.class);
    metricsService.startAndWait();
    streamService = injector.getInstance(StreamService.class);
    streamService.startAndWait();
    serviceStore = injector.getInstance(ServiceStore.class);
    serviceStore.startAndWait();
    metadataService = injector.getInstance(MetadataService.class);
    metadataService.startAndWait();
    locationFactory = getInjector().getInstance(LocationFactory.class);
    streamClient = new StreamClient(getClientConfig(discoveryClient, Constants.Service.STREAMS));
    datasetClient = new DatasetClient(getClientConfig(discoveryClient, Constants.Service.DATASET_MANAGER));
    createNamespaces();
}
Also used : StreamService(co.cask.cdap.data.stream.service.StreamService) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) MetricsQueryService(co.cask.cdap.metrics.query.MetricsQueryService) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) AppFabricServer(co.cask.cdap.internal.app.services.AppFabricServer) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) MetadataService(co.cask.cdap.metadata.MetadataService) Service(com.google.common.util.concurrent.Service) MessagingService(co.cask.cdap.messaging.MessagingService) MetricsQueryService(co.cask.cdap.metrics.query.MetricsQueryService) StreamService(co.cask.cdap.data.stream.service.StreamService) RemoteSystemOperationsService(co.cask.cdap.gateway.handlers.meta.RemoteSystemOperationsService) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) DatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor) RemoteSystemOperationsService(co.cask.cdap.gateway.handlers.meta.RemoteSystemOperationsService) ServiceDiscovered(org.apache.twill.discovery.ServiceDiscovered) MetadataService(co.cask.cdap.metadata.MetadataService) AbstractModule(com.google.inject.AbstractModule) MessagingService(co.cask.cdap.messaging.MessagingService) LocationFactory(org.apache.twill.filesystem.LocationFactory) TransactionSystemClient(org.apache.tephra.TransactionSystemClient) DatasetClient(co.cask.cdap.client.DatasetClient) ServiceStore(co.cask.cdap.app.store.ServiceStore) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) EndpointStrategy(co.cask.cdap.common.discovery.EndpointStrategy) StreamClient(co.cask.cdap.client.StreamClient) TransactionManager(org.apache.tephra.TransactionManager) CurrentUGIProvider(co.cask.cdap.security.impersonation.CurrentUGIProvider) AppFabricTestModule(co.cask.cdap.internal.guice.AppFabricTestModule) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy)

Example 4 with AppFabricTestModule

use of co.cask.cdap.internal.guice.AppFabricTestModule in project cdap by caskdata.

the class LocalMRJobInfoFetcherTest method startMetricsService.

public static Injector startMetricsService(CConfiguration conf) {
    Injector injector = Guice.createInjector(new AppFabricTestModule(conf));
    injector.getInstance(TransactionManager.class).startAndWait();
    injector.getInstance(DatasetOpExecutor.class).startAndWait();
    injector.getInstance(DatasetService.class).startAndWait();
    return injector;
}
Also used : Injector(com.google.inject.Injector) TransactionManager(org.apache.tephra.TransactionManager) AppFabricTestModule(co.cask.cdap.internal.guice.AppFabricTestModule) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) DatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor)

Example 5 with AppFabricTestModule

use of co.cask.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) {
        configuration = conf;
        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));
        MessagingService messagingService = injector.getInstance(MessagingService.class);
        if (messagingService instanceof Service) {
            ((Service) messagingService).startAndWait();
        }
        injector.getInstance(TransactionManager.class).startAndWait();
        injector.getInstance(DatasetOpExecutor.class).startAndWait();
        injector.getInstance(DatasetService.class).startAndWait();
        injector.getInstance(StreamCoordinatorClient.class).startAndWait();
        injector.getInstance(NotificationService.class).startAndWait();
        injector.getInstance(MetricsCollectionService.class).startAndWait();
        injector.getInstance(ProgramNotificationSubscriberService.class).startAndWait();
        Scheduler programScheduler = injector.getInstance(Scheduler.class);
        if (programScheduler instanceof Service) {
            ((Service) programScheduler).startAndWait();
        }
        // 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 : MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) Scheduler(co.cask.cdap.scheduler.Scheduler) MessagingService(co.cask.cdap.messaging.MessagingService) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) ProgramNotificationSubscriberService(co.cask.cdap.internal.app.services.ProgramNotificationSubscriberService) NotificationService(co.cask.cdap.notifications.service.NotificationService) CoreSchedulerService(co.cask.cdap.scheduler.CoreSchedulerService) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) Service(com.google.common.util.concurrent.Service) StreamCoordinatorClient(co.cask.cdap.data.stream.StreamCoordinatorClient) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) NotificationService(co.cask.cdap.notifications.service.NotificationService) DatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor) ProgramNotificationSubscriberService(co.cask.cdap.internal.app.services.ProgramNotificationSubscriberService) IOException(java.io.IOException) NamespaceAlreadyExistsException(co.cask.cdap.common.NamespaceAlreadyExistsException) MessagingService(co.cask.cdap.messaging.MessagingService) TransactionManager(org.apache.tephra.TransactionManager) CoreSchedulerService(co.cask.cdap.scheduler.CoreSchedulerService) AppFabricTestModule(co.cask.cdap.internal.guice.AppFabricTestModule)

Aggregations

AppFabricTestModule (co.cask.cdap.internal.guice.AppFabricTestModule)9 DatasetService (co.cask.cdap.data2.datafabric.dataset.service.DatasetService)6 TransactionManager (org.apache.tephra.TransactionManager)6 CConfiguration (co.cask.cdap.common.conf.CConfiguration)5 Injector (com.google.inject.Injector)5 DatasetOpExecutor (co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor)4 MessagingService (co.cask.cdap.messaging.MessagingService)4 Service (com.google.common.util.concurrent.Service)4 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)4 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)3 AbstractModule (com.google.inject.AbstractModule)3 SConfiguration (co.cask.cdap.common.conf.SConfiguration)2 DiscoveryRuntimeModule (co.cask.cdap.common.guice.DiscoveryRuntimeModule)2 NamespaceAdmin (co.cask.cdap.common.namespace.NamespaceAdmin)2 StreamService (co.cask.cdap.data.stream.service.StreamService)2 AppFabricServer (co.cask.cdap.internal.app.services.AppFabricServer)2 MetricsQueryService (co.cask.cdap.metrics.query.MetricsQueryService)2 NotificationService (co.cask.cdap.notifications.service.NotificationService)2 RouteStore (co.cask.cdap.route.store.RouteStore)2 AccessTokenTransformer (co.cask.cdap.security.auth.AccessTokenTransformer)2