/** * Returns the {@link MapReduceTaskContextProvider} associated with this ClassLoader. */ public MapReduceTaskContextProvider getTaskContextProvider() { // Logging context needs to be set in main thread. LoggingContext loggingContext = createMapReduceLoggingContext(); LoggingContextAccessor.setLoggingContext(loggingContext); synchronized (this) { taskContextProvider = Optional.fromNullable(taskContextProvider).or(taskContextProviderSupplier); } taskContextProvider.startAndWait(); return taskContextProvider; }
@Override public final void append(ILoggingEvent eventObject) { LoggingContext loggingContext; // If the context is not setup, pickup the context from thread-local. // If the context is already setup, use the context (in async mode). if (eventObject instanceof LogMessage) { loggingContext = ((LogMessage) eventObject).getLoggingContext(); } else { loggingContext = LoggingContextAccessor.getLoggingContext(); if (loggingContext == null) { return; } addExtraTags(eventObject); } LogMessage logMessage = new LogMessage(eventObject, loggingContext); appendEvent(logMessage); }
@Override public final void append(ILoggingEvent eventObject) { LoggingContext loggingContext; // If the context is not setup, pickup the context from thread-local. // If the context is already setup, use the context (in async mode). if (eventObject instanceof LogMessage) { loggingContext = ((LogMessage) eventObject).getLoggingContext(); } else { loggingContext = LoggingContextAccessor.getLoggingContext(); if (loggingContext == null) { return; } addExtraTags(eventObject); } LogMessage logMessage = new LogMessage(eventObject, loggingContext); appendEvent(logMessage); }
@Override protected void startUp() throws Exception { LoggingContextAccessor.setLoggingContext(loggingContext); runningThread = Thread.currentThread(); createLocalDatasets(); workflow = initializeWorkflow(); }
/** * Returns the {@link MapReduceTaskContextProvider} associated with this ClassLoader. */ public MapReduceTaskContextProvider getTaskContextProvider() { // Logging context needs to be set in main thread. LoggingContext loggingContext = createMapReduceLoggingContext(); LoggingContextAccessor.setLoggingContext(loggingContext); synchronized (this) { taskContextProvider = Optional.fromNullable(taskContextProvider).or(taskContextProviderSupplier); } taskContextProvider.startAndWait(); return taskContextProvider; }
@Override protected void startUp() throws Exception { LoggingContextAccessor.setLoggingContext(loggingContext); runningThread = Thread.currentThread(); createLocalDatasets(); workflow = initializeWorkflow(); }
/** * Runs the runnable with the logging context set to the program run's context. Anything logged within the runnable * will be treated as if they were logs in the program run. * * @param programRunId the program run to log as * @param systemArgs system arguments for the run * @param runnable the runnable to run */ private void runWithProgramLogging(ProgramRunId programRunId, Map<String, String> systemArgs, Runnable runnable) { LoggingContext loggingContext = LoggingContextHelper.getLoggingContextWithRunId(programRunId, systemArgs); Cancellable cancellable = LoggingContextAccessor.setLoggingContext(loggingContext); try { runnable.run(); } finally { cancellable.cancel(); } }
/** * Runs the runnable with the logging context set to the program run's context. Anything logged within the runnable * will be treated as if they were logs in the program run. * * @param programRunId the program run to log as * @param systemArgs system arguments for the run * @param runnable the runnable to run */ private void runWithProgramLogging(ProgramRunId programRunId, Map<String, String> systemArgs, Runnable runnable) { LoggingContext loggingContext = LoggingContextHelper.getLoggingContextWithRunId(programRunId, systemArgs); Cancellable cancellable = LoggingContextAccessor.setLoggingContext(loggingContext); try { runnable.run(); } finally { cancellable.cancel(); } }
@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; }
@Override protected Injector doInit(TwillContext context) { getCConfiguration().set(Constants.Transaction.Container.ADDRESS, context.getHost().getCanonicalHostName()); // Set the hostname of the machine so that cConf can be used to start internal services LOG.info("{} Setting host name to {}", name, context.getHost().getCanonicalHostName()); String txClientId = String.format("cdap.service.%s.%d", Constants.Service.TRANSACTION, 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.TRANSACTION)); return injector; }
@Override protected void startUp() throws Exception { LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(Id.Namespace.SYSTEM.getId(), Constants.Logging.COMPONENT_NAME, Constants.Service.METRICS)); LOG.info("Starting Metrics Service..."); httpService.start(); LOG.info("Started Metrics HTTP Service..."); // Register the service cancelDiscovery = discoveryService.register( ResolvingDiscoverable.of(new Discoverable(Constants.Service.METRICS, httpService.getBindAddress()))); LOG.info("Metrics Service started successfully on {}", httpService.getBindAddress()); }
@Override protected void startUp() throws Exception { LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(Id.Namespace.SYSTEM.getId(), Constants.Logging.COMPONENT_NAME, Constants.Service.METRICS_PROCESSOR)); LOG.info("Starting MetricsProcessor Status Service..."); httpService.start(); cancellable = discoveryService.register( ResolvingDiscoverable.of(new Discoverable(Constants.Service.METRICS_PROCESSOR, httpService.getBindAddress()))); LOG.info("Started MetricsProcessor Status Service."); }
@Override protected void run() throws Exception { LoggingContextAccessor.setLoggingContext(loggingContext);
@Override protected Injector doInit(TwillContext context) { getCConfiguration().set(Constants.MetricsProcessor.ADDRESS, context.getHost().getCanonicalHostName()); // Set the hostname of the machine so that cConf can be used to start internal services LOG.info("{} Setting host name to {}", name, context.getHost().getCanonicalHostName()); String txClientId = String.format("cdap.service.%s.%d", Constants.Service.METRICS_PROCESSOR, context.getInstanceId()); injector = createGuiceInjector(getCConfiguration(), getConfiguration(), txClientId, context); injector.getInstance(LogAppenderInitializer.class).initialize(); LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.METRICS_PROCESSOR)); return injector; }
@Override protected void startUp() throws Exception { LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(Id.Namespace.SYSTEM.getId(), Constants.Logging.COMPONENT_NAME, Constants.Service.METRICS_PROCESSOR)); LOG.info("Starting MetricsProcessor Status Service..."); httpService.start(); cancellable = discoveryService.register( ResolvingDiscoverable.of(new Discoverable(Constants.Service.METRICS_PROCESSOR, httpService.getBindAddress()))); LOG.info("Started MetricsProcessor Status Service."); }
@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( new Discoverable(Constants.Service.EXPLORE_HTTP_USER_SERVICE, httpService.getBindAddress()))); LOG.info("{} started successfully on {}", ExploreExecutorService.class.getSimpleName(), httpService.getBindAddress()); }
@Override protected void startUp() throws Exception { LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(Id.Namespace.SYSTEM.getId(), Constants.Logging.COMPONENT_NAME, Constants.Service.METRICS)); LOG.info("Starting Metrics Service..."); httpService.start(); LOG.info("Started Metrics HTTP Service..."); // Register the service cancelDiscovery = discoveryService.register( ResolvingDiscoverable.of(new Discoverable(Constants.Service.METRICS, httpService.getBindAddress()))); LOG.info("Metrics Service started successfully on {}", httpService.getBindAddress()); }
@Override protected void startUp() throws Exception { LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getEntityName(), Constants.Logging.COMPONENT_NAME, Constants.Service.DATASET_EXECUTOR)); LOG.info("Starting DatasetOpExecutorService..."); httpService.start(); cancellable = discoveryService.register( ResolvingDiscoverable.of(new Discoverable(Constants.Service.DATASET_EXECUTOR, httpService.getBindAddress()))); LOG.info("DatasetOpExecutorService started successfully on {}", httpService.getBindAddress()); }
@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( new Discoverable(Constants.Service.EXPLORE_HTTP_USER_SERVICE, httpService.getBindAddress()))); LOG.info("{} started successfully on {}", ExploreExecutorService.class.getSimpleName(), httpService.getBindAddress()); }
@Override protected void startUp() throws Exception { LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getEntityName(), Constants.Logging.COMPONENT_NAME, Constants.Service.DATASET_EXECUTOR)); LOG.info("Starting DatasetOpExecutorService..."); httpService.start(); cancellable = discoveryService.register( ResolvingDiscoverable.of(new Discoverable(Constants.Service.DATASET_EXECUTOR, httpService.getBindAddress()))); LOG.info("DatasetOpExecutorService started successfully on {}", httpService.getBindAddress()); }