diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/filecontroller/LogAggregationFileController.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/filecontroller/LogAggregationFileController.java index 7157db1ed96..78b8e388d94 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/filecontroller/LogAggregationFileController.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/filecontroller/LogAggregationFileController.java @@ -109,6 +109,8 @@ protected int retentionSize; protected String fileControllerName; + protected boolean fsSupportsChmod = true; + public LogAggregationFileController() {} /** @@ -278,15 +280,27 @@ public void verifyAndCreateRemoteLogDir() { "Failed to check permissions for dir [" + remoteRootLogDir + "]", e); } + + Path qualified = + remoteRootLogDir.makeQualified(remoteFS.getUri(), + remoteFS.getWorkingDirectory()); if (!remoteExists) { LOG.warn("Remote Root Log Dir [" + remoteRootLogDir + "] does not exist. Attempting to create it."); try { - Path qualified = - remoteRootLogDir.makeQualified(remoteFS.getUri(), - remoteFS.getWorkingDirectory()); remoteFS.mkdirs(qualified, new FsPermission(TLDIR_PERMISSIONS)); - remoteFS.setPermission(qualified, new FsPermission(TLDIR_PERMISSIONS)); + + // Not possible to query FileSystem API to check if it supports + // chmod, chown etc. Hence resorting to catching exceptions here. + // Remove when FS APi is ready + try { + remoteFS.setPermission(qualified, new FsPermission(TLDIR_PERMISSIONS)); + } catch ( UnsupportedOperationException use) { + LOG.info("Unable to set permissions for configured filesystem since" + + " it does not support this", + remoteFS.getScheme()); + fsSupportsChmod = false; + } UserGroupInformation loginUser = UserGroupInformation.getLoginUser(); String primaryGroupName = null; @@ -299,13 +313,31 @@ public void verifyAndCreateRemoteLogDir() { } // set owner on the remote directory only if the primary group exists if (primaryGroupName != null) { - remoteFS.setOwner(qualified, - loginUser.getShortUserName(), primaryGroupName); + try { + remoteFS.setOwner(qualified, loginUser.getShortUserName(), + primaryGroupName); + } catch(UnsupportedOperationException use) { + LOG.info("File System does not support setting user/group" + + remoteFS.getScheme(), use); + } } } catch (IOException e) { throw new YarnRuntimeException("Failed to create remoteLogDir [" + remoteRootLogDir + "]", e); } + } else { + //Check if FS has capability to set permissions + try { + remoteFS.setPermission(qualified, new FsPermission(TLDIR_PERMISSIONS)); + } catch ( UnsupportedOperationException use) { + LOG.info("Unable to set permissions for configured filesystem since" + + " it does not support this", + remoteFS.getScheme()); + fsSupportsChmod = false; + } catch (IOException e) { + LOG.warn("Failed to check if FileSystem suppports permissions on " + + "remoteLogDir [" + remoteRootLogDir + "]", e); + } } } @@ -381,11 +413,16 @@ protected FileSystem getFileSystem(Configuration conf) throws IOException { protected void createDir(FileSystem fs, Path path, FsPermission fsPerm) throws IOException { - FsPermission dirPerm = new FsPermission(fsPerm); - fs.mkdirs(path, dirPerm); - FsPermission umask = FsPermission.getUMask(fs.getConf()); - if (!dirPerm.equals(dirPerm.applyUMask(umask))) { - fs.setPermission(path, new FsPermission(fsPerm)); + + if ( fsSupportsChmod ) { + FsPermission dirPerm = new FsPermission(fsPerm); + fs.mkdirs(path, dirPerm); + FsPermission umask = FsPermission.getUMask(fs.getConf()); + if (!dirPerm.equals(dirPerm.applyUMask(umask))) { + fs.setPermission(path, new FsPermission(fsPerm)); + } + } else { + fs.mkdirs(path); } } @@ -394,8 +431,10 @@ protected boolean checkExists(FileSystem fs, Path path, FsPermission fsPerm) boolean exists = true; try { FileStatus appDirStatus = fs.getFileStatus(path); - if (!APP_DIR_PERMISSIONS.equals(appDirStatus.getPermission())) { - fs.setPermission(path, APP_DIR_PERMISSIONS); + if ( fsSupportsChmod) { + if (!APP_DIR_PERMISSIONS.equals(appDirStatus.getPermission())) { + fs.setPermission(path, APP_DIR_PERMISSIONS); + } } } catch (FileNotFoundException fnfe) { exists = false;