use of org.apache.oozie.util.XLog in project oozie by apache.
the class JsonRestServlet method logHeaderInfo.
private void logHeaderInfo(HttpServletRequest request) {
XLog log = XLog.getLog(getClass());
StringBuilder traceInfo = new StringBuilder(4096);
// Display request URL and request.getHeaderNames();
Enumeration<String> names = (Enumeration<String>) request.getHeaderNames();
traceInfo.append("Request URL: ").append(getRequestUrl(request)).append("\nRequest Headers:\n");
while (names.hasMoreElements()) {
String name = names.nextElement();
String value = request.getHeader(name);
traceInfo.append(name).append(" : ").append(value).append("\n");
}
log.trace(traceInfo);
}
use of org.apache.oozie.util.XLog in project oozie by apache.
the class XLogService method init.
/**
* Initialize the log service.
*
* @param services services instance.
* @throws ServiceException thrown if the log service could not be initialized.
*/
public void init(Services services) throws ServiceException {
String oozieHome = Services.getOozieHome();
String oozieLogs = System.getProperty(OOZIE_LOG_DIR, oozieHome + "/logs");
System.setProperty(OOZIE_LOG_DIR, oozieLogs);
try {
LogManager.resetConfiguration();
log4jFileName = System.getProperty(LOG4J_FILE, DEFAULT_LOG4J_PROPERTIES);
if (log4jFileName.contains("/")) {
throw new ServiceException(ErrorCode.E0011, log4jFileName);
}
if (!log4jFileName.endsWith(".properties")) {
throw new ServiceException(ErrorCode.E0012, log4jFileName);
}
String configPath = ConfigurationService.getConfigurationDirectory();
File log4jFile = new File(configPath, log4jFileName);
if (log4jFile.exists()) {
fromClasspath = false;
} else {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL log4jUrl = cl.getResource(log4jFileName);
if (log4jUrl == null) {
throw new ServiceException(ErrorCode.E0013, log4jFileName, configPath);
}
fromClasspath = true;
}
if (fromClasspath) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL log4jUrl = cl.getResource(log4jFileName);
PropertyConfigurator.configure(log4jUrl);
} else {
interval = Long.parseLong(System.getProperty(LOG4J_RELOAD, DEFAULT_RELOAD_INTERVAL));
PropertyConfigurator.configureAndWatch(log4jFile.toString(), interval * 1000);
}
log = new XLog(LogFactory.getLog(getClass()));
log.info(XLog.OPS, STARTUP_MESSAGE, BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_VERSION), BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_USER_NAME), BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_TIME), BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_VC_REVISION), BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_VC_URL));
String from = (fromClasspath) ? "CLASSPATH" : configPath;
String reload = (fromClasspath) ? "disabled" : Long.toString(interval) + " sec";
log.info("Log4j configuration file [{0}]", log4jFileName);
log.info("Log4j configuration file loaded from [{0}]", from);
log.info("Log4j reload interval [{0}]", reload);
XLog.Info.reset();
XLog.Info.defineParameter(USER);
XLog.Info.defineParameter(GROUP);
XLogFilter.reset();
XLogFilter.defineParameter(USER);
XLogFilter.defineParameter(GROUP);
// Getting configuration for oozie log via WS
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream is = (fromClasspath) ? cl.getResourceAsStream(log4jFileName) : new FileInputStream(log4jFile);
extractInfoForLogWebService(is);
} catch (IOException ex) {
throw new ServiceException(ErrorCode.E0010, ex.getMessage(), ex);
}
}
use of org.apache.oozie.util.XLog in project oozie by apache.
the class RecoveryService method mergeConfig.
/**
* Merge Bundle job config and the configuration from the coord job to pass
* to Coord Engine
*
* @param coordElem the coordinator configuration
* @return Configuration merged configuration
* @throws CommandException thrown if failed to merge configuration
*/
private static Configuration mergeConfig(Element coordElem, BundleJobBean bundleJob) throws CommandException {
XLog.Info.get().clear();
XLog log = XLog.getLog("RecoveryService");
String jobConf = bundleJob.getConf();
// Step 1: runConf = jobConf
Configuration runConf = null;
try {
runConf = new XConfiguration(new StringReader(jobConf));
} catch (IOException e1) {
log.warn("Configuration parse error in:" + jobConf);
throw new CommandException(ErrorCode.E1306, e1.getMessage(), e1);
}
// Step 2: Merge local properties into runConf
// extract 'property' tags under 'configuration' block in the coordElem
// convert Element to XConfiguration
Element localConfigElement = coordElem.getChild("configuration", coordElem.getNamespace());
if (localConfigElement != null) {
String strConfig = XmlUtils.prettyPrint(localConfigElement).toString();
Configuration localConf;
try {
localConf = new XConfiguration(new StringReader(strConfig));
} catch (IOException e1) {
log.warn("Configuration parse error in:" + strConfig);
throw new CommandException(ErrorCode.E1307, e1.getMessage(), e1);
}
// copy configuration properties in the coordElem to the runConf
XConfiguration.copy(localConf, runConf);
}
// Step 3: Extract value of 'app-path' in coordElem, save it as a
// new property called 'oozie.coord.application.path', and normalize.
String appPath = coordElem.getChild("app-path", coordElem.getNamespace()).getValue();
runConf.set(OozieClient.COORDINATOR_APP_PATH, appPath);
// Normalize coordinator appPath here;
try {
JobUtils.normalizeAppPath(runConf.get(OozieClient.USER_NAME), runConf.get(OozieClient.GROUP_NAME), runConf);
} catch (IOException e) {
throw new CommandException(ErrorCode.E1001, runConf.get(OozieClient.COORDINATOR_APP_PATH));
}
return runConf;
}
use of org.apache.oozie.util.XLog in project oozie by apache.
the class TestXLogStreamingService method testAuditLog.
public void testAuditLog() throws Exception {
setupXLog();
XLogFilter xf = new XLogAuditFilter(new XLogUserFilterParam(null));
xf.setParameter("USER", "oozie");
xf.setLogLevel("DEBUG|INFO");
File log4jFile = new File(getTestCaseConfDir(), "test-log4j.properties");
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream is = cl.getResourceAsStream("test-no-dash-log4j.properties");
Properties log4jProps = new Properties();
log4jProps.load(is);
// prevent conflicts with other tests by changing the log file location
log4jProps.setProperty("log4j.appender.oozie.File", getTestCaseDir() + "/oozie.log");
log4jProps.setProperty("log4j.appender.oozieaudit.File", getTestCaseDir() + "/oozie-audit.log");
log4jProps.store(new FileOutputStream(log4jFile), "");
setSystemProperty(XLogService.LOG4J_FILE, log4jFile.getName());
try {
new Services().init();
XLog auditLog = XLog.getLog("oozieaudit");
xf.setParameter(DagXLogInfoService.JOB, "0000000-150322000230582-oozie-puru-C");
auditLog.info("2015-03-22 00:04:35,494 INFO oozieaudit:520 - IP [127.0.0.1], USER [purushah], GROUP [null], " + "APP [-], JOBID [0000000-150322000230582-oozie-puru-C], OPERATION [start], " + "PARAMETER [null], STATUS [SUCCESS], HTTPCODE [200], ERRORCODE [null], ERRORMESSAGE [L1]");
auditLog.info("2015-03-22 00:05:13,823 INFO oozieaudit:520 - IP [127.0.0.1], USER [purushah], GROUP [null], " + "APP [-], JOBID [0000000-150322000230582-oozie-puru-C], OPERATION [suspend], " + "PARAMETER [0000000-150322000230582-oozie-puru-C], STATUS [SUCCESS], HTTPCODE [200], ERRORCODE [null], " + "ERRORMESSAGE [L2]");
auditLog.info("2015-03-22 00:05:13,823 INFO oozieaudit:520 - IP [127.0.0.1], USER [purushah], GROUP [null], " + "APP [-], JOBID [0000001-150322000230582-oozie-puru-C], OPERATION [suspend], " + "PARAMETER [0000001-150322000230582-oozie-puru-C], STATUS [SUCCESS], HTTPCODE [200], ERRORCODE [null], " + "ERRORMESSAGE [L3]");
String out = doStreamAuditLog(xf);
String[] outArr = out.split("\n");
// Lines 2 and 4 are filtered out because they have the wrong user
assertEquals(2, outArr.length);
assertTrue(outArr[0].contains("L1"));
assertTrue(out.contains("L2"));
assertFalse(out.contains("L3"));
} finally {
Services.get().destroy();
}
}
use of org.apache.oozie.util.XLog in project oozie by apache.
the class XTestCase method waitFor.
/**
* Wait for a condition, expressed via a {@link Predicate} to become true.
*
* @param timeout maximum time in milliseconds to wait for the predicate to become true.
* @param predicate predicate waiting on.
* @return the waited time.
*/
protected long waitFor(int timeout, Predicate predicate) {
ParamChecker.notNull(predicate, "predicate");
XLog log = new XLog(LogFactory.getLog(getClass()));
long started = System.currentTimeMillis();
long mustEnd = System.currentTimeMillis() + (long) (WAITFOR_RATIO * timeout);
long lastEcho = 0;
try {
long waiting = mustEnd - System.currentTimeMillis();
log.info("Waiting up to [{0}] msec", waiting);
boolean eval;
while (!(eval = predicate.evaluate()) && System.currentTimeMillis() < mustEnd) {
if ((System.currentTimeMillis() - lastEcho) > 1000) {
waiting = mustEnd - System.currentTimeMillis();
log.info("Waiting up to [{0}] msec", waiting);
lastEcho = System.currentTimeMillis();
}
Thread.sleep(1000);
}
if (!eval) {
log.info("Waiting timed out after [{0}] msec", timeout);
}
return System.currentTimeMillis() - started;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
Aggregations