From 516756bc3a0e0aef9e8a5d5cf3f77d7ff15a91e9 Mon Sep 17 00:00:00 2001 From: Adam Antal Date: Fri, 6 Sep 2019 17:06:58 +0200 Subject: [PATCH] YARN-9814. JobHistoryServer can't delete aggregated files, if remote app root directory is created by NodeManager --- .../hadoop/yarn/conf/YarnConfiguration.java | 6 +++ .../LogAggregationFileController.java | 21 ++++++---- .../TestLogAggregationFileController.java | 40 +++++++++++++++++++ 3 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/filecontroller/TestLogAggregationFileController.java diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java index 0f1c544a8ed..11f47293a0d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java @@ -1461,6 +1461,12 @@ public static boolean isAclEnabled(Configuration conf) { public static final boolean DEFAULT_NM_REMOTE_APP_LOG_DIR_INCLUDE_OLDER = true; + /** + * Specifies the group of the aggregated log directory. + */ + public static final String NM_REMOTE_APP_LOG_DIR_GROUP = + NM_PREFIX + "remote-app-log-dir.group"; + public static final String YARN_LOG_SERVER_URL = YARN_PREFIX + "log.server.url"; 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 661e3219d33..f24ea704e39 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 @@ -346,13 +346,20 @@ public void verifyAndCreateRemoteLogDir() { } 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."); + String primaryGroupName = conf.get( + YarnConfiguration.NM_REMOTE_APP_LOG_DIR_GROUP); + if (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."); + } + } else { + LOG.debug("The group of remote root log directory has been " + + "determined from the configuration, and set to " + + primaryGroupName); } // set owner on the remote directory only if the primary group exists if (primaryGroupName != null) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/filecontroller/TestLogAggregationFileController.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/filecontroller/TestLogAggregationFileController.java new file mode 100644 index 00000000000..58c0ef7c2f5 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/filecontroller/TestLogAggregationFileController.java @@ -0,0 +1,40 @@ +package org.apache.hadoop.yarn.logaggregation.filecontroller; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.junit.Test; +import org.mockito.Mockito; + +import java.io.FileNotFoundException; +import java.net.URI; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class TestLogAggregationFileController { + @Test + public void test() throws Exception { + String testGroupName = "testGroup"; + + FileSystem fs = mock(FileSystem.class); + doReturn(new URI("")).when(fs).getUri(); + doThrow(FileNotFoundException.class).when(fs).getFileStatus(any(Path.class)); + + Configuration conf = new Configuration(); + conf.set(YarnConfiguration.NM_REMOTE_APP_LOG_DIR_GROUP, testGroupName); + LogAggregationFileController controller = mock( + LogAggregationFileController.class, Mockito.CALLS_REAL_METHODS); + doReturn(fs).when(controller).getFileSystem(any(Configuration.class)); + + controller.initialize(conf, "TFile"); + controller.verifyAndCreateRemoteLogDir(); + + verify(fs).setOwner(any(), any(), eq(testGroupName)); + } +} -- 2.21.0