Search in sources :

Example 1 with LogAppenderInitializer

use of co.cask.cdap.logging.appender.LogAppenderInitializer in project cdap by caskdata.

the class AbstractProgramTwillRunnable method initialize.

@Override
public void initialize(TwillContext context) {
    name = context.getSpecification().getName();
    LOG.info("Initializing runnable: " + name);
    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
    System.setSecurityManager(new RunnableSecurityManager(System.getSecurityManager()));
    // Install the JUL to SLF4J Bridge
    SLF4JBridgeHandler.install();
    runLatch = new CountDownLatch(1);
    coreServices = new ArrayList<>();
    try {
        CommandLine cmdLine = parseArgs(context.getApplicationArguments());
        ClassLoader classLoader = getClass().getClassLoader();
        // Loads configurations
        hConf = new Configuration();
        hConf.clear();
        hConf.addResource(classLoader.getResource(cmdLine.getOptionValue(RunnableOptions.HADOOP_CONF_FILE)));
        UserGroupInformation.setConfiguration(hConf);
        cConf = CConfiguration.create();
        cConf.clear();
        cConf.addResource(classLoader.getResource(cmdLine.getOptionValue(RunnableOptions.CDAP_CONF_FILE)));
        programOpts = createProgramOptions(cmdLine, context, context.getSpecification().getConfigs());
        // This impersonation info is added in PropertiesResolver#getSystemProperties
        // if kerberos is enabled we expect the principal to be provided in the program options as we
        // need it to be used later in ExploreClient to make request. If kerberos is disabled this will be null
        String principal = programOpts.getArguments().getOption(ProgramOptionConstants.PRINCIPAL);
        ProgramId programId = GSON.fromJson(cmdLine.getOptionValue(RunnableOptions.PROGRAM_ID), ProgramId.class);
        String instanceId = programOpts.getArguments().getOption(ProgramOptionConstants.INSTANCE_ID);
        String runId = programOpts.getArguments().getOption(ProgramOptionConstants.RUN_ID);
        Injector injector = Guice.createInjector(createModule(context, programId, runId, instanceId, principal));
        coreServices.add(injector.getInstance(ZKClientService.class));
        coreServices.add(injector.getInstance(KafkaClientService.class));
        coreServices.add(injector.getInstance(BrokerService.class));
        coreServices.add(injector.getInstance(MetricsCollectionService.class));
        coreServices.add(injector.getInstance(StreamCoordinatorClient.class));
        // Initialize log appender
        logAppenderInitializer = injector.getInstance(LogAppenderInitializer.class);
        logAppenderInitializer.initialize();
        // Create the ProgramRunner
        programRunner = createProgramRunner(injector);
        try {
            Location programJarLocation = Locations.toLocation(new File(cmdLine.getOptionValue(RunnableOptions.JAR)));
            ApplicationSpecification appSpec = readAppSpec(new File(cmdLine.getOptionValue(RunnableOptions.APP_SPEC_FILE)));
            program = Programs.create(cConf, programRunner, new ProgramDescriptor(programId, appSpec), programJarLocation, new File(cmdLine.getOptionValue(RunnableOptions.EXPANDED_JAR)));
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
        coreServices.add(new ProgramRunnableResourceReporter(program.getId(), injector.getInstance(MetricsCollectionService.class), context));
        LOG.info("Runnable initialized: {}", name);
    } catch (Throwable t) {
        LOG.error(t.getMessage(), t);
        throw Throwables.propagate(t);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) KafkaClientService(org.apache.twill.kafka.client.KafkaClientService) CConfiguration(co.cask.cdap.common.conf.CConfiguration) Configuration(org.apache.hadoop.conf.Configuration) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) StreamCoordinatorClient(co.cask.cdap.data.stream.StreamCoordinatorClient) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) ProgramId(co.cask.cdap.proto.id.ProgramId) CommandLine(org.apache.commons.cli.CommandLine) LogAppenderInitializer(co.cask.cdap.logging.appender.LogAppenderInitializer) ZKClientService(org.apache.twill.zookeeper.ZKClientService) Injector(com.google.inject.Injector) ProgramDescriptor(co.cask.cdap.app.program.ProgramDescriptor) UncaughtExceptionHandler(co.cask.cdap.common.logging.common.UncaughtExceptionHandler) BrokerService(org.apache.twill.kafka.client.BrokerService) File(java.io.File) Location(org.apache.twill.filesystem.Location)

Example 2 with LogAppenderInitializer

use of co.cask.cdap.logging.appender.LogAppenderInitializer in project cdap by caskdata.

the class TestFileLogging method setUpContext.

@BeforeClass
public static void setUpContext() throws Exception {
    Configuration hConf = HBaseConfiguration.create();
    final CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TMP_FOLDER.newFolder().getAbsolutePath());
    cConf.setInt(LoggingConfiguration.LOG_MAX_FILE_SIZE_BYTES, 20 * 1024);
    String logBaseDir = cConf.get(LoggingConfiguration.LOG_BASE_DIR) + "/" + TestFileLogging.class.getSimpleName();
    cConf.set(LoggingConfiguration.LOG_BASE_DIR, logBaseDir);
    injector = Guice.createInjector(new ConfigModule(cConf, hConf), new NonCustomLocationUnitTestModule().getModule(), new TransactionModules().getInMemoryModules(), new LoggingModules().getInMemoryModules(), new DataSetsModules().getInMemoryModules(), new SystemDatasetRuntimeModule().getInMemoryModules(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getNoOpModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class);
            bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
            bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
            bind(NamespaceQueryAdmin.class).to(SimpleNamespaceQueryAdmin.class);
        }
    });
    txManager = injector.getInstance(TransactionManager.class);
    txManager.startAndWait();
    LogAppender appender = injector.getInstance(LocalLogAppender.class);
    new LogAppenderInitializer(appender).initialize("TestFileLogging");
    Logger logger = LoggerFactory.getLogger("TestFileLogging");
    LoggingTester loggingTester = new LoggingTester();
    loggingTester.generateLogs(logger, new FlowletLoggingContext("TFL_NS_1", "APP_1", "FLOW_1", "FLOWLET_1", "RUN1", "INSTANCE1"));
    appender.stop();
}
Also used : CConfiguration(co.cask.cdap.common.conf.CConfiguration) LoggingConfiguration(co.cask.cdap.logging.LoggingConfiguration) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) NoOpMetricsCollectionService(co.cask.cdap.common.metrics.NoOpMetricsCollectionService) ConfigModule(co.cask.cdap.common.guice.ConfigModule) AuthenticationContextModules(co.cask.cdap.security.auth.context.AuthenticationContextModules) LocalLogAppender(co.cask.cdap.logging.framework.local.LocalLogAppender) LogAppender(co.cask.cdap.logging.appender.LogAppender) DataSetsModules(co.cask.cdap.data.runtime.DataSetsModules) DefaultOwnerAdmin(co.cask.cdap.security.impersonation.DefaultOwnerAdmin) OwnerAdmin(co.cask.cdap.security.impersonation.OwnerAdmin) UGIProvider(co.cask.cdap.security.impersonation.UGIProvider) UnsupportedUGIProvider(co.cask.cdap.security.impersonation.UnsupportedUGIProvider) NonCustomLocationUnitTestModule(co.cask.cdap.common.guice.NonCustomLocationUnitTestModule) Logger(org.slf4j.Logger) CConfiguration(co.cask.cdap.common.conf.CConfiguration) AuthorizationTestModule(co.cask.cdap.security.authorization.AuthorizationTestModule) LoggingModules(co.cask.cdap.logging.guice.LoggingModules) AbstractModule(com.google.inject.AbstractModule) TransactionModules(org.apache.tephra.runtime.TransactionModules) LoggingTester(co.cask.cdap.logging.appender.LoggingTester) LogAppenderInitializer(co.cask.cdap.logging.appender.LogAppenderInitializer) TransactionManager(org.apache.tephra.TransactionManager) NamespaceQueryAdmin(co.cask.cdap.common.namespace.NamespaceQueryAdmin) SimpleNamespaceQueryAdmin(co.cask.cdap.common.namespace.SimpleNamespaceQueryAdmin) SystemDatasetRuntimeModule(co.cask.cdap.data.runtime.SystemDatasetRuntimeModule) FlowletLoggingContext(co.cask.cdap.logging.context.FlowletLoggingContext) AuthorizationEnforcementModule(co.cask.cdap.security.authorization.AuthorizationEnforcementModule) BeforeClass(org.junit.BeforeClass)

Example 3 with LogAppenderInitializer

use of co.cask.cdap.logging.appender.LogAppenderInitializer in project cdap by caskdata.

the class TestKafkaLogging method init.

@BeforeClass
public static void init() throws Exception {
    txManager = KAFKA_TESTER.getInjector().getInstance(TransactionManager.class);
    txManager.startAndWait();
    KafkaLogAppender appender = KAFKA_TESTER.getInjector().getInstance(KafkaLogAppender.class);
    new LogAppenderInitializer(appender).initialize("TestKafkaLogging");
    Logger logger = LoggerFactory.getLogger("TestKafkaLogging");
    LoggingTester loggingTester = new LoggingTester();
    loggingTester.generateLogs(logger, new FlowletLoggingContext("TKL_NS_1", "APP_1", "FLOW_1", "FLOWLET_1", "RUN1", "INSTANCE1"));
    appender.stop();
}
Also used : LoggingTester(co.cask.cdap.logging.appender.LoggingTester) LogAppenderInitializer(co.cask.cdap.logging.appender.LogAppenderInitializer) TransactionManager(org.apache.tephra.TransactionManager) Logger(org.slf4j.Logger) FlowletLoggingContext(co.cask.cdap.logging.context.FlowletLoggingContext) BeforeClass(org.junit.BeforeClass)

Aggregations

LogAppenderInitializer (co.cask.cdap.logging.appender.LogAppenderInitializer)3 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)2 CConfiguration (co.cask.cdap.common.conf.CConfiguration)2 LoggingTester (co.cask.cdap.logging.appender.LoggingTester)2 FlowletLoggingContext (co.cask.cdap.logging.context.FlowletLoggingContext)2 Configuration (org.apache.hadoop.conf.Configuration)2 TransactionManager (org.apache.tephra.TransactionManager)2 BeforeClass (org.junit.BeforeClass)2 Logger (org.slf4j.Logger)2 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)1 ProgramDescriptor (co.cask.cdap.app.program.ProgramDescriptor)1 ConfigModule (co.cask.cdap.common.guice.ConfigModule)1 NonCustomLocationUnitTestModule (co.cask.cdap.common.guice.NonCustomLocationUnitTestModule)1 UncaughtExceptionHandler (co.cask.cdap.common.logging.common.UncaughtExceptionHandler)1 NoOpMetricsCollectionService (co.cask.cdap.common.metrics.NoOpMetricsCollectionService)1 NamespaceQueryAdmin (co.cask.cdap.common.namespace.NamespaceQueryAdmin)1 SimpleNamespaceQueryAdmin (co.cask.cdap.common.namespace.SimpleNamespaceQueryAdmin)1 DataSetsModules (co.cask.cdap.data.runtime.DataSetsModules)1 SystemDatasetRuntimeModule (co.cask.cdap.data.runtime.SystemDatasetRuntimeModule)1 StreamCoordinatorClient (co.cask.cdap.data.stream.StreamCoordinatorClient)1