You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by tb...@apache.org on 2015/02/18 14:59:04 UTC
ambari git commit: AMBARI-9686 - RU: Author for config change should
be something more appropriate than _anonymous (tbeerbower)
Repository: ambari
Updated Branches:
refs/heads/trunk e9c8b2660 -> 43f916b90
AMBARI-9686 - RU: Author for config change should be something more appropriate than _anonymous (tbeerbower)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/43f916b9
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/43f916b9
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/43f916b9
Branch: refs/heads/trunk
Commit: 43f916b9056c8cea813cc6b5d514344da194d11a
Parents: e9c8b26
Author: tbeerbower <tb...@hortonworks.com>
Authored: Wed Feb 18 06:07:59 2015 -0500
Committer: tbeerbower <tb...@hortonworks.com>
Committed: Wed Feb 18 08:58:55 2015 -0500
----------------------------------------------------------------------
.../ambari/server/actionmanager/Stage.java | 18 ++++--
.../internal/UpgradeResourceProvider.java | 1 +
.../server/serveraction/ServerAction.java | 3 +-
.../serveraction/upgrades/ConfigureAction.java | 16 ++++-
.../ambari/server/actionmanager/StageTest.java | 64 ++++++++++++++++++++
.../serveraction/ServerActionExecutorTest.java | 2 +-
6 files changed, 95 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/43f916b9/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java
index 097145d..51d5e8a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java
@@ -341,7 +341,7 @@ public class Stage {
@Nullable Integer timeout,
boolean retryAllowed) {
- addServerActionCommand(actionName, role, command, clusterName, StageUtils.getHostName(), event,
+ addServerActionCommand(actionName, null, role, command, clusterName, StageUtils.getHostName(), event,
commandParams, commandDetail, configTags, timeout, retryAllowed);
}
@@ -357,26 +357,29 @@ public class Stage {
* instantiated and invoked as needed.
*
* @param actionName a String declaring the action name (in the form of a classname) to execute
+ * @param userName the name of the user who created this stage; may be null for anonymous user
* @param role the Role for this command
* @param command the RoleCommand for this command
* @param clusterName a String identifying the cluster on which to to execute this command
* @param hostName the name of the host
* @param event a ServiceComponentHostServerActionEvent
* @param commandParams a Map of String to String data used to pass to the action - this may be
- * empty or null if no data is relevant
+* empty or null if no data is relevant
* @param commandDetail a String declaring a descriptive name to pass to the action - null or an
- * empty string indicates no value is to be set
+* empty string indicates no value is to be set
* @param configTags a Map of configuration tags to set for this command - if null, no
- * configurations will be available for the command
+* configurations will be available for the command
* @param timeout an Integer declaring the timeout for this action - if null, a default
* @param retryAllowed indicates whether retry after failure is allowed
*/
- public synchronized void addServerActionCommand(String actionName, Role role, RoleCommand command,
+ public synchronized void addServerActionCommand(String actionName,
+ @Nullable String userName,
+ Role role, RoleCommand command,
String clusterName, String hostName,
ServiceComponentHostServerActionEvent event,
@Nullable Map<String, String> commandParams,
@Nullable String commandDetail,
- @Nullable Map<String, Map<String,String>> configTags,
+ @Nullable Map<String, Map<String, String>> configTags,
@Nullable Integer timeout, boolean retryAllowed) {
ExecutionCommandWrapper commandWrapper =
addGenericExecutionCommand(clusterName, hostName, role, command, event, retryAllowed);
@@ -405,6 +408,9 @@ public class Stage {
Map<String, String> roleParams = new HashMap<String, String>();
roleParams.put(ServerAction.ACTION_NAME, actionName);
+ if (userName != null) {
+ roleParams.put(ServerAction.ACTION_USER_NAME, userName);
+ }
cmd.setRoleParams(roleParams);
if(commandDetail != null) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/43f916b9/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
index 3d52492..1feb65d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
@@ -859,6 +859,7 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
String host = cluster.getAllHostsDesiredConfigs().keySet().iterator().next();
stage.addServerActionCommand(task.getImplementationClass(),
+ getManagementController().getAuthName(),
Role.AMBARI_SERVER_ACTION,
RoleCommand.EXECUTE,
cluster.getClusterName(),
http://git-wip-us.apache.org/repos/asf/ambari/blob/43f916b9/ambari-server/src/main/java/org/apache/ambari/server/serveraction/ServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/ServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/ServerAction.java
index 99e3029..b9bf5ce 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/ServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/ServerAction.java
@@ -30,7 +30,8 @@ import java.util.concurrent.ConcurrentMap;
*/
public interface ServerAction {
- public static final String ACTION_NAME = "ACTION_NAME";
+ public static final String ACTION_NAME = "ACTION_NAME";
+ public static final String ACTION_USER_NAME = "ACTION_USER_NAME";
/**
http://git-wip-us.apache.org/repos/asf/ambari/blob/43f916b9/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/ConfigureAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/ConfigureAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/ConfigureAction.java
index 12a0c5e..a687c5e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/ConfigureAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/ConfigureAction.java
@@ -25,9 +25,11 @@ import java.util.concurrent.ConcurrentMap;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.actionmanager.HostRoleStatus;
import org.apache.ambari.server.agent.CommandReport;
+import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.ConfigurationRequest;
import org.apache.ambari.server.serveraction.AbstractServerAction;
+import org.apache.ambari.server.serveraction.ServerAction;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.Config;
@@ -62,6 +64,12 @@ public class ConfigureAction extends AbstractServerAction {
private ConfigHelper m_configHelper;
/**
+ * The Ambari configuration.
+ */
+ @Inject
+ private Configuration configuration;
+
+ /**
* {@inheritDoc}
*/
@Override
@@ -108,8 +116,14 @@ public class ConfigureAction extends AbstractServerAction {
String serviceVersionNote = "Stack Upgrade";
+ String auditName = getExecutionCommand().getRoleParams().get(ServerAction.ACTION_USER_NAME);
+
+ if (auditName == null) {
+ auditName = configuration.getAnonymousAuditName();
+ }
+
m_configHelper.createConfigType(cluster, m_controller, configType,
- config.getProperties(), m_controller.getAuthName(), serviceVersionNote);
+ config.getProperties(), auditName, serviceVersionNote);
String message = "Updated ''{0}'' with ''{1}={2}''";
message = MessageFormat.format(message, configType, key, value);
http://git-wip-us.apache.org/repos/asf/ambari/blob/43f916b9/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/StageTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/StageTest.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/StageTest.java
new file mode 100644
index 0000000..cd424d4
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/StageTest.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.actionmanager;
+
+import org.apache.ambari.server.Role;
+import org.apache.ambari.server.RoleCommand;
+import org.apache.ambari.server.serveraction.ServerAction;
+import org.apache.ambari.server.serveraction.upgrades.ConfigureAction;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostServerActionEvent;
+import org.apache.ambari.server.utils.StageUtils;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Stage tests.
+ */
+public class StageTest {
+
+ private static final String SERVER_HOST_NAME = StageUtils.getHostName();
+ private static final String CLUSTER_HOST_INFO = "{all_hosts=["
+ + SERVER_HOST_NAME + "], slave_hosts=["
+ + SERVER_HOST_NAME + "]}";
+
+
+ @Test
+ public void testAddServerActionCommand_userName() throws Exception {
+ final Stage stage = new Stage((long) 1, "/tmp", "cluster1", (long) 978, "context", CLUSTER_HOST_INFO,
+ "{\"host_param\":\"param_value\"}", "{\"stage_param\":\"param_value\"}");
+
+ stage.addServerActionCommand(ConfigureAction.class.getName(),
+ "user1", Role.AMBARI_SERVER_ACTION,
+ RoleCommand.EXECUTE,
+ "cluster1", SERVER_HOST_NAME,
+ new ServiceComponentHostServerActionEvent(StageUtils.getHostName(), System.currentTimeMillis()),
+ Collections.<String, String>emptyMap(), null, null, 1200, false);
+
+ List<ExecutionCommandWrapper> executionCommands = stage.getExecutionCommands(SERVER_HOST_NAME);
+ assertEquals(1, executionCommands.size());
+
+ String actionUserName = executionCommands.get(0).getExecutionCommand().getRoleParams().get(ServerAction.ACTION_USER_NAME);
+
+ assertEquals("user1", actionUserName);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/43f916b9/ambari-server/src/test/java/org/apache/ambari/server/serveraction/ServerActionExecutorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/ServerActionExecutorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/ServerActionExecutorTest.java
index 3a1dea6..580351f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/ServerActionExecutorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/ServerActionExecutorTest.java
@@ -95,7 +95,7 @@ public class ServerActionExecutorTest {
"{\"host_param\":\"param_value\"}", "{\"stage_param\":\"param_value\"}");
stage.addServerActionCommand(ManualStageAction.class.getName(),
- Role.AMBARI_SERVER_ACTION,
+ null, Role.AMBARI_SERVER_ACTION,
RoleCommand.EXECUTE,
"cluster1", SERVER_HOST_NAME,
new ServiceComponentHostServerActionEvent(StageUtils.getHostName(), System.currentTimeMillis()),