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