Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 87351200C0A for ; Sat, 28 Jan 2017 18:27:48 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 85BE7160B51; Sat, 28 Jan 2017 17:27:48 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 77752160B33 for ; Sat, 28 Jan 2017 18:27:47 +0100 (CET) Received: (qmail 7743 invoked by uid 500); 28 Jan 2017 17:27:46 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 7734 invoked by uid 99); 28 Jan 2017 17:27:46 -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; Sat, 28 Jan 2017 17:27:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6FCAFDFBE6; Sat, 28 Jan 2017 17:27:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: stoader@apache.org To: commits@ambari.apache.org Message-Id: <1cac56ba213440bb93d10ff953a59e57@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ambari git commit: AMBARI-19726. Post user creation hook is passed the hdfs user from the hadoop-env config type. (Laszlo Puskas via stoader) Date: Sat, 28 Jan 2017 17:27:46 +0000 (UTC) archived-at: Sat, 28 Jan 2017 17:27:48 -0000 Repository: ambari Updated Branches: refs/heads/trunk c2907860e -> 86fbb3810 AMBARI-19726. Post user creation hook is passed the hdfs user from the hadoop-env config type. (Laszlo Puskas via stoader) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/86fbb381 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/86fbb381 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/86fbb381 Branch: refs/heads/trunk Commit: 86fbb38108e2d9b87f22b1920cada3a655677285 Parents: c290786 Author: Laszlo Puskas Authored: Sat Jan 28 18:27:31 2017 +0100 Committer: Toader, Sebastian Committed: Sat Jan 28 18:27:31 2017 +0100 ---------------------------------------------------------------------- .../server/hooks/users/UserHookParams.java | 3 ++- .../server/hooks/users/UserHookService.java | 23 ++++++++++++++------ .../users/CsvFilePersisterService.java | 6 ++--- .../users/PostUserCreationHookServerAction.java | 8 ++++++- .../scripts/post-user-creation-hook.sh | 9 ++++++-- .../server/hooks/users/UserHookServiceTest.java | 9 ++++++++ .../PostUserCreationHookServerActionTest.java | 3 ++- 7 files changed, 45 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/86fbb381/ambari-server/src/main/java/org/apache/ambari/server/hooks/users/UserHookParams.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/hooks/users/UserHookParams.java b/ambari-server/src/main/java/org/apache/ambari/server/hooks/users/UserHookParams.java index 6970dcc..4b1b5aa 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/hooks/users/UserHookParams.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/hooks/users/UserHookParams.java @@ -34,7 +34,8 @@ public enum UserHookParams { // identify security related values CLUSTER_SECURITY_TYPE("cluster-security-type"), CMD_HDFS_PRINCIPAL("cmd-hdfs-principal"), - CMD_HDFS_KEYTAB("cmd-hdfs-keytab"); + CMD_HDFS_KEYTAB("cmd-hdfs-keytab"), + CMD_HDFS_USER("cmd-hdfs-user"); private String param; http://git-wip-us.apache.org/repos/asf/ambari/blob/86fbb381/ambari-server/src/main/java/org/apache/ambari/server/hooks/users/UserHookService.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/hooks/users/UserHookService.java b/ambari-server/src/main/java/org/apache/ambari/server/hooks/users/UserHookService.java index c4ff1e4..69463ab 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/hooks/users/UserHookService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/hooks/users/UserHookService.java @@ -170,8 +170,10 @@ public class UserHookService implements HookService { commandParams.put(UserHookParams.CMD_HDFS_KEYTAB.param(), clusterData.getKeytab()); commandParams.put(UserHookParams.CMD_HDFS_PRINCIPAL.param(), clusterData.getPrincipal()); + commandParams.put(UserHookParams.CMD_HDFS_USER.param(), clusterData.getHdfsUser()); commandParams.put(UserHookParams.CMD_INPUT_FILE.param(), generateInputFileName()); + commandParams.put(UserHookParams.PAYLOAD.param(), objectMapper.writeValueAsString(context.getUserGroups())); return commandParams; @@ -228,15 +230,16 @@ public class UserHookService implements HookService { break; } - return new ClusterData(cluster.getClusterName(), cluster.getClusterId(), cluster.getSecurityType().name(), principal, keyTab); - } - private void getSecurityData(Configuration configuraiton) { - //principal + return new ClusterData(cluster.getClusterName(), cluster.getClusterId(), cluster.getSecurityType().name(), principal, keyTab, getHdfsUser(cluster)); + } - //keytab + private String getHdfsUser(Cluster cluster) { + String hdfsUser = cluster.getDesiredConfigByType("hadoop-env").getProperties().get("hdfs_user"); + return hdfsUser; } + /** * Local representation of cluster data. */ @@ -247,12 +250,15 @@ public class UserHookService implements HookService { private String principal; private String keytab; - public ClusterData(String clusterName, Long clusterId, String securityType, String principal, String keytab) { + private String hdfsUser; + + public ClusterData(String clusterName, Long clusterId, String securityType, String principal, String keytab, String hdfsUser) { this.clusterName = clusterName; this.clusterId = clusterId; this.securityType = securityType; this.principal = principal; this.keytab = keytab; + this.hdfsUser = hdfsUser; } public String getClusterName() { @@ -274,6 +280,9 @@ public class UserHookService implements HookService { public String getKeytab() { return keytab; } - } + public String getHdfsUser() { + return hdfsUser; + } + } } http://git-wip-us.apache.org/repos/asf/ambari/blob/86fbb381/ambari-server/src/main/java/org/apache/ambari/server/serveraction/users/CsvFilePersisterService.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/users/CsvFilePersisterService.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/users/CsvFilePersisterService.java index fe6bf35..b78a127 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/users/CsvFilePersisterService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/users/CsvFilePersisterService.java @@ -18,15 +18,12 @@ package org.apache.ambari.server.serveraction.users; -import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.PosixFilePermission; -import java.nio.file.attribute.PosixFilePermissions; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -72,7 +69,8 @@ public class CsvFilePersisterService implements CollectionPersisterService clsMap = new HashMap<>(); clsMap.put("test-cluster", clusterMock); + Map configMap = new HashMap<>(); + configMap.put("hdfs_user", "hdfs-test-user"); + EasyMock.expect(clusterMock.getClusterId()).andReturn(1l); EasyMock.expect(clusterMock.getClusterName()).andReturn("test-cluster"); EasyMock.expect(clusterMock.getSecurityType()).andReturn(SecurityType.NONE).times(3); + EasyMock.expect(clusterMock.getDesiredConfigByType("hadoop-env")).andReturn(configMock); + EasyMock.expect(configMock.getProperties()).andReturn(configMap); EasyMock.expect(actionManagerMock.getNextRequestId()).andReturn(1l); http://git-wip-us.apache.org/repos/asf/ambari/blob/86fbb381/ambari-server/src/test/java/org/apache/ambari/server/serveraction/users/PostUserCreationHookServerActionTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/users/PostUserCreationHookServerActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/users/PostUserCreationHookServerActionTest.java index a4d50ef..6d6e42c 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/users/PostUserCreationHookServerActionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/users/PostUserCreationHookServerActionTest.java @@ -115,6 +115,7 @@ public class PostUserCreationHookServerActionTest extends EasyMockSupport { commandParams.put(UserHookParams.CMD_TIME_FRAME.param(), "1000"); commandParams.put(UserHookParams.CMD_INPUT_FILE.param(), "/test/user_data.csv"); commandParams.put(UserHookParams.CLUSTER_SECURITY_TYPE.param(), SecurityType.KERBEROS.name()); + commandParams.put(UserHookParams.CMD_HDFS_USER.param(), "test-hdfs-user"); EasyMock.expect(executionCommand.getCommandParams()).andReturn(commandParams); EasyMock.expect(objectMapperMock.readValue(payloadJson, Map.class)).andReturn(payload); @@ -139,7 +140,7 @@ public class PostUserCreationHookServerActionTest extends EasyMockSupport { String[] commandArray = commandCapture.getValue(); Assert.assertNotNull("The command to be executed must not be null!", commandArray); - Assert.assertEquals("The command argument array length is not as expected!", 5, commandArray.length); + Assert.assertEquals("The command argument array length is not as expected!", 6, commandArray.length); Assert.assertEquals("The command script is not as expected", "/hookfolder/hook.name", commandArray[0]); }