Search in sources :

Example 1 with TxCallable

use of io.cdap.cdap.spi.data.transaction.TxCallable in project cdap by caskdata.

the class AppFabricServer method startUp.

/**
 * Configures the AppFabricService pre-start.
 */
@Override
protected void startUp() throws Exception {
    LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.APP_FABRIC_HTTP));
    Futures.allAsList(ImmutableList.of(provisioningService.start(), applicationLifecycleService.start(), bootstrapService.start(), programRuntimeService.start(), programNotificationSubscriberService.start(), runRecordCorrectorService.start(), coreSchedulerService.start(), eventPublishManager.start(), runRecordCounterService.start())).get();
    // Create handler hooks
    List<MetricsReporterHook> handlerHooks = handlerHookNames.stream().map(name -> new MetricsReporterHook(metricsCollectionService, name)).collect(Collectors.toList());
    // Run http service on random port
    NettyHttpService.Builder httpServiceBuilder = new CommonNettyHttpServiceBuilder(cConf, Constants.Service.APP_FABRIC_HTTP).setHost(hostname.getCanonicalHostName()).setHandlerHooks(handlerHooks).setHttpHandlers(handlers).setConnectionBacklog(cConf.getInt(Constants.AppFabric.BACKLOG_CONNECTIONS, Constants.AppFabric.DEFAULT_BACKLOG)).setExecThreadPoolSize(cConf.getInt(Constants.AppFabric.EXEC_THREADS, Constants.AppFabric.DEFAULT_EXEC_THREADS)).setBossThreadPoolSize(cConf.getInt(Constants.AppFabric.BOSS_THREADS, Constants.AppFabric.DEFAULT_BOSS_THREADS)).setWorkerThreadPoolSize(cConf.getInt(Constants.AppFabric.WORKER_THREADS, Constants.AppFabric.DEFAULT_WORKER_THREADS)).setPort(cConf.getInt(Constants.AppFabric.SERVER_PORT));
    if (sslEnabled) {
        new HttpsEnabler().configureKeyStore(cConf, sConf).enable(httpServiceBuilder);
    }
    cancelHttpService = startHttpService(httpServiceBuilder.build());
    long applicationCount = TransactionRunners.run(transactionRunner, (TxCallable<Long>) context -> AppMetadataStore.create(context).getApplicationCount());
    long namespaceCount = new DefaultNamespaceStore(transactionRunner).getNamespaceCount();
    metricsCollectionService.getContext(Collections.emptyMap()).gauge(Constants.Metrics.Program.APPLICATION_COUNT, applicationCount);
    metricsCollectionService.getContext(Collections.emptyMap()).gauge(Constants.Metrics.Program.NAMESPACE_COUNT, namespaceCount);
}
Also used : HttpsEnabler(io.cdap.cdap.common.security.HttpsEnabler) ResolvingDiscoverable(io.cdap.cdap.common.discovery.ResolvingDiscoverable) TransactionRunners(io.cdap.cdap.spi.data.transaction.TransactionRunners) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Inject(com.google.inject.Inject) MetricsReporterHook(io.cdap.cdap.common.metrics.MetricsReporterHook) LoggerFactory(org.slf4j.LoggerFactory) TxCallable(io.cdap.cdap.spi.data.transaction.TxCallable) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) ProvisioningService(io.cdap.cdap.internal.provision.ProvisioningService) ImmutableList(com.google.common.collect.ImmutableList) AbstractIdleService(com.google.common.util.concurrent.AbstractIdleService) NettyHttpService(io.cdap.http.NettyHttpService) Cancellable(org.apache.twill.common.Cancellable) Nullable(javax.annotation.Nullable) DiscoveryService(org.apache.twill.discovery.DiscoveryService) AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) DefaultNamespaceStore(io.cdap.cdap.store.DefaultNamespaceStore) Logger(org.slf4j.Logger) URIScheme(io.cdap.cdap.common.discovery.URIScheme) Set(java.util.Set) LoggingContextAccessor(io.cdap.cdap.common.logging.LoggingContextAccessor) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) ProgramRuntimeService(io.cdap.cdap.app.runtime.ProgramRuntimeService) CoreSchedulerService(io.cdap.cdap.scheduler.CoreSchedulerService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) SystemAppManagementService(io.cdap.cdap.internal.sysapp.SystemAppManagementService) HttpHandler(io.cdap.http.HttpHandler) Futures(com.google.common.util.concurrent.Futures) CommonNettyHttpServiceBuilder(io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder) List(java.util.List) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) Named(com.google.inject.name.Named) Constants(io.cdap.cdap.common.conf.Constants) BootstrapService(io.cdap.cdap.internal.bootstrap.BootstrapService) EventPublishManager(io.cdap.cdap.internal.events.EventPublishManager) Collections(java.util.Collections) ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) MetricsReporterHook(io.cdap.cdap.common.metrics.MetricsReporterHook) CommonNettyHttpServiceBuilder(io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder) NettyHttpService(io.cdap.http.NettyHttpService) DefaultNamespaceStore(io.cdap.cdap.store.DefaultNamespaceStore) HttpsEnabler(io.cdap.cdap.common.security.HttpsEnabler) ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 AbstractIdleService (com.google.common.util.concurrent.AbstractIdleService)1 Futures (com.google.common.util.concurrent.Futures)1 Inject (com.google.inject.Inject)1 Named (com.google.inject.name.Named)1 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)1 ProgramRuntimeService (io.cdap.cdap.app.runtime.ProgramRuntimeService)1 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)1 Constants (io.cdap.cdap.common.conf.Constants)1 SConfiguration (io.cdap.cdap.common.conf.SConfiguration)1 ResolvingDiscoverable (io.cdap.cdap.common.discovery.ResolvingDiscoverable)1 URIScheme (io.cdap.cdap.common.discovery.URIScheme)1 CommonNettyHttpServiceBuilder (io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder)1 LoggingContextAccessor (io.cdap.cdap.common.logging.LoggingContextAccessor)1 ServiceLoggingContext (io.cdap.cdap.common.logging.ServiceLoggingContext)1 MetricsReporterHook (io.cdap.cdap.common.metrics.MetricsReporterHook)1 HttpsEnabler (io.cdap.cdap.common.security.HttpsEnabler)1 AppMetadataStore (io.cdap.cdap.internal.app.store.AppMetadataStore)1 BootstrapService (io.cdap.cdap.internal.bootstrap.BootstrapService)1 EventPublishManager (io.cdap.cdap.internal.events.EventPublishManager)1