Search in sources :

Example 1 with XLogUserFilterParam

use of org.apache.oozie.util.XLogUserFilterParam in project oozie by apache.

the class TestXLogStreamingService method testErrorLog.

public void testErrorLog() throws Exception {
    setupXLog();
    XLogFilter xf = new XLogFilter(new XLogUserFilterParam(null));
    xf.setParameter("USER", "oozie");
    xf.setLogLevel("DEBUG|INFO");
    // Previously, a dash ("-") was always required somewhere in a line in order for that line to pass the filter; this test
    // checks that this condition is no longer required for log streaming to work
    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.oozieError.File", getTestCaseDir() + "/oozie-error.log");
    log4jProps.store(new FileOutputStream(log4jFile), "");
    setSystemProperty(XLogService.LOG4J_FILE, log4jFile.getName());
    try {
        new Services().init();
        assertFalse(doStreamDisabledCheck());
        LogFactory.getLog("a").info("2009-06-24 02:43:14,505 INFO _L1_:317 - SERVER[foo] USER[oozie] GROUP[oozie] TOKEN[-] " + "APP[-] JOB[-] ACTION[-] Released Lock");
        LogFactory.getLog("a").warn("2009-06-24 02:44:14,505 WARN _L2_:317 - SERVER[foo] USER[oozie] GROUP[oozie] TOKEN[-] " + "APP[-] JOB[-] ACTION[-] Error while writing to file");
        LogFactory.getLog("a").info("2009-06-24 02:45:14,505 INFO _L3_:317 - SERVER[foo] USER[blah] GROUP[oozie] TOKEN[-]" + "APP[-] JOB[-] ACTION[-] Released Lock");
        LogFactory.getLog("a").error("2009-06-24 02:46:14,505 ERROR _L4_:317 - SERVER[foo] USER[oozie] GROUP[oozie] TOKEN[-] " + "APP[-] JOB[-] ACTION[-] Error while writing to DB");
        LogFactory.getLog("a").info("2009-06-24 02:47:14,505 INFO _L5_:317 SERVER[foo] USER[oozie] GROUP[oozie] TOKEN[-] " + "APP[-] JOB[-] ACTION[-] Released Lock");
        LogFactory.getLog("a").fatal("2009-06-24 02:48:14,505 FATAL _L6_:317 SERVER[foo] USER[blah] GROUP[oozie] TOKEN[-] " + "APP[-] JOB[-] ACTION[-] Released Lock");
        String out = doStreamLog(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_"));
        assertFalse(out.contains("_L3_"));
        assertTrue(outArr[1].contains("_L5_"));
        assertFalse(out.contains("_L4_"));
        XLogFilter.reset();
        XLogFilter.defineParameter("USER");
        XLogFilter.defineParameter("GROUP");
        XLogFilter.defineParameter("TOKEN");
        XLogFilter.defineParameter("APP");
        XLogFilter.defineParameter("JOB");
        XLogFilter.defineParameter("ACTION");
        xf = new XLogFilter(new XLogUserFilterParam(null));
        xf.setParameter("USER", "oozie");
        String errorOut = doStreamErrorLog(xf);
        String[] errorOutArr = errorOut.split("\n");
        // Lines 2 and 4 are filtered out because they have the wrong user
        assertEquals(2, errorOutArr.length);
        assertTrue(errorOutArr[0].contains("_L2_"));
        assertTrue(errorOutArr[1].contains("_L4_"));
        assertFalse(errorOut.contains("_L6_"));
    } finally {
        Services.get().destroy();
    }
}
Also used : XLogFilter(org.apache.oozie.util.XLogFilter) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) XLogUserFilterParam(org.apache.oozie.util.XLogUserFilterParam) File(java.io.File)

Example 2 with XLogUserFilterParam

use of org.apache.oozie.util.XLogUserFilterParam 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)

Example 3 with XLogUserFilterParam

use of org.apache.oozie.util.XLogUserFilterParam in project oozie by apache.

the class TestXLogUserFilterParam method testNoException_Withrecent.

// Test log duration - in range
public void testNoException_Withrecent() throws Exception {
    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.store(new FileOutputStream(log4jFile), "");
    setSystemProperty(XLogService.LOG4J_FILE, log4jFile.getName());
    new Services().init();
    Services.get().getConf().setInt(XLogFilter.MAX_SCAN_DURATION, 10);
    Map<String, String[]> paramMap = new HashMap<String, String[]>();
    String param = XLogUserFilterParam.RECENT_LOG_OFFSET + "=9";
    paramMap.put(RestConstants.LOG_FILTER_OPTION, new String[] { param });
    XLogFilter filter = new XLogFilter(new XLogUserFilterParam(paramMap));
    Date startDate = new Date();
    Date endDate = new Date(startDate.getTime() + 60 * 60 * 1000 * 15);
    try {
        doStreamLog(filter, startDate, endDate);
    } catch (Exception e) {
        fail("should not throw exception");
    }
}
Also used : HashMap(java.util.HashMap) XLogFilter(org.apache.oozie.util.XLogFilter) InputStream(java.io.InputStream) Properties(java.util.Properties) Date(java.util.Date) Services(org.apache.oozie.service.Services) FileOutputStream(java.io.FileOutputStream) File(java.io.File) XLogUserFilterParam(org.apache.oozie.util.XLogUserFilterParam)

Example 4 with XLogUserFilterParam

use of org.apache.oozie.util.XLogUserFilterParam in project oozie by apache.

the class TestXLogUserFilterParam method testCombination.

// Test multiple combination
public void testCombination() throws Exception {
    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);
    log4jProps.setProperty("log4j.appender.oozie.File", getTestCaseDir() + "/oozie.log");
    log4jProps.store(new FileOutputStream(log4jFile), "");
    setSystemProperty(XLogService.LOG4J_FILE, log4jFile.getName());
    new Services().init();
    XLogFilter.reset();
    Map<String, String[]> paramMap = new HashMap<String, String[]>();
    String param = "start=14-02-20 02:06:25,499;end=14-02-27 02:06:47,550;debug;loglevel=ERROR|WARN;recent=3m";
    paramMap.put(RestConstants.LOG_FILTER_OPTION, new String[] { param });
    XLogFilter filter = new XLogFilter(new XLogUserFilterParam(paramMap));
    // Param date will be overwritten by user param
    String out = doStreamLog(filter, new Date(), new Date());
    assertEquals(out.split(System.getProperty("line.separator")).length, 1);
    assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log start time = Tue Feb 27 02:03:47"));
    assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log end time = Tue Feb 27 02:06:47"));
}
Also used : Services(org.apache.oozie.service.Services) HashMap(java.util.HashMap) XLogFilter(org.apache.oozie.util.XLogFilter) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) File(java.io.File) XLogUserFilterParam(org.apache.oozie.util.XLogUserFilterParam) Date(java.util.Date)

Example 5 with XLogUserFilterParam

use of org.apache.oozie.util.XLogUserFilterParam in project oozie by apache.

the class TestXLogUserFilterParam method testStartEnd_startAbsolute.

// Test start and end date, both absolute
public void testStartEnd_startAbsolute() throws Exception {
    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.store(new FileOutputStream(log4jFile), "");
    setSystemProperty(XLogService.LOG4J_FILE, log4jFile.getName());
    new Services().init();
    Map<String, String[]> paramMap = new HashMap<String, String[]>();
    String param = "start=14-03-20 02:06:25,499;end=4m;debug";
    paramMap.put(RestConstants.LOG_FILTER_OPTION, new String[] { param });
    XLogFilter filter = new XLogFilter(new XLogUserFilterParam(paramMap));
    // Param date will be overwritten by user param
    String out = doStreamLog(filter, dt.parse("14-01-20 02:06:25,499"), dt.parse("14-02-20 02:06:25,499"));
    assertEquals(out.split(System.getProperty("line.separator")).length, 1);
    assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log start time = Tue Mar 20 02:06:25"));
    assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log end time = Tue Mar 20 02:12:25"));
}
Also used : Services(org.apache.oozie.service.Services) HashMap(java.util.HashMap) XLogFilter(org.apache.oozie.util.XLogFilter) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) File(java.io.File) XLogUserFilterParam(org.apache.oozie.util.XLogUserFilterParam)

Aggregations

XLogFilter (org.apache.oozie.util.XLogFilter)16 XLogUserFilterParam (org.apache.oozie.util.XLogUserFilterParam)16 HashMap (java.util.HashMap)12 File (java.io.File)9 FileOutputStream (java.io.FileOutputStream)9 InputStream (java.io.InputStream)9 Properties (java.util.Properties)9 Services (org.apache.oozie.service.Services)6 Date (java.util.Date)5 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 CommandException (org.apache.oozie.command.CommandException)1 XLogStreamingService (org.apache.oozie.service.XLogStreamingService)1 XLog (org.apache.oozie.util.XLog)1 XLogAuditFilter (org.apache.oozie.util.XLogAuditFilter)1 XLogStreamer (org.apache.oozie.util.XLogStreamer)1