Search in sources :

Example 1 with XLogAuditFilter

use of org.apache.oozie.util.XLogAuditFilter 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();
    }
}
Also used : XLogAuditFilter(org.apache.oozie.util.XLogAuditFilter) XLogFilter(org.apache.oozie.util.XLogFilter) XLog(org.apache.oozie.util.XLog) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) XLogUserFilterParam(org.apache.oozie.util.XLogUserFilterParam) File(java.io.File)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1 XLog (org.apache.oozie.util.XLog)1 XLogAuditFilter (org.apache.oozie.util.XLogAuditFilter)1 XLogFilter (org.apache.oozie.util.XLogFilter)1 XLogUserFilterParam (org.apache.oozie.util.XLogUserFilterParam)1