Search in sources :

Example 21 with ServiceLoggingContext

use of io.cdap.cdap.common.logging.ServiceLoggingContext in project cdap by cdapio.

the class SystemWorkerTwillRunnable method doInitialize.

private void doInitialize(TwillContext context) throws Exception {
    CConfiguration cConf = CConfiguration.create(new File(getArgument("cConf")).toURI().toURL());
    // Overwrite the app fabric temp directory with the task worker temp directory
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, cConf.get(Constants.TaskWorker.LOCAL_DATA_DIR));
    Configuration hConf = new Configuration();
    hConf.clear();
    hConf.addResource(new File(getArgument("hConf")).toURI().toURL());
    Injector injector = createInjector(cConf, hConf);
    // Initialize logging context
    logAppenderInitializer = injector.getInstance(LogAppenderInitializer.class);
    logAppenderInitializer.initialize();
    metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
    metricsCollectionService.startAndWait();
    LoggingContext loggingContext = new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, SystemWorkerTwillApplication.NAME);
    LoggingContextAccessor.setLoggingContext(loggingContext);
    taskWorker = injector.getInstance(TaskWorkerService.class);
}
Also used : LogAppenderInitializer(io.cdap.cdap.logging.appender.LogAppenderInitializer) Configuration(org.apache.hadoop.conf.Configuration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) LoggingContext(io.cdap.cdap.common.logging.LoggingContext) ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext) Injector(com.google.inject.Injector) ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) File(java.io.File) TaskWorkerService(io.cdap.cdap.internal.app.worker.TaskWorkerService)

Example 22 with ServiceLoggingContext

use of io.cdap.cdap.common.logging.ServiceLoggingContext in project cdap by cdapio.

the class ArtifactLocalizerTwillRunnable method doInitialize.

private void doInitialize() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.clear();
    cConf.addResource(new File(getArgument("cConf")).toURI().toURL());
    Configuration hConf = new Configuration();
    hConf.clear();
    hConf.addResource(new File(getArgument("hConf")).toURI().toURL());
    Injector injector = createInjector(cConf, hConf);
    // Initialize logging context
    logAppenderInitializer = injector.getInstance(LogAppenderInitializer.class);
    logAppenderInitializer.initialize();
    LoggingContext loggingContext = new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.ARTIFACT_LOCALIZER);
    LoggingContextAccessor.setLoggingContext(loggingContext);
    tokenManager = injector.getInstance(TokenManager.class);
    tokenManager.startAndWait();
    artifactLocalizerService = injector.getInstance(ArtifactLocalizerService.class);
}
Also used : LogAppenderInitializer(io.cdap.cdap.logging.appender.LogAppenderInitializer) Configuration(org.apache.hadoop.conf.Configuration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) LoggingContext(io.cdap.cdap.common.logging.LoggingContext) ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext) Injector(com.google.inject.Injector) ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext) TokenManager(io.cdap.cdap.security.auth.TokenManager) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) File(java.io.File)

Example 23 with ServiceLoggingContext

use of io.cdap.cdap.common.logging.ServiceLoggingContext in project cdap by cdapio.

the class ExploreExecutorService method startUp.

@Override
protected void startUp() throws Exception {
    LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.EXPLORE_HTTP_USER_SERVICE));
    LOG.info("Starting {}...", ExploreExecutorService.class.getSimpleName());
    if (!startOnDemand) {
        exploreService.startAndWait();
    }
    httpService.start();
    cancellable = discoveryService.register(ResolvingDiscoverable.of(URIScheme.createDiscoverable(Constants.Service.EXPLORE_HTTP_USER_SERVICE, httpService)));
    LOG.info("{} started successfully on {}", ExploreExecutorService.class.getSimpleName(), httpService.getBindAddress());
}
Also used : ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext)

Example 24 with ServiceLoggingContext

use of io.cdap.cdap.common.logging.ServiceLoggingContext in project cdap by cdapio.

the class PreviewHttpServer 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.PREVIEW_HTTP));
    if (previewManager instanceof Service) {
        ((Service) previewManager).startAndWait();
    }
    httpService.start();
    cancelHttpService = discoveryService.register(ResolvingDiscoverable.of(URIScheme.createDiscoverable(Constants.Service.PREVIEW_HTTP, httpService)));
    LOG.info("Preview HTTP server started on {}", httpService.getBindAddress());
}
Also used : AbstractIdleService(com.google.common.util.concurrent.AbstractIdleService) NettyHttpService(io.cdap.http.NettyHttpService) DiscoveryService(org.apache.twill.discovery.DiscoveryService) Service(com.google.common.util.concurrent.Service) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext)

Example 25 with ServiceLoggingContext

use of io.cdap.cdap.common.logging.ServiceLoggingContext in project cdap by cdapio.

the class DefaultPreviewRunner method startUp.

@Override
protected void startUp() throws Exception {
    LOG.debug("Starting preview runner service");
    StoreDefinition.createAllTables(structuredTableAdmin);
    if (messagingService instanceof Service) {
        ((Service) messagingService).startAndWait();
    }
    dsOpExecService.startAndWait();
    datasetService.startAndWait();
    // It is recommended to initialize log appender after datasetService is started,
    // since log appender instantiates a dataset.
    logAppenderInitializer.initialize();
    LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.PREVIEW_HTTP));
    Futures.allAsList(applicationLifecycleService.start(), programRuntimeService.start(), metricsCollectionService.start(), programNotificationSubscriberService.start()).get();
    Files.createDirectories(previewIdDirPath);
    // Reconcile status for abruptly terminated preview runs
    try (Stream<Path> paths = Files.walk(Paths.get(previewIdDirPath.toString()))) {
        paths.filter(Files::isRegularFile).forEach(path -> {
            try (Reader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
                ProgramId programId = GSON.fromJson(reader, ProgramId.class);
                long submitTimeMillis = RunIds.getTime(programId.getApplication(), TimeUnit.MILLISECONDS);
                PreviewStatus status = new PreviewStatus(PreviewStatus.Status.KILLED_BY_EXCEEDING_MEMORY_LIMIT, submitTimeMillis, new BasicThrowable(new Exception("Preview runner container killed possibly because of out of memory. " + "Please try running preview again.")), null, null);
                previewTerminated(programId, status);
            } catch (IOException e) {
                LOG.warn("Error reading file {}. Ignoring", path, e);
            }
        });
    }
}
Also used : Path(java.nio.file.Path) PreviewStatus(io.cdap.cdap.app.preview.PreviewStatus) ProgramNotificationSubscriberService(io.cdap.cdap.internal.app.services.ProgramNotificationSubscriberService) MessagingService(io.cdap.cdap.messaging.MessagingService) ApplicationLifecycleService(io.cdap.cdap.internal.app.services.ApplicationLifecycleService) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) LevelDBTableService(io.cdap.cdap.data2.dataset2.lib.table.leveldb.LevelDBTableService) AbstractIdleService(com.google.common.util.concurrent.AbstractIdleService) DatasetOpExecutorService(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) ProgramLifecycleService(io.cdap.cdap.internal.app.services.ProgramLifecycleService) ProgramRuntimeService(io.cdap.cdap.app.runtime.ProgramRuntimeService) Service(com.google.common.util.concurrent.Service) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) Reader(java.io.Reader) IOException(java.io.IOException) ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext) ProgramId(io.cdap.cdap.proto.id.ProgramId) BasicThrowable(io.cdap.cdap.proto.BasicThrowable) TimeoutException(java.util.concurrent.TimeoutException) NamespaceAlreadyExistsException(io.cdap.cdap.common.NamespaceAlreadyExistsException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ServiceLoggingContext (io.cdap.cdap.common.logging.ServiceLoggingContext)46 LogAppenderInitializer (io.cdap.cdap.logging.appender.LogAppenderInitializer)20 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)18 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)12 LoggingContext (io.cdap.cdap.common.logging.LoggingContext)12 Configuration (org.apache.hadoop.conf.Configuration)12 Injector (com.google.inject.Injector)10 File (java.io.File)10 AbstractIdleService (com.google.common.util.concurrent.AbstractIdleService)6 ImmutableList (com.google.common.collect.ImmutableList)4 Service (com.google.common.util.concurrent.Service)4 ProgramRuntimeService (io.cdap.cdap.app.runtime.ProgramRuntimeService)4 SConfiguration (io.cdap.cdap.common.conf.SConfiguration)4 IOException (java.io.IOException)4 TransactionRunner (io.cdap.cdap.spi.data.transaction.TransactionRunner)3 NettyHttpService (io.cdap.http.NettyHttpService)3 ArrayList (java.util.ArrayList)3 DiscoveryService (org.apache.twill.discovery.DiscoveryService)3 LoggerContext (ch.qos.logback.classic.LoggerContext)2 MetricDataQuery (io.cdap.cdap.api.metrics.MetricDataQuery)2