diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/LogAggregationService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/LogAggregationService.java index 48bf96b725e..de89a968478 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/LogAggregationService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/LogAggregationService.java @@ -218,6 +218,21 @@ public class LogAggregationService extends AbstractService implements remoteFS.getWorkingDirectory()); remoteFS.mkdirs(qualified, new FsPermission(TLDIR_PERMISSIONS)); remoteFS.setPermission(qualified, new FsPermission(TLDIR_PERMISSIONS)); + + UserGroupInformation loginUser = UserGroupInformation.getLoginUser(); + String primaryGroupName = null; + try { + primaryGroupName = loginUser.getPrimaryGroupName(); + } catch (IOException e) { + LOG.warn("No primary group found. The remote root log directory" + + " will be created with the HDFS superuser being its group " + + "owner. JobHistoryServer may be unable to read the directory."); + } + // set owner on the remote directory only if the primary group exists + if (primaryGroupName != null) { + remoteFS.setOwner(qualified, + loginUser.getShortUserName(), primaryGroupName); + } } catch (IOException e) { throw new YarnRuntimeException("Failed to create remoteLogDir [" + this.remoteRootLogDir + "]", e); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java index c0a3f3a853a..0667d198804 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java @@ -605,7 +605,7 @@ public class TestLogAggregationService extends BaseContainerManagerTest { throws Exception { this.conf.set(YarnConfiguration.NM_LOG_DIRS, localLogDir.getAbsolutePath()); File aNewFile = new File(String.valueOf("tmp"+System.currentTimeMillis())); - this.conf.set(YarnConfiguration.NM_REMOTE_APP_LOG_DIR, + this.conf.set(YarnConfiguration.NM_REMOTE_APP_LOG_DIR, aNewFile.getAbsolutePath()); LogAggregationService logAggregationService = spy( @@ -622,6 +622,28 @@ public class TestLogAggregationService extends BaseContainerManagerTest { aNewFile.delete(); //housekeeping } + @Test + public void testRemoteRootLogDirIsCreatedWithCorrectGroupOwner() + throws IOException { + this.conf.set(YarnConfiguration.NM_LOG_DIRS, localLogDir.getAbsolutePath()); + Path aNewFile = new Path(String.valueOf("tmp"+System.currentTimeMillis())); + this.conf.set(YarnConfiguration.NM_REMOTE_APP_LOG_DIR, aNewFile.getName()); + + LogAggregationService logAggregationService = new LogAggregationService( + dispatcher, this.context, this.delSrvc, super.dirsHandler); + logAggregationService.init(this.conf); + logAggregationService.verifyAndCreateRemoteLogDir(this.conf); + + String targetGroup = + UserGroupInformation.getLoginUser().getPrimaryGroupName(); + FileSystem fs = FileSystem.get(this.conf); + FileStatus fileStatus = fs.getFileStatus(aNewFile); + Assert.assertEquals("The new aggregate file is not successfully created", + fileStatus.getGroup(), targetGroup); + + fs.delete(aNewFile, true); + } + @Test public void testAppLogDirCreation() throws Exception { final String logSuffix = "logs";