Search in sources :

Example 16 with ServiceLoggingContext

use of co.cask.cdap.common.logging.ServiceLoggingContext in project cdap by caskdata.

the class LogSaverStatusService method startUp.

@Override
protected void startUp() throws Exception {
    LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(Id.Namespace.SYSTEM.getId(), Constants.Logging.COMPONENT_NAME, Constants.Service.LOGSAVER));
    httpService.startAndWait();
    cancellable = discoveryService.register(ResolvingDiscoverable.of(new Discoverable(Constants.Service.LOGSAVER, httpService.getBindAddress())));
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) ResolvingDiscoverable(co.cask.cdap.common.discovery.ResolvingDiscoverable) ServiceLoggingContext(co.cask.cdap.common.logging.ServiceLoggingContext)

Example 17 with ServiceLoggingContext

use of co.cask.cdap.common.logging.ServiceLoggingContext in project cdap by caskdata.

the class MetricsTwillRunnable method doInit.

@Override
protected Injector doInit(TwillContext context) {
    // Set the hostname of the machine so that cConf can be used to start internal services
    getCConfiguration().set(Constants.Metrics.ADDRESS, context.getHost().getCanonicalHostName());
    LOG.info("{} Setting host name to {}", name, context.getHost().getCanonicalHostName());
    String txClientId = String.format("cdap.service.%s.%d", Constants.Service.METRICS, context.getInstanceId());
    injector = createGuiceInjector(getCConfiguration(), getConfiguration(), txClientId);
    injector.getInstance(LogAppenderInitializer.class).initialize();
    LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.METRICS));
    return injector;
}
Also used : LogAppenderInitializer(co.cask.cdap.logging.appender.LogAppenderInitializer) ServiceLoggingContext(co.cask.cdap.common.logging.ServiceLoggingContext)

Example 18 with ServiceLoggingContext

use of co.cask.cdap.common.logging.ServiceLoggingContext in project cdap by caskdata.

the class DistributedLogFrameworkTest method testFramework.

@Test
public void testFramework() throws Exception {
    DistributedLogFramework framework = injector.getInstance(DistributedLogFramework.class);
    CConfiguration cConf = injector.getInstance(CConfiguration.class);
    framework.startAndWait();
    // Send some logs to Kafka.
    LoggingContext context = new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, "test");
    // Make sure all events get flushed in the same batch
    long eventTimeBase = System.currentTimeMillis() + cConf.getInt(Constants.Logging.PIPELINE_EVENT_DELAY_MS);
    final int msgCount = 50;
    for (int i = 0; i < msgCount; i++) {
        // Publish logs in descending timestamp order
        publishLog(cConf.get(Constants.Logging.KAFKA_TOPIC), context, ImmutableList.of(createLoggingEvent("co.cask.test." + i, Level.INFO, "Testing " + i, eventTimeBase - i)));
    }
    // Read the logs back. They should be sorted by timestamp order.
    final FileMetaDataReader metaDataReader = injector.getInstance(FileMetaDataReader.class);
    Tasks.waitFor(true, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            List<LogLocation> locations = metaDataReader.listFiles(new LogPathIdentifier(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, "test"), 0, Long.MAX_VALUE);
            if (locations.size() != 1) {
                return false;
            }
            LogLocation location = locations.get(0);
            int i = 0;
            try {
                try (CloseableIterator<LogEvent> iter = location.readLog(Filter.EMPTY_FILTER, 0, Long.MAX_VALUE, msgCount)) {
                    while (iter.hasNext()) {
                        String expectedMsg = "Testing " + (msgCount - i - 1);
                        LogEvent event = iter.next();
                        if (!expectedMsg.equals(event.getLoggingEvent().getMessage())) {
                            return false;
                        }
                        i++;
                    }
                    return i == msgCount;
                }
            } catch (Exception e) {
                // and the time when actual content are flushed to the file
                return false;
            }
        }
    }, 10, TimeUnit.SECONDS, msgCount, TimeUnit.MILLISECONDS);
    framework.stopAndWait();
    // Check the checkpoint is persisted correctly. Since all messages are processed,
    // the checkpoint should be the same as the message count.
    Checkpoint checkpoint = injector.getInstance(CheckpointManagerFactory.class).create(cConf.get(Constants.Logging.KAFKA_TOPIC), Bytes.toBytes(100)).getCheckpoint(0);
    Assert.assertEquals(msgCount, checkpoint.getNextOffset());
}
Also used : CloseableIterator(co.cask.cdap.api.dataset.lib.CloseableIterator) LoggingContext(co.cask.cdap.common.logging.LoggingContext) ServiceLoggingContext(co.cask.cdap.common.logging.ServiceLoggingContext) LogEvent(co.cask.cdap.logging.read.LogEvent) ServiceLoggingContext(co.cask.cdap.common.logging.ServiceLoggingContext) CConfiguration(co.cask.cdap.common.conf.CConfiguration) Checkpoint(co.cask.cdap.logging.meta.Checkpoint) IOException(java.io.IOException) Checkpoint(co.cask.cdap.logging.meta.Checkpoint) LogLocation(co.cask.cdap.logging.write.LogLocation) FileMetaDataReader(co.cask.cdap.logging.meta.FileMetaDataReader) LogPathIdentifier(co.cask.cdap.logging.appender.system.LogPathIdentifier) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 19 with ServiceLoggingContext

use of co.cask.cdap.common.logging.ServiceLoggingContext in project cdap by caskdata.

the class DatasetOpExecutorServerTwillRunnable method doInit.

@Override
protected Injector doInit(TwillContext context) {
    CConfiguration cConf = getCConfiguration();
    Configuration hConf = getConfiguration();
    // Set the host name to the one provided by Twill
    cConf.set(Constants.Dataset.Executor.ADDRESS, context.getHost().getHostName());
    String txClientId = String.format("cdap.service.%s.%d", Constants.Service.DATASET_EXECUTOR, context.getInstanceId());
    injector = createInjector(cConf, hConf, txClientId);
    injector.getInstance(LogAppenderInitializer.class).initialize();
    LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.DATASET_EXECUTOR));
    return injector;
}
Also used : LogAppenderInitializer(co.cask.cdap.logging.appender.LogAppenderInitializer) CConfiguration(co.cask.cdap.common.conf.CConfiguration) Configuration(org.apache.hadoop.conf.Configuration) ServiceLoggingContext(co.cask.cdap.common.logging.ServiceLoggingContext) CConfiguration(co.cask.cdap.common.conf.CConfiguration)

Example 20 with ServiceLoggingContext

use of co.cask.cdap.common.logging.ServiceLoggingContext in project cdap by caskdata.

the class MessagingServiceTwillRunnable method doInit.

@Override
protected Injector doInit(TwillContext context) {
    CConfiguration cConf = getCConfiguration();
    cConf.set(Constants.MessagingSystem.HTTP_SERVER_BIND_ADDRESS, context.getHost().getHostName());
    cConf.setInt(Constants.MessagingSystem.CONTAINER_INSTANCE_ID, context.getInstanceId());
    injector = createInjector(cConf, getConfiguration());
    injector.getInstance(LogAppenderInitializer.class).initialize();
    LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.MESSAGING_SERVICE));
    HBaseTableFactory tableFactory = getHBaseTableFactory(injector.getInstance(TableFactory.class));
    // Upgrade the TMS Message and Payload Tables
    if (tableFactory != null) {
        try {
            tableFactory.upgradeMessageTable(cConf.get(Constants.MessagingSystem.MESSAGE_TABLE_NAME));
        } catch (IOException ex) {
            LOG.warn("Exception while trying to upgrade TMS MessageTable.", ex);
        }
        try {
            tableFactory.upgradePayloadTable(cConf.get(Constants.MessagingSystem.PAYLOAD_TABLE_NAME));
        } catch (IOException ex) {
            LOG.warn("Exception while trying to upgrade TMS PayloadTable.", ex);
        }
    }
    return injector;
}
Also used : LogAppenderInitializer(co.cask.cdap.logging.appender.LogAppenderInitializer) HBaseTableFactory(co.cask.cdap.messaging.store.hbase.HBaseTableFactory) ForwardingTableFactory(co.cask.cdap.messaging.store.ForwardingTableFactory) TableFactory(co.cask.cdap.messaging.store.TableFactory) HBaseTableFactory(co.cask.cdap.messaging.store.hbase.HBaseTableFactory) IOException(java.io.IOException) ServiceLoggingContext(co.cask.cdap.common.logging.ServiceLoggingContext) CConfiguration(co.cask.cdap.common.conf.CConfiguration)

Aggregations

ServiceLoggingContext (co.cask.cdap.common.logging.ServiceLoggingContext)20 ResolvingDiscoverable (co.cask.cdap.common.discovery.ResolvingDiscoverable)8 Discoverable (org.apache.twill.discovery.Discoverable)8 LogAppenderInitializer (co.cask.cdap.logging.appender.LogAppenderInitializer)7 CConfiguration (co.cask.cdap.common.conf.CConfiguration)5 ImmutableList (com.google.common.collect.ImmutableList)3 Configuration (org.apache.hadoop.conf.Configuration)3 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)2 LoggingContext (co.cask.cdap.common.logging.LoggingContext)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 CloseableIterator (co.cask.cdap.api.dataset.lib.CloseableIterator)1 MetricDataQuery (co.cask.cdap.api.metrics.MetricDataQuery)1 MetricStore (co.cask.cdap.api.metrics.MetricStore)1 ProgramRuntimeService (co.cask.cdap.app.runtime.ProgramRuntimeService)1 CommonNettyHttpServiceBuilder (co.cask.cdap.common.http.CommonNettyHttpServiceBuilder)1 ApplicationLoggingContext (co.cask.cdap.common.logging.ApplicationLoggingContext)1 ComponentLoggingContext (co.cask.cdap.common.logging.ComponentLoggingContext)1 NamespaceLoggingContext (co.cask.cdap.common.logging.NamespaceLoggingContext)1