Skip to content

Commit 49e1292

Browse files
committed
YARN-9524. Fixed TestAHSWebService and TestLogsCLI unit tests.
Contributed by Prabhu Joseph
1 parent 93f2283 commit 49e1292

File tree

5 files changed

+92
-21
lines changed

5 files changed

+92
-21
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ public void testFetchFinishedApplictionLogs() throws Exception {
407407

408408
Path path =
409409
new Path(remoteLogRootDir + ugi.getShortUserName()
410-
+ "/logs/application_0_0001");
410+
+ "/bucket_logs/0001/application_0_0001");
411411
if (fs.exists(path)) {
412412
fs.delete(path, true);
413413
}
@@ -925,7 +925,6 @@ public void testFetchRunningApplicationLogs() throws Exception {
925925
public void testFetchApplictionLogsAsAnotherUser() throws Exception {
926926
String remoteLogRootDir = "target/logs/";
927927
String rootLogDir = "target/LocalLogs";
928-
929928
String testUser = "test";
930929
UserGroupInformation testUgi = UserGroupInformation
931930
.createRemoteUser(testUser);
@@ -966,9 +965,9 @@ public void testFetchApplictionLogsAsAnotherUser() throws Exception {
966965
// create container logs in localLogDir for app
967966
createContainerLogInLocalDir(appLogsDir, containerId, fs, logTypes);
968967

969-
// create the remote app dir for app
970-
// but for a different user testUser"
971-
Path path = new Path(remoteLogRootDir + testUser + "/logs/" + appId);
968+
// create the remote app dir for app but for a different user testUser
969+
Path path = new Path(remoteLogRootDir + testUser + "/bucket_logs/0001/"
970+
+ appId);
972971
if (fs.exists(path)) {
973972
fs.delete(path, true);
974973
}
@@ -1016,6 +1015,22 @@ public void testFetchApplictionLogsAsAnotherUser() throws Exception {
10161015
logMessage(containerId, "syslog")));
10171016
sysOutStream.reset();
10181017

1018+
// Verify appOwner guessed correctly with older log dir dtructure
1019+
path = new Path(remoteLogRootDir + testUser + "/logs/" + appId);
1020+
if (fs.exists(path)) {
1021+
fs.delete(path, true);
1022+
}
1023+
assertTrue(fs.mkdirs(path));
1024+
uploadContainerLogIntoRemoteDir(testUgi, configuration, rootLogDirs,
1025+
nodeId, containerId, path, fs);
1026+
1027+
exitCode = cli.run(new String[] {
1028+
"-applicationId", appId.toString()});
1029+
assertTrue(exitCode == 0);
1030+
assertTrue(sysOutStream.toString().contains(
1031+
logMessage(containerId, "syslog")));
1032+
sysOutStream.reset();
1033+
10191034
// Verify that we could get the err message "Can not find the appOwner"
10201035
// if we do not specify the appOwner, can not get appReport, and
10211036
// the app does not exist in remote dir.
@@ -1034,7 +1049,7 @@ public void testFetchApplictionLogsAsAnotherUser() throws Exception {
10341049
System.currentTimeMillis(), 1000);
10351050
String priorityUser = "priority";
10361051
Path pathWithoutPerm = new Path(remoteLogRootDir + priorityUser
1037-
+ "/logs/" + appTest);
1052+
+ "/bucket_logs/1000/" + appTest);
10381053
if (fs.exists(pathWithoutPerm)) {
10391054
fs.delete(pathWithoutPerm, true);
10401055
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/LogAggregationUtils.java

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,30 @@ public static Path getOlderRemoteAppLogDir(ApplicationId appId,
8383
suffix), appId.toString());
8484
}
8585

86+
public static Path getOlderRemoteAppLogDir(Configuration conf,
87+
ApplicationId appId, String user, Path remoteRootLogDir, String suffix)
88+
throws IOException {
89+
org.apache.hadoop.fs.Path remoteAppDir = null;
90+
if (user == null) {
91+
org.apache.hadoop.fs.Path qualifiedRemoteRootLogDir =
92+
FileContext.getFileContext(conf).makeQualified(remoteRootLogDir);
93+
FileContext fc = FileContext.getFileContext(
94+
qualifiedRemoteRootLogDir.toUri(), conf);
95+
org.apache.hadoop.fs.Path toMatch = LogAggregationUtils
96+
.getOlderRemoteAppLogDir(appId, "*", remoteRootLogDir, suffix);
97+
FileStatus[] matching = fc.util().globStatus(toMatch);
98+
if (matching == null || matching.length != 1) {
99+
throw new IOException("Can not find remote application directory for "
100+
+ "the application:" + appId);
101+
}
102+
remoteAppDir = matching[0].getPath();
103+
} else {
104+
remoteAppDir = LogAggregationUtils.getOlderRemoteAppLogDir(
105+
appId, user, remoteRootLogDir, suffix);
106+
}
107+
return remoteAppDir;
108+
}
109+
86110
/**
87111
* Gets the remote suffixed log dir for the user.
88112
* @param remoteRootLogDir the aggregated log remote root log dir
@@ -274,19 +298,19 @@ public static RemoteIterator<FileStatus> getRemoteNodeFileDir(
274298
StringBuilder diagnosticsMsg = new StringBuilder();
275299

276300
// Get Node Files from new app log dir
277-
Path remoteAppLogDir = getRemoteAppLogDir(conf, appId, appOwner,
278-
remoteRootLogDir, suffix);
279301
try {
302+
Path remoteAppLogDir = getRemoteAppLogDir(conf, appId, appOwner,
303+
remoteRootLogDir, suffix);
280304
nodeFilesCur = getNodeFiles(conf, remoteAppLogDir, appId, appOwner);
281305
} catch (IOException ex) {
282306
diagnosticsMsg.append(ex.getMessage() + "\n");
283307
}
284308

285309
// Get Node Files from old app log dir
286310
if (isOlderPathEnabled(conf)) {
287-
remoteAppLogDir = getOlderRemoteAppLogDir(appId, appOwner,
288-
remoteRootLogDir, suffix);
289311
try {
312+
Path remoteAppLogDir = getOlderRemoteAppLogDir(conf, appId, appOwner,
313+
remoteRootLogDir, suffix);
290314
nodeFilesPrev = getNodeFiles(conf,
291315
remoteAppLogDir, appId, appOwner);
292316
} catch (IOException ex) {
@@ -338,14 +362,14 @@ public static List<FileStatus> getRemoteNodeFileList(
338362
org.apache.hadoop.fs.Path remoteRootLogDir, String suffix)
339363
throws IOException {
340364
StringBuilder diagnosticsMsg = new StringBuilder();
341-
Path remoteAppLogDir = getRemoteAppLogDir(conf, appId, appOwner,
342-
remoteRootLogDir, suffix);
343365
List<FileStatus> nodeFiles = new ArrayList<>();
344-
Path qualifiedLogDir =
345-
FileContext.getFileContext(conf).makeQualified(remoteAppLogDir);
346366

347367
// Get Node Files from new app log dir
348368
try {
369+
Path remoteAppLogDir = getRemoteAppLogDir(conf, appId, appOwner,
370+
remoteRootLogDir, suffix);
371+
Path qualifiedLogDir =
372+
FileContext.getFileContext(conf).makeQualified(remoteAppLogDir);
349373
nodeFiles.addAll(Arrays.asList(FileContext.getFileContext(
350374
qualifiedLogDir.toUri(), conf).util().listStatus(remoteAppLogDir)));
351375
} catch (IOException ex) {
@@ -354,11 +378,11 @@ public static List<FileStatus> getRemoteNodeFileList(
354378

355379
// Get Node Files from old app log dir
356380
if (isOlderPathEnabled(conf)) {
357-
remoteAppLogDir = getOlderRemoteAppLogDir(appId, appOwner,
358-
remoteRootLogDir, suffix);
359-
qualifiedLogDir = FileContext.getFileContext(conf).
360-
makeQualified(remoteAppLogDir);
361381
try {
382+
Path remoteAppLogDir = getOlderRemoteAppLogDir(conf, appId, appOwner,
383+
remoteRootLogDir, suffix);
384+
Path qualifiedLogDir = FileContext.getFileContext(conf).
385+
makeQualified(remoteAppLogDir);
362386
nodeFiles.addAll(Arrays.asList(FileContext.getFileContext(
363387
qualifiedLogDir.toUri(), conf).util().listStatus(remoteAppLogDir)));
364388
} catch (IOException ex) {

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/LogCLIHelpers.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,58 @@ public static String getOwnerForAppIdOrNull(
8888
String suffix = LogAggregationUtils.getRemoteNodeLogDirSuffix(conf);
8989
Path fullPath = LogAggregationUtils.getRemoteAppLogDir(remoteRootLogDir,
9090
appId, bestGuess, suffix);
91+
9192
FileContext fc =
9293
FileContext.getFileContext(remoteRootLogDir.toUri(), conf);
9394
String pathAccess = fullPath.toString();
9495
try {
9596
if (fc.util().exists(fullPath)) {
9697
return bestGuess;
9798
}
99+
100+
boolean scanOldPath = LogAggregationUtils.isOlderPathEnabled(conf);
101+
if (scanOldPath) {
102+
Path olderAppPath = LogAggregationUtils.getOlderRemoteAppLogDir(appId,
103+
bestGuess, remoteRootLogDir, suffix);
104+
if (fc.util().exists(olderAppPath)) {
105+
return bestGuess;
106+
}
107+
}
108+
98109
Path toMatch = LogAggregationUtils.
99110
getRemoteAppLogDir(remoteRootLogDir, appId, "*", suffix);
111+
100112
pathAccess = toMatch.toString();
101113
FileStatus[] matching = fc.util().globStatus(toMatch);
102114
if (matching == null || matching.length != 1) {
115+
if (scanOldPath) {
116+
toMatch = LogAggregationUtils.getOlderRemoteAppLogDir(appId, "*",
117+
remoteRootLogDir, suffix);
118+
try {
119+
matching = fc.util().globStatus(toMatch);
120+
if (matching != null && matching.length == 1) {
121+
//fetch the user from the old path /app-logs/user[/suffix]/app_id
122+
Path parent = matching[0].getPath().getParent();
123+
//skip the suffix too
124+
if (suffix != null && !StringUtils.isEmpty(suffix)) {
125+
parent = parent.getParent();
126+
}
127+
return parent.getName();
128+
}
129+
} catch (IOException e) {
130+
// Ignore IOException from accessing older app log dir
131+
}
132+
}
103133
return null;
104134
}
105-
//fetch the user from the full path /app-logs/user[/suffix]/app_id
135+
//fetch the user from the full path /app-logs/user[/suffix]/bucket/app_id
106136
Path parent = matching[0].getPath().getParent();
107137
//skip the suffix too
108138
if (suffix != null && !StringUtils.isEmpty(suffix)) {
109139
parent = parent.getParent();
110140
}
141+
//skip the bucket
142+
parent = parent.getParent();
111143
return parent.getName();
112144
} catch (AccessControlException | AccessDeniedException ex) {
113145
logDirNoAccessPermission(pathAccess, bestGuess, ex.getMessage());

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/filecontroller/LogAggregationFileController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ public Path getRemoteAppLogDir(ApplicationId appId, String appOwner)
470470
*/
471471
public Path getOlderRemoteAppLogDir(ApplicationId appId, String appOwner)
472472
throws IOException {
473-
return LogAggregationUtils.getOlderRemoteAppLogDir(appId, appOwner,
473+
return LogAggregationUtils.getOlderRemoteAppLogDir(conf, appId, appOwner,
474474
this.remoteRootLogDir, this.remoteRootLogDirSuffix);
475475
}
476476

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/filecontroller/ifile/LogAggregationIndexedFileController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ public Path getRemoteAppLogDir(ApplicationId appId, String user)
822822
@Override
823823
public Path getOlderRemoteAppLogDir(ApplicationId appId, String user)
824824
throws IOException {
825-
return LogAggregationUtils.getOlderRemoteAppLogDir(appId, user,
825+
return LogAggregationUtils.getOlderRemoteAppLogDir(conf, appId, user,
826826
this.remoteRootLogDir, this.remoteRootLogDirSuffix);
827827
}
828828

0 commit comments

Comments
 (0)