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())));
}
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;
}
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());
}
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;
}
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;
}
Aggregations