|
@@ -153,6 +153,7 @@ import org.slf4j.LoggerFactory;
|
|
|
public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
|
|
|
private Map<ApplicationAccessType, String> acls = createAppAcls();
|
|
|
+ private static final String[] EMPTY_FILES = new String[] {"zero"};
|
|
|
|
|
|
static {
|
|
|
LOG = LoggerFactory.getLogger(TestLogAggregationService.class);
|
|
@@ -219,7 +220,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
ContainerId container11 = ContainerId.newContainerId(appAttemptId, 1);
|
|
|
// Simulate log-file creation
|
|
|
writeContainerLogs(app1LogDir, container11, new String[] { "stdout",
|
|
|
- "stderr", "syslog" });
|
|
|
+ "stderr", "syslog" }, EMPTY_FILES);
|
|
|
logAggregationService.handle(
|
|
|
new LogHandlerContainerFinishedEvent(container11,
|
|
|
ContainerType.APPLICATION_MASTER, 0));
|
|
@@ -342,7 +343,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
BuilderUtils.newApplicationAttemptId(app, 1);
|
|
|
ContainerId cont = ContainerId.newContainerId(appAttemptId, 1);
|
|
|
writeContainerLogs(appLogDir, cont, new String[] { "stdout",
|
|
|
- "stderr", "syslog" });
|
|
|
+ "stderr", "syslog" }, EMPTY_FILES);
|
|
|
logAggregationService.handle(new LogHandlerContainerFinishedEvent(cont,
|
|
|
ContainerType.APPLICATION_MASTER, 0));
|
|
|
logAggregationService.handle(new LogHandlerAppFinishedEvent(app));
|
|
@@ -432,7 +433,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
ContainerId container11 = ContainerId.newContainerId(appAttemptId1, 1);
|
|
|
|
|
|
// Simulate log-file creation
|
|
|
- writeContainerLogs(app1LogDir, container11, fileNames);
|
|
|
+ writeContainerLogs(app1LogDir, container11, fileNames, EMPTY_FILES);
|
|
|
logAggregationService.handle(
|
|
|
new LogHandlerContainerFinishedEvent(container11,
|
|
|
ContainerType.APPLICATION_MASTER, 0));
|
|
@@ -454,14 +455,14 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
|
|
|
ContainerId container21 = ContainerId.newContainerId(appAttemptId2, 1);
|
|
|
|
|
|
- writeContainerLogs(app2LogDir, container21, fileNames);
|
|
|
+ writeContainerLogs(app2LogDir, container21, fileNames, EMPTY_FILES);
|
|
|
logAggregationService.handle(
|
|
|
new LogHandlerContainerFinishedEvent(container21,
|
|
|
ContainerType.APPLICATION_MASTER, 0));
|
|
|
|
|
|
ContainerId container12 = ContainerId.newContainerId(appAttemptId1, 2);
|
|
|
|
|
|
- writeContainerLogs(app1LogDir, container12, fileNames);
|
|
|
+ writeContainerLogs(app1LogDir, container12, fileNames, EMPTY_FILES);
|
|
|
logAggregationService.handle(
|
|
|
new LogHandlerContainerFinishedEvent(container12,
|
|
|
ContainerType.TASK, 0));
|
|
@@ -497,25 +498,25 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
reset(appEventHandler);
|
|
|
|
|
|
ContainerId container31 = ContainerId.newContainerId(appAttemptId3, 1);
|
|
|
- writeContainerLogs(app3LogDir, container31, fileNames);
|
|
|
+ writeContainerLogs(app3LogDir, container31, fileNames, EMPTY_FILES);
|
|
|
logAggregationService.handle(
|
|
|
new LogHandlerContainerFinishedEvent(container31,
|
|
|
ContainerType.APPLICATION_MASTER, 0));
|
|
|
|
|
|
ContainerId container32 = ContainerId.newContainerId(appAttemptId3, 2);
|
|
|
- writeContainerLogs(app3LogDir, container32, fileNames);
|
|
|
+ writeContainerLogs(app3LogDir, container32, fileNames, EMPTY_FILES);
|
|
|
logAggregationService.handle(
|
|
|
new LogHandlerContainerFinishedEvent(container32,
|
|
|
ContainerType.TASK, 1)); // Failed
|
|
|
|
|
|
ContainerId container22 = ContainerId.newContainerId(appAttemptId2, 2);
|
|
|
- writeContainerLogs(app2LogDir, container22, fileNames);
|
|
|
+ writeContainerLogs(app2LogDir, container22, fileNames, EMPTY_FILES);
|
|
|
logAggregationService.handle(
|
|
|
new LogHandlerContainerFinishedEvent(container22,
|
|
|
ContainerType.TASK, 0));
|
|
|
|
|
|
ContainerId container33 = ContainerId.newContainerId(appAttemptId3, 3);
|
|
|
- writeContainerLogs(app3LogDir, container33, fileNames);
|
|
|
+ writeContainerLogs(app3LogDir, container33, fileNames, EMPTY_FILES);
|
|
|
logAggregationService.handle(
|
|
|
new LogHandlerContainerFinishedEvent(container33,
|
|
|
ContainerType.TASK, 0));
|
|
@@ -531,13 +532,15 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
assertEquals(0, logAggregationService.getNumAggregators());
|
|
|
|
|
|
verifyContainerLogs(logAggregationService, application1,
|
|
|
- new ContainerId[] { container11, container12 }, fileNames, 3, false);
|
|
|
+ new ContainerId[] {container11, container12}, fileNames, 4, false,
|
|
|
+ EMPTY_FILES);
|
|
|
|
|
|
verifyContainerLogs(logAggregationService, application2,
|
|
|
- new ContainerId[] { container21 }, fileNames, 3, false);
|
|
|
+ new ContainerId[] {container21}, fileNames, 4, false, EMPTY_FILES);
|
|
|
|
|
|
verifyContainerLogs(logAggregationService, application3,
|
|
|
- new ContainerId[] { container31, container32 }, fileNames, 3, false);
|
|
|
+ new ContainerId[] {container31, container32}, fileNames, 4, false,
|
|
|
+ EMPTY_FILES);
|
|
|
|
|
|
dispatcher.await();
|
|
|
|
|
@@ -935,7 +938,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
}
|
|
|
|
|
|
private void writeContainerLogs(File appLogDir, ContainerId containerId,
|
|
|
- String[] fileName) throws IOException {
|
|
|
+ String[] fileName, String[] emptyFiles) throws IOException {
|
|
|
// ContainerLogDir should be created
|
|
|
String containerStr = containerId.toString();
|
|
|
File containerLogDir = new File(appLogDir, containerStr);
|
|
@@ -947,17 +950,22 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
writer11.write(containerStr + " Hello " + fileType + "!");
|
|
|
writer11.close();
|
|
|
}
|
|
|
+ for (String emptyFile : emptyFiles) {
|
|
|
+ Writer writer11 = new FileWriter(new File(containerLogDir, emptyFile));
|
|
|
+ writer11.write("");
|
|
|
+ writer11.close();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private LogFileStatusInLastCycle verifyContainerLogs(
|
|
|
LogAggregationService logAggregationService,
|
|
|
ApplicationId appId, ContainerId[] expectedContainerIds,
|
|
|
String[] logFiles, int numOfLogsPerContainer,
|
|
|
- boolean multiLogs) throws IOException {
|
|
|
+ boolean multiLogs, String[] zeroLengthFiles) throws IOException {
|
|
|
return verifyContainerLogs(logAggregationService, appId,
|
|
|
expectedContainerIds, expectedContainerIds.length,
|
|
|
expectedContainerIds.length, logFiles, numOfLogsPerContainer,
|
|
|
- multiLogs);
|
|
|
+ multiLogs, zeroLengthFiles);
|
|
|
}
|
|
|
|
|
|
// expectedContainerIds is the minimal set of containers to check.
|
|
@@ -968,7 +976,8 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
LogAggregationService logAggregationService,
|
|
|
ApplicationId appId, ContainerId[] expectedContainerIds,
|
|
|
int minNumOfContainers, int maxNumOfContainers,
|
|
|
- String[] logFiles, int numOfLogsPerContainer, boolean multiLogs)
|
|
|
+ String[] logFiles, int numOfLogsPerContainer, boolean multiLogs,
|
|
|
+ String[] zeroLengthLogFiles)
|
|
|
throws IOException {
|
|
|
Path appLogDir = logAggregationService.getLogAggregationFileController(
|
|
|
conf).getRemoteAppLogDir(appId, this.user);
|
|
@@ -1089,6 +1098,11 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
+ " not present in aggregated log-file!", foundValue);
|
|
|
Assert.assertEquals(expectedValue, foundValue);
|
|
|
}
|
|
|
+ for (String emptyFile : zeroLengthLogFiles) {
|
|
|
+ String foundValue = thisContainerMap.remove(emptyFile);
|
|
|
+ String expectedValue = "\nEnd of LogType:" + emptyFile;
|
|
|
+ Assert.assertEquals(expectedValue, foundValue);
|
|
|
+ }
|
|
|
Assert.assertEquals(0, thisContainerMap.size());
|
|
|
}
|
|
|
Assert.assertTrue("number of remaining containers should be at least " +
|
|
@@ -1584,7 +1598,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
|
|
|
// Simulate log-file creation
|
|
|
writeContainerLogs(appLogDir1, container1, new String[] { "stdout",
|
|
|
- "stderr", "syslog" });
|
|
|
+ "stderr", "syslog" }, EMPTY_FILES);
|
|
|
logAggregationService.handle(new LogHandlerContainerFinishedEvent(
|
|
|
container1, ContainerType.APPLICATION_MASTER, 0));
|
|
|
|
|
@@ -1605,7 +1619,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
ContainerId container2 = ContainerId.newContainerId(appAttemptId2, 1);
|
|
|
|
|
|
writeContainerLogs(app2LogDir, container2, new String[] { "stdout",
|
|
|
- "stderr", "syslog" });
|
|
|
+ "stderr", "syslog" }, EMPTY_FILES);
|
|
|
logAggregationService.handle(
|
|
|
new LogHandlerContainerFinishedEvent(container2,
|
|
|
ContainerType.APPLICATION_MASTER, 0));
|
|
@@ -1629,7 +1643,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
this.user, null, this.acls, context1));
|
|
|
ContainerId container3 = ContainerId.newContainerId(appAttemptId3, 1);
|
|
|
writeContainerLogs(app3LogDir, container3, new String[] { "stdout",
|
|
|
- "sys.log", "std.log", "out.log", "err.log", "log" });
|
|
|
+ "sys.log", "std.log", "out.log", "err.log", "log" }, EMPTY_FILES);
|
|
|
logAggregationService.handle(
|
|
|
new LogHandlerContainerFinishedEvent(container3,
|
|
|
ContainerType.APPLICATION_MASTER, 0));
|
|
@@ -1654,7 +1668,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
this.user, null, this.acls, context2));
|
|
|
ContainerId container4 = ContainerId.newContainerId(appAttemptId4, 1);
|
|
|
writeContainerLogs(app4LogDir, container4, new String[] { "stdout",
|
|
|
- "sys.log", "std.log", "out.log", "err.log", "log" });
|
|
|
+ "sys.log", "std.log", "out.log", "err.log", "log" }, EMPTY_FILES);
|
|
|
logAggregationService.handle(
|
|
|
new LogHandlerContainerFinishedEvent(container4,
|
|
|
ContainerType.APPLICATION_MASTER, 0));
|
|
@@ -1682,19 +1696,19 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
|
|
|
String[] logFiles = new String[] { "stdout", "syslog" };
|
|
|
verifyContainerLogs(logAggregationService, application1,
|
|
|
- new ContainerId[] { container1 }, logFiles, 2, false);
|
|
|
+ new ContainerId[] {container1}, logFiles, 2, false, new String[] {});
|
|
|
|
|
|
logFiles = new String[] { "stderr" };
|
|
|
verifyContainerLogs(logAggregationService, application2,
|
|
|
- new ContainerId[] { container2 }, logFiles, 1, false);
|
|
|
+ new ContainerId[] {container2}, logFiles, 2, false, EMPTY_FILES);
|
|
|
|
|
|
logFiles = new String[] { "out.log", "err.log" };
|
|
|
verifyContainerLogs(logAggregationService, application3,
|
|
|
- new ContainerId[] { container3 }, logFiles, 2, false);
|
|
|
+ new ContainerId[] {container3}, logFiles, 2, false, new String[] {});
|
|
|
|
|
|
logFiles = new String[] { "sys.log" };
|
|
|
verifyContainerLogs(logAggregationService, application4,
|
|
|
- new ContainerId[] { container4 }, logFiles, 1, false);
|
|
|
+ new ContainerId[] {container4}, logFiles, 1, false, new String[] {});
|
|
|
|
|
|
dispatcher.await();
|
|
|
|
|
@@ -1721,8 +1735,8 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
// When the app is running, we only aggregate the log with
|
|
|
// the name stdout. After the app finishes, we only aggregate
|
|
|
// the log with the name std_final.
|
|
|
- logAggregationContext.setRolledLogsIncludePattern("stdout");
|
|
|
- logAggregationContext.setIncludePattern("std_final");
|
|
|
+ logAggregationContext.setRolledLogsIncludePattern("stdout|zero");
|
|
|
+ logAggregationContext.setIncludePattern("std_final|empty_final");
|
|
|
this.conf.set(
|
|
|
YarnConfiguration.NM_LOG_DIRS, localLogDir.getAbsolutePath());
|
|
|
//configure YarnConfiguration.NM_REMOTE_APP_LOG_DIR to
|
|
@@ -1767,7 +1781,8 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
// until the app finishes.
|
|
|
String[] logFilesWithFinalLog =
|
|
|
new String[] {"stdout", "std_final"};
|
|
|
- writeContainerLogs(appLogDir, container, logFilesWithFinalLog);
|
|
|
+ String[] zeroFiles = new String[] {"zero", "empty_final"};
|
|
|
+ writeContainerLogs(appLogDir, container, logFilesWithFinalLog, zeroFiles);
|
|
|
|
|
|
// Do log aggregation
|
|
|
AppLogAggregatorImpl aggregator =
|
|
@@ -1781,7 +1796,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
|
|
|
String[] logFiles = new String[] { "stdout" };
|
|
|
verifyContainerLogs(logAggregationService, application,
|
|
|
- new ContainerId[] {container}, logFiles, 1, true);
|
|
|
+ new ContainerId[] {container}, logFiles, 2, true, EMPTY_FILES);
|
|
|
|
|
|
logAggregationService.handle(
|
|
|
new LogHandlerContainerFinishedEvent(container,
|
|
@@ -1800,8 +1815,9 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
// This container finishes.
|
|
|
// The log "std_final" should be aggregated this time.
|
|
|
String[] logFinalLog = new String[] {"std_final"};
|
|
|
+ String[] emptyFinalLog = new String[] {"empty_final"};
|
|
|
verifyContainerLogs(logAggregationService, application,
|
|
|
- new ContainerId[] {container}, logFinalLog, 1, true);
|
|
|
+ new ContainerId[] {container}, logFinalLog, 2, true, emptyFinalLog);
|
|
|
|
|
|
logAggregationService.handle(new LogHandlerAppFinishedEvent(application));
|
|
|
|
|
@@ -1823,7 +1839,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
finishApplication(appId, logAggregationService);
|
|
|
|
|
|
verifyContainerLogs(logAggregationService, appId,
|
|
|
- new ContainerId[] {container1}, logFiles, 0, false);
|
|
|
+ new ContainerId[] {container1}, logFiles, 0, false, EMPTY_FILES);
|
|
|
|
|
|
verifyLogAggFinishEvent(appId);
|
|
|
}
|
|
@@ -1847,7 +1863,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
finishApplication(appId, logAggregationService);
|
|
|
|
|
|
verifyContainerLogs(logAggregationService, appId,
|
|
|
- new ContainerId[] { container1 }, logFiles, 1, false);
|
|
|
+ new ContainerId[] {container1}, logFiles, 2, false, EMPTY_FILES);
|
|
|
|
|
|
verifyLogAggFinishEvent(appId);
|
|
|
}
|
|
@@ -1871,7 +1887,8 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
finishApplication(appId, logAggregationService);
|
|
|
|
|
|
verifyContainerLogs(logAggregationService, appId,
|
|
|
- new ContainerId[] { container1, container2 }, logFiles, 1, false);
|
|
|
+ new ContainerId[] {container1, container2}, logFiles, 2, false,
|
|
|
+ EMPTY_FILES);
|
|
|
|
|
|
verifyLogAggFinishEvent(appId);
|
|
|
}
|
|
@@ -1895,7 +1912,8 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
finishApplication(appId, logAggregationService);
|
|
|
|
|
|
verifyContainerLogs(logAggregationService, appId,
|
|
|
- new ContainerId[] { container2, container3 }, logFiles, 1, false);
|
|
|
+ new ContainerId[] {container2, container3}, logFiles, 2, false,
|
|
|
+ EMPTY_FILES);
|
|
|
|
|
|
verifyLogAggFinishEvent(appId);
|
|
|
}
|
|
@@ -1931,7 +1949,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
finishApplication(appId, logAggregationService);
|
|
|
|
|
|
verifyContainerLogs(logAggregationService, appId,
|
|
|
- new ContainerId[] { container1 }, logFiles, 1, false);
|
|
|
+ new ContainerId[] {container1}, logFiles, 2, false, EMPTY_FILES);
|
|
|
|
|
|
verifyLogAggFinishEvent(appId);
|
|
|
}
|
|
@@ -2080,7 +2098,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
|
|
|
verifyContainerLogs(logAggregationService, appId,
|
|
|
new ContainerId[] { container1, container2, container3 },
|
|
|
- logFiles, 1, false);
|
|
|
+ logFiles, 2, false, EMPTY_FILES);
|
|
|
|
|
|
verifyLogAggFinishEvent(appId);
|
|
|
}
|
|
@@ -2162,7 +2180,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
verifyContainerLogs(logAggregationService, appId,
|
|
|
containerIds.toArray(new ContainerId[containerIds.size()]),
|
|
|
minOfContainersWithLogs, maxOfContainersWithLogs,
|
|
|
- logFiles, 1, false);
|
|
|
+ logFiles, 2, false, EMPTY_FILES);
|
|
|
|
|
|
verifyLogAggFinishEvent(appId);
|
|
|
}
|
|
@@ -2240,7 +2258,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
File appLogDir1 =
|
|
|
new File(localLogDir, application1.toString());
|
|
|
appLogDir1.mkdir();
|
|
|
- writeContainerLogs(appLogDir1, containerId, logFiles);
|
|
|
+ writeContainerLogs(appLogDir1, containerId, logFiles, EMPTY_FILES);
|
|
|
|
|
|
logAggregationService.handle(new LogHandlerContainerFinishedEvent(
|
|
|
containerId, containerType, exitCode));
|
|
@@ -2361,7 +2379,8 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
String[] logFiles1WithFinalLog =
|
|
|
new String[] { "stdout", "stderr", "syslog", "std_final" };
|
|
|
String[] logFiles1 = new String[] { "stdout", "stderr", "syslog"};
|
|
|
- writeContainerLogs(appLogDir, container, logFiles1WithFinalLog);
|
|
|
+ writeContainerLogs(appLogDir, container, logFiles1WithFinalLog,
|
|
|
+ EMPTY_FILES);
|
|
|
|
|
|
// Do log aggregation
|
|
|
AppLogAggregatorImpl aggregator =
|
|
@@ -2378,7 +2397,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
}
|
|
|
// Container logs should be uploaded
|
|
|
logFileStatusInLastCycle = verifyContainerLogs(logAggregationService, application,
|
|
|
- new ContainerId[] { container }, logFiles1, 3, true);
|
|
|
+ new ContainerId[] {container}, logFiles1, 4, true, EMPTY_FILES);
|
|
|
for(String logFile : logFiles1) {
|
|
|
Assert.assertTrue(logFileStatusInLastCycle.getLogFileTypesInLastCycle()
|
|
|
.contains(logFile));
|
|
@@ -2403,7 +2422,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
|
|
|
// Do log aggregation
|
|
|
String[] logFiles2 = new String[] { "stdout_1", "stderr_1", "syslog_1" };
|
|
|
- writeContainerLogs(appLogDir, container, logFiles2);
|
|
|
+ writeContainerLogs(appLogDir, container, logFiles2, EMPTY_FILES);
|
|
|
|
|
|
aggregator.doLogAggregationOutOfBand();
|
|
|
|
|
@@ -2416,7 +2435,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
}
|
|
|
// Container logs should be uploaded
|
|
|
logFileStatusInLastCycle = verifyContainerLogs(logAggregationService, application,
|
|
|
- new ContainerId[] { container }, logFiles2, 3, true);
|
|
|
+ new ContainerId[] {container}, logFiles2, 4, true, EMPTY_FILES);
|
|
|
|
|
|
for(String logFile : logFiles2) {
|
|
|
Assert.assertTrue(logFileStatusInLastCycle.getLogFileTypesInLastCycle()
|
|
@@ -2430,7 +2449,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
|
|
|
// create another logs
|
|
|
String[] logFiles3 = new String[] { "stdout_2", "stderr_2", "syslog_2" };
|
|
|
- writeContainerLogs(appLogDir, container, logFiles3);
|
|
|
+ writeContainerLogs(appLogDir, container, logFiles3, EMPTY_FILES);
|
|
|
|
|
|
logAggregationService.handle(
|
|
|
new LogHandlerContainerFinishedEvent(container,
|
|
@@ -2450,7 +2469,8 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
|
|
|
String[] logFiles3WithFinalLog =
|
|
|
new String[] { "stdout_2", "stderr_2", "syslog_2", "std_final" };
|
|
|
verifyContainerLogs(logAggregationService, application,
|
|
|
- new ContainerId[] { container }, logFiles3WithFinalLog, 4, true);
|
|
|
+ new ContainerId[] {container}, logFiles3WithFinalLog, 5, true,
|
|
|
+ EMPTY_FILES);
|
|
|
logAggregationService.stop();
|
|
|
assertEquals(0, logAggregationService.getNumAggregators());
|
|
|
}
|