Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 539D418341 for ; Tue, 23 Jun 2015 18:43:40 +0000 (UTC) Received: (qmail 28999 invoked by uid 500); 23 Jun 2015 18:43:40 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 28922 invoked by uid 500); 23 Jun 2015 18:43:40 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 28913 invoked by uid 99); 23 Jun 2015 18:43:40 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Jun 2015 18:43:40 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EF547E04AC; Tue, 23 Jun 2015 18:43:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vinodkv@apache.org To: common-commits@hadoop.apache.org Message-Id: <6bf3ee91714445d1aa3adc289005e7ef@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: MAPREDUCE-6410. Fixed MapReduce JobHistory server to use the right (login) UGI to refresh log and cleaner settings. Contributed by Varun Saxena. Date: Tue, 23 Jun 2015 18:43:39 +0000 (UTC) Repository: hadoop Updated Branches: refs/heads/branch-2.7 4a8db40f3 -> a90e9b2f6 MAPREDUCE-6410. Fixed MapReduce JobHistory server to use the right (login) UGI to refresh log and cleaner settings. Contributed by Varun Saxena. (cherry picked from commit d481684c7c9293a94f54ef622a92753531c6acc7) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/a90e9b2f Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/a90e9b2f Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/a90e9b2f Branch: refs/heads/branch-2.7 Commit: a90e9b2f6f88ccce9fedb4aec7b1096f359ff035 Parents: 4a8db40 Author: Vinod Kumar Vavilapalli Authored: Tue Jun 23 11:39:55 2015 -0700 Committer: Vinod Kumar Vavilapalli Committed: Tue Jun 23 11:41:31 2015 -0700 ---------------------------------------------------------------------- hadoop-mapreduce-project/CHANGES.txt | 3 ++ .../mapreduce/v2/hs/server/HSAdminServer.java | 43 ++++++++++++++- .../v2/hs/server/TestHSAdminServer.java | 55 ++++++++++++++++++++ 3 files changed, 99 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/a90e9b2f/hadoop-mapreduce-project/CHANGES.txt ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 6631ec1..b02dca6 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -43,6 +43,9 @@ Release 2.7.1 - UNRELEASED MAPREDUCE-6387. Serialize the recently added Task#encryptedSpillKey field at the end. (Arun Suresh via kasha) + MAPREDUCE-6410. Fixed MapReduce JobHistory server to use the right (login) + UGI to refresh log and cleaner settings. (Varun Saxena via vinodkv) + Release 2.7.0 - 2015-04-20 INCOMPATIBLE CHANGES http://git-wip-us.apache.org/repos/asf/hadoop/blob/a90e9b2f/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/server/HSAdminServer.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/server/HSAdminServer.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/server/HSAdminServer.java index ef79bf8..3fef5e2 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/server/HSAdminServer.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/server/HSAdminServer.java @@ -20,6 +20,7 @@ package org.apache.hadoop.mapreduce.v2.hs.server; import java.io.IOException; import java.net.InetSocketAddress; +import java.security.PrivilegedExceptionAction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -52,6 +53,7 @@ import org.apache.hadoop.mapreduce.v2.hs.JobHistory; import org.apache.hadoop.mapreduce.v2.hs.proto.HSAdminRefreshProtocolProtos.HSAdminRefreshProtocolService; import org.apache.hadoop.mapreduce.v2.hs.protocolPB.HSAdminRefreshProtocolServerSideTranslatorPB; +import com.google.common.annotations.VisibleForTesting; import com.google.protobuf.BlockingService; @Private @@ -67,6 +69,8 @@ public class HSAdminServer extends AbstractService implements HSAdminProtocol { private static final String HISTORY_ADMIN_SERVER = "HSAdminServer"; private JobHistory jobHistoryService = null; + private UserGroupInformation loginUGI; + public HSAdminServer(AggregatedLogDeletionService aggLogDelService, JobHistory jobHistoryService) { super(HSAdminServer.class.getName()); @@ -125,9 +129,24 @@ public class HSAdminServer extends AbstractService implements HSAdminProtocol { @Override protected void serviceStart() throws Exception { + if (UserGroupInformation.isSecurityEnabled()) { + loginUGI = UserGroupInformation.getLoginUser(); + } else { + loginUGI = UserGroupInformation.getCurrentUser(); + } clientRpcServer.start(); } + @VisibleForTesting + UserGroupInformation getLoginUGI() { + return loginUGI; + } + + @VisibleForTesting + void setLoginUGI(UserGroupInformation ugi) { + loginUGI = ugi; + } + @Override protected void serviceStop() throws Exception { if (clientRpcServer != null) { @@ -233,7 +252,17 @@ public class HSAdminServer extends AbstractService implements HSAdminProtocol { public void refreshLogRetentionSettings() throws IOException { UserGroupInformation user = checkAcls("refreshLogRetentionSettings"); - aggLogDelService.refreshLogRetentionSettings(); + try { + loginUGI.doAs(new PrivilegedExceptionAction() { + @Override + public Void run() throws IOException { + aggLogDelService.refreshLogRetentionSettings(); + return null; + } + }); + } catch (InterruptedException e) { + throw new IOException(e); + } HSAuditLogger.logSuccess(user.getShortUserName(), "refreshLogRetentionSettings", "HSAdminServer"); @@ -243,7 +272,17 @@ public class HSAdminServer extends AbstractService implements HSAdminProtocol { public void refreshJobRetentionSettings() throws IOException { UserGroupInformation user = checkAcls("refreshJobRetentionSettings"); - jobHistoryService.refreshJobRetentionSettings(); + try { + loginUGI.doAs(new PrivilegedExceptionAction() { + @Override + public Void run() throws IOException { + jobHistoryService.refreshJobRetentionSettings(); + return null; + } + }); + } catch (InterruptedException e) { + throw new IOException(e); + } HSAuditLogger.logSuccess(user.getShortUserName(), "refreshJobRetentionSettings", HISTORY_ADMIN_SERVER); http://git-wip-us.apache.org/repos/asf/hadoop/blob/a90e9b2f/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/server/TestHSAdminServer.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/server/TestHSAdminServer.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/server/TestHSAdminServer.java index 7ab90f0..d831347 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/server/TestHSAdminServer.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/server/TestHSAdminServer.java @@ -21,6 +21,8 @@ package org.apache.hadoop.mapreduce.v2.hs.server; import static org.junit.Assert.*; import java.io.IOException; +import java.security.PrivilegedAction; +import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -45,6 +47,9 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; @@ -286,6 +291,56 @@ public class TestHSAdminServer { verify(jobHistoryService).refreshJobRetentionSettings(); } + @SuppressWarnings("unchecked") + @Test + public void testUGIForLogAndJobRefresh() throws Exception { + UserGroupInformation ugi = + UserGroupInformation.createUserForTesting("test", new String[] {"grp"}); + UserGroupInformation loginUGI = spy(hsAdminServer.getLoginUGI()); + hsAdminServer.setLoginUGI(loginUGI); + + // Run refresh log retention settings with test user + ugi.doAs(new PrivilegedAction() { + @Override + public Void run() { + String[] args = new String[1]; + args[0] = "-refreshLogRetentionSettings"; + try { + hsAdminClient.run(args); + } catch (Exception e) { + fail("refreshLogRetentionSettings should have been successful"); + } + return null; + } + }); + // Verify if AggregatedLogDeletionService#refreshLogRetentionSettings was + // called with login UGI, instead of the UGI command was run with. + verify(loginUGI).doAs(any(PrivilegedExceptionAction.class)); + verify(alds).refreshLogRetentionSettings(); + + // Reset for refresh job retention settings + reset(loginUGI); + + // Run refresh job retention settings with test user + ugi.doAs(new PrivilegedAction() { + @Override + public Void run() { + String[] args = new String[1]; + args[0] = "-refreshJobRetentionSettings"; + try { + hsAdminClient.run(args); + } catch (Exception e) { + fail("refreshJobRetentionSettings should have been successful"); + } + return null; + } + }); + // Verify if JobHistory#refreshJobRetentionSettings was called with + // login UGI, instead of the UGI command was run with. + verify(loginUGI).doAs(any(PrivilegedExceptionAction.class)); + verify(jobHistoryService).refreshJobRetentionSettings(); + } + @After public void cleanUp() { if (hsAdminServer != null)