AMBARI-22136 Enable server_action tasks defined in EU/RU upgrade pack xml files to take parameters (dili)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d5dd1938 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d5dd1938 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d5dd1938 Branch: refs/heads/branch-feature-AMBARI-14714 Commit: d5dd19389bd4b43c587f72dd8ab8230e34b98bfc Parents: 0ed128f Author: Di Li <[email protected]> Authored: Thu Oct 5 13:53:46 2017 -0400 Committer: Di Li <[email protected]> Committed: Thu Oct 5 13:53:46 2017 -0400 ---------------------------------------------------------------------- .../ambari/server/actionmanager/Stage.java | 3 +- .../internal/UpgradeResourceProvider.java | 2 + .../stack/upgrade/ServerSideActionTask.java | 15 +++++++ .../state/stack/upgrade/TaskParameter.java | 41 ++++++++++++++++++++ .../src/main/resources/upgrade-pack.xsd | 9 +++++ 5 files changed, 69 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/d5dd1938/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 f466ce9..b88275a 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 @@ -465,7 +465,8 @@ public class Stage { * @param retryAllowed * indicates whether retry after failure is allowed */ - public synchronized void addServerActionCommand(String actionName, @Nullable String userName, + public synchronized void addServerActionCommand(String actionName, + @Nullable String userName, Role role, RoleCommand command, String clusterName, ServiceComponentHostServerActionEvent event, @Nullable Map<String, String> commandParams, @Nullable String commandDetail, @Nullable Map<String, Map<String, String>> configTags, http://git-wip-us.apache.org/repos/asf/ambari/blob/d5dd1938/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 85f3a1b..a1ec98a 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 @@ -1378,6 +1378,8 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider stage.setStageId(stageId); entity.setStageId(Long.valueOf(stageId)); + Map<String, String> taskParameters = task.getParameters(); + commandParams.putAll(taskParameters); stage.addServerActionCommand(task.getImplementationClass(), getManagementController().getAuthName(), Role.AMBARI_SERVER_ACTION, RoleCommand.EXECUTE, cluster.getClusterName(), http://git-wip-us.apache.org/repos/asf/ambari/blob/d5dd1938/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ServerSideActionTask.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ServerSideActionTask.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ServerSideActionTask.java index c593c04..844ef24 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ServerSideActionTask.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ServerSideActionTask.java @@ -18,7 +18,9 @@ package org.apache.ambari.server.state.stack.upgrade; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; @@ -31,6 +33,19 @@ public abstract class ServerSideActionTask extends Task { @XmlAttribute(name="class") protected String implClass; + @XmlElement(name = "parameter") + public List<TaskParameter> parameters; + + public Map<String, String> getParameters(){ + Map<String, String> result = new HashMap<String, String>(); + if (parameters != null) { + for (TaskParameter parameter : parameters) { + result.put(parameter.name, parameter.value); + } + } + return result; + } + public static final String actionVerb = "Executing"; public String getImplementationClass() { http://git-wip-us.apache.org/repos/asf/ambari/blob/d5dd1938/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskParameter.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskParameter.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskParameter.java new file mode 100644 index 0000000..7773a67 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskParameter.java @@ -0,0 +1,41 @@ +/* + * 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.state.stack.upgrade; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlValue; + +/** + * Optional parameter defined in upgrade packs to be used by server actions. + * These parameters are passed to corresponding server action as part of the command parameters. + * */ +public class TaskParameter { + + /** + * Name of the parameter + * */ + @XmlAttribute (name = "name") + public String name; + + /** + * Parameter value + * */ + @XmlValue + public String value; +} http://git-wip-us.apache.org/repos/asf/ambari/blob/d5dd1938/ambari-server/src/main/resources/upgrade-pack.xsd ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/upgrade-pack.xsd b/ambari-server/src/main/resources/upgrade-pack.xsd index 21606bd..79c50a7 100644 --- a/ambari-server/src/main/resources/upgrade-pack.xsd +++ b/ambari-server/src/main/resources/upgrade-pack.xsd @@ -292,6 +292,15 @@ <xs:extension base="abstract-task-type"> <xs:sequence> <xs:element name="message" minOccurs="0" maxOccurs="unbounded" /> + <xs:element name="parameter" minOccurs="0" maxOccurs="unbounded"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="name" /> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> </xs:sequence> </xs:extension> </xs:complexContent>
