You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2014/01/13 23:09:04 UTC

[7/7] git commit: AMBARI-4270. Add decommission support for TaskTracker and modify support for DataNode to match

AMBARI-4270. Add decommission support for TaskTracker and modify support for DataNode to match


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/5d3677f7
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5d3677f7
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5d3677f7

Branch: refs/heads/trunk
Commit: 5d3677f7485f4d1016a9caaa105e6be42813bce8
Parents: c869765
Author: Sumit Mohanty <sm...@hortonworks.com>
Authored: Mon Jan 13 14:08:35 2014 -0800
Committer: Sumit Mohanty <sm...@hortonworks.com>
Committed: Mon Jan 13 14:08:35 2014 -0800

----------------------------------------------------------------------
 .../libraries/script/script.py                  |    4 +-
 .../java/org/apache/ambari/server/Role.java     |    1 -
 .../ambari/server/actionmanager/Stage.java      |   14 +-
 .../controller/AmbariActionExecutionHelper.java |    2 +-
 .../AmbariCustomCommandExecutionHelper.java     |  688 +-
 .../AmbariCustomCommandExecutionHelperImpl.java |  593 --
 .../AmbariManagementControllerImpl.java         |   49 +-
 .../server/controller/ControllerModule.java     |    2 +-
 .../controller/ServiceComponentHostRequest.java |   18 +
 .../ServiceComponentHostResponse.java           |   63 +-
 .../internal/HostComponentResourceProvider.java |   96 +-
 .../ambari/server/metadata/ActionMetadata.java  |   13 +-
 .../HostComponentDesiredStateEntity.java        |   16 +-
 .../server/state/HostComponentAdminState.java   |   34 +
 .../ambari/server/state/ServiceComponent.java   |    2 +
 .../server/state/ServiceComponentHost.java      |    4 +
 .../state/ServiceComponentHostFactory.java      |    3 +-
 .../server/state/ServiceComponentImpl.java      |   98 +-
 .../svccomphost/ServiceComponentHostImpl.java   |   72 +-
 .../apache/ambari/server/utils/StageUtils.java  |  205 +-
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |    2 +-
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |    2 +-
 .../resources/Ambari-DDL-Postgres-CREATE.sql    |    2 +-
 .../src/main/resources/properties.json          |    1 +
 .../1.3.4/hooks/before-START/scripts/params.py  |   10 -
 .../scripts/shared_initialization.py            |   11 -
 .../HDP/1.3.4/services/HBASE/metainfo.xml       |   10 +
 .../stacks/HDP/1.3.4/services/HDFS/metainfo.xml |   10 +
 .../HDFS/package/scripts/hdfs_namenode.py       |   20 +
 .../services/HDFS/package/scripts/namenode.py   |    7 +
 .../services/HDFS/package/scripts/params.py     |    4 +
 .../package/templates/exclude_hosts_list.j2     |    3 +
 .../HDP/1.3.4/services/MAPREDUCE/metainfo.xml   |   10 +
 .../MAPREDUCE/package/scripts/jobtracker.py     |   22 +
 .../MAPREDUCE/package/scripts/params.py         |    6 +-
 .../package/templates/exclude_hosts_list.j2     |    3 +
 .../2.0.8/hooks/before-START/scripts/params.py  |   10 -
 .../scripts/shared_initialization.py            |   11 -
 .../HDP/2.0.8/services/HBASE/metainfo.xml       |   20 +-
 .../stacks/HDP/2.0.8/services/HDFS/metainfo.xml |   10 +
 .../HDFS/package/scripts/hdfs_namenode.py       |   27 +
 .../services/HDFS/package/scripts/namenode.py   |    7 +
 .../services/HDFS/package/scripts/params.py     |    4 +
 .../package/templates/exclude_hosts_list.j2     |    3 +
 .../stacks/HDP/2.0.8/services/YARN/metainfo.xml |   10 +
 .../upgrade/ddl/Ambari-DDL-MySQL-UPGRADE.sql    |    7 +-
 .../upgrade/ddl/Ambari-DDL-Oracle-UPGRADE.sql   |    3 +
 .../ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql   |    3 +
 .../api/util/StackExtensionHelperTest.java      |   36 +-
 .../AmbariManagementControllerTest.java         |  491 +-
 .../HostComponentResourceProviderTest.java      |    8 +-
 .../internal/HostResourceProviderTest.java      |   36 +-
 .../internal/ServiceResourceProviderTest.java   |   49 +-
 .../server/state/ServiceComponentTest.java      |   10 +-
 .../server/state/cluster/ClusterTest.java       |    4 +-
 .../svccomphost/ServiceComponentHostTest.java   |   12 +-
 .../ambari/server/utils/TestStageUtils.java     |   23 +-
 .../services/HDFS/configuration/core-site.xml   |  167 +
 .../services/HDFS/configuration/global.xml      |  192 +
 .../HDFS/configuration/hadoop-policy.xml        |  134 +
 .../services/HDFS/configuration/hdfs-site.xml   |  513 ++
 .../stacks/HDP/2.0.7/services/HDFS/metainfo.xml |  152 +
 .../stacks/HDP/2.0.7/services/HDFS/metrics.json | 7800 ++++++++++++++++++
 .../HDFS/package/files/checkForFormat.sh        |   62 +
 .../services/HDFS/package/files/checkWebUI.py   |   53 +
 .../services/HDFS/package/scripts/datanode.py   |   57 +
 .../HDFS/package/scripts/hdfs_client.py         |   49 +
 .../HDFS/package/scripts/hdfs_datanode.py       |   56 +
 .../HDFS/package/scripts/hdfs_namenode.py       |  180 +
 .../HDFS/package/scripts/hdfs_snamenode.py      |   53 +
 .../HDFS/package/scripts/journalnode.py         |   74 +
 .../services/HDFS/package/scripts/namenode.py   |   61 +
 .../services/HDFS/package/scripts/params.py     |  180 +
 .../HDFS/package/scripts/service_check.py       |  107 +
 .../services/HDFS/package/scripts/snamenode.py  |   64 +
 .../HDFS/package/scripts/status_params.py       |   31 +
 .../services/HDFS/package/scripts/utils.py      |  138 +
 .../services/HDFS/package/scripts/zkfc_slave.py |   62 +
 .../services/HIVE/configuration/hive-site.xml   |  267 +
 .../stacks/HDP/2.0.7/services/HIVE/metainfo.xml |   47 +
 .../services/HIVE/package/files/addMysqlUser.sh |   41 +
 .../services/HIVE/package/files/hcatSmoke.sh    |   35 +
 .../services/HIVE/package/files/hiveSmoke.sh    |   23 +
 .../services/HIVE/package/files/hiveserver2.sql |   23 +
 .../HIVE/package/files/hiveserver2Smoke.sh      |   31 +
 .../services/HIVE/package/files/pigSmoke.sh     |   18 +
 .../HIVE/package/files/startHiveserver2.sh      |   22 +
 .../HIVE/package/files/startMetastore.sh        |   22 +
 .../services/HIVE/package/scripts/__init__.py   |   19 +
 .../2.0.7/services/HIVE/package/scripts/hcat.py |   47 +
 .../HIVE/package/scripts/hcat_client.py         |   43 +
 .../HIVE/package/scripts/hcat_service_check.py  |   63 +
 .../2.0.7/services/HIVE/package/scripts/hive.py |  122 +
 .../HIVE/package/scripts/hive_client.py         |   41 +
 .../HIVE/package/scripts/hive_metastore.py      |   63 +
 .../HIVE/package/scripts/hive_server.py         |   63 +
 .../HIVE/package/scripts/hive_service.py        |   56 +
 .../HIVE/package/scripts/mysql_server.py        |   77 +
 .../HIVE/package/scripts/mysql_service.py       |   44 +
 .../services/HIVE/package/scripts/params.py     |  123 +
 .../HIVE/package/scripts/service_check.py       |   56 +
 .../HIVE/package/scripts/status_params.py       |   30 +
 .../HIVE/package/templates/hcat-env.sh.j2       |   25 +
 .../HIVE/package/templates/hive-env.sh.j2       |   55 +
 .../stacks/HDP/2.0.7/services/YARN/metainfo.xml |  178 +-
 105 files changed, 13482 insertions(+), 1221 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/5d3677f7/ambari-agent/src/main/python/resource_management/libraries/script/script.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/libraries/script/script.py b/ambari-agent/src/main/python/resource_management/libraries/script/script.py
index b8c9d83..702aafe 100644
--- a/ambari-agent/src/main/python/resource_management/libraries/script/script.py
+++ b/ambari-agent/src/main/python/resource_management/libraries/script/script.py
@@ -98,7 +98,7 @@ class Script(object):
       # Non-zero exit code is interpreted as an INSTALLED status of a component
       sys.exit(1)
     except Fail:
-      logger.exception("Got exception while executing command {0}:".format(command_name))
+      logger.exception("Error while executing command '{0}':".format(command_name))
       sys.exit(1)
 
 
@@ -108,7 +108,7 @@ class Script(object):
     """
     self_methods = dir(self)
     if not command_name in self_methods:
-      raise Fail("Script {0} has not method '{1}'".format(sys.argv[0], command_name))
+      raise Fail("Script '{0}' has no method '{1}'".format(sys.argv[0], command_name))
     method = getattr(self, command_name)
     return method
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d3677f7/ambari-server/src/main/java/org/apache/ambari/server/Role.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/Role.java b/ambari-server/src/main/java/org/apache/ambari/server/Role.java
index f579062..9eff713 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/Role.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/Role.java
@@ -53,7 +53,6 @@ public class Role {
   
   public static final Role AMBARI_SERVER_ACTION = valueOf("AMBARI_SERVER_ACTION"); 
   public static final Role DATANODE = valueOf("DATANODE");
-  public static final Role DECOMMISSION_DATANODE = valueOf("DECOMMISSION_DATANODE");
   public static final Role FLUME_SERVER = valueOf("FLUME_SERVER");
   public static final Role GANGLIA_MONITOR = valueOf("GANGLIA_MONITOR");
   public static final Role GANGLIA_SERVER = valueOf("GANGLIA_SERVER");

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d3677f7/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 3a9cc5c..c0272ec 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
@@ -50,11 +50,7 @@ public class Stage {
   private long stageId = -1;
   private final String logDir;
   private final String requestContext;
-  private final String clusterHostInfo;
-
-  public String getClusterHostInfo() {
-    return clusterHostInfo;
-  }
+  private String clusterHostInfo;
 
   private int taskTimeout = -1;
   private int perTaskTimeFactor = 60000;
@@ -147,6 +143,14 @@ public class Stage {
     return commands;
   }
 
+  public String getClusterHostInfo() {
+    return clusterHostInfo;
+  }
+
+  public void setClusterHostInfo(String clusterHostInfo) {
+    this.clusterHostInfo = clusterHostInfo;
+  }
+
   public synchronized void setStageId(long stageId) {
     if (this.stageId != -1) {
       throw new RuntimeException("Attempt to set stageId again! Not allowed.");

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d3677f7/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
index fb7ac0c..4e32f2a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
@@ -295,7 +295,7 @@ public class AmbariActionExecutionHelper {
 
       // Generate cluster host info
       execCmd.setClusterHostInfo(
-          StageUtils.getClusterHostInfo(clusters.getHostsForCluster(clusterName), cluster, hostsMap, configuration));
+          StageUtils.getClusterHostInfo(clusters.getHostsForCluster(clusterName), cluster));
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d3677f7/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
index 6165f59..0ac7e6a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
@@ -1,37 +1,675 @@
+/**
+ * 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.controller;
 
+import com.google.gson.Gson;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.Stage;
+import org.apache.ambari.server.agent.ExecutionCommand;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.metadata.ActionMetadata;
 import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.CommandScriptDefinition;
+import org.apache.ambari.server.state.ComponentInfo;
+import org.apache.ambari.server.state.ConfigHelper;
+import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.HostComponentAdminState;
+import org.apache.ambari.server.state.RepositoryInfo;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.state.ServiceInfo;
+import org.apache.ambari.server.state.ServiceOsSpecific;
+import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpInProgressEvent;
+import org.apache.ambari.server.utils.StageUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMMAND_TIMEOUT;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMMAND_TIMEOUT_DEFAULT;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.CUSTOM_COMMAND;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.DB_DRIVER_FILENAME;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.DB_NAME;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JAVA_HOME;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JCE_NAME;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JDK_LOCATION;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JDK_NAME;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.MYSQL_JDBC_URL;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.ORACLE_JDBC_URL;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.PACKAGE_LIST;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.REPO_INFO;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCHEMA_VERSION;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCRIPT;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCRIPT_TYPE;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SERVICE_METADATA_FOLDER;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SERVICE_REPO_INFO;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_NAME;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_VERSION;
+
+
+/**
+ * Helper class containing logic to process custom command execution requests .
+ * This class has special support needed for SERVICE_CHECK and DECOMMISSION.
+ * These commands are not pass through as Ambari has specific persistence requirements.
+ */
+@Singleton
+public class AmbariCustomCommandExecutionHelper {
+  private final static Logger LOG =
+      LoggerFactory.getLogger(AmbariCustomCommandExecutionHelper.class);
+  // TODO: Remove the hard-coded mapping when stack definition indicates which slave types can be decommissioned
+  private static final Map<String, String> masterToSlaveMappingForDecom = new HashMap<String, String>();
+
+  static {
+    masterToSlaveMappingForDecom.put("NAMENODE", "DATANODE");
+    masterToSlaveMappingForDecom.put("RESOURCEMANAGER", "NODEMANAGER");
+    masterToSlaveMappingForDecom.put("HBASE_MASTER", "HBASE_REGIONSERVER");
+    masterToSlaveMappingForDecom.put("JOBTRACKER", "TASKTRACKER");
+  }
+
+  private static String DECOM_INCLUDED_HOSTS = "included_hosts";
+  private static String DECOM_EXCLUDED_HOSTS = "excluded_hosts";
+  private static String DECOM_SLAVE_COMPONENT = "slave_type";
+  @Inject
+  private ActionMetadata actionMetadata;
+  @Inject
+  private Clusters clusters;
+  @Inject
+  private AmbariManagementController amc;
+  @Inject
+  private Gson gson;
+  @Inject
+  private Configuration configs;
+  @Inject
+  private AmbariMetaInfo ambariMetaInfo;
+  @Inject
+  private ConfigHelper configHelper;
+  ;
+
+  private Boolean isServiceCheckCommand(String command, String service) {
+    List<String> actions = actionMetadata.getActions(service);
+    if (actions == null || actions.size() == 0) {
+      return false;
+    }
+
+    if (!actions.contains(command)) {
+      return false;
+    }
+
+    return true;
+  }
+
+  private Boolean isValidCustomCommand(ExecuteActionRequest actionRequest) throws AmbariException {
+    String clustername = actionRequest.getClusterName();
+    Cluster cluster = clusters.getCluster(clustername);
+    StackId stackId = cluster.getDesiredStackVersion();
+    String serviceName = actionRequest.getServiceName();
+    String componentName = actionRequest.getComponentName();
+    String commandName = actionRequest.getCommandName();
+
+    if (componentName == null) {
+      return false;
+    }
+    ComponentInfo componentInfo = ambariMetaInfo.getComponent(
+        stackId.getStackName(), stackId.getStackVersion(),
+        serviceName, componentName);
+
+    if (!componentInfo.isCustomCommand(commandName) &&
+        !actionMetadata.isDefaultHostComponentCommand(commandName)) {
+      return false;
+    }
+    return true;
+  }
+
+  public void validateCustomCommand(ExecuteActionRequest actionRequest) throws AmbariException {
+    if (actionRequest.getServiceName() == null
+        || actionRequest.getServiceName().isEmpty()
+        || actionRequest.getCommandName() == null
+        || actionRequest.getCommandName().isEmpty()) {
+      throw new AmbariException("Invalid request : " + "cluster="
+          + actionRequest.getClusterName() + ", service="
+          + actionRequest.getServiceName() + ", command="
+          + actionRequest.getCommandName());
+    }
+
+    LOG.info("Received a command execution request"
+        + ", clusterName=" + actionRequest.getClusterName()
+        + ", serviceName=" + actionRequest.getServiceName()
+        + ", request=" + actionRequest.toString());
+
+    if (!isServiceCheckCommand(actionRequest.getCommandName(), actionRequest.getServiceName())
+        && !isValidCustomCommand(actionRequest)) {
+      throw new AmbariException(
+          "Unsupported action " + actionRequest.getCommandName() + " for Service: " + actionRequest.getServiceName()
+              + " and Component: " + actionRequest.getComponentName());
+    }
+  }
+
+  /**
+   * Other than Service_Check and Decommission all other commands are pass-through
+   *
+   * @param actionRequest   received request to execute a command
+   * @param stage           the initial stage for task creation
+   * @param hostLevelParams specific parameters for the hosts
+   * @throws AmbariException
+   */
+  public void addAction(ExecuteActionRequest actionRequest, Stage stage,
+                        Map<String, String> hostLevelParams)
+      throws AmbariException {
+    if (actionRequest.getCommandName().contains("SERVICE_CHECK")) {
+      findHostAndAddServiceCheckAction(actionRequest, stage, hostLevelParams);
+    } else if (actionRequest.getCommandName().equals("DECOMMISSION")) {
+      addDecommissionAction(actionRequest, stage, hostLevelParams);
+    } else if (isValidCustomCommand(actionRequest)) {
+      addCustomCommandAction(actionRequest, stage, hostLevelParams);
+    } else {
+      throw new AmbariException("Unsupported action " + actionRequest.getCommandName());
+    }
+  }
+
+  private void addCustomCommandAction(ExecuteActionRequest actionRequest,
+                                      Stage stage, Map<String, String> hostLevelParams)
+      throws AmbariException {
+
+    if (actionRequest.getHosts().isEmpty()) {
+      throw new AmbariException("Invalid request : No hosts specified.");
+    }
+
+    String serviceName = actionRequest.getServiceName();
+    String componentName = actionRequest.getComponentName();
+    String commandName = actionRequest.getCommandName();
+
+    String clusterName = stage.getClusterName();
+    Cluster cluster = clusters.getCluster(clusterName);
+    StackId stackId = cluster.getDesiredStackVersion();
+    AmbariMetaInfo ambariMetaInfo = amc.getAmbariMetaInfo();
+    ServiceInfo serviceInfo =
+        ambariMetaInfo.getServiceInfo(stackId.getStackName(),
+            stackId.getStackVersion(), serviceName);
+
+    long nowTimestamp = System.currentTimeMillis();
+
+    for (String hostName : actionRequest.getHosts()) {
+
+      stage.addHostRoleExecutionCommand(hostName, Role.valueOf(componentName),
+          RoleCommand.CUSTOM_COMMAND,
+          new ServiceComponentHostOpInProgressEvent(componentName,
+              hostName, nowTimestamp), cluster.getClusterName(), serviceName);
+
+      Map<String, Map<String, String>> configurations =
+          new TreeMap<String, Map<String, String>>();
+      Map<String, Map<String, String>> configTags =
+          amc.findConfigurationTagsWithOverrides(cluster, hostName);
+
+      ExecutionCommand execCmd = stage.getExecutionCommandWrapper(hostName,
+          componentName).getExecutionCommand();
+
+      execCmd.setConfigurations(configurations);
+      execCmd.setConfigurationTags(configTags);
+
+      execCmd.setClusterHostInfo(
+          StageUtils.getClusterHostInfo(clusters.getHostsForCluster(clusterName), cluster));
+
+      if (hostLevelParams == null) {
+        hostLevelParams = new TreeMap<String, String>();
+      }
+      hostLevelParams.put(JDK_LOCATION, amc.getJdkResourceUrl());
+      hostLevelParams.put(JAVA_HOME, amc.getJavaHome());
+      hostLevelParams.put(JDK_NAME, amc.getJDKName());
+      hostLevelParams.put(JCE_NAME, amc.getJCEName());
+      hostLevelParams.put(STACK_NAME, stackId.getStackName());
+      hostLevelParams.put(STACK_VERSION, stackId.getStackVersion());
+      hostLevelParams.put(CUSTOM_COMMAND, commandName);
+      execCmd.setHostLevelParams(hostLevelParams);
+
+      Map<String, String> commandParams = new TreeMap<String, String>();
+      commandParams.put(SCHEMA_VERSION, serviceInfo.getSchemaVersion());
+
+      String commandTimeout = COMMAND_TIMEOUT_DEFAULT;
+
+      if (serviceInfo.getSchemaVersion().equals(AmbariMetaInfo.SCHEMA_VERSION_2)) {
+        // Service check command is not custom command
+        ComponentInfo componentInfo = ambariMetaInfo.getComponent(
+            stackId.getStackName(), stackId.getStackVersion(),
+            serviceName, componentName);
+        CommandScriptDefinition script = componentInfo.getCommandScript();
+
+        if (script != null) {
+          commandParams.put(SCRIPT, script.getScript());
+          commandParams.put(SCRIPT_TYPE, script.getScriptType().toString());
+          commandTimeout = String.valueOf(script.getTimeout());
+        } else {
+          String message = String.format("Component %s has not command script " +
+              "defined. It is not possible to run service check" +
+              " for this service", componentName);
+          throw new AmbariException(message);
+        }
+        // We don't need package/repo infomation to perform service check
+      }
+      commandParams.put(COMMAND_TIMEOUT, commandTimeout);
+
+      commandParams.put(SERVICE_METADATA_FOLDER,
+          serviceInfo.getServiceMetadataFolder());
+
+      execCmd.setCommandParams(commandParams);
+
+    }
+  }
+
+  private void findHostAndAddServiceCheckAction(ExecuteActionRequest actionRequest, Stage stage,
+                                                Map<String, String> hostLevelParams)
+      throws AmbariException {
+    String clusterName = actionRequest.getClusterName();
+    String componentName = actionMetadata.getClient(actionRequest
+        .getServiceName());
+    String serviceName = actionRequest.getServiceName();
+    String smokeTestRole = actionRequest.getCommandName();
+    long nowTimestamp = System.currentTimeMillis();
+    Map<String, String> actionParameters = actionRequest.getParameters();
+
+    String hostName;
+    if (componentName != null) {
+      Map<String, ServiceComponentHost> components = clusters
+          .getCluster(clusterName).getService(actionRequest.getServiceName())
+          .getServiceComponent(componentName).getServiceComponentHosts();
+
+      if (components.isEmpty()) {
+        throw new AmbariException("Hosts not found, component="
+            + componentName + ", service=" + actionRequest.getServiceName()
+            + ", cluster=" + clusterName);
+      }
+      hostName = amc.getHealthyHost(components.keySet());
+    } else {
+      Map<String, ServiceComponent> components = clusters
+          .getCluster(clusterName).getService(actionRequest.getServiceName())
+          .getServiceComponents();
+
+      if (components.isEmpty()) {
+        throw new AmbariException("Components not found, service="
+            + actionRequest.getServiceName() + ", cluster=" + clusterName);
+      }
+
+      ServiceComponent serviceComponent = components.values().iterator()
+          .next();
+
+      if (serviceComponent.getServiceComponentHosts().isEmpty()) {
+        throw new AmbariException("Hosts not found, component="
+            + serviceComponent.getName() + ", service="
+            + actionRequest.getServiceName() + ", cluster=" + clusterName);
+      }
+
+      hostName = serviceComponent.getServiceComponentHosts().keySet()
+          .iterator().next();
+    }
+
+
+    addServiceCheckAction(stage, hostName, smokeTestRole, nowTimestamp,
+        serviceName, componentName, actionParameters,
+        hostLevelParams);
+  }
+
+  /**
+   * Creates and populates service check EXECUTION_COMMAND for host.
+   * Not all EXECUTION_COMMAND parameters are populated here because they
+   * are not needed by service check.
+   */
+  public void addServiceCheckAction(Stage stage,
+                                    String hostname, String smokeTestRole,
+                                    long nowTimestamp,
+                                    String serviceName,
+                                    String componentName,
+                                    Map<String, String> actionParameters,
+                                    Map<String, String> hostLevelParams)
+      throws AmbariException {
+
+    String clusterName = stage.getClusterName();
+    Cluster cluster = clusters.getCluster(clusterName);
+    StackId stackId = cluster.getDesiredStackVersion();
+    AmbariMetaInfo ambariMetaInfo = amc.getAmbariMetaInfo();
+    ServiceInfo serviceInfo =
+        ambariMetaInfo.getServiceInfo(stackId.getStackName(),
+            stackId.getStackVersion(), serviceName);
+
+
+    stage.addHostRoleExecutionCommand(hostname,
+        Role.valueOf(smokeTestRole),
+        RoleCommand.SERVICE_CHECK,
+        new ServiceComponentHostOpInProgressEvent(componentName, hostname,
+            nowTimestamp), cluster.getClusterName(), serviceName);
+
+    // [ type -> [ key, value ] ]
+    Map<String, Map<String, String>> configurations =
+        new TreeMap<String, Map<String, String>>();
+    Map<String, Map<String, String>> configTags =
+        amc.findConfigurationTagsWithOverrides(cluster, hostname);
+
+    ExecutionCommand execCmd = stage.getExecutionCommandWrapper(hostname,
+        smokeTestRole).getExecutionCommand();
+
+    execCmd.setConfigurations(configurations);
+    execCmd.setConfigurationTags(configTags);
+
+    // Generate cluster host info
+    execCmd.setClusterHostInfo(
+        StageUtils.getClusterHostInfo(clusters.getHostsForCluster(clusterName), cluster));
+
+    if (hostLevelParams == null) {
+      hostLevelParams = new TreeMap<String, String>();
+    }
+    hostLevelParams.put(JDK_LOCATION, amc.getJdkResourceUrl());
+    hostLevelParams.put(JAVA_HOME, amc.getJavaHome());
+    hostLevelParams.put(JDK_NAME, amc.getJDKName());
+    hostLevelParams.put(JCE_NAME, amc.getJCEName());
+    hostLevelParams.put(STACK_NAME, stackId.getStackName());
+    hostLevelParams.put(STACK_VERSION, stackId.getStackVersion());
+    hostLevelParams.putAll(amc.getRcaParameters());
+    execCmd.setHostLevelParams(hostLevelParams);
+
+    Map<String, String> commandParams = new TreeMap<String, String>();
+    commandParams.put(SCHEMA_VERSION, serviceInfo.getSchemaVersion());
+
+    String commandTimeout = COMMAND_TIMEOUT_DEFAULT;
+
+
+    if (serviceInfo.getSchemaVersion().equals(AmbariMetaInfo.SCHEMA_VERSION_2)) {
+      // Service check command is not custom command
+      CommandScriptDefinition script = serviceInfo.getCommandScript();
+      if (script != null) {
+        commandParams.put(SCRIPT, script.getScript());
+        commandParams.put(SCRIPT_TYPE, script.getScriptType().toString());
+        commandTimeout = String.valueOf(script.getTimeout());
+      } else {
+        String message = String.format("Service %s has no command script " +
+            "defined. It is not possible to run service check" +
+            " for this service", serviceName);
+        throw new AmbariException(message);
+      }
+      // We don't need package/repo information to perform service check
+    }
+    commandParams.put(COMMAND_TIMEOUT, commandTimeout);
+
+    commandParams.put(SERVICE_METADATA_FOLDER,
+        serviceInfo.getServiceMetadataFolder());
+
+    execCmd.setCommandParams(commandParams);
+
+    if (actionParameters != null) { // If defined
+      execCmd.setRoleParams(actionParameters);
+    }
+
+  }
+
+  private Set<String> getHostList(Map<String, String> cmdParameters, String key) {
+    Set<String> hosts = new HashSet<String>();
+    if (cmdParameters.containsKey(key)) {
+      String allHosts = cmdParameters.get(key);
+      if (allHosts != null) {
+        for (String hostName : allHosts.trim().split(",")) {
+          hosts.add(hostName.trim());
+        }
+      }
+    }
+    return hosts;
+  }
+
+  /**
+   * Processes decommission command. Modifies the host components as needed and then
+   * calls into the implementation of a custom command
+   */
+  private void addDecommissionAction(ExecuteActionRequest request, Stage stage,
+                                     Map<String, String> hostLevelParams)
+      throws AmbariException {
+
+    String clusterName = request.getClusterName();
+    Cluster cluster = clusters.getCluster(clusterName);
+    String serviceName = request.getServiceName();
+
+    if (request.getHosts() != null && request.getHosts().size() != 0) {
+      throw new AmbariException("Decommission command cannot be issued with target host(s) specified.");
+    }
+
+    //Get all hosts to be added and removed
+    Set<String> excludedHosts = getHostList(request.getParameters(), DECOM_EXCLUDED_HOSTS);
+    Set<String> includedHosts = getHostList(request.getParameters(), DECOM_INCLUDED_HOSTS);
+    String slaveCompType = request.getParameters().get(DECOM_SLAVE_COMPONENT);
+
+    Set<String> cloneSet = new HashSet<String>(excludedHosts);
+    cloneSet.retainAll(includedHosts);
+    if (cloneSet.size() > 0) {
+      throw new AmbariException("Same host cannot be specified for inclusion as well as exclusion. Hosts: "
+          + cloneSet.toString());
+    }
+
+    Service service = cluster.getService(serviceName);
+    if (service == null) {
+      throw new AmbariException("Specified service " + serviceName + " is not a valid/deployed service.");
+    }
+
+    String masterCompType = request.getComponentName();
+    Map<String, ServiceComponent> svcComponents = service.getServiceComponents();
+    if (!svcComponents.containsKey(masterCompType)) {
+      throw new AmbariException("Specified component " + masterCompType + " does not belong to service "
+          + serviceName + ".");
+    }
+
+    ServiceComponent masterComponent = svcComponents.get(masterCompType);
+    if (!masterComponent.isMasterComponent()) {
+      throw new AmbariException("Specified component " + masterCompType + " is not a MASTER for service "
+          + serviceName + ".");
+    }
+
+    if (!masterToSlaveMappingForDecom.containsKey(masterCompType)) {
+      throw new AmbariException("Decommissioning is not supported for " + masterCompType);
+    }
+
+    // Find the slave component
+    if (slaveCompType == null || slaveCompType.equals("")) {
+      slaveCompType = masterToSlaveMappingForDecom.get(masterCompType);
+    } else if (!masterToSlaveMappingForDecom.get(masterCompType).equals(slaveCompType)) {
+      throw new AmbariException("Component " + slaveCompType + " is not supported for decommissioning.");
+    }
+
+    // Set/reset decommissioned flag on all components
+    for (ServiceComponentHost sch : svcComponents.get(slaveCompType).getServiceComponentHosts().values()) {
+      if (excludedHosts.contains(sch.getHostName())) {
+        sch.setComponentAdminState(HostComponentAdminState.DECOMMISSIONED);
+        LOG.info("Adding " + slaveCompType + " host to decommissioned list : " + sch.getHostName());
+      }
+      if (includedHosts.contains(sch.getHostName())) {
+        sch.setComponentAdminState(HostComponentAdminState.INSERVICE);
+        LOG.info("Removing " + slaveCompType + " host from the decommissioned list: " + sch.getHostName());
+      }
+    }
+
+    Set<String> masterHosts = masterComponent.getServiceComponentHosts().keySet();
+    ExecuteActionRequest commandRequest = new ExecuteActionRequest(
+        request.getClusterName(), request.getCommandName(), request.getActionName(), request.getServiceName(),
+        masterComponent.getName(), new ArrayList<String>(masterHosts), null);
+
+    String clusterHostInfoJson = StageUtils.getGson().toJson(
+        StageUtils.getClusterHostInfo(clusters.getHostsForCluster(cluster.getClusterName()), cluster));
+
+    // Reset cluster host info as it has changed
+    stage.setClusterHostInfo(clusterHostInfoJson);
+
+    addCustomCommandAction(commandRequest, stage, hostLevelParams);
+  }
+
+  /**
+   * Creates and populates an EXECUTION_COMMAND for host
+   */
+  public void createHostAction(Cluster cluster,
+                               Stage stage, ServiceComponentHost scHost,
+                               Map<String, Map<String, String>> configurations,
+                               Map<String, Map<String, String>> configTags,
+                               RoleCommand roleCommand,
+                               Map<String, String> commandParams,
+                               ServiceComponentHostEvent event)
+      throws AmbariException {
+
+    stage.addHostRoleExecutionCommand(scHost.getHostName(), Role.valueOf(scHost
+        .getServiceComponentName()), roleCommand,
+        event, scHost.getClusterName(),
+        scHost.getServiceName());
+    String serviceName = scHost.getServiceName();
+    String componentName = event.getServiceComponentName();
+    String hostname = scHost.getHostName();
+    String osType = clusters.getHost(hostname).getOsType();
+    StackId stackId = cluster.getDesiredStackVersion();
+    ServiceInfo serviceInfo = ambariMetaInfo.getServiceInfo(stackId.getStackName(),
+        stackId.getStackVersion(), serviceName);
+    ComponentInfo componentInfo = ambariMetaInfo.getComponent(
+        stackId.getStackName(), stackId.getStackVersion(),
+        serviceName, componentName);
+
+    ExecutionCommand execCmd = stage.getExecutionCommandWrapper(scHost.getHostName(),
+        scHost.getServiceComponentName()).getExecutionCommand();
+
+    Host host = clusters.getHost(scHost.getHostName());
+
+    // Hack - Remove passwords from configs
+    if (event.getServiceComponentName().equals(Role.HIVE_CLIENT.toString())) {
+      configHelper.applyCustomConfig(configurations, Configuration.HIVE_CONFIG_TAG,
+          Configuration.HIVE_METASTORE_PASSWORD_PROPERTY, "", true);
+    }
+
+    execCmd.setConfigurations(configurations);
+    execCmd.setConfigurationTags(configTags);
+    if (commandParams == null) { // if not defined
+      commandParams = new TreeMap<String, String>();
+    }
+    commandParams.put(SCHEMA_VERSION, serviceInfo.getSchemaVersion());
+
+
+    // Get command script info for custom command/custom action
+    /*
+     * TODO: Custom actions are not supported yet, that's why we just pass
+     * component main commandScript to agent. This script is only used for
+     * default commads like INSTALL/STOP/START/CONFIGURE
+     */
+    String commandTimeout = ExecutionCommand.KeyNames.COMMAND_TIMEOUT_DEFAULT;
+    CommandScriptDefinition script = componentInfo.getCommandScript();
+    if (serviceInfo.getSchemaVersion().equals(AmbariMetaInfo.SCHEMA_VERSION_2)) {
+      if (script != null) {
+        commandParams.put(SCRIPT, script.getScript());
+        commandParams.put(SCRIPT_TYPE, script.getScriptType().toString());
+        commandTimeout = String.valueOf(script.getTimeout());
+      } else {
+        String message = String.format("Component %s of service %s has no " +
+            "command script defined", componentName, serviceName);
+        throw new AmbariException(message);
+      }
+    }
+    commandParams.put(COMMAND_TIMEOUT, commandTimeout);
+    commandParams.put(SERVICE_METADATA_FOLDER,
+        serviceInfo.getServiceMetadataFolder());
+
+    execCmd.setCommandParams(commandParams);
+
+    Map<String, List<RepositoryInfo>> repos = ambariMetaInfo.getRepository(
+        stackId.getStackName(), stackId.getStackVersion());
+    String repoInfo = "";
+    if (!repos.containsKey(host.getOsType())) {
+      // FIXME should this be an error?
+      LOG.warn("Could not retrieve repo information for host"
+          + ", hostname=" + scHost.getHostName()
+          + ", clusterName=" + cluster.getClusterName()
+          + ", stackInfo=" + stackId.getStackId());
+    } else {
+      repoInfo = gson.toJson(repos.get(host.getOsType()));
+    }
+
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Sending repo information to agent"
+          + ", hostname=" + scHost.getHostName()
+          + ", clusterName=" + cluster.getClusterName()
+          + ", stackInfo=" + stackId.getStackId()
+          + ", repoInfo=" + repoInfo);
+    }
+
+    Map<String, String> hostParams = new TreeMap<String, String>();
+    // TODO: Move parameter population to org.apache.ambari.server.controller.AmbariManagementControllerImpl.createAction()
+    hostParams.put(REPO_INFO, repoInfo);
+    hostParams.put(JDK_LOCATION, amc.getJdkResourceUrl());
+    hostParams.put(JAVA_HOME, amc.getJavaHome());
+    hostParams.put(JDK_NAME, amc.getJDKName());
+    hostParams.put(JCE_NAME, amc.getJCEName());
+    hostParams.put(STACK_NAME, stackId.getStackName());
+    hostParams.put(STACK_VERSION, stackId.getStackVersion());
+    hostParams.put(DB_NAME, amc.getServerDB());
+    hostParams.put(MYSQL_JDBC_URL, amc.getMysqljdbcUrl());
+    hostParams.put(ORACLE_JDBC_URL, amc.getOjdbcUrl());
+    hostParams.putAll(amc.getRcaParameters());
+
+    // Write down os specific info for the service
+    ServiceOsSpecific anyOs = null;
+    if (serviceInfo.getOsSpecifics().containsKey(AmbariMetaInfo.ANY_OS)) {
+      anyOs = serviceInfo.getOsSpecifics().get(AmbariMetaInfo.ANY_OS);
+    }
+    ServiceOsSpecific hostOs = null;
+    if (serviceInfo.getOsSpecifics().containsKey(osType)) {
+      hostOs = serviceInfo.getOsSpecifics().get(osType);
+      // Choose repo that is relevant for host
+      ServiceOsSpecific.Repo serviceRepo = hostOs.getRepo();
+      if (serviceRepo != null) {
+        String serviceRepoInfo = gson.toJson(serviceRepo);
+        hostParams.put(SERVICE_REPO_INFO, serviceRepoInfo);
+      }
+    }
+    // Build package list that is relevant for host
+    List<ServiceOsSpecific.Package> packages =
+        new ArrayList<ServiceOsSpecific.Package>();
+    if (anyOs != null) {
+      packages.addAll(anyOs.getPackages());
+    }
+
+    if (hostOs != null) {
+      packages.addAll(hostOs.getPackages());
+    }
+    String packageList = gson.toJson(packages);
+    hostParams.put(PACKAGE_LIST, packageList);
+
+    if (configs.getServerDBName().equalsIgnoreCase(Configuration
+        .ORACLE_DB_NAME)) {
+      hostParams.put(DB_DRIVER_FILENAME, configs.getOjdbcJarName());
+    } else if (configs.getServerDBName().equalsIgnoreCase(Configuration
+        .MYSQL_DB_NAME)) {
+      hostParams.put(DB_DRIVER_FILENAME, configs.getMySQLJarName());
+    }
+    execCmd.setHostLevelParams(hostParams);
 
-public interface AmbariCustomCommandExecutionHelper {
-  void validateCustomCommand(ExecuteActionRequest actionRequest) throws AmbariException;
-
-  void addAction(ExecuteActionRequest actionRequest, Stage stage,
-                 HostsMap hostsMap, Map<String, String> hostLevelParams)
-      throws AmbariException;
-
-  void addServiceCheckActionImpl(Stage stage,
-                                 String hostname, String smokeTestRole,
-                                 long nowTimestamp,
-                                 String serviceName,
-                                 String componentName,
-                                 Map<String, String> roleParameters,
-                                 HostsMap hostsMap,
-                                 Map<String, String> hostLevelParams)
-              throws AmbariException;
-
-  void createHostAction(Cluster cluster,
-                        Stage stage, ServiceComponentHost scHost,
-                        Map<String, Map<String, String>> configurations,
-                        Map<String, Map<String, String>> configTags,
-                        RoleCommand roleCommand,
-                        Map<String, String> commandParams,
-                        ServiceComponentHostEvent event)
-                      throws AmbariException;
+    Map<String, String> roleParams = new TreeMap<String, String>();
+    execCmd.setRoleParams(roleParams);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d3677f7/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperImpl.java
deleted file mode 100644
index 8c5d733..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperImpl.java
+++ /dev/null
@@ -1,593 +0,0 @@
-/**
- * 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.controller;
-
-import com.google.gson.Gson;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.Role;
-import org.apache.ambari.server.RoleCommand;
-import org.apache.ambari.server.actionmanager.Stage;
-import org.apache.ambari.server.agent.ExecutionCommand;
-import org.apache.ambari.server.api.services.AmbariMetaInfo;
-import org.apache.ambari.server.configuration.Configuration;
-import org.apache.ambari.server.metadata.ActionMetadata;
-import org.apache.ambari.server.state.*;
-import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpInProgressEvent;
-import org.apache.ambari.server.utils.StageUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.*;
-
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.*;
-
-
-/**
- * Helper class containing logic to process custom command execution requests
- */
-@Singleton
-public class AmbariCustomCommandExecutionHelperImpl implements AmbariCustomCommandExecutionHelper {
-  private final static Logger LOG =
-      LoggerFactory.getLogger(AmbariCustomCommandExecutionHelperImpl.class);
-
-  @Inject
-  private ActionMetadata actionMetadata;
-  @Inject
-  private Clusters clusters;
-  @Inject
-  private AmbariManagementController amc;
-  @Inject
-  private Gson gson;
-  @Inject
-  private Configuration configs;
-  @Inject
-  private AmbariMetaInfo ambariMetaInfo;
-  @Inject
-  private ConfigHelper configHelper;
-
-
-  @Override
-  public void validateCustomCommand(ExecuteActionRequest actionRequest) throws AmbariException {
-    if (actionRequest.getServiceName() == null
-        || actionRequest.getServiceName().isEmpty()
-        || actionRequest.getCommandName() == null
-        || actionRequest.getCommandName().isEmpty()) {
-      throw new AmbariException("Invalid request : " + "cluster="
-          + actionRequest.getClusterName() + ", service="
-          + actionRequest.getServiceName() + ", command="
-          + actionRequest.getCommandName());
-    }
-
-    LOG.info("Received a command execution request"
-        + ", clusterName=" + actionRequest.getClusterName()
-        + ", serviceName=" + actionRequest.getServiceName()
-        + ", request=" + actionRequest.toString());
-
-    if (!isValidCommand(actionRequest.getCommandName(),
-      actionRequest.getServiceName()) && !isValidCustomCommand(actionRequest)) {
-      throw new AmbariException(
-          "Unsupported action " + actionRequest.getCommandName() + " for " + actionRequest.getServiceName());
-    }
-  }
-
-  private Boolean isValidCommand(String command, String service) {
-    List<String> actions = actionMetadata.getActions(service);
-    if (actions == null || actions.size() == 0) {
-      return false;
-    }
-
-    if (!actions.contains(command)) {
-      return false;
-    }
-
-    return true;
-  }
-
-  private Boolean isValidCustomCommand(ExecuteActionRequest actionRequest) throws AmbariException {
-    String clustername = actionRequest.getClusterName();
-    Cluster cluster = clusters.getCluster(clustername);
-    StackId stackId = cluster.getDesiredStackVersion();
-    String serviceName = actionRequest.getServiceName();
-    String componentName = actionRequest.getComponentName();
-    String commandName = actionRequest.getCommandName();
-
-    if (componentName == null) {
-      return false;
-    }
-    ComponentInfo componentInfo = ambariMetaInfo.getComponent(
-      stackId.getStackName(), stackId.getStackVersion(),
-      serviceName, componentName);
-
-    if (!componentInfo.isCustomCommand(commandName) &&
-      !actionMetadata.isDefaultHostComponentCommand(commandName)) {
-      return false;
-    }
-    return true;
-  }
-
-  @Override
-  public void addAction(ExecuteActionRequest actionRequest, Stage stage,
-                        HostsMap hostsMap, Map<String, String> hostLevelParams)
-      throws AmbariException {
-    if (actionRequest.getCommandName().contains("SERVICE_CHECK")) {
-      addServiceCheckAction(actionRequest, stage, hostsMap, hostLevelParams);
-    } else if (actionRequest.getCommandName().equals("DECOMMISSION_DATANODE")) {
-      addDecommissionDatanodeAction(actionRequest, stage, hostLevelParams);
-    } else if (isValidCustomCommand(actionRequest)) {
-      addCustomcommandAction(actionRequest, stage, hostsMap, hostLevelParams);
-    } else {
-      throw new AmbariException("Unsupported action " + actionRequest.getCommandName());
-    }
-  }
-
-  private void addCustomcommandAction(ExecuteActionRequest actionRequest,
-    Stage stage, HostsMap hostsMap, Map<String, String> hostLevelParams)
-    throws AmbariException {
-
-    if (actionRequest.getHosts().isEmpty()) {
-      throw new AmbariException("Invalid request : No hosts specified.");
-    }
-
-    String serviceName = actionRequest.getServiceName();
-    String componentName = actionRequest.getComponentName();
-    String commandName = actionRequest.getCommandName();
-
-    String clusterName = stage.getClusterName();
-    Cluster cluster = clusters.getCluster(clusterName);
-    StackId stackId = cluster.getDesiredStackVersion();
-    AmbariMetaInfo ambariMetaInfo = amc.getAmbariMetaInfo();
-    ServiceInfo serviceInfo =
-      ambariMetaInfo.getServiceInfo(stackId.getStackName(),
-        stackId.getStackVersion(), serviceName);
-
-    long nowTimestamp = System.currentTimeMillis();
-
-    for (String hostName: actionRequest.getHosts()) {
-
-      stage.addHostRoleExecutionCommand(hostName, Role.valueOf(componentName),
-        RoleCommand.CUSTOM_COMMAND,
-        new ServiceComponentHostOpInProgressEvent(componentName,
-        hostName, nowTimestamp), cluster.getClusterName(), serviceName);
-
-      Map<String, Map<String, String>> configurations =
-        new TreeMap<String, Map<String, String>>();
-      Map<String, Map<String, String>> configTags =
-        amc.findConfigurationTagsWithOverrides(cluster, hostName);
-
-      ExecutionCommand execCmd =  stage.getExecutionCommandWrapper(hostName,
-        componentName).getExecutionCommand();
-
-      execCmd.setConfigurations(configurations);
-      execCmd.setConfigurationTags(configTags);
-
-      execCmd.setClusterHostInfo(
-        StageUtils.getClusterHostInfo(clusters.getHostsForCluster(clusterName), cluster, hostsMap, configs));
-
-      if (hostLevelParams == null) {
-        hostLevelParams = new TreeMap<String, String>();
-      }
-      hostLevelParams.put(JDK_LOCATION, amc.getJdkResourceUrl());
-      hostLevelParams.put(JAVA_HOME, amc.getJavaHome());
-      hostLevelParams.put(JDK_NAME, amc.getJDKName());
-      hostLevelParams.put(JCE_NAME, amc.getJCEName());
-      hostLevelParams.put(STACK_NAME, stackId.getStackName());
-      hostLevelParams.put(STACK_VERSION,stackId.getStackVersion());
-      hostLevelParams.put(CUSTOM_COMMAND, commandName);
-      execCmd.setHostLevelParams(hostLevelParams);
-
-      Map<String,String> commandParams = new TreeMap<String, String>();
-      commandParams.put(SCHEMA_VERSION, serviceInfo.getSchemaVersion());
-
-      String commandTimeout = COMMAND_TIMEOUT_DEFAULT;
-
-      if (serviceInfo.getSchemaVersion().equals(AmbariMetaInfo.SCHEMA_VERSION_2)) {
-        // Service check command is not custom command
-        ComponentInfo componentInfo = ambariMetaInfo.getComponent(
-          stackId.getStackName(), stackId.getStackVersion(),
-          serviceName, componentName);
-        CommandScriptDefinition script = componentInfo.getCommandScript();
-
-        if (script != null) {
-          commandParams.put(SCRIPT, script.getScript());
-          commandParams.put(SCRIPT_TYPE, script.getScriptType().toString());
-          commandTimeout = String.valueOf(script.getTimeout());
-        } else {
-          String message = String.format("Component %s has not command script " +
-            "defined. It is not possible to run service check" +
-            " for this service", componentName);
-          throw new AmbariException(message);
-        }
-        // We don't need package/repo infomation to perform service check
-      }
-      commandParams.put(COMMAND_TIMEOUT, commandTimeout);
-
-      commandParams.put(SERVICE_METADATA_FOLDER,
-        serviceInfo.getServiceMetadataFolder());
-
-      execCmd.setCommandParams(commandParams);
-
-    }
-  }
-
-  private void addServiceCheckAction(ExecuteActionRequest actionRequest, Stage stage,
-                                     HostsMap hostsMap,
-                                     Map<String, String> hostLevelParams)
-      throws AmbariException {
-    String clusterName = actionRequest.getClusterName();
-    String componentName = actionMetadata.getClient(actionRequest
-        .getServiceName());
-    String serviceName = actionRequest.getServiceName();
-    String smokeTestRole = actionRequest.getCommandName();
-    long nowTimestamp = System.currentTimeMillis();
-    Map<String, String> roleParameters = actionRequest.getParameters();
-
-    String hostName;
-    if (componentName != null) {
-      Map<String, ServiceComponentHost> components = clusters
-          .getCluster(clusterName).getService(actionRequest.getServiceName())
-          .getServiceComponent(componentName).getServiceComponentHosts();
-
-      if (components.isEmpty()) {
-        throw new AmbariException("Hosts not found, component="
-            + componentName + ", service=" + actionRequest.getServiceName()
-            + ", cluster=" + clusterName);
-      }
-      hostName = amc.getHealthyHost(components.keySet());
-    } else {
-      Map<String, ServiceComponent> components = clusters
-          .getCluster(clusterName).getService(actionRequest.getServiceName())
-          .getServiceComponents();
-
-      if (components.isEmpty()) {
-        throw new AmbariException("Components not found, service="
-            + actionRequest.getServiceName() + ", cluster=" + clusterName);
-      }
-
-      ServiceComponent serviceComponent = components.values().iterator()
-          .next();
-
-      if (serviceComponent.getServiceComponentHosts().isEmpty()) {
-        throw new AmbariException("Hosts not found, component="
-            + serviceComponent.getName() + ", service="
-            + actionRequest.getServiceName() + ", cluster=" + clusterName);
-      }
-
-      hostName = serviceComponent.getServiceComponentHosts().keySet()
-          .iterator().next();
-    }
-
-
-    addServiceCheckActionImpl(stage, hostName, smokeTestRole, nowTimestamp,
-            serviceName, componentName, roleParameters, hostsMap,
-            hostLevelParams);
-  }
-
-
-
-  /**
-   * Creates and populates service check EXECUTION_COMMAND for host.
-   * Not all EXECUTION_COMMAND parameters are populated here because they
-   * are not needed by service check.
-   */
-  @Override
-  public void addServiceCheckActionImpl(Stage stage,
-                                        String hostname, String smokeTestRole,
-                                        long nowTimestamp,
-                                        String serviceName,
-                                        String componentName,
-                                        Map<String, String> roleParameters,
-                                        HostsMap hostsMap,
-                                        Map<String, String> hostLevelParams)
-          throws AmbariException{
-
-    String clusterName = stage.getClusterName();
-    Cluster cluster = clusters.getCluster(clusterName);
-    StackId stackId = cluster.getDesiredStackVersion();
-    AmbariMetaInfo ambariMetaInfo = amc.getAmbariMetaInfo();
-    ServiceInfo serviceInfo =
-            ambariMetaInfo.getServiceInfo(stackId.getStackName(),
-              stackId.getStackVersion(), serviceName);
-
-
-    stage.addHostRoleExecutionCommand(hostname,
-            Role.valueOf(smokeTestRole),
-            RoleCommand.SERVICE_CHECK,
-            new ServiceComponentHostOpInProgressEvent(componentName, hostname,
-                    nowTimestamp), cluster.getClusterName(), serviceName);
-
-    // [ type -> [ key, value ] ]
-    Map<String, Map<String, String>> configurations =
-            new TreeMap<String, Map<String, String>>();
-    Map<String, Map<String, String>> configTags =
-            amc.findConfigurationTagsWithOverrides(cluster, hostname);
-
-    ExecutionCommand execCmd =  stage.getExecutionCommandWrapper(hostname,
-            smokeTestRole).getExecutionCommand();
-
-    execCmd.setConfigurations(configurations);
-    execCmd.setConfigurationTags(configTags);
-
-    // Generate cluster host info
-    execCmd.setClusterHostInfo(
-            StageUtils.getClusterHostInfo(clusters.getHostsForCluster(clusterName), cluster, hostsMap, configs));
-
-    if (hostLevelParams == null) {
-      hostLevelParams = new TreeMap<String, String>();
-    }
-    hostLevelParams.put(JDK_LOCATION, amc.getJdkResourceUrl());
-    hostLevelParams.put(JAVA_HOME, amc.getJavaHome());
-    hostLevelParams.put(JDK_NAME, amc.getJDKName());
-    hostLevelParams.put(JCE_NAME, amc.getJCEName());
-    hostLevelParams.put(STACK_NAME, stackId.getStackName());
-    hostLevelParams.put(STACK_VERSION,stackId.getStackVersion());
-    hostLevelParams.putAll(amc.getRcaParameters());
-    execCmd.setHostLevelParams(hostLevelParams);
-
-    Map<String,String> commandParams = new TreeMap<String, String>();
-    commandParams.put(SCHEMA_VERSION, serviceInfo.getSchemaVersion());
-
-    String commandTimeout = COMMAND_TIMEOUT_DEFAULT;
-
-
-    if (serviceInfo.getSchemaVersion().equals(AmbariMetaInfo.SCHEMA_VERSION_2)) {
-      // Service check command is not custom command
-      CommandScriptDefinition script = serviceInfo.getCommandScript();
-      if (script != null) {
-        commandParams.put(SCRIPT, script.getScript());
-        commandParams.put(SCRIPT_TYPE, script.getScriptType().toString());
-        commandTimeout = String.valueOf(script.getTimeout());
-      } else {
-        String message = String.format("Service %s has no command script " +
-                "defined. It is not possible to run service check" +
-                " for this service", serviceName);
-        throw new AmbariException(message);
-      }
-      // We don't need package/repo infomation to perform service check
-    }
-    commandParams.put(COMMAND_TIMEOUT, commandTimeout);
-
-    commandParams.put(SERVICE_METADATA_FOLDER,
-            serviceInfo.getServiceMetadataFolder());
-
-    execCmd.setCommandParams(commandParams);
-
-    if (roleParameters != null) { // If defined
-      execCmd.setRoleParams(roleParameters);
-    }
-
-  }
-
-  private void addDecommissionDatanodeAction(ExecuteActionRequest decommissionRequest, Stage stage,
-                                             Map<String, String> hostLevelParams)
-      throws AmbariException {
-    String hdfsExcludeFileType = "hdfs-exclude-file";
-    // Find hdfs admin host, just decommission from namenode.
-    String clusterName = decommissionRequest.getClusterName();
-    Cluster cluster = clusters.getCluster(clusterName);
-    String serviceName = decommissionRequest.getServiceName();
-    String namenodeHost = clusters.getCluster(clusterName)
-        .getService(serviceName).getServiceComponent(Role.NAMENODE.toString())
-        .getServiceComponentHosts().keySet().iterator().next();
-
-    String excludeFileTag = null;
-    if (decommissionRequest.getParameters() != null
-        && (decommissionRequest.getParameters().get("excludeFileTag") != null)) {
-      excludeFileTag = decommissionRequest.getParameters()
-          .get("excludeFileTag");
-    }
-
-    if (excludeFileTag == null) {
-      throw new AmbariException("No exclude file specified"
-          + " when decommissioning datanodes. Provide parameter excludeFileTag with the tag for config type "
-          + hdfsExcludeFileType);
-    }
-
-    Config config = clusters.getCluster(clusterName).getConfig(
-        hdfsExcludeFileType, excludeFileTag);
-    if (config == null) {
-      throw new AmbariException("Decommissioning datanodes requires the cluster to be associated with config type " +
-          hdfsExcludeFileType + " with a list of datanodes to be decommissioned (\"datanodes\" : list).");
-    }
-
-    LOG.info("Decommissioning data nodes: " + config.getProperties().get("datanodes") +
-        " " + hdfsExcludeFileType + " tag: " + excludeFileTag);
-
-    Map<String, Map<String, String>> configurations =
-        new TreeMap<String, Map<String, String>>();
-
-
-    Map<String, Map<String, String>> configTags = amc.findConfigurationTagsWithOverrides(cluster, namenodeHost);
-
-    // Add the tag for hdfs-exclude-file
-    Map<String, String> excludeTags = new HashMap<String, String>();
-    excludeTags.put(ConfigHelper.CLUSTER_DEFAULT_TAG, config.getVersionTag());
-    configTags.put(hdfsExcludeFileType, excludeTags);
-
-    stage.addHostRoleExecutionCommand(
-        namenodeHost,
-        Role.DECOMMISSION_DATANODE,
-        RoleCommand.EXECUTE,
-        new ServiceComponentHostOpInProgressEvent(Role.DECOMMISSION_DATANODE
-            .toString(), namenodeHost, System.currentTimeMillis()),
-        clusterName, serviceName);
-
-    ExecutionCommand execCmd = stage.getExecutionCommandWrapper(namenodeHost,
-        Role.DECOMMISSION_DATANODE.toString()).getExecutionCommand();
-
-    execCmd.setConfigurations(configurations);
-    execCmd.setConfigurationTags(configTags);
-    /*
-     TODO: When migrating to custom services, datanode decommision
-     probably will be implemented as a custom action; that's why
-     we have no schema version 2 command parameters here
-    */
-    execCmd.setHostLevelParams(hostLevelParams);
-  }
-
-
-  /**
-   * Creates and populates an EXECUTION_COMMAND for host
-   */
-  @Override
-  public void createHostAction(Cluster cluster,
-                               Stage stage, ServiceComponentHost scHost,
-                               Map<String, Map<String, String>> configurations,
-                               Map<String, Map<String, String>> configTags,
-                               RoleCommand roleCommand,
-                               Map<String, String> commandParams,
-                               ServiceComponentHostEvent event)
-          throws AmbariException {
-
-    stage.addHostRoleExecutionCommand(scHost.getHostName(), Role.valueOf(scHost
-            .getServiceComponentName()), roleCommand,
-            event, scHost.getClusterName(),
-            scHost.getServiceName());
-    String serviceName = scHost.getServiceName();
-    String componentName = event.getServiceComponentName();
-    String hostname = scHost.getHostName();
-    String osType = clusters.getHost(hostname).getOsType();
-    StackId stackId = cluster.getDesiredStackVersion();
-    ServiceInfo serviceInfo = ambariMetaInfo.getServiceInfo(stackId.getStackName(),
-            stackId.getStackVersion(), serviceName);
-    ComponentInfo componentInfo = ambariMetaInfo.getComponent(
-            stackId.getStackName(), stackId.getStackVersion(),
-            serviceName, componentName);
-
-    ExecutionCommand execCmd = stage.getExecutionCommandWrapper(scHost.getHostName(),
-            scHost.getServiceComponentName()).getExecutionCommand();
-
-    Host host = clusters.getHost(scHost.getHostName());
-
-    // Hack - Remove passwords from configs
-    if (event.getServiceComponentName().equals(Role.HIVE_CLIENT.toString())) {
-      configHelper.applyCustomConfig(configurations, Configuration.HIVE_CONFIG_TAG,
-              Configuration.HIVE_METASTORE_PASSWORD_PROPERTY, "", true);
-    }
-
-    execCmd.setConfigurations(configurations);
-    execCmd.setConfigurationTags(configTags);
-    if (commandParams == null) { // if not defined
-      commandParams = new TreeMap<String, String>();
-    }
-    commandParams.put(SCHEMA_VERSION, serviceInfo.getSchemaVersion());
-
-
-    // Get command script info for custom command/custom action
-    /*
-     * TODO: Custom actions are not supported yet, that's why we just pass
-     * component main commandScript to agent. This script is only used for
-     * default commads like INSTALL/STOP/START/CONFIGURE
-     */
-    String commandTimeout = ExecutionCommand.KeyNames.COMMAND_TIMEOUT_DEFAULT;
-    CommandScriptDefinition script = componentInfo.getCommandScript();
-    if (serviceInfo.getSchemaVersion().equals(AmbariMetaInfo.SCHEMA_VERSION_2)) {
-      if (script != null) {
-        commandParams.put(SCRIPT, script.getScript());
-        commandParams.put(SCRIPT_TYPE, script.getScriptType().toString());
-        commandTimeout = String.valueOf(script.getTimeout());
-      } else {
-        String message = String.format("Component %s of service %s has not " +
-                "command script defined", componentName, serviceName);
-        throw new AmbariException(message);
-      }
-    }
-    commandParams.put(COMMAND_TIMEOUT, commandTimeout);
-    commandParams.put(SERVICE_METADATA_FOLDER,
-            serviceInfo.getServiceMetadataFolder());
-
-    execCmd.setCommandParams(commandParams);
-
-    Map<String, List<RepositoryInfo>> repos = ambariMetaInfo.getRepository(
-            stackId.getStackName(), stackId.getStackVersion());
-    String repoInfo = "";
-    if (!repos.containsKey(host.getOsType())) {
-      // FIXME should this be an error?
-      LOG.warn("Could not retrieve repo information for host"
-              + ", hostname=" + scHost.getHostName()
-              + ", clusterName=" + cluster.getClusterName()
-              + ", stackInfo=" + stackId.getStackId());
-    } else {
-      repoInfo = gson.toJson(repos.get(host.getOsType()));
-    }
-
-    if (LOG.isDebugEnabled()) {
-      LOG.debug("Sending repo information to agent"
-              + ", hostname=" + scHost.getHostName()
-              + ", clusterName=" + cluster.getClusterName()
-              + ", stackInfo=" + stackId.getStackId()
-              + ", repoInfo=" + repoInfo);
-    }
-
-    Map<String, String> hostParams = new TreeMap<String, String>();
-    // TODO: Move parameter population to org.apache.ambari.server.controller.AmbariManagementControllerImpl.createAction()
-    hostParams.put(REPO_INFO, repoInfo);
-    hostParams.put(JDK_LOCATION, amc.getJdkResourceUrl());
-    hostParams.put(JAVA_HOME, amc.getJavaHome());
-    hostParams.put(JDK_NAME, amc.getJDKName());
-    hostParams.put(JCE_NAME, amc.getJCEName());
-    hostParams.put(STACK_NAME, stackId.getStackName());
-    hostParams.put(STACK_VERSION, stackId.getStackVersion());
-    hostParams.put(DB_NAME, amc.getServerDB());
-    hostParams.put(MYSQL_JDBC_URL, amc.getMysqljdbcUrl());
-    hostParams.put(ORACLE_JDBC_URL, amc.getOjdbcUrl());
-    hostParams.putAll(amc.getRcaParameters());
-
-    // Write down os specific info for the service
-    ServiceOsSpecific anyOs = null;
-    if (serviceInfo.getOsSpecifics().containsKey(AmbariMetaInfo.ANY_OS)) {
-      anyOs = serviceInfo.getOsSpecifics().get(AmbariMetaInfo.ANY_OS);
-    }
-    ServiceOsSpecific hostOs = null;
-    if (serviceInfo.getOsSpecifics().containsKey(osType)) {
-      hostOs = serviceInfo.getOsSpecifics().get(osType);
-      // Choose repo that is relevant for host
-      ServiceOsSpecific.Repo serviceRepo= hostOs.getRepo();
-      if (serviceRepo != null) {
-        String serviceRepoInfo = gson.toJson(serviceRepo);
-        hostParams.put(SERVICE_REPO_INFO, serviceRepoInfo);
-      }
-    }
-    // Build package list that is relevant for host
-    List<ServiceOsSpecific.Package> packages =
-            new ArrayList<ServiceOsSpecific.Package>();
-    if (anyOs != null) {
-      packages.addAll(anyOs.getPackages());
-    }
-
-    if (hostOs != null) {
-      packages.addAll(hostOs.getPackages());
-    }
-    String packageList = gson.toJson(packages);
-    hostParams.put(PACKAGE_LIST, packageList);
-
-    if (configs.getServerDBName().equalsIgnoreCase(Configuration
-            .ORACLE_DB_NAME)) {
-      hostParams.put(DB_DRIVER_FILENAME, configs.getOjdbcJarName());
-    } else if (configs.getServerDBName().equalsIgnoreCase(Configuration
-            .MYSQL_DB_NAME)) {
-      hostParams.put(DB_DRIVER_FILENAME, configs.getMySQLJarName());
-    }
-    execCmd.setHostLevelParams(hostParams);
-
-    Map<String, String> roleParams = new TreeMap<String, String>();
-    execCmd.setRoleParams(roleParams);
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d3677f7/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index afff8e4..570e574 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -457,8 +457,7 @@ public class AmbariManagementControllerImpl implements
       boolean isClient = compInfo.isClient();
 
       ServiceComponentHost sch =
-          serviceComponentHostFactory.createNew(sc, request.getHostname(),
-              isClient);
+          serviceComponentHostFactory.createNew(sc, request.getHostname());
 
       if (request.getDesiredState() != null
           && !request.getDesiredState().isEmpty()) {
@@ -538,7 +537,10 @@ public class AmbariManagementControllerImpl implements
 
   private Stage createNewStage(Cluster cluster, long requestId, String requestContext, String clusterHostInfo) {
     String logDir = BASE_LOG_DIR + File.pathSeparator + requestId;
-    return stageFactory.createNew(requestId, logDir, cluster.getClusterName(), requestContext, clusterHostInfo);
+    Stage stage =
+        stageFactory.createNew(requestId, logDir, cluster.getClusterName(), requestContext, clusterHostInfo);
+    stage.setStageId(0);
+    return stage;
   }
 
 
@@ -691,6 +693,14 @@ public class AmbariManagementControllerImpl implements
                 && (desiredStateToCheck != sch.getDesiredState())) {
               continue;
             }
+            if (request.getAdminState() != null) {
+              String stringToMatch =
+                  sch.getComponentAdminState() == null ? "" : sch.getComponentAdminState().name();
+              if (!request.getAdminState().equals(stringToMatch)) {
+                continue;
+              }
+            }
+
             ServiceComponentHostResponse r = sch.convertToResponse();
             if (filterBasedConfigStaleness && r.isStaleConfig() != staleConfig) {
               continue;
@@ -714,6 +724,14 @@ public class AmbariManagementControllerImpl implements
               continue;
             }
 
+            if (request.getAdminState() != null) {
+              String stringToMatch =
+                  sch.getComponentAdminState() == null ? "" : sch.getComponentAdminState().name();
+              if (!request.getAdminState().equals(stringToMatch)) {
+                continue;
+              }
+            }
+
             ServiceComponentHostResponse r = sch.convertToResponse();
             if (filterBasedConfigStaleness && r.isStaleConfig() != staleConfig) {
               continue;
@@ -1082,15 +1100,12 @@ public class AmbariManagementControllerImpl implements
 
       // FIXME cannot work with a single stage
       // multiple stages may be needed for reconfigure
-      long stageId = 0;
       Map<String, Set<String>> clusterHostInfo = StageUtils.getClusterHostInfo(
-          clusters.getHostsForCluster(cluster.getClusterName()), cluster, hostsMap, injector.getInstance(Configuration.class));
-      
-      
+          clusters.getHostsForCluster(cluster.getClusterName()), cluster);
+
       String clusterHostInfoJson = StageUtils.getGson().toJson(clusterHostInfo);
       
       Stage stage = createNewStage(cluster, requestId, requestContext, clusterHostInfoJson);
-      stage.setStageId(stageId);
 
       //HACK
       String jobtrackerHost = getJobTrackerHost(cluster);
@@ -1263,9 +1278,9 @@ public class AmbariManagementControllerImpl implements
           continue;
         }
         Configuration configuration = injector.getInstance(Configuration.class);
-        customCommandExecutionHelper.addServiceCheckActionImpl(stage, clientHost,
-                smokeTestRole, nowTimestamp, serviceName,
-                null, null, hostsMap, null);
+        customCommandExecutionHelper.addServiceCheckAction(stage, clientHost,
+            smokeTestRole, nowTimestamp, serviceName,
+            null, null, null);
 
       }
 
@@ -1582,6 +1597,11 @@ public class AmbariManagementControllerImpl implements
           + ", cluster name, component name and host name should be"
           + " provided");
     }
+
+    if (request.getAdminState() != null) {
+      throw new IllegalArgumentException("Property adminState cannot be modified through update. Use service " +
+          "specific DECOMMISSION action to decommision/recommission components.");
+    }
   }
 
   private String findServiceName(Cluster cluster, String componentName) throws AmbariException {
@@ -2019,14 +2039,11 @@ public class AmbariManagementControllerImpl implements
     }
 
     Map<String, Set<String>> clusterHostInfo = StageUtils.getClusterHostInfo(
-        clusters.getHostsForCluster(cluster.getClusterName()), cluster, hostsMap,
-        configs);
+        clusters.getHostsForCluster(cluster.getClusterName()), cluster);
 
     String clusterHostInfoJson = StageUtils.getGson().toJson(clusterHostInfo);
     Stage stage = createNewStage(cluster, actionManager.getNextRequestId(), requestContext, clusterHostInfoJson);
 
-    stage.setStageId(0);
-
     Map<String, String> params = new TreeMap<String, String>();
     // TODO : Update parameter population to be done only here
     params.put(JDK_LOCATION, this.jdkResourceUrl);
@@ -2034,7 +2051,7 @@ public class AmbariManagementControllerImpl implements
     params.putAll(getRcaParameters());
 
     if (actionRequest.isCommand()) {
-      customCommandExecutionHelper.addAction(actionRequest, stage, hostsMap, params);
+      customCommandExecutionHelper.addAction(actionRequest, stage, params);
     } else {
       actionExecutionHelper.addAction(actionExecContext, stage, configs, hostsMap, params);
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d3677f7/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index b3776e7..b4d96ee 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -104,7 +104,7 @@ public class ControllerModule extends AbstractModule {
     bind(SecureRandom.class).in(Scopes.SINGLETON);
 
     bind(Clusters.class).to(ClustersImpl.class);
-    bind(AmbariCustomCommandExecutionHelper.class).to(AmbariCustomCommandExecutionHelperImpl.class);
+    bind(AmbariCustomCommandExecutionHelper.class);
     bind(ActionDBAccessor.class).to(ActionDBAccessorImpl.class);
     bind(CustomActionDBAccessor.class).to(CustomActionDBAccessorImpl.class);
     bindConstant().annotatedWith(Names.named("schedulerSleeptime")).to(10000L);

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d3677f7/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
index 13cbde9..6b673b0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
@@ -35,6 +35,8 @@ public class ServiceComponentHostRequest {
   private String desiredStackId; // UPDATE
 
   private String staleConfig; // GET - predicate
+
+  private String adminState; // GET - predicate
   
   public ServiceComponentHostRequest(String clusterName,
                                      String serviceName,
@@ -147,6 +149,20 @@ public class ServiceComponentHostRequest {
     return this.staleConfig;
   }
 
+  /**
+   * @param adminState the adminState to use as predicate
+   */
+  public void setAdminState(String adminState) {
+    this.adminState = adminState;
+  }
+
+  /**
+   * @return the admin state of the component
+   */
+  public String getAdminState() {
+    return this.adminState;
+  }
+
   public String toString() {
     StringBuilder sb = new StringBuilder();
     sb.append("{"
@@ -156,6 +172,8 @@ public class ServiceComponentHostRequest {
         + ", hostname=" + hostname
         + ", desiredState=" + desiredState
         + ", desiredStackId=" + desiredStackId
+        + ", staleConfig=" + staleConfig
+        + ", adminState=" + adminState
         + "}");
     return sb.toString();
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d3677f7/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java
index d746733..a776ac2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java
@@ -18,7 +18,7 @@
 
 package org.apache.ambari.server.controller;
 
-import org.apache.ambari.server.state.DesiredConfig;
+import org.apache.ambari.server.state.HostComponentAdminState;
 import org.apache.ambari.server.state.HostConfig;
 
 import java.util.Map;
@@ -26,32 +26,24 @@ import java.util.Map;
 public class ServiceComponentHostResponse {
 
   private String clusterName; // REF
-
   private String serviceName;
-
   private String componentName;
-
   private String hostname;
-
   // type -> desired config
   private Map<String, HostConfig> actualConfigs;
-
   private String liveState;
-
   private String stackVersion;
-
   private String desiredStackVersion;
-
   private String desiredState;
-  
   private boolean staleConfig = false;
+  private String adminState = null;
 
 
   public ServiceComponentHostResponse(String clusterName, String serviceName,
                                       String componentName, String hostname,
-                                      String liveState,
-                                      String stackVersion,
-                                      String desiredState, String desiredStackVersion) {
+                                      String liveState, String stackVersion,
+                                      String desiredState, String desiredStackVersion,
+                                      HostComponentAdminState adminState) {
     this.clusterName = clusterName;
     this.serviceName = serviceName;
     this.componentName = componentName;
@@ -60,6 +52,9 @@ public class ServiceComponentHostResponse {
     this.stackVersion = stackVersion;
     this.desiredState = desiredState;
     this.desiredStackVersion = desiredStackVersion;
+    if (adminState != null) {
+      this.adminState = adminState.name();
+    }
   }
 
   /**
@@ -174,10 +169,28 @@ public class ServiceComponentHostResponse {
     this.clusterName = clusterName;
   }
 
+  /**
+   * @return the admin state of the host component
+   */
+  public String getAdminState() {
+    return adminState;
+  }
+
+  /**
+   * @param adminState of the host component
+   */
+  public void setAdminState(String adminState) {
+    this.adminState = adminState;
+  }
+
   @Override
   public boolean equals(Object o) {
-    if (this == o) return true;
-    if (o == null || getClass() != o.getClass()) return false;
+    if (this == o) {
+      return true;
+    }
+    if (o == null || getClass() != o.getClass()) {
+      return false;
+    }
 
     ServiceComponentHostResponse that =
         (ServiceComponentHostResponse) o;
@@ -191,7 +204,7 @@ public class ServiceComponentHostResponse {
       return false;
     }
     if (componentName != null ?
-        !componentName.equals(that.componentName) : that.componentName != null){
+        !componentName.equals(that.componentName) : that.componentName != null) {
       return false;
     }
     if (hostname != null ?
@@ -206,19 +219,12 @@ public class ServiceComponentHostResponse {
   public int hashCode() {
     int result = clusterName != null ? clusterName.hashCode() : 0;
     result = 71 * result + (serviceName != null ? serviceName.hashCode() : 0);
-    result = 71 * result + (componentName != null ? componentName.hashCode():0);
+    result = 71 * result + (componentName != null ? componentName.hashCode() : 0);
     result = 71 * result + (hostname != null ? hostname.hashCode() : 0);
     return result;
   }
 
   /**
-   * @param configs the actual configs
-   */
-  public void setActualConfigs(Map<String, HostConfig> configs) {
-    actualConfigs = configs;
-  }
-  
-  /**
    * @return the actual configs
    */
   public Map<String, HostConfig> getActualConfigs() {
@@ -226,12 +232,19 @@ public class ServiceComponentHostResponse {
   }
 
   /**
+   * @param configs the actual configs
+   */
+  public void setActualConfigs(Map<String, HostConfig> configs) {
+    actualConfigs = configs;
+  }
+
+  /**
    * @return if the configs are stale
    */
   public boolean isStaleConfig() {
     return staleConfig;
   }
-  
+
   /**
    * @param stale
    */