Search in sources :

Example 41 with MessagingService

use of io.cdap.cdap.messaging.MessagingService in project cdap by caskdata.

the class TetheringClientHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    // Define all StructuredTable before starting any services that need StructuredTable
    StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
    CConfiguration conf = CConfiguration.create();
    serverHandler = new MockTetheringServerHandler();
    serverService = new CommonNettyHttpServiceBuilder(conf, getClass().getSimpleName() + "_server").setHttpHandlers(serverHandler).build();
    serverService.start();
    serverConfig = ClientConfig.builder().setConnectionConfig(ConnectionConfig.builder().setHostname(serverService.getBindAddress().getHostName()).setPort(serverService.getBindAddress().getPort()).setSSLEnabled(false).build()).build();
    cConf.setInt(Constants.Tethering.CONNECTION_INTERVAL, 1);
    cConf.setInt(Constants.Tethering.CONNECTION_TIMEOUT_SECONDS, 5);
    cConf.set(Constants.INSTANCE_NAME, CLIENT_INSTANCE);
    List<Permission> tetheringPermissions = Arrays.asList(InstancePermission.TETHER);
    InMemoryAccessController inMemoryAccessController = new InMemoryAccessController();
    inMemoryAccessController.grant(Authorizable.fromEntityId(InstanceId.SELF), MASTER_PRINCIPAL, Collections.unmodifiableSet(new HashSet<>(tetheringPermissions)));
    ContextAccessEnforcer contextAccessEnforcer = new DefaultContextAccessEnforcer(new AuthenticationTestContext(), inMemoryAccessController);
    AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
    MessagingService messagingService = injector.getInstance(MessagingService.class);
    clientService = new CommonNettyHttpServiceBuilder(conf, getClass().getSimpleName() + "_client").setHttpHandlers(new TetheringClientHandler(tetheringStore, contextAccessEnforcer), new TetheringHandler(cConf, tetheringStore, messagingService)).build();
    clientService.start();
    clientConfig = ClientConfig.builder().setConnectionConfig(ConnectionConfig.builder().setHostname(clientService.getBindAddress().getHostName()).setPort(clientService.getBindAddress().getPort()).setSSLEnabled(false).build()).build();
    tetheringAgentService = new TetheringAgentService(cConf, injector.getInstance(TransactionRunner.class), tetheringStore, injector.getInstance(MessagingService.class), injector.getInstance(RemoteAuthenticator.class));
    Assert.assertEquals(Service.State.RUNNING, tetheringAgentService.startAndWait());
}
Also used : CommonNettyHttpServiceBuilder(io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) MessagingService(io.cdap.cdap.messaging.MessagingService) InMemoryAccessController(io.cdap.cdap.security.authorization.InMemoryAccessController) InstancePermission(io.cdap.cdap.proto.security.InstancePermission) Permission(io.cdap.cdap.proto.security.Permission) DefaultContextAccessEnforcer(io.cdap.cdap.security.authorization.DefaultContextAccessEnforcer) DefaultContextAccessEnforcer(io.cdap.cdap.security.authorization.DefaultContextAccessEnforcer) ContextAccessEnforcer(io.cdap.cdap.security.spi.authorization.ContextAccessEnforcer) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 42 with MessagingService

use of io.cdap.cdap.messaging.MessagingService in project cdap by caskdata.

the class TetheringServerHandlerTest method setup.

@BeforeClass
public static void setup() throws IOException {
    cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    topicPrefix = cConf.get(Constants.Tethering.TOPIC_PREFIX);
    injector = Guice.createInjector(new ConfigModule(cConf), new SystemDatasetRuntimeModule().getInMemoryModules(), new TransactionModules().getInMemoryModules(), new TransactionExecutorModule(), new InMemoryDiscoveryModule(), new LocalLocationModule(), new MessagingServerRuntimeModule().getInMemoryModules(), new StorageModule(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule(), new PrivateModule() {

        @Override
        protected void configure() {
            bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class).in(Scopes.SINGLETON);
            expose(MetricsCollectionService.class);
        }
    });
    tetheringStore = new TetheringStore(injector.getInstance(TransactionRunner.class));
    messagingService = injector.getInstance(MessagingService.class);
    if (messagingService instanceof Service) {
        ((Service) messagingService).startAndWait();
    }
    txManager = injector.getInstance(TransactionManager.class);
    txManager.startAndWait();
}
Also used : InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) StorageModule(io.cdap.cdap.data.runtime.StorageModule) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) NettyHttpService(io.cdap.http.NettyHttpService) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) MessagingService(io.cdap.cdap.messaging.MessagingService) Service(com.google.common.util.concurrent.Service) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) MessagingServerRuntimeModule(io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) AuthorizationTestModule(io.cdap.cdap.security.authorization.AuthorizationTestModule) MessagingService(io.cdap.cdap.messaging.MessagingService) TransactionModules(org.apache.tephra.runtime.TransactionModules) TransactionExecutorModule(io.cdap.cdap.data.runtime.TransactionExecutorModule) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) TransactionManager(org.apache.tephra.TransactionManager) SystemDatasetRuntimeModule(io.cdap.cdap.data.runtime.SystemDatasetRuntimeModule) AuthorizationEnforcementModule(io.cdap.cdap.security.authorization.AuthorizationEnforcementModule) PrivateModule(com.google.inject.PrivateModule) BeforeClass(org.junit.BeforeClass)

Example 43 with MessagingService

use of io.cdap.cdap.messaging.MessagingService in project cdap by caskdata.

the class DefaultRuntimeJob method createCoreServices.

@VisibleForTesting
Deque<Service> createCoreServices(Injector injector, Arguments systemArgs, Cluster cluster) {
    Deque<Service> services = new LinkedList<>();
    services.add(injector.getInstance(LogAppenderLoaderService.class));
    MessagingService messagingService = injector.getInstance(MessagingService.class);
    if (messagingService instanceof Service) {
        services.add((Service) messagingService);
    }
    services.add(injector.getInstance(MessagingHttpService.class));
    // Metrics need TMS, hence start it after TMS.
    MetricsCollectionService metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
    services.add(metricsCollectionService);
    // Starts the traffic relay if monitoring is done through SSH tunnel
    if (injector.getInstance(RuntimeMonitorType.class) == RuntimeMonitorType.SSH) {
        services.add(injector.getInstance(TrafficRelayService.class));
    }
    services.add(injector.getInstance(RuntimeClientService.class));
    // Creates a service to emit profile metrics
    ProgramRunId programRunId = injector.getInstance(ProgramRunId.class);
    ProfileId profileId = SystemArguments.getProfileIdFromArgs(programRunId.getNamespaceId(), systemArgs.asMap()).orElseThrow(() -> new IllegalStateException("Missing profile information for program run " + programRunId));
    services.add(new ProfileMetricService(metricsCollectionService, programRunId, profileId, cluster.getNodes().size()));
    return services;
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) LogAppenderLoaderService(io.cdap.cdap.logging.appender.loader.LogAppenderLoaderService) RuntimeMonitorType(io.cdap.cdap.runtime.spi.RuntimeMonitorType) ProfileMetricService(io.cdap.cdap.internal.profile.ProfileMetricService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) RuntimeClientService(io.cdap.cdap.internal.app.runtime.monitor.RuntimeClientService) Service(com.google.common.util.concurrent.Service) ProfileMetricService(io.cdap.cdap.internal.profile.ProfileMetricService) LogAppenderLoaderService(io.cdap.cdap.logging.appender.loader.LogAppenderLoaderService) MessagingService(io.cdap.cdap.messaging.MessagingService) AbstractIdleService(com.google.common.util.concurrent.AbstractIdleService) MessagingHttpService(io.cdap.cdap.messaging.server.MessagingHttpService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) MessagingHttpService(io.cdap.cdap.messaging.server.MessagingHttpService) LinkedList(java.util.LinkedList) MessagingService(io.cdap.cdap.messaging.MessagingService) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) RuntimeClientService(io.cdap.cdap.internal.app.runtime.monitor.RuntimeClientService) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 44 with MessagingService

use of io.cdap.cdap.messaging.MessagingService 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 45 with MessagingService

use of io.cdap.cdap.messaging.MessagingService in project cdap by caskdata.

the class StandaloneMain method startUp.

/**
 * Start the service.
 */
public void startUp() throws Exception {
    // Workaround for release of file descriptors opened by URLClassLoader - https://issues.cask.co/browse/CDAP-2841
    URLConnections.setDefaultUseCaches(false);
    ConfigurationLogger.logImportantConfig(cConf);
    if (messagingService instanceof Service) {
        ((Service) messagingService).startAndWait();
    }
    // TODO: CDAP-7688, remove next line after the issue is resolved
    injector.getInstance(MessagingHttpService.class).startAndWait();
    if (txService != null) {
        txService.startAndWait();
    }
    // Define all StructuredTable before starting any services that need StructuredTable
    StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
    metadataStorage.createIndex();
    metricsCollectionService.startAndWait();
    datasetOpExecutorService.startAndWait();
    datasetService.startAndWait();
    serviceStore.startAndWait();
    remoteExecutionTwillRunnerService.start();
    metadataSubscriberService.startAndWait();
    // Validate the logging pipeline configuration.
    // Do it explicitly as Standalone doesn't have a separate master check phase as the distributed does.
    new LogPipelineLoader(cConf).validate();
    // It is recommended to initialize log appender after datasetService is started,
    // since log appender instantiates a dataset.
    logAppenderInitializer.initialize();
    runtimeServer.startAndWait();
    Service.State state = appFabricServer.startAndWait();
    if (state != Service.State.RUNNING) {
        throw new Exception("Failed to start Application Fabric");
    }
    previewHttpServer.startAndWait();
    previewRunnerManager.startAndWait();
    metricsQueryService.startAndWait();
    logQueryService.startAndWait();
    router.startAndWait();
    if (userInterfaceService != null) {
        userInterfaceService.startAndWait();
    }
    if (SecurityUtil.isManagedSecurity(cConf)) {
        externalAuthenticationServer.startAndWait();
    }
    if (exploreExecutorService != null) {
        exploreExecutorService.startAndWait();
    }
    metadataService.startAndWait();
    operationalStatsService.startAndWait();
    secureStoreService.startAndWait();
    supportBundleInternalService.startAndWait();
    appFabricHealthCheckService.startAndWait();
    String protocol = sslEnabled ? "https" : "http";
    int dashboardPort = sslEnabled ? cConf.getInt(Constants.Dashboard.SSL_BIND_PORT) : cConf.getInt(Constants.Dashboard.BIND_PORT);
    System.out.println("CDAP Sandbox started successfully.");
    System.out.printf("Connect to the CDAP UI at %s://%s:%d\n", protocol, "localhost", dashboardPort);
}
Also used : StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) NoopTwillRunnerService(io.cdap.cdap.common.twill.NoopTwillRunnerService) MetadataSubscriberService(io.cdap.cdap.metadata.MetadataSubscriberService) OperationalStatsService(io.cdap.cdap.operations.OperationalStatsService) ExploreExecutorService(io.cdap.cdap.explore.executor.ExploreExecutorService) SecureStoreService(io.cdap.cdap.security.store.SecureStoreService) LevelDBTableService(io.cdap.cdap.data2.dataset2.lib.table.leveldb.LevelDBTableService) DatasetOpExecutorService(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) TwillRunnerService(org.apache.twill.api.TwillRunnerService) Service(com.google.common.util.concurrent.Service) MetadataService(io.cdap.cdap.metadata.MetadataService) HealthCheckService(io.cdap.cdap.common.service.HealthCheckService) MetricsQueryService(io.cdap.cdap.metrics.query.MetricsQueryService) 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) MessagingHttpService(io.cdap.cdap.messaging.server.MessagingHttpService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) InMemoryTransactionService(org.apache.tephra.inmemory.InMemoryTransactionService) LogPipelineLoader(io.cdap.cdap.logging.framework.LogPipelineLoader) MessagingHttpService(io.cdap.cdap.messaging.server.MessagingHttpService) IOException(java.io.IOException) ServiceBindException(io.cdap.cdap.common.ServiceBindException)

Aggregations

MessagingService (io.cdap.cdap.messaging.MessagingService)64 Service (com.google.common.util.concurrent.Service)52 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)48 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)34 Injector (com.google.inject.Injector)24 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)20 NoOpMetricsCollectionService (io.cdap.cdap.common.metrics.NoOpMetricsCollectionService)20 DatasetService (io.cdap.cdap.data2.datafabric.dataset.service.DatasetService)20 AbstractModule (com.google.inject.AbstractModule)18 DatasetOpExecutorService (io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService)18 MessagingServerRuntimeModule (io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule)18 IOException (java.io.IOException)18 LocalLocationModule (io.cdap.cdap.common.guice.LocalLocationModule)16 AuthenticationContextModules (io.cdap.cdap.security.auth.context.AuthenticationContextModules)16 Test (org.junit.Test)16 MultiThreadMessagingContext (io.cdap.cdap.messaging.context.MultiThreadMessagingContext)14 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)14 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)14 Before (org.junit.Before)14 MetadataService (io.cdap.cdap.metadata.MetadataService)12