use of co.cask.cdap.logging.context.UserServiceLoggingContext in project cdap by caskdata.
the class MockLogReader method generateLogs.
public void generateLogs() throws InterruptedException {
// Add logs for app testApp2, flow testFlow1
generateLogs(new FlowletLoggingContext(NamespaceId.DEFAULT.getEntityName(), "testApp2", "testFlow1", "testFlowlet1", "", ""), NamespaceId.DEFAULT.app("testApp2").flow("testFlow1"), ProgramRunStatus.RUNNING);
// Add logs for app testApp3, mapreduce testMapReduce1
generateLogs(new MapReduceLoggingContext(NamespaceId.DEFAULT.getEntityName(), "testApp3", "testMapReduce1", ""), NamespaceId.DEFAULT.app("testApp3").mr("testMapReduce1"), ProgramRunStatus.SUSPENDED);
// Add logs for app testApp1, service testService1
generateLogs(new UserServiceLoggingContext(NamespaceId.DEFAULT.getEntityName(), "testApp4", "testService1", "test1", "", ""), NamespaceId.DEFAULT.app("testApp4").service("testService1"), ProgramRunStatus.RUNNING);
// Add logs for app testApp1, mapreduce testMapReduce1
generateLogs(new MapReduceLoggingContext(TEST_NAMESPACE_ID.getNamespace(), "testTemplate1", "testMapReduce1", ""), TEST_NAMESPACE_ID.app("testTemplate1").mr("testMapReduce1"), ProgramRunStatus.COMPLETED);
// Add logs for app testApp1, flow testFlow1 in testNamespace
generateLogs(new FlowletLoggingContext(TEST_NAMESPACE_ID.getNamespace(), "testApp1", "testFlow1", "testFlowlet1", "", ""), TEST_NAMESPACE_ID.app("testApp1").flow("testFlow1"), ProgramRunStatus.COMPLETED);
// Add logs for app testApp1, service testService1 in testNamespace
generateLogs(new UserServiceLoggingContext(TEST_NAMESPACE_ID.getNamespace(), "testApp4", "testService1", "test1", "", ""), TEST_NAMESPACE_ID.app("testApp4").service("testService1"), ProgramRunStatus.KILLED);
// Add logs for testWorkflow1 in testNamespace
generateLogs(new WorkflowLoggingContext(TEST_NAMESPACE_ID.getNamespace(), "testTemplate1", "testWorkflow1", "testRun1"), TEST_NAMESPACE_ID.app("testTemplate1").workflow("testWorkflow1"), ProgramRunStatus.COMPLETED);
// Add logs for testWorkflow1 in default namespace
generateLogs(new WorkflowLoggingContext(NamespaceId.DEFAULT.getEntityName(), "testTemplate1", "testWorkflow1", "testRun2"), NamespaceId.DEFAULT.app("testTemplate1").workflow("testWorkflow1"), ProgramRunStatus.COMPLETED);
generateWorkflowLogs();
}
use of co.cask.cdap.logging.context.UserServiceLoggingContext in project cdap by caskdata.
the class ServiceHttpServer method startUp.
/**
* Starts the {@link NettyHttpService} and announces this runnable as well.
*/
@Override
public void startUp() {
// All handlers of a Service run in the same Twill runnable and each Netty thread gets its own
// instance of a handler (and handlerContext). Creating the logging context here ensures that the logs
// during startup/shutdown and in each thread created are published.
LoggingContextAccessor.setLoggingContext(new UserServiceLoggingContext(program.getNamespaceId(), program.getApplicationId(), program.getId().getProgram(), program.getId().getProgram(), context.getRunId().getId(), String.valueOf(context.getInstanceId())));
LOG.debug("Starting HTTP server for Service {}", program.getId());
ProgramId programId = program.getId();
service.startAndWait();
// announce the twill runnable
InetSocketAddress bindAddress = service.getBindAddress();
int port = bindAddress.getPort();
// Announce the service with its version as the payload
cancelDiscovery = serviceAnnouncer.announce(ServiceDiscoverable.getName(programId), port, Bytes.toBytes(programId.getVersion()));
LOG.info("Announced HTTP Service for Service {} at {}", programId, bindAddress);
// Create a Timer thread to periodically collect handler that are no longer in used and call destroy on it
timer = new Timer("http-handler-gc", true);
long cleanupPeriod = DEFAULT_HANDLER_CLEANUP_PERIOD_MILLIS;
String cleanupPeriodProperty = System.getProperty(HANDLER_CLEANUP_PERIOD_MILLIS);
if (cleanupPeriodProperty != null) {
cleanupPeriod = Long.parseLong(cleanupPeriodProperty);
}
timer.scheduleAtFixedRate(createHandlerDestroyTask(), cleanupPeriod, cleanupPeriod);
}
Aggregations