Search in sources :

Example 1 with ServiceStore

use of io.cdap.cdap.app.store.ServiceStore in project cdap by caskdata.

the class MonitorHandlerAuthorizationTest method createMonitorHandler.

private static MonitorHandler createMonitorHandler(Authorizable authorizable, List<Permission> requiredPermissions) {
    Map<String, MasterServiceManager> masterServiceManagerMap = new HashMap<>();
    MasterServiceManager mockMasterServiceManager = mock(MasterServiceManager.class);
    when(mockMasterServiceManager.getInstances()).thenReturn(1);
    when(mockMasterServiceManager.isServiceEnabled()).thenReturn(true);
    when(mockMasterServiceManager.getMinInstances()).thenReturn(1);
    when(mockMasterServiceManager.getMaxInstances()).thenReturn(1);
    when(mockMasterServiceManager.setInstances(any(Integer.class))).thenReturn(true);
    masterServiceManagerMap.put(SERVICE_NAME, mockMasterServiceManager);
    ServiceStore mockServiceStore = mock(ServiceStore.class);
    InMemoryAccessController inMemoryAccessController = new InMemoryAccessController();
    inMemoryAccessController.grant(authorizable, MASTER_PRINCIPAL, Collections.unmodifiableSet(new HashSet<>(requiredPermissions)));
    AuthenticationContext authenticationContext = new AuthenticationTestContext();
    DefaultContextAccessEnforcer contextAccessEnforcer = new DefaultContextAccessEnforcer(authenticationContext, inMemoryAccessController);
    return new MonitorHandler(masterServiceManagerMap, mockServiceStore, contextAccessEnforcer);
}
Also used : AuthenticationContext(io.cdap.cdap.security.spi.authentication.AuthenticationContext) MasterServiceManager(io.cdap.cdap.common.twill.MasterServiceManager) ServiceStore(io.cdap.cdap.app.store.ServiceStore) HashMap(java.util.HashMap) MonitorHandler(io.cdap.cdap.gateway.handlers.MonitorHandler) InMemoryAccessController(io.cdap.cdap.security.authorization.InMemoryAccessController) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) DefaultContextAccessEnforcer(io.cdap.cdap.security.authorization.DefaultContextAccessEnforcer) HashSet(java.util.HashSet)

Example 2 with ServiceStore

use of io.cdap.cdap.app.store.ServiceStore in project cdap by caskdata.

the class AppFabricTestBase method initializeAndStartServices.

protected static void initializeAndStartServices(CConfiguration cConf, Module overrides) throws Exception {
    injector = Guice.createInjector(Modules.override(new AppFabricTestModule(cConf, null)).with(overrides));
    int connectionTimeout = cConf.getInt(Constants.HTTP_CLIENT_CONNECTION_TIMEOUT_MS);
    int readTimeout = cConf.getInt(Constants.HTTP_CLIENT_READ_TIMEOUT_MS);
    httpRequestConfig = new HttpRequestConfig(connectionTimeout, readTimeout, false);
    messagingService = injector.getInstance(MessagingService.class);
    if (messagingService instanceof Service) {
        ((Service) messagingService).startAndWait();
    }
    txManager = injector.getInstance(TransactionManager.class);
    txManager.startAndWait();
    // Define all StructuredTable before starting any services that need StructuredTable
    StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
    metadataStorage = injector.getInstance(MetadataStorage.class);
    metadataStorage.createIndex();
    dsOpService = injector.getInstance(DatasetOpExecutorService.class);
    dsOpService.startAndWait();
    datasetService = injector.getInstance(DatasetService.class);
    datasetService.startAndWait();
    appFabricServer = injector.getInstance(AppFabricServer.class);
    appFabricServer.startAndWait();
    DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class);
    appFabricEndpointStrategy = new RandomEndpointStrategy(() -> discoveryClient.discover(Constants.Service.APP_FABRIC_HTTP));
    txClient = injector.getInstance(TransactionSystemClient.class);
    metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
    metricsCollectionService.startAndWait();
    serviceStore = injector.getInstance(ServiceStore.class);
    serviceStore.startAndWait();
    metadataService = injector.getInstance(MetadataService.class);
    metadataService.startAndWait();
    metadataSubscriberService = injector.getInstance(MetadataSubscriberService.class);
    metadataSubscriberService.startAndWait();
    logQueryService = injector.getInstance(LogQueryService.class);
    logQueryService.startAndWait();
    locationFactory = getInjector().getInstance(LocationFactory.class);
    datasetClient = new DatasetClient(getClientConfig(discoveryClient, Constants.Service.DATASET_MANAGER));
    remoteClientFactory = new RemoteClientFactory(discoveryClient, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
    metadataClient = new MetadataClient(getClientConfig(discoveryClient, Constants.Service.METADATA_SERVICE));
    metadataServiceClient = new DefaultMetadataServiceClient(remoteClientFactory);
    metricStore = injector.getInstance(MetricStore.class);
    Scheduler programScheduler = injector.getInstance(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);
        }
    }
    createNamespaces();
}
Also used : MetricStore(io.cdap.cdap.api.metrics.MetricStore) RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) Scheduler(io.cdap.cdap.scheduler.Scheduler) AppFabricServer(io.cdap.cdap.internal.app.services.AppFabricServer) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) MetadataService(io.cdap.cdap.metadata.MetadataService) LogQueryService(io.cdap.cdap.logging.service.LogQueryService) TransactionSystemClient(org.apache.tephra.TransactionSystemClient) MetadataClient(io.cdap.cdap.client.MetadataClient) DefaultMetadataServiceClient(io.cdap.cdap.data2.metadata.writer.DefaultMetadataServiceClient) ServiceStore(io.cdap.cdap.app.store.ServiceStore) CoreSchedulerService(io.cdap.cdap.scheduler.CoreSchedulerService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) MetadataSubscriberService(io.cdap.cdap.metadata.MetadataSubscriberService) DatasetOpExecutorService(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) Service(com.google.common.util.concurrent.Service) MetadataService(io.cdap.cdap.metadata.MetadataService) MessagingService(io.cdap.cdap.messaging.MessagingService) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) LogQueryService(io.cdap.cdap.logging.service.LogQueryService) CoreSchedulerService(io.cdap.cdap.scheduler.CoreSchedulerService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) HttpRequestConfig(io.cdap.common.http.HttpRequestConfig) Constraint(io.cdap.cdap.internal.schedule.constraint.Constraint) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) IOException(java.io.IOException) NotFoundException(io.cdap.cdap.common.NotFoundException) UnauthenticatedException(io.cdap.cdap.security.spi.authentication.UnauthenticatedException) MessagingService(io.cdap.cdap.messaging.MessagingService) LocationFactory(org.apache.twill.filesystem.LocationFactory) DatasetClient(io.cdap.cdap.client.DatasetClient) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) TransactionManager(org.apache.tephra.TransactionManager) DatasetOpExecutorService(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) MetadataSubscriberService(io.cdap.cdap.metadata.MetadataSubscriberService) MetadataStorage(io.cdap.cdap.spi.metadata.MetadataStorage) AppFabricTestModule(io.cdap.cdap.internal.guice.AppFabricTestModule) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy)

Example 3 with ServiceStore

use of io.cdap.cdap.app.store.ServiceStore in project cdap by caskdata.

the class SupportBundleTestBase method initializeAndStartServices.

protected static void initializeAndStartServices(CConfiguration cConf, Module overrides) throws Exception {
    injector = Guice.createInjector(Modules.override(new AppFabricTestModule(cConf, null)).with(overrides));
    int connectionTimeout = cConf.getInt(Constants.HTTP_CLIENT_CONNECTION_TIMEOUT_MS);
    int readTimeout = cConf.getInt(Constants.HTTP_CLIENT_READ_TIMEOUT_MS);
    httpRequestConfig = new HttpRequestConfig(connectionTimeout, readTimeout, false);
    messagingService = injector.getInstance(MessagingService.class);
    if (messagingService instanceof Service) {
        ((Service) messagingService).startAndWait();
    }
    txManager = injector.getInstance(TransactionManager.class);
    txManager.startAndWait();
    // Define all StructuredTable before starting any services that need StructuredTable
    StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
    metadataStorage = injector.getInstance(MetadataStorage.class);
    metadataStorage.createIndex();
    dsOpService = injector.getInstance(DatasetOpExecutorService.class);
    dsOpService.startAndWait();
    datasetService = injector.getInstance(DatasetService.class);
    datasetService.startAndWait();
    appFabricServer = injector.getInstance(AppFabricServer.class);
    appFabricServer.startAndWait();
    DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class);
    appFabricEndpointStrategy = new RandomEndpointStrategy(() -> discoveryClient.discover(Constants.Service.APP_FABRIC_HTTP));
    metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
    metricsCollectionService.startAndWait();
    serviceStore = injector.getInstance(ServiceStore.class);
    serviceStore.startAndWait();
    metadataService = injector.getInstance(MetadataService.class);
    metadataService.startAndWait();
    metadataSubscriberService = injector.getInstance(MetadataSubscriberService.class);
    metadataSubscriberService.startAndWait();
    logQueryService = injector.getInstance(LogQueryService.class);
    logQueryService.startAndWait();
    locationFactory = getInjector().getInstance(LocationFactory.class);
    datasetClient = new DatasetClient(getClientConfig(discoveryClient, Constants.Service.DATASET_MANAGER));
    remoteClientFactory = new RemoteClientFactory(discoveryClient, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
    metadataClient = new MetadataClient(getClientConfig(discoveryClient, Constants.Service.METADATA_SERVICE));
    appFabricHealthCheckService = injector.getInstance(HealthCheckService.class);
    appFabricHealthCheckService.helper(Constants.AppFabricHealthCheck.APP_FABRIC_HEALTH_CHECK_SERVICE, cConf, Constants.Service.MASTER_SERVICES_BIND_ADDRESS);
    appFabricHealthCheckService.startAndWait();
    supportBundleInternalService = injector.getInstance(SupportBundleInternalService.class);
    supportBundleInternalService.startAndWait();
    Scheduler programScheduler = injector.getInstance(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);
        }
    }
}
Also used : RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) Scheduler(io.cdap.cdap.scheduler.Scheduler) AppFabricServer(io.cdap.cdap.internal.app.services.AppFabricServer) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) MetadataService(io.cdap.cdap.metadata.MetadataService) LogQueryService(io.cdap.cdap.logging.service.LogQueryService) MetadataClient(io.cdap.cdap.client.MetadataClient) ServiceStore(io.cdap.cdap.app.store.ServiceStore) CoreSchedulerService(io.cdap.cdap.scheduler.CoreSchedulerService) HealthCheckService(io.cdap.cdap.common.service.HealthCheckService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) MetadataSubscriberService(io.cdap.cdap.metadata.MetadataSubscriberService) DatasetOpExecutorService(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) Service(com.google.common.util.concurrent.Service) MetadataService(io.cdap.cdap.metadata.MetadataService) HealthCheckService(io.cdap.cdap.common.service.HealthCheckService) MessagingService(io.cdap.cdap.messaging.MessagingService) SupportBundleInternalService(io.cdap.cdap.support.internal.app.services.SupportBundleInternalService) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) LogQueryService(io.cdap.cdap.logging.service.LogQueryService) CoreSchedulerService(io.cdap.cdap.scheduler.CoreSchedulerService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) HttpRequestConfig(io.cdap.common.http.HttpRequestConfig) Constraint(io.cdap.cdap.internal.schedule.constraint.Constraint) IOException(java.io.IOException) MessagingService(io.cdap.cdap.messaging.MessagingService) LocationFactory(org.apache.twill.filesystem.LocationFactory) DatasetClient(io.cdap.cdap.client.DatasetClient) SupportBundleInternalService(io.cdap.cdap.support.internal.app.services.SupportBundleInternalService) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) TransactionManager(org.apache.tephra.TransactionManager) DatasetOpExecutorService(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) MetadataSubscriberService(io.cdap.cdap.metadata.MetadataSubscriberService) MetadataStorage(io.cdap.cdap.spi.metadata.MetadataStorage) AppFabricTestModule(io.cdap.cdap.internal.guice.AppFabricTestModule) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy)

Example 4 with ServiceStore

use of io.cdap.cdap.app.store.ServiceStore in project cdap by caskdata.

the class MonitorHandlerModule method configure.

@Override
protected void configure() {
    // Only MonitorHandler use MasterServiceManager
    install(new PrivateModule() {

        @Override
        protected void configure() {
            if (isHadoop) {
                addHadoopBindings(binder());
            } else {
                addNonHadoopBindings(binder());
            }
            bind(DatasetFramework.class).annotatedWith(Names.named("local.ds.framework")).toProvider(DatasetFrameworkProvider.class);
            // Need to expose ServiceStore for master and standalone main to start/stop it
            bind(ServiceStore.class).to(DatasetServiceStore.class).in(Scopes.SINGLETON);
            expose(ServiceStore.class);
            // Expose the MonitorHandler so that it can be bounded to the multibinder
            bind(MonitorHandler.class);
            expose(MonitorHandler.class);
        }
    });
    Multibinder<HttpHandler> handlerBinder = Multibinder.newSetBinder(binder(), HttpHandler.class, Names.named(Constants.AppFabric.HANDLERS_BINDING));
    handlerBinder.addBinding().to(MonitorHandler.class);
}
Also used : DatasetFramework(io.cdap.cdap.data2.dataset2.DatasetFramework) InMemoryDatasetFramework(io.cdap.cdap.data2.dataset2.InMemoryDatasetFramework) HttpHandler(io.cdap.http.HttpHandler) ServiceStore(io.cdap.cdap.app.store.ServiceStore) DatasetServiceStore(io.cdap.cdap.gateway.handlers.DatasetServiceStore) MonitorHandler(io.cdap.cdap.gateway.handlers.MonitorHandler) PrivateModule(com.google.inject.PrivateModule)

Aggregations

ServiceStore (io.cdap.cdap.app.store.ServiceStore)4 AuthenticationTestContext (io.cdap.cdap.security.auth.context.AuthenticationTestContext)3 Service (com.google.common.util.concurrent.Service)2 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)2 DatasetClient (io.cdap.cdap.client.DatasetClient)2 MetadataClient (io.cdap.cdap.client.MetadataClient)2 RandomEndpointStrategy (io.cdap.cdap.common.discovery.RandomEndpointStrategy)2 DefaultInternalAuthenticator (io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator)2 RemoteClientFactory (io.cdap.cdap.common.internal.remote.RemoteClientFactory)2 DatasetService (io.cdap.cdap.data2.datafabric.dataset.service.DatasetService)2 DatasetOpExecutorService (io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService)2 MonitorHandler (io.cdap.cdap.gateway.handlers.MonitorHandler)2 AppFabricServer (io.cdap.cdap.internal.app.services.AppFabricServer)2 AppFabricTestModule (io.cdap.cdap.internal.guice.AppFabricTestModule)2 Constraint (io.cdap.cdap.internal.schedule.constraint.Constraint)2 LogQueryService (io.cdap.cdap.logging.service.LogQueryService)2 MessagingService (io.cdap.cdap.messaging.MessagingService)2 MetadataService (io.cdap.cdap.metadata.MetadataService)2 MetadataSubscriberService (io.cdap.cdap.metadata.MetadataSubscriberService)2 CoreSchedulerService (io.cdap.cdap.scheduler.CoreSchedulerService)2