Search in sources :

Example 31 with Service

use of com.google.common.util.concurrent.Service in project cdap by caskdata.

the class TestBase method finish.

@AfterClass
public static void finish() throws Exception {
    if (--nestedStartCount != 0) {
        return;
    }
    if (cConf.getBoolean(Constants.Security.Authorization.ENABLED)) {
        InstanceId instance = new InstanceId(cConf.get(Constants.INSTANCE_NAME));
        Principal principal = new Principal(System.getProperty("user.name"), Principal.PrincipalType.USER);
        authorizerInstantiator.get().grant(instance, principal, ImmutableSet.of(Action.ADMIN));
        authorizerInstantiator.get().grant(NamespaceId.DEFAULT, principal, ImmutableSet.of(Action.ADMIN));
    }
    namespaceAdmin.delete(NamespaceId.DEFAULT);
    authorizerInstantiator.close();
    if (programScheduler instanceof Service) {
        ((Service) programScheduler).stopAndWait();
    }
    streamCoordinatorClient.stopAndWait();
    metricsQueryService.stopAndWait();
    metricsCollectionService.stopAndWait();
    if (scheduler instanceof Service) {
        ((Service) scheduler).stopAndWait();
    }
    if (exploreClient != null) {
        Closeables.closeQuietly(exploreClient);
    }
    if (exploreExecutorService != null) {
        exploreExecutorService.stopAndWait();
    }
    datasetService.stopAndWait();
    dsOpService.stopAndWait();
    txService.stopAndWait();
    if (messagingService instanceof Service) {
        ((Service) messagingService).stopAndWait();
    }
}
Also used : InstanceId(co.cask.cdap.proto.id.InstanceId) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) LocalStreamFileJanitorService(co.cask.cdap.data.stream.service.LocalStreamFileJanitorService) ExploreExecutorService(co.cask.cdap.explore.executor.ExploreExecutorService) Service(com.google.common.util.concurrent.Service) MessagingService(co.cask.cdap.messaging.MessagingService) MetricsQueryService(co.cask.cdap.metrics.query.MetricsQueryService) StreamFileJanitorService(co.cask.cdap.data.stream.service.StreamFileJanitorService) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) Principal(co.cask.cdap.proto.security.Principal) AfterClass(org.junit.AfterClass)

Example 32 with Service

use of com.google.common.util.concurrent.Service in project cdap by caskdata.

the class MetricsTestBase method init.

@Before
public void init() throws IOException, UnsupportedTypeException {
    cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    injector = Guice.createInjector(getModules());
    messagingService = injector.getInstance(MessagingService.class);
    if (messagingService instanceof Service) {
        ((Service) messagingService).startAndWait();
    }
    metricValueType = TypeToken.of(MetricValues.class);
    schema = new ReflectionSchemaGenerator().generate(metricValueType.getType());
    recordWriter = new ASMDatumWriterFactory(new ASMFieldAccessorFactory()).create(metricValueType, schema);
}
Also used : ASMFieldAccessorFactory(co.cask.cdap.internal.io.ASMFieldAccessorFactory) ASMDatumWriterFactory(co.cask.cdap.internal.io.ASMDatumWriterFactory) MessagingService(co.cask.cdap.messaging.MessagingService) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) NoOpMetricsCollectionService(co.cask.cdap.common.metrics.NoOpMetricsCollectionService) Service(com.google.common.util.concurrent.Service) MetricValues(co.cask.cdap.api.metrics.MetricValues) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) MessagingService(co.cask.cdap.messaging.MessagingService) Before(org.junit.Before)

Example 33 with Service

use of com.google.common.util.concurrent.Service in project cdap by caskdata.

the class MessagingServiceTwillRunnable method addServices.

@Override
protected void addServices(List<? super Service> services) {
    MessagingService messagingService = injector.getInstance(MessagingService.class);
    if (messagingService instanceof Service) {
        services.add((Service) messagingService);
    }
    services.add(injector.getInstance(MessagingHttpService.class));
}
Also used : MessagingService(co.cask.cdap.messaging.MessagingService) MessagingHttpService(co.cask.cdap.messaging.server.MessagingHttpService) Service(com.google.common.util.concurrent.Service) MessagingHttpService(co.cask.cdap.messaging.server.MessagingHttpService) MessagingService(co.cask.cdap.messaging.MessagingService)

Example 34 with Service

use of com.google.common.util.concurrent.Service 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);
    cleanupTempDir();
    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();
    // Authorization bootstrapping is a blocking call, because CDAP will not start successfully if it does not
    // succeed on an authorization-enabled cluster
    authorizationBootstrapper.run();
    txService.startAndWait();
    metricsCollectionService.startAndWait();
    datasetService.startAndWait();
    serviceStore.startAndWait();
    streamService.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();
    Service.State state = appFabricServer.startAndWait();
    if (state != Service.State.RUNNING) {
        throw new Exception("Failed to start Application Fabric");
    }
    metricsQueryService.startAndWait();
    router.startAndWait();
    if (userInterfaceService != null) {
        userInterfaceService.startAndWait();
    }
    if (securityEnabled) {
        externalAuthenticationServer.startAndWait();
    }
    if (exploreExecutorService != null) {
        exploreExecutorService.startAndWait();
    }
    metadataService.startAndWait();
    if (trackerAppCreationService != null) {
        trackerAppCreationService.startAndWait();
    }
    wranglerAppCreationService.startAndWait();
    remoteSystemOperationsService.startAndWait();
    operationalStatsService.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 : MessagingService(co.cask.cdap.messaging.MessagingService) MessagingHttpService(co.cask.cdap.messaging.server.MessagingHttpService) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) MetricsQueryService(co.cask.cdap.metrics.query.MetricsQueryService) StreamService(co.cask.cdap.data.stream.service.StreamService) RemoteSystemOperationsService(co.cask.cdap.gateway.handlers.meta.RemoteSystemOperationsService) MetadataService(co.cask.cdap.metadata.MetadataService) ExploreExecutorService(co.cask.cdap.explore.executor.ExploreExecutorService) OperationalStatsService(co.cask.cdap.operations.OperationalStatsService) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) Service(com.google.common.util.concurrent.Service) InMemoryTransactionService(org.apache.tephra.inmemory.InMemoryTransactionService) LogPipelineLoader(co.cask.cdap.logging.framework.LogPipelineLoader) MessagingHttpService(co.cask.cdap.messaging.server.MessagingHttpService) ServiceBindException(co.cask.cdap.common.ServiceBindException) IOException(java.io.IOException)

Example 35 with Service

use of com.google.common.util.concurrent.Service in project cdap by caskdata.

the class RetryOnStartFailureServiceTest method testRetryFail.

@Test
public void testRetryFail() throws InterruptedException {
    CountDownLatch startLatch = new CountDownLatch(1);
    Service service = new RetryOnStartFailureService(createServiceSupplier(1000, startLatch, new CountDownLatch(1), false), RetryStrategies.limit(10, RetryStrategies.fixDelay(10, TimeUnit.MILLISECONDS)));
    final CountDownLatch failureLatch = new CountDownLatch(1);
    service.addListener(new ServiceListenerAdapter() {

        @Override
        public void failed(Service.State from, Throwable failure) {
            failureLatch.countDown();
        }
    }, Threads.SAME_THREAD_EXECUTOR);
    service.start();
    Assert.assertTrue(failureLatch.await(1, TimeUnit.SECONDS));
    Assert.assertFalse(startLatch.await(100, TimeUnit.MILLISECONDS));
}
Also used : Service(com.google.common.util.concurrent.Service) AbstractIdleService(com.google.common.util.concurrent.AbstractIdleService) ServiceListenerAdapter(org.apache.twill.internal.ServiceListenerAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

Service (com.google.common.util.concurrent.Service)43 MessagingService (co.cask.cdap.messaging.MessagingService)15 AbstractIdleService (com.google.common.util.concurrent.AbstractIdleService)15 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)14 Test (org.junit.Test)14 IOException (java.io.IOException)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ProgramId (co.cask.cdap.proto.id.ProgramId)7 ProgramContextAware (co.cask.cdap.data.ProgramContextAware)6 DatasetService (co.cask.cdap.data2.datafabric.dataset.service.DatasetService)6 BasicProgramContext (co.cask.cdap.internal.app.runtime.BasicProgramContext)6 ProgramType (co.cask.cdap.proto.ProgramType)6 RunId (org.apache.twill.api.RunId)6 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)5 CConfiguration (co.cask.cdap.common.conf.CConfiguration)5 Injector (com.google.inject.Injector)5 PluginInstantiator (co.cask.cdap.internal.app.runtime.plugin.PluginInstantiator)4 RunId (com.continuuity.weave.api.RunId)4 ZKClientService (com.continuuity.weave.zookeeper.ZKClientService)4 Configuration (org.apache.hadoop.conf.Configuration)4