use of org.apache.oozie.test.EmbeddedServletContainer 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();
}
}
use of org.apache.oozie.test.EmbeddedServletContainer 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();
}
}
use of org.apache.oozie.test.EmbeddedServletContainer in project oozie by apache.
the class TestJsonRestServlet method runTest.
private void runTest(JsonRestServlet.ResourceInfo[] resourceInfo, Callable<Void> assertions) throws Exception {
container = new EmbeddedServletContainer("test");
Services services = new Services();
try {
services.init();
MyJsonRestServlet.ACTIVE = resourceInfo;
container.addServletEndpoint("/dummy/*", MyJsonRestServlet.class);
container.start();
assertions.call();
} finally {
container.stop();
services.destroy();
}
}
Aggregations