Search in sources :

Example 16 with XLogFilter

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

the class TestZKXLogStreamingService method testNoDashInConversionPattern.

public void testNoDashInConversionPattern() throws Exception {
    XLogFilter.reset();
    XLogFilter.defineParameter("USER");
    XLogFilter.defineParameter("GROUP");
    XLogFilter.defineParameter("TOKEN");
    XLogFilter.defineParameter("APP");
    XLogFilter.defineParameter("JOB");
    XLogFilter.defineParameter("ACTION");
    XLogFilter xf = new XLogFilter();
    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.store(new FileOutputStream(log4jFile), "");
    setSystemProperty(XLogService.LOG4J_FILE, log4jFile.getName());
    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").info("2009-06-24 02:43:14,505 INFO _L2_:317 - SERVER[foo] USER[blah] GROUP[oozie] TOKEN[-] APP[-] " + "JOB[-] ACTION[-] Released Lock");
    LogFactory.getLog("a").info("2009-06-24 02:43:14,505 INFO _L3_:317 SERVER[foo] USER[oozie] GROUP[oozie] TOKEN[-] APP[-] " + "JOB[-] ACTION[-] Released Lock");
    LogFactory.getLog("a").info("2009-06-24 02:43:14,505 INFO _L4_: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("_L2_"));
    assertTrue(outArr[1].contains("_L3_"));
    assertFalse(out.contains("_L4_"));
}
Also used : XLogFilter(org.apache.oozie.util.XLogFilter) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) File(java.io.File)

Example 17 with XLogFilter

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

the class TestXLogUserFilterParam method testsearchText_logLevel.

// Test text search with log level
public void testsearchText_logLevel() throws Exception {
    setLogFile();
    String param = XLogUserFilterParam.SEARCH_TEXT + "=substitution;" + XLogUserFilterParam.LOG_LEVEL + "=DEBUG";
    Map<String, String[]> paramMap = new HashMap<String, String[]>();
    paramMap.put(RestConstants.LOG_FILTER_OPTION, new String[] { param });
    XLogFilter filter = new XLogFilter(new XLogUserFilterParam(paramMap));
    String out = doStreamLog(filter);
    String[] lines = out.split(System.getProperty("line.separator"));
    assertEquals(lines.length, 1);
    assertTrue(lines[0].contains("2014-02-27 02:06:47,499 DEBUG CoordActionStartXCommand:536 [pool-2-thread-236] - USER[-]"));
    assertTrue(lines[0].contains("E0803: IO error, Variable substitution depth too large: 20 ${dniInputDir}"));
}
Also used : HashMap(java.util.HashMap) XLogFilter(org.apache.oozie.util.XLogFilter) XLogUserFilterParam(org.apache.oozie.util.XLogUserFilterParam)

Example 18 with XLogFilter

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

the class TestXLogUserFilterParam method testLength.

// test length
public void testLength() throws Exception {
    setLogFile();
    String logLevel = XLogUserFilterParam.LIMIT + "=1";
    Map<String, String[]> paramMap = new HashMap<String, String[]>();
    paramMap.put(RestConstants.LOG_FILTER_OPTION, new String[] { logLevel });
    XLogFilter xf = new XLogFilter(new XLogUserFilterParam(paramMap));
    String out = doStreamLog(xf);
    String[] lines = out.split(System.getProperty("line.separator"));
    assertEquals(lines.length, 1);
}
Also used : HashMap(java.util.HashMap) XLogFilter(org.apache.oozie.util.XLogFilter) XLogUserFilterParam(org.apache.oozie.util.XLogUserFilterParam)

Example 19 with XLogFilter

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

the class TestXLogUserFilterParam method testStartEnd_EndOffset.

// Test start and end date, start as absolute
public void testStartEnd_EndOffset() 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();
    XLogFilter.reset();
    Map<String, String[]> paramMap = new HashMap<String, String[]>();
    String param = "start=14-02-20 02:06:25,499;end=3m;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-02-20 02:06:25,499"), 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 20 02:06:25"));
    assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log end time = Tue Feb 20 02:11: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) Date(java.util.Date)

Example 20 with XLogFilter

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

the class TestXLogUserFilterParam method testloglevel_ErrorWithLen.

// test log level with length
public void testloglevel_ErrorWithLen() throws Exception {
    setLogFile();
    String logLevel = XLogUserFilterParam.LOG_LEVEL + "=ERROR;" + XLogUserFilterParam.LIMIT + "=1";
    Map<String, String[]> paramMap = new HashMap<String, String[]>();
    paramMap.put(RestConstants.LOG_FILTER_OPTION, new String[] { logLevel });
    XLogFilter xf = new XLogFilter(new XLogUserFilterParam(paramMap));
    String out = doStreamLog(xf);
    String[] lines = out.split(System.getProperty("line.separator"));
    assertEquals(lines.length, 1);
}
Also used : HashMap(java.util.HashMap) XLogFilter(org.apache.oozie.util.XLogFilter) XLogUserFilterParam(org.apache.oozie.util.XLogUserFilterParam)

Aggregations

XLogFilter (org.apache.oozie.util.XLogFilter)23 XLogUserFilterParam (org.apache.oozie.util.XLogUserFilterParam)16 File (java.io.File)15 FileOutputStream (java.io.FileOutputStream)15 InputStream (java.io.InputStream)15 Properties (java.util.Properties)15 HashMap (java.util.HashMap)13 Date (java.util.Date)9 Services (org.apache.oozie.service.Services)6 FileWriter (java.io.FileWriter)3 EmbeddedServletContainer (org.apache.oozie.test.EmbeddedServletContainer)3 XLogStreamingService (org.apache.oozie.service.XLogStreamingService)2 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 CoordinatorAction (org.apache.oozie.client.CoordinatorAction)1 CommandException (org.apache.oozie.command.CommandException)1 DagXLogInfoService (org.apache.oozie.service.DagXLogInfoService)1