Search in sources :

Example 11 with XLogFilter

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

the class CoordinatorEngine method streamLog.

/**
 * Add list of actions to the filter based on conditions
 *
 * @param jobId Job Id
 * @param logRetrievalScope Value for the retrieval type
 * @param logRetrievalType Based on which filter criteria the log is retrieved
 * @param writer writer to stream the log to
 * @param requestParameters additional parameters from the request
 * @throws IOException in case of IO error
 * @throws BaseEngineException if there is an error during streaming
 * @throws CommandException if a parameter could not be parsed
 */
public void streamLog(String jobId, String logRetrievalScope, String logRetrievalType, Writer writer, Map<String, String[]> requestParameters) throws IOException, BaseEngineException, CommandException {
    Date startTime = null;
    Date endTime = null;
    XLogFilter filter = new XLogFilter(new XLogUserFilterParam(requestParameters));
    filter.setParameter(DagXLogInfoService.JOB, jobId);
    if (logRetrievalScope != null && logRetrievalType != null) {
        // if coordinator action logs are to be retrieved based on action id range
        if (logRetrievalType.equals(RestConstants.JOB_LOG_ACTION)) {
            // Use set implementation that maintains order or elements to achieve reproducibility:
            Set<String> actionSet = new LinkedHashSet<String>();
            String[] list = logRetrievalScope.split(",");
            for (String s : list) {
                s = s.trim();
                if (s.contains("-")) {
                    String[] range = s.split("-");
                    if (range.length != 2) {
                        throw new CommandException(ErrorCode.E0302, "format is wrong for action's range '" + s + "'");
                    }
                    int start;
                    int end;
                    try {
                        start = Integer.parseInt(range[0].trim());
                    } catch (NumberFormatException ne) {
                        throw new CommandException(ErrorCode.E0302, "could not parse " + range[0].trim() + "into an integer", ne);
                    }
                    try {
                        end = Integer.parseInt(range[1].trim());
                    } catch (NumberFormatException ne) {
                        throw new CommandException(ErrorCode.E0302, "could not parse " + range[1].trim() + "into an integer", ne);
                    }
                    if (start > end) {
                        throw new CommandException(ErrorCode.E0302, "format is wrong for action's range '" + s + "'");
                    }
                    for (int i = start; i <= end; i++) {
                        actionSet.add(jobId + "@" + i);
                    }
                } else {
                    try {
                        Integer.parseInt(s);
                    } catch (NumberFormatException ne) {
                        throw new CommandException(ErrorCode.E0302, "format is wrong for action id'" + s + "'. Integer only.");
                    }
                    actionSet.add(jobId + "@" + s);
                }
            }
            if (actionSet.size() >= maxNumActionsForLog) {
                throw new CommandException(ErrorCode.E0302, "Retrieving log of too many coordinator actions. Max count is " + maxNumActionsForLog + " actions");
            }
            Iterator<String> actionsIterator = actionSet.iterator();
            StringBuilder orSeparatedActions = new StringBuilder("");
            boolean orRequired = false;
            while (actionsIterator.hasNext()) {
                if (orRequired) {
                    orSeparatedActions.append("|");
                }
                orSeparatedActions.append(actionsIterator.next().toString());
                orRequired = true;
            }
            if (actionSet.size() > 1 && orRequired) {
                orSeparatedActions.insert(0, "(");
                orSeparatedActions.append(")");
            }
            filter.setParameter(DagXLogInfoService.ACTION, orSeparatedActions.toString());
            if (actionSet != null && actionSet.size() == 1) {
                CoordinatorActionBean actionBean = getCoordAction(actionSet.iterator().next());
                startTime = actionBean.getCreatedTime();
                endTime = actionBean.getStatus().equals(CoordinatorAction.Status.RUNNING) ? new Date() : actionBean.getLastModifiedTime();
                filter.setActionList(true);
            } else if (actionSet != null && actionSet.size() > 0) {
                List<String> tempList = new ArrayList<String>(actionSet);
                Collections.sort(tempList, new Comparator<String>() {

                    public int compare(String a, String b) {
                        return Integer.valueOf(a.substring(a.lastIndexOf("@") + 1)).compareTo(Integer.valueOf(b.substring(b.lastIndexOf("@") + 1)));
                    }
                });
                startTime = getCoordAction(tempList.get(0)).getCreatedTime();
                endTime = CoordActionsInDateRange.getCoordActionsLastModifiedDate(jobId, tempList.get(0), tempList.get(tempList.size() - 1));
                filter.setActionList(true);
            }
        }
        // this block gets the corresponding list of coordinator actions to be used by the log filter
        if (logRetrievalType.equalsIgnoreCase(RestConstants.JOB_LOG_DATE)) {
            List<String> coordActionIdList = null;
            try {
                coordActionIdList = CoordActionsInDateRange.getCoordActionIdsFromDates(jobId, logRetrievalScope);
            } catch (XException xe) {
                throw new CommandException(ErrorCode.E0302, "Error in date range for coordinator actions", xe);
            }
            if (coordActionIdList.size() >= maxNumActionsForLog) {
                throw new CommandException(ErrorCode.E0302, "Retrieving log of too many coordinator actions. Max count is " + maxNumActionsForLog + " actions");
            }
            StringBuilder orSeparatedActions = new StringBuilder("");
            boolean orRequired = false;
            for (String coordActionId : coordActionIdList) {
                if (orRequired) {
                    orSeparatedActions.append("|");
                }
                orSeparatedActions.append(coordActionId);
                orRequired = true;
            }
            if (coordActionIdList.size() > 1 && orRequired) {
                orSeparatedActions.insert(0, "(");
                orSeparatedActions.append(")");
            }
            filter.setParameter(DagXLogInfoService.ACTION, orSeparatedActions.toString());
            if (coordActionIdList != null && coordActionIdList.size() == 1) {
                CoordinatorActionBean actionBean = getCoordAction(coordActionIdList.get(0));
                startTime = actionBean.getCreatedTime();
                endTime = actionBean.getStatus().equals(CoordinatorAction.Status.RUNNING) ? new Date() : actionBean.getLastModifiedTime();
                filter.setActionList(true);
            } else if (coordActionIdList != null && coordActionIdList.size() > 0) {
                Collections.sort(coordActionIdList, new Comparator<String>() {

                    public int compare(String a, String b) {
                        return Integer.valueOf(a.substring(a.lastIndexOf("@") + 1)).compareTo(Integer.valueOf(b.substring(b.lastIndexOf("@") + 1)));
                    }
                });
                startTime = getCoordAction(coordActionIdList.get(0)).getCreatedTime();
                endTime = CoordActionsInDateRange.getCoordActionsLastModifiedDate(jobId, coordActionIdList.get(0), coordActionIdList.get(coordActionIdList.size() - 1));
                filter.setActionList(true);
            }
        }
    }
    if (startTime == null || endTime == null) {
        CoordinatorJobBean job = getCoordJobWithNoActionInfo(jobId);
        if (startTime == null) {
            startTime = job.getCreatedTime();
        }
        if (endTime == null) {
            if (job.isTerminalStatus()) {
                endTime = job.getLastModifiedTime();
            }
            if (endTime == null) {
                endTime = new Date();
            }
        }
    }
    Services.get().get(XLogStreamingService.class).streamLog(new XLogStreamer(filter, requestParameters), startTime, endTime, writer);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) XLogFilter(org.apache.oozie.util.XLogFilter) XLogStreamer(org.apache.oozie.util.XLogStreamer) CommandException(org.apache.oozie.command.CommandException) Date(java.util.Date) Comparator(java.util.Comparator) XLogStreamingService(org.apache.oozie.service.XLogStreamingService) List(java.util.List) ArrayList(java.util.ArrayList) XLogUserFilterParam(org.apache.oozie.util.XLogUserFilterParam)

Example 12 with XLogFilter

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

the class TestXLogStreamingService method testNoDashInConversionPattern.

public void testNoDashInConversionPattern() 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.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").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_"));
    } 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 13 with XLogFilter

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

the class TestZKXLogStreamingService method testStreamingWithMultipleOozieServers_coordActionList.

public void testStreamingWithMultipleOozieServers_coordActionList() throws Exception {
    XLogFilter.reset();
    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());
    Services.get().get(XLogService.class).init(Services.get());
    File logFile = new File(Services.get().get(XLogService.class).getOozieLogPath(), Services.get().get(XLogService.class).getOozieLogName());
    logFile.getParentFile().mkdirs();
    FileWriter logWriter = new FileWriter(logFile);
    // local logs
    StringBuffer bf = new StringBuffer();
    bf.append("2014-02-06 00:26:56,126 DEBUG CoordActionInputCheckXCommand:545 [pool-2-thread-26] - USER[-] GROUP[-] " + "TOKEN[-] APP[-] JOB[0000003-140205233038063-oozie-oozi-C] ACTION[0000003-140205233038063-oozie-oozi-C@1] " + "checking for the file ~:8020/user/purushah/examples/input-data/rawLogs/2010/01/01/01/00/_SUCCESS\n").append("2014-02-06 00:26:56,150  INFO CoordActionInputCheckXCommand:539 [pool-2-thread-26] - USER[-] GROUP[-] " + "TOKEN[-] APP[-] JOB[0000003-140205233038063-oozie-oozi-C] ACTION[0000003-140205233038063-oozie-oozi-C@1] " + "[0000003-140205233038063-oozie-oozi-C@1]::ActionInputCheck:: File::8020/user/purushah/examples/input-data/" + "rawLogs/2010/01/01/01/00/_SUCCESS, Exists? :false" + "Action updated in DB! _L1_").append("\n").append("2014-02-06 00:27:56,126 DEBUG CoordActionInputCheckXCommand:545 [pool-2-thread-26] - USER[-] GROUP[-] " + "TOKEN[-] APP[-] JOB[0000003-140205233038063-oozie-oozi-C] ACTION[0000003-140205233038063-oozie-oozi-C@2] " + "checking for the file ~:8020/user/purushah/examples/input-data/rawLogs/2010/01/01/01/00/_SUCCESS\n").append("2014-02-06 00:27:56,150  INFO CoordActionInputCheckXCommand:539 [pool-2-thread-26] - USER[-] GROUP[-] " + "TOKEN[-] APP[-] JOB[0000003-140205233038063-oozie-oozi-C] ACTION[0000003-140205233038063-oozie-oozi-C@2] " + "[0000003-140205233038063-oozie-oozi-C@2]::ActionInputCheck:: File::8020/user/purushah/examples/input-data/" + "rawLogs/2010/01/01/01/00/_SUCCESS, Exists? :false" + "Action updated in DB! _L2_").append("\n");
    logWriter.append(bf);
    logWriter.close();
    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.setLogLevel("DEBUG|INFO");
    xf.setParameter("USER", ".*");
    xf.setParameter("GROUP", ".*");
    xf.setParameter("TOKEN", ".*");
    xf.setParameter("APP", ".*");
    xf.setParameter("JOB", "0000003-140205233038063-oozie-oozi-C");
    xf.setParameter(DagXLogInfoService.ACTION, "0000003-140205233038063-oozie-oozi-C@1");
    String out = doStreamLog(xf);
    String[] outArr = out.split("\n");
    assertEquals(2, outArr.length);
    assertTrue(out.contains("_L1_"));
    assertFalse(out.contains("_L2_"));
    // We'll use a DummyZKOozie to create an entry in ZK and then set its
    // url to an (unrelated) servlet that will simply return
    // some log messages
    DummyZKOozie dummyOozie = null;
    EmbeddedServletContainer container = new EmbeddedServletContainer("oozie");
    container.addServletEndpoint("/other-oozie-server/*", DummyLogStreamingServlet.class);
    try {
        container.start();
        dummyOozie = new DummyZKOozie("9876", container.getServletURL("/other-oozie-server/*"));
        DummyLogStreamingServlet.logs = "";
        DummyLogStreamingServlet.lastQueryString = null;
        Map<String, String[]> param = new HashMap<String, String[]>();
        param.put(RestConstants.JOB_COORD_RANGE_TYPE_PARAM, new String[] { RestConstants.JOB_LOG_ACTION });
        param.put(RestConstants.JOB_COORD_SCOPE_PARAM, new String[] { "1" });
        out = doStreamLog(xf, param);
        assertTrue(DummyLogStreamingServlet.lastQueryString.contains("show=log&allservers=false"));
        assertTrue(DummyLogStreamingServlet.lastQueryString.contains("type=" + RestConstants.JOB_LOG_ACTION));
        assertTrue(DummyLogStreamingServlet.lastQueryString.contains(RestConstants.JOB_COORD_SCOPE_PARAM + "=1"));
        param.clear();
        param.put(RestConstants.JOB_COORD_RANGE_TYPE_PARAM, new String[] { RestConstants.JOB_LOG_ACTION });
        param.put(RestConstants.JOB_COORD_SCOPE_PARAM, new String[] { "1-4,5" });
        out = doStreamLog(xf, param);
        assertTrue(DummyLogStreamingServlet.lastQueryString.contains("show=log&allservers=false"));
        assertTrue(DummyLogStreamingServlet.lastQueryString.contains("type=" + RestConstants.JOB_LOG_ACTION));
        assertTrue(DummyLogStreamingServlet.lastQueryString.contains(RestConstants.JOB_COORD_SCOPE_PARAM + "=1-4,5"));
        param.clear();
        Date endDate = new Date();
        Date createdDate = new Date(endDate.getTime() / 2);
        String date = DateUtils.formatDateOozieTZ(createdDate) + "::" + DateUtils.formatDateOozieTZ(endDate);
        param.put(RestConstants.JOB_COORD_RANGE_TYPE_PARAM, new String[] { RestConstants.JOB_LOG_DATE });
        param.put(RestConstants.JOB_COORD_SCOPE_PARAM, new String[] { date });
        out = doStreamLog(xf, param);
        assertTrue(DummyLogStreamingServlet.lastQueryString.contains("show=log&allservers=false"));
        assertTrue(DummyLogStreamingServlet.lastQueryString.contains("type=" + RestConstants.JOB_LOG_DATE));
        assertTrue(DummyLogStreamingServlet.lastQueryString.contains(RestConstants.JOB_COORD_SCOPE_PARAM + "=" + date));
        container.stop();
    } finally {
        if (dummyOozie != null) {
            dummyOozie.teardown();
        }
        container.stop();
    }
}
Also used : XLogFilter(org.apache.oozie.util.XLogFilter) HashMap(java.util.HashMap) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) EmbeddedServletContainer(org.apache.oozie.test.EmbeddedServletContainer) Properties(java.util.Properties) Date(java.util.Date) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 14 with XLogFilter

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

the class TestZKXLogStreamingService method testStreamingWithMultipleOozieServers_errorLog.

public void testStreamingWithMultipleOozieServers_errorLog() throws Exception {
    XLogFilter.reset();
    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());
    Services.get().get(XLogService.class).init(Services.get());
    File logFile = new File(Services.get().get(XLogService.class).getOozieErrorLogPath(), Services.get().get(XLogService.class).getOozieErrorLogName());
    logFile.getParentFile().mkdirs();
    FileWriter logWriter = new FileWriter(logFile);
    // local logs
    StringBuffer bf = new StringBuffer();
    bf.append("2014-02-06 00:26:56,126 WARN CoordActionInputCheckXCommand:545 [pool-2-thread-26] - USER[-] GROUP[-] " + "TOKEN[-] APP[-] JOB[0000003-140205233038063-oozie-oozi-C] ACTION[0000003-140205233038063-oozie-oozi-C@1] " + "checking for the file ~:8020/user/purushah/examples/input-data/rawLogs/2010/01/01/01/00/_SUCCESS\n").append("2014-02-06 00:26:56,150  WARN CoordActionInputCheckXCommand:539 [pool-2-thread-26] - USER[-] GROUP[-] " + "TOKEN[-] APP[-] JOB[0000003-140205233038063-oozie-oozi-C] ACTION[0000003-140205233038063-oozie-oozi-C@1] " + "[0000003-140205233038063-oozie-oozi-C@1]::ActionInputCheck::File::8020/user/purushah/examples/input-data/" + "rawLogs/2010/01/01/01/00/_SUCCESS, Exists? :false" + "Action updated in DB! _L1_").append("\n").append("2014-02-06 00:27:56,126 WARN CoordActionInputCheckXCommand:545 [pool-2-thread-26] - USER[-] GROUP[-] " + "TOKEN[-] APP[-] JOB[0000003-140205233038063-oozie-oozi-C] ACTION[0000003-140205233038063-oozie-oozi-C@2] " + "checking for the file ~:8020/user/purushah/examples/input-data/rawLogs/2010/01/01/01/00/_SUCCESS\n").append("2014-02-06 00:27:56,150  WARN CoordActionInputCheckXCommand:539 [pool-2-thread-26] - USER[-] GROUP[-] " + "TOKEN[-] APP[-] JOB[0000003-140205233038063-oozie-oozi-C] ACTION[0000003-140205233038063-oozie-oozi-C@2] " + "[0000003-140205233038063-oozie-oozi-C@2]::ActionInputCheck::File::8020/user/purushah/examples/input-data/" + "rawLogs/2010/01/01/01/00/_SUCCESS, Exists? :false" + "Action updated in DB! _L2_").append("\n");
    logWriter.append(bf);
    logWriter.close();
    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", ".*");
    xf.setParameter("GROUP", ".*");
    xf.setParameter("TOKEN", ".*");
    xf.setParameter("APP", ".*");
    xf.setParameter("JOB", "0000003-140205233038063-oozie-oozi-C");
    xf.setParameter(DagXLogInfoService.ACTION, "0000003-140205233038063-oozie-oozi-C@1");
    String out = doStreamErrorLog(xf);
    String[] outArr = out.split("\n");
    assertEquals(2, outArr.length);
    assertTrue(out.contains("_L1_"));
    assertFalse(out.contains("_L2_"));
    // We'll use a DummyZKOozie to create an entry in ZK and then set its
    // url to an (unrelated) servlet that will simply return
    // some log messages
    DummyZKOozie dummyOozie = null;
    EmbeddedServletContainer container = new EmbeddedServletContainer("oozie");
    container.addServletEndpoint("/other-oozie-server/*", DummyLogStreamingServlet.class);
    try {
        container.start();
        dummyOozie = new DummyZKOozie("9876", container.getServletURL("/other-oozie-server/*"));
        StringBuffer newLog = new StringBuffer();
        newLog.append("2014-02-07 00:26:56,126 WARN CoordActionInputCheckXCommand:545 [pool-2-thread-26] - USER[-] GROUP[-] " + "TOKEN[-] APP[-] JOB[0000003-140205233038063-oozie-oozi-C] ACTION[0000003-140205233038063-oozie-oozi-C@1] " + "checking for the file ~:8020/user/purushah/examples/input-data/rawLogs/2010/01/01/01/00/_SUCCESS\n").append("2014-02-07 00:26:56,150  WARN CoordActionInputCheckXCommand:539 [pool-2-thread-26] - USER[-] GROUP[-] " + "TOKEN[-] APP[-] JOB[0000003-140205233038063-oozie-oozi-C] ACTION[0000003-140205233038063-oozie-oozi-C@1] " + "[0000003-140205233038063-oozie-oozi-C@1]::ActionInputCheck::File::8020/user/purushah/examples/input-data/" + "rawLogs/2010/01/01/01/00/_SUCCESS, Exists? :false" + "Action updated in DB! _L3_").append("\n");
        DummyLogStreamingServlet.logs = newLog.toString();
        out = doStreamErrorLog(xf);
        outArr = out.split("\n");
        assertEquals(4, outArr.length);
        assertTrue(out.contains("_L1_"));
        assertTrue(out.contains("_L3_"));
        assertFalse(out.contains("_L2_"));
        container.stop();
    } finally {
        if (dummyOozie != null) {
            dummyOozie.teardown();
        }
        container.stop();
    }
}
Also used : XLogFilter(org.apache.oozie.util.XLogFilter) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) EmbeddedServletContainer(org.apache.oozie.test.EmbeddedServletContainer) Properties(java.util.Properties) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 15 with XLogFilter

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

the class TestZKXLogStreamingService method testTuncateLog.

public void testTuncateLog() throws Exception {
    XLogFilter.reset();
    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());
    File logFile = new File(Services.get().get(XLogService.class).getOozieLogPath(), Services.get().get(XLogService.class).getOozieLogName());
    logFile.getParentFile().mkdirs();
    ConfigurationService.set(XLogFilter.MAX_SCAN_DURATION, "1");
    Date startDate = new Date();
    Date endDate = new Date(startDate.getTime() + 60 * 60 * 1000 * 15);
    String log = doStreamLog(new XLogFilter(), startDate, endDate);
    assertTrue(log.contains("Truncated logs to max log scan duration"));
    String logError = doStreamErrorLog(new XLogFilter(), startDate, endDate);
    assertFalse(logError.contains("Truncated logs to max log scan duration"));
}
Also used : XLogFilter(org.apache.oozie.util.XLogFilter) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) File(java.io.File) Date(java.util.Date)

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