|
@@ -68,83 +68,113 @@ public class LogCLIHelpers implements Configurable {
|
|
return dumpAContainerLogsForLogType(options, false);
|
|
return dumpAContainerLogsForLogType(options, false);
|
|
}
|
|
}
|
|
|
|
|
|
- @Private
|
|
|
|
- @VisibleForTesting
|
|
|
|
- /**
|
|
|
|
- * Return the owner for a given AppId
|
|
|
|
- * @param remoteRootLogDir
|
|
|
|
- * @param appId
|
|
|
|
- * @param bestGuess
|
|
|
|
- * @param conf
|
|
|
|
- * @return the owner or null
|
|
|
|
- * @throws IOException
|
|
|
|
- */
|
|
|
|
- public static String getOwnerForAppIdOrNull(
|
|
|
|
- ApplicationId appId, String bestGuess,
|
|
|
|
- Configuration conf) throws IOException {
|
|
|
|
- Path remoteRootLogDir = new Path(conf.get(
|
|
|
|
- YarnConfiguration.NM_REMOTE_APP_LOG_DIR,
|
|
|
|
- YarnConfiguration.DEFAULT_NM_REMOTE_APP_LOG_DIR));
|
|
|
|
- String suffix = LogAggregationUtils.getRemoteNodeLogDirSuffix(conf);
|
|
|
|
- Path fullPath = LogAggregationUtils.getRemoteAppLogDir(remoteRootLogDir,
|
|
|
|
- appId, bestGuess, suffix);
|
|
|
|
|
|
+ public static String guessOwnerWithFileFormat(
|
|
|
|
+ LogAggregationFileController fileFormat, ApplicationId appId,
|
|
|
|
+ String bestGuess, Configuration conf) throws IOException {
|
|
|
|
|
|
|
|
+ boolean scanOldPath = LogAggregationUtils.isOlderPathEnabled(conf);
|
|
|
|
+ Path remoteRootLogDir = fileFormat.getRemoteRootLogDir();
|
|
|
|
+ String suffix = fileFormat.getRemoteRootLogDirSuffix();
|
|
|
|
+ Path fullPath = fileFormat.getRemoteAppLogDir(appId, bestGuess);
|
|
FileContext fc =
|
|
FileContext fc =
|
|
FileContext.getFileContext(remoteRootLogDir.toUri(), conf);
|
|
FileContext.getFileContext(remoteRootLogDir.toUri(), conf);
|
|
String pathAccess = fullPath.toString();
|
|
String pathAccess = fullPath.toString();
|
|
|
|
+
|
|
try {
|
|
try {
|
|
if (fc.util().exists(fullPath)) {
|
|
if (fc.util().exists(fullPath)) {
|
|
return bestGuess;
|
|
return bestGuess;
|
|
}
|
|
}
|
|
|
|
|
|
- boolean scanOldPath = LogAggregationUtils.isOlderPathEnabled(conf);
|
|
|
|
if (scanOldPath) {
|
|
if (scanOldPath) {
|
|
- Path olderAppPath = LogAggregationUtils.getOlderRemoteAppLogDir(appId,
|
|
|
|
- bestGuess, remoteRootLogDir, suffix);
|
|
|
|
|
|
+ Path olderAppPath = fileFormat.getOlderRemoteAppLogDir(appId,
|
|
|
|
+ bestGuess);
|
|
|
|
+ pathAccess = olderAppPath.toString();
|
|
if (fc.util().exists(olderAppPath)) {
|
|
if (fc.util().exists(olderAppPath)) {
|
|
return bestGuess;
|
|
return bestGuess;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ } catch (AccessControlException | AccessDeniedException ex) {
|
|
|
|
+ logDirNoAccessPermission(pathAccess, bestGuess, ex.getMessage());
|
|
|
|
+ throw ex;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ Path toMatch = fileFormat.getRemoteAppLogDir(appId, null);
|
|
|
|
+ FileStatus[] matching = fc.util().globStatus(toMatch);
|
|
|
|
+ if (matching != null && matching.length == 1) {
|
|
|
|
+ //fetch user from new path /app-logs/user[/suffix]/bucket/app_id
|
|
|
|
+ Path parent = matching[0].getPath().getParent();
|
|
|
|
+ //skip the suffix too
|
|
|
|
+ if (suffix != null && !StringUtils.isEmpty(suffix)) {
|
|
|
|
+ parent = parent.getParent();
|
|
|
|
+ }
|
|
|
|
+ //skip the bucket
|
|
|
|
+ parent = parent.getParent();
|
|
|
|
+ return parent.getName();
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ // Ignore IOException thrown from wrong file format
|
|
|
|
+ }
|
|
|
|
|
|
- Path toMatch = LogAggregationUtils.
|
|
|
|
- getRemoteAppLogDir(remoteRootLogDir, appId, "*", suffix);
|
|
|
|
-
|
|
|
|
- pathAccess = toMatch.toString();
|
|
|
|
- FileStatus[] matching = fc.util().globStatus(toMatch);
|
|
|
|
- if (matching == null || matching.length != 1) {
|
|
|
|
- if (scanOldPath) {
|
|
|
|
- toMatch = LogAggregationUtils.getOlderRemoteAppLogDir(appId, "*",
|
|
|
|
- remoteRootLogDir, suffix);
|
|
|
|
- try {
|
|
|
|
- matching = fc.util().globStatus(toMatch);
|
|
|
|
- if (matching != null && matching.length == 1) {
|
|
|
|
- //fetch the user from the old path /app-logs/user[/suffix]/app_id
|
|
|
|
- Path parent = matching[0].getPath().getParent();
|
|
|
|
- //skip the suffix too
|
|
|
|
- if (suffix != null && !StringUtils.isEmpty(suffix)) {
|
|
|
|
- parent = parent.getParent();
|
|
|
|
- }
|
|
|
|
- return parent.getName();
|
|
|
|
- }
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- // Ignore IOException from accessing older app log dir
|
|
|
|
|
|
+ if (scanOldPath) {
|
|
|
|
+ try {
|
|
|
|
+ Path toMatch = fileFormat.getOlderRemoteAppLogDir(appId, null);
|
|
|
|
+ FileStatus[] matching = fc.util().globStatus(toMatch);
|
|
|
|
+ if (matching != null && matching.length == 1) {
|
|
|
|
+ //fetch user from old path /app-logs/user[/suffix]/app_id
|
|
|
|
+ Path parent = matching[0].getPath().getParent();
|
|
|
|
+ //skip the suffix too
|
|
|
|
+ if (suffix != null && !StringUtils.isEmpty(suffix)) {
|
|
|
|
+ parent = parent.getParent();
|
|
}
|
|
}
|
|
|
|
+ return parent.getName();
|
|
}
|
|
}
|
|
- return null;
|
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ // Ignore IOException thrown from wrong file format
|
|
}
|
|
}
|
|
- //fetch the user from the full path /app-logs/user[/suffix]/bucket/app_id
|
|
|
|
- Path parent = matching[0].getPath().getParent();
|
|
|
|
- //skip the suffix too
|
|
|
|
- if (suffix != null && !StringUtils.isEmpty(suffix)) {
|
|
|
|
- parent = parent.getParent();
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Private
|
|
|
|
+ @VisibleForTesting
|
|
|
|
+ /**
|
|
|
|
+ * Return the owner for a given AppId
|
|
|
|
+ * @param remoteRootLogDir
|
|
|
|
+ * @param appId
|
|
|
|
+ * @param bestGuess
|
|
|
|
+ * @param conf
|
|
|
|
+ * @return the owner or null
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public static String getOwnerForAppIdOrNull(
|
|
|
|
+ ApplicationId appId, String bestGuess,
|
|
|
|
+ Configuration conf) {
|
|
|
|
+ LogAggregationFileControllerFactory factory =
|
|
|
|
+ new LogAggregationFileControllerFactory(conf);
|
|
|
|
+ List<LogAggregationFileController> fileControllers = factory
|
|
|
|
+ .getConfiguredLogAggregationFileControllerList();
|
|
|
|
+
|
|
|
|
+ if (fileControllers != null && !fileControllers.isEmpty()) {
|
|
|
|
+ String owner = null;
|
|
|
|
+ for (LogAggregationFileController fileFormat : fileControllers) {
|
|
|
|
+ try {
|
|
|
|
+ owner = guessOwnerWithFileFormat(fileFormat, appId, bestGuess, conf);
|
|
|
|
+ if (owner != null) {
|
|
|
|
+ return owner;
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- //skip the bucket
|
|
|
|
- parent = parent.getParent();
|
|
|
|
- return parent.getName();
|
|
|
|
- } catch (AccessControlException | AccessDeniedException ex) {
|
|
|
|
- logDirNoAccessPermission(pathAccess, bestGuess, ex.getMessage());
|
|
|
|
- return null;
|
|
|
|
|
|
+ } else {
|
|
|
|
+ System.err.println("Can not find any valid fileControllers. " +
|
|
|
|
+ " The configurated fileControllers: " +
|
|
|
|
+ YarnConfiguration.LOG_AGGREGATION_FILE_FORMATS);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
@Private
|
|
@Private
|
|
@@ -215,7 +245,8 @@ public class LogCLIHelpers implements Configurable {
|
|
}
|
|
}
|
|
if (!foundAnyLogs) {
|
|
if (!foundAnyLogs) {
|
|
emptyLogDir(LogAggregationUtils.getRemoteAppLogDir(
|
|
emptyLogDir(LogAggregationUtils.getRemoteAppLogDir(
|
|
- conf, options.getAppId(), options.getAppOwner())
|
|
|
|
|
|
+ conf, options.getAppId(), options.getAppOwner(),
|
|
|
|
+ fc.getRemoteRootLogDir(), fc.getRemoteRootLogDirSuffix())
|
|
.toString());
|
|
.toString());
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
@@ -286,12 +317,11 @@ public class LogCLIHelpers implements Configurable {
|
|
appOwner, fileFormat.getRemoteRootLogDir(),
|
|
appOwner, fileFormat.getRemoteRootLogDir(),
|
|
fileFormat.getRemoteRootLogDirSuffix());
|
|
fileFormat.getRemoteRootLogDirSuffix());
|
|
} catch (FileNotFoundException fnf) {
|
|
} catch (FileNotFoundException fnf) {
|
|
- logDirNotExist(LogAggregationUtils.getRemoteAppLogDir(
|
|
|
|
- conf, appId, appOwner).toString());
|
|
|
|
|
|
+ logDirNotExist(fileFormat.getRemoteAppLogDir(appId,
|
|
|
|
+ appOwner).toString());
|
|
} catch (AccessControlException | AccessDeniedException ace) {
|
|
} catch (AccessControlException | AccessDeniedException ace) {
|
|
- logDirNoAccessPermission(LogAggregationUtils.getRemoteAppLogDir(
|
|
|
|
- conf, appId, appOwner).toString(), appOwner,
|
|
|
|
- ace.getMessage());
|
|
|
|
|
|
+ logDirNoAccessPermission(fileFormat.getRemoteAppLogDir(appId,
|
|
|
|
+ appOwner).toString(), appOwner, ace.getMessage());
|
|
}
|
|
}
|
|
if (nodeFiles == null) {
|
|
if (nodeFiles == null) {
|
|
return;
|
|
return;
|