ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From magyari_san...@apache.org
Subject [2/2] ambari git commit: AMBARI-18553. Provision actions to happen based only on specified dependencies (magyari_sandor)
Date Thu, 20 Oct 2016 16:22:45 GMT
AMBARI-18553. Provision actions to happen based only on specified dependencies (magyari_sandor)


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

Branch: refs/heads/branch-2.5
Commit: a040cbfc549be03945f1e6b889fcbab16ad0c5f0
Parents: 29945c6
Author: Sandor Magyari <smagyari@hortonworks.com>
Authored: Tue Oct 4 19:23:19 2016 +0200
Committer: Sandor Magyari <smagyari@hortonworks.com>
Committed: Thu Oct 20 18:16:21 2016 +0200

----------------------------------------------------------------------
 .../server/actionmanager/ActionScheduler.java   | 117 ++++++++++++------
 .../actionmanager/CommandExecutionType.java     |  35 ++++++
 .../ambari/server/actionmanager/Stage.java      |  34 ++++-
 .../server/configuration/Configuration.java     |  14 +++
 .../AmbariManagementControllerImpl.java         |  17 ++-
 .../server/controller/ControllerModule.java     |  49 ++++----
 .../CachedRoleCommandOrderProvider.java         | 112 +++++++++++++++++
 .../server/metadata/RoleCommandOrder.java       | 123 ++++++-------------
 .../metadata/RoleCommandOrderProvider.java      |  30 +++++
 .../ambari/server/metadata/RoleCommandPair.java |  68 ++++++++++
 .../ambari/server/orm/entities/StageEntity.java |  17 +++
 .../ambari/server/stageplanner/RoleGraph.java   |  65 ++++++----
 .../server/stageplanner/RoleGraphFactory.java   |   4 +-
 .../stageplanner/RoleGraphFactoryImpl.java      |  54 --------
 .../server/upgrade/UpgradeCatalog250.java       |   7 ++
 .../main/resources/Ambari-DDL-Derby-CREATE.sql  |   1 +
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |   1 +
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |   1 +
 .../resources/Ambari-DDL-Postgres-CREATE.sql    |   1 +
 .../resources/Ambari-DDL-SQLAnywhere-CREATE.sql |   1 +
 .../resources/Ambari-DDL-SQLServer-CREATE.sql   |   1 +
 .../server/controller/KerberosHelperTest.java   |  40 +++---
 .../ActiveWidgetLayoutResourceProviderTest.java |   8 +-
 .../StackUpgradeConfigurationMergeTest.java     |   4 +-
 .../UserAuthorizationResourceProviderTest.java  |  32 +++--
 .../internal/UserResourceProviderTest.java      |   8 +-
 .../internal/ViewURLResourceProviderTest.java   |  65 +++-------
 .../server/metadata/RoleCommandOrderTest.java   |  69 +++++------
 .../ambari/server/metadata/RoleGraphTest.java   |  18 +--
 .../server/stageplanner/TestStagePlanner.java   | 107 +++++++++++-----
 .../cluster/ClusterEffectiveVersionTest.java    |   3 +-
 31 files changed, 714 insertions(+), 392 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
index 8cbfb1e..7a84536 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
@@ -50,6 +50,9 @@ import org.apache.ambari.server.events.ActionFinalReportReceivedEvent;
 import org.apache.ambari.server.events.jpa.EntityManagerCacheInvalidationEvent;
 import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
 import org.apache.ambari.server.events.publishers.JPAEventPublisher;
+import org.apache.ambari.server.metadata.RoleCommandOrder;
+import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
+import org.apache.ambari.server.metadata.RoleCommandPair;
 import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
 import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
 import org.apache.ambari.server.orm.entities.RequestEntity;
@@ -66,6 +69,7 @@ import org.apache.ambari.server.state.ServiceComponentHostEvent;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpFailedEvent;
 import org.apache.ambari.server.utils.StageUtils;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -94,7 +98,10 @@ class ActionScheduler implements Runnable {
   private static Logger LOG = LoggerFactory.getLogger(ActionScheduler.class);
 
   public static final String FAILED_TASK_ABORT_REASONING =
-          "Server considered task failed and automatically aborted it";
+    "Server considered task failed and automatically aborted it";
+
+  @Inject
+  private RoleCommandOrderProvider roleCommandOrderProvider;
 
   @Inject
   private UnitOfWork unitOfWork;
@@ -154,7 +161,7 @@ class ActionScheduler implements Runnable {
    * but are not cancelled yet
    */
   private final Set<Long> requestsToBeCancelled =
-          Collections.newSetFromMap(new ConcurrentHashMap<Long, Boolean>());
+    Collections.newSetFromMap(new ConcurrentHashMap<Long, Boolean>());
 
   /**
    * Maps request IDs to reasoning for cancelling request.
@@ -162,7 +169,7 @@ class ActionScheduler implements Runnable {
    * requestsToBeCancelled object
    */
   private final Map<Long, String> requestCancelReasons =
-          new HashMap<Long, String>();
+    new HashMap<Long, String>();
 
   /**
    * true if scheduler should run ASAP.
@@ -185,8 +192,8 @@ class ActionScheduler implements Runnable {
    */
   @Inject
   public ActionScheduler(@Named("schedulerSleeptime") long sleepTime,
-      @Named("actionTimeout") long actionTimeout, ActionDBAccessor db,
-      JPAEventPublisher jpaPublisher) {
+                         @Named("actionTimeout") long actionTimeout, ActionDBAccessor db,
+                         JPAEventPublisher jpaPublisher) {
 
     this.sleepTime = sleepTime;
     this.actionTimeout = actionTimeout;
@@ -217,10 +224,10 @@ class ActionScheduler implements Runnable {
    * @param hostRoleCommandFactory
    */
   protected ActionScheduler(long sleepTimeMilliSec, long actionTimeoutMilliSec, ActionDBAccessor db,
-      ActionQueue actionQueue, Clusters fsmObject, int maxAttempts, HostsMap hostsMap,
-      UnitOfWork unitOfWork, AmbariEventPublisher ambariEventPublisher,
-      Configuration configuration, Provider<EntityManager> entityManagerProvider,
-      HostRoleCommandDAO hostRoleCommandDAO, HostRoleCommandFactory hostRoleCommandFactory) {
+                            ActionQueue actionQueue, Clusters fsmObject, int maxAttempts, HostsMap hostsMap,
+                            UnitOfWork unitOfWork, AmbariEventPublisher ambariEventPublisher,
+                            Configuration configuration, Provider<EntityManager> entityManagerProvider,
+                            HostRoleCommandDAO hostRoleCommandDAO, HostRoleCommandFactory hostRoleCommandFactory) {
 
     sleepTime = sleepTimeMilliSec;
     actionTimeout = actionTimeoutMilliSec;
@@ -244,10 +251,10 @@ class ActionScheduler implements Runnable {
   /**
    * Initializes the caches.
    */
-  private void initializeCaches(){
+  private void initializeCaches() {
     clusterHostInfoCache = CacheBuilder.newBuilder().
-        expireAfterAccess(5, TimeUnit.MINUTES).
-        build();
+      expireAfterAccess(5, TimeUnit.MINUTES).
+      build();
 
     commandParamsStageCache = CacheBuilder.newBuilder().
       expireAfterAccess(5, TimeUnit.MINUTES).
@@ -294,7 +301,7 @@ class ActionScheduler implements Runnable {
       try {
         synchronized (wakeupSyncObject) {
           if (!activeAwakeRequest) {
-              wakeupSyncObject.wait(sleepTime);
+            wakeupSyncObject.wait(sleepTime);
           }
           activeAwakeRequest = false;
         }
@@ -367,14 +374,14 @@ class ActionScheduler implements Runnable {
       // a list does not change between invocations
       for (Stage stage : stages) {
         // Check if we can process this stage in parallel with another stages
-        i_stage ++;
+        i_stage++;
         long requestId = stage.getRequestId();
         LOG.debug("==> STAGE_i = " + i_stage + "(requestId=" + requestId + ",StageId=" + stage.getStageId() + ")");
 
         RequestEntity request = db.getRequestEntity(requestId);
 
         if (request.isExclusive()) {
-          if (runningRequestIds.size() > 0 ) {
+          if (runningRequestIds.size() > 0) {
             // As a result, we will wait until any previous stages are finished
             LOG.debug("Stage requires exclusive execution, but other requests are already executing. Stopping for now");
             break;
@@ -395,7 +402,8 @@ class ActionScheduler implements Runnable {
         }
 
         // Commands that will be scheduled in current scheduler wakeup
-        List<ExecutionCommand> commandsToSchedule = new ArrayList<ExecutionCommand>();
+        List<ExecutionCommand> commandsToSchedule = new ArrayList<>();
+
         Map<String, RoleStats> roleStats = processInProgressStage(stage, commandsToSchedule);
 
         // Check if stage is failed
@@ -500,7 +508,7 @@ class ActionScheduler implements Runnable {
         }
         LOG.debug("==> Finished.");
 
-        if (! configuration.getParallelStageExecution()) { // If disabled
+        if (!configuration.getParallelStageExecution()) { // If disabled
           return;
         }
 
@@ -519,11 +527,11 @@ class ActionScheduler implements Runnable {
     }
   }
 
+
   /**
    * Returns the list of hosts that have a task assigned
    *
    * @param stages
-   *
    * @return
    */
   private HashSet<String> getListOfHostsWithPendingTask(List<Stage> stages) {
@@ -653,7 +661,7 @@ class ActionScheduler implements Runnable {
         return false;
       }
 
-      Map<Role, Integer> hostCountsForRoles       = new HashMap<Role, Integer>();
+      Map<Role, Integer> hostCountsForRoles = new HashMap<Role, Integer>();
       Map<Role, Integer> failedHostCountsForRoles = new HashMap<Role, Integer>();
 
       for (String host : prevStage.getHostRoleCommands().keySet()) {
@@ -687,16 +695,15 @@ class ActionScheduler implements Runnable {
   /**
    * This method processes command timeouts and retry attempts, and
    * adds new (pending) execution commands to commandsToSchedule list.
-   *
    * @return the stats for the roles in the stage which are used to determine
    * whether stage has succeeded or failed
    */
-  protected Map<String, RoleStats> processInProgressStage(Stage s,
-      List<ExecutionCommand> commandsToSchedule) throws AmbariException {
+  protected Map<String, RoleStats> processInProgressStage(Stage s, List<ExecutionCommand> commandsToSchedule) throws AmbariException {
     LOG.debug("==> Collecting commands to schedule...");
     // Map to track role status
     Map<String, RoleStats> roleStats = initRoleStats(s);
     long now = System.currentTimeMillis();
+    Set<RoleCommandPair> rolesCommandsInProgress = s.getHostRolesInProgress();
 
     Cluster cluster = null;
     if (null != s.getClusterName()) {
@@ -716,14 +723,14 @@ class ActionScheduler implements Runnable {
       int i_my = 0;
       LOG.trace("===>host=" + host);
 
-      for(ExecutionCommandWrapper wrapper : commandWrappers) {
+      for (ExecutionCommandWrapper wrapper : commandWrappers) {
         ExecutionCommand c = wrapper.getExecutionCommand();
         String roleStr = c.getRole();
         HostRoleStatus status = s.getHostRoleStatus(host, roleStr);
-        i_my ++;
+        i_my++;
         if (LOG.isTraceEnabled()) {
           LOG.trace("Host task " + i_my + ") id = " + c.getTaskId() + " status = " + status.toString() +
-            " (role=" + roleStr + "), roleCommand = "+ c.getRoleCommand());
+            " (role=" + roleStr + "), roleCommand = " + c.getRoleCommand());
         }
         boolean hostDeleted = false;
         if (null != cluster) {
@@ -741,8 +748,8 @@ class ActionScheduler implements Runnable {
             }
           } catch (ServiceComponentNotFoundException scnex) {
             String msg = String.format(
-                    "%s is not not a service component, assuming its an action",
-                    roleStr);
+              "%s is not not a service component, assuming its an action",
+              roleStr);
             LOG.debug(msg);
           }
 
@@ -750,7 +757,7 @@ class ActionScheduler implements Runnable {
           if (hostDeleted) {
             String message = String.format(
               "Host component information has not been found.  Details:" +
-              "cluster=%s; host=%s; service=%s; component=%s; ",
+                "cluster=%s; host=%s; service=%s; component=%s; ",
               c.getClusterName(), host,
               svcComp == null ? "null" : svcComp.getServiceName(),
               svcComp == null ? "null" : svcComp.getName());
@@ -768,7 +775,7 @@ class ActionScheduler implements Runnable {
             commandTimeout += Long.parseLong(timeoutStr) * 1000; // Converting to milliseconds
           } else {
             LOG.error("Execution command has no timeout parameter" +
-                    c.toString());
+              c.toString());
           }
         }
 
@@ -777,10 +784,10 @@ class ActionScheduler implements Runnable {
 
           String message = String.format(
             "Host not found when trying to schedule an execution command. " +
-            "The most probable reason for that is that host or host component " +
-            "has been deleted recently. The command has been aborted and dequeued." +
-            "Execution command details: " +
-            "cmdId: %s; taskId: %s; roleCommand: %s",
+              "The most probable reason for that is that host or host component " +
+              "has been deleted recently. The command has been aborted and dequeued." +
+              "Execution command details: " +
+              "cmdId: %s; taskId: %s; roleCommand: %s",
             c.getCommandId(), c.getTaskId(), c.getRoleCommand());
           LOG.warn("Host {} has been detected as non-available. {}", host, message);
           // Abort the command itself
@@ -794,7 +801,7 @@ class ActionScheduler implements Runnable {
           // Process command timeouts
           if (s.getAttemptCount(host, roleStr) >= maxAttempts) {
             LOG.warn("Host: {}, role: {}, actionId: {} expired and will be failed", host, roleStr,
-                s.getActionId());
+              s.getActionId());
 
             // determine if the task should be auto skipped
             boolean isSkipSupported = s.isAutoSkipOnFailureSupported();
@@ -826,19 +833,28 @@ class ActionScheduler implements Runnable {
             cancelCommandOnTimeout(Collections.singletonList(s.getHostRoleCommand(host, roleStr)));
 
             LOG.info("Host: {}, role: {}, actionId: {} timed out and will be rescheduled", host,
-                roleStr, s.getActionId());
+              roleStr, s.getActionId());
 
             // reschedule command
             commandsToSchedule.add(c);
             LOG.trace("===> commandsToSchedule(reschedule)=" + commandsToSchedule.size());
           }
         } else if (status.equals(HostRoleStatus.PENDING)) {
-          //Need to schedule first time
-          commandsToSchedule.add(c);
-          LOG.trace("===>commandsToSchedule(first_time)=" + commandsToSchedule.size());
+          // in case of DEPENDENCY_ORDERED stage command can be scheduled only if all of it's dependencies are
+          // already finished
+          if (CommandExecutionType.STAGE == s.getCommandExecutionType() ||
+                (CommandExecutionType.DEPENDENCY_ORDERED == s.getCommandExecutionType() &&
+                  CommandExecutionType.DEPENDENCY_ORDERED == configuration.getStageExecutionType() &&
+                  areCommandDependenciesFinished(c, s, rolesCommandsInProgress))) {
+
+            //Need to schedule first time
+            commandsToSchedule.add(c);
+            LOG.trace("===>commandsToSchedule(first_time)=" + commandsToSchedule.size());
+          }
         }
 
         updateRoleStats(status, roleStats.get(roleStr));
+
       }
     }
     LOG.debug("Collected {} commands to schedule in this wakeup.", commandsToSchedule.size());
@@ -846,6 +862,31 @@ class ActionScheduler implements Runnable {
   }
 
   /**
+   * Returns true if all command dependencies are already finished (not IN_PROGRESS states).
+   * @param command
+   * @param stage
+   * @param rolesCommandsInProgress
+   * @return
+   */
+  private boolean areCommandDependenciesFinished(ExecutionCommand command, Stage stage, Set<RoleCommandPair>
+    rolesCommandsInProgress) {
+    boolean areCommandDependenciesFinished = true;
+    RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(stage.getClusterId());
+    if (rco != null) {
+      Set<RoleCommandPair> roleCommandDependencies = rco.getDependencies().get(new
+        RoleCommandPair(Role.valueOf(command.getRole()), command.getRoleCommand()));
+
+      // check if there are any dependencies IN_PROGRESS
+      if (roleCommandDependencies != null && CollectionUtils.containsAny(rolesCommandsInProgress, roleCommandDependencies)) {
+        areCommandDependenciesFinished = false;
+      }
+    }
+
+    return areCommandDependenciesFinished;
+
+  }
+
+  /**
    * Generate a OPFailed event before aborting all operations in the stage
    * @param stage
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CommandExecutionType.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CommandExecutionType.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CommandExecutionType.java
new file mode 100644
index 0000000..08fb21a
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CommandExecutionType.java
@@ -0,0 +1,35 @@
+/*
+ * 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;
+/**
+ * Enum which indicates the execution type of commands for a stage.
+ */
+public enum CommandExecutionType {
+
+  /**
+   * One or more stages are created depending on dependencies. This is the default.
+   */
+  STAGE,
+
+  /**
+   * Create only one stage for each request and instead of handling dependencies with multiple stage, verify that
+   * dependencies are satisfied before scheduling a new command.
+   */
+  DEPENDENCY_ORDERED
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/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 f03d8ea..319d72d 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
@@ -19,7 +19,9 @@ package org.apache.ambari.server.actionmanager;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.EnumSet;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -32,6 +34,8 @@ import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.agent.AgentCommand.AgentCommandType;
 import org.apache.ambari.server.agent.ExecutionCommand;
+import org.apache.ambari.server.metadata.RoleCommandOrder;
+import org.apache.ambari.server.metadata.RoleCommandPair;
 import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
 import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
 import org.apache.ambari.server.orm.entities.RoleSuccessCriteriaEntity;
@@ -76,6 +80,8 @@ public class Stage {
   private String commandParamsStage;
   private String hostParamsStage;
 
+  private CommandExecutionType commandExecutionType = CommandExecutionType.STAGE;
+
   private boolean skippable;
   private boolean supportsAutoSkipOnFailure;
 
@@ -138,7 +144,7 @@ public class Stage {
     supportsAutoSkipOnFailure = stageEntity.isAutoSkipOnFailureSupported();
     logDir = stageEntity.getLogInfo();
 
-    long clusterId = stageEntity.getClusterId().longValue();
+    clusterId = stageEntity.getClusterId().longValue();
     if (-1L != clusterId) {
       try {
         clusterName = clusters.getClusterById(clusterId).getClusterName();
@@ -152,6 +158,7 @@ public class Stage {
     clusterHostInfo = stageEntity.getClusterHostInfo();
     commandParamsStage = stageEntity.getCommandParamsStage();
     hostParamsStage = stageEntity.getHostParamsStage();
+    commandExecutionType = stageEntity.getCommandExecutionType();
 
     List<Long> taskIds = hostRoleCommandDAO.findTaskIdsByStage(requestId, stageId);
     Collection<HostRoleCommand> commands = dbAccessor.getTasks(taskIds);
@@ -191,6 +198,7 @@ public class Stage {
     stageEntity.setClusterHostInfo(clusterHostInfo);
     stageEntity.setCommandParamsStage(commandParamsStage);
     stageEntity.setHostParamsStage(hostParamsStage);
+    stageEntity.setCommandExecutionType(commandExecutionType);
 
     for (Role role : successFactors.keySet()) {
       RoleSuccessCriteriaEntity roleSuccessCriteriaEntity = new RoleSuccessCriteriaEntity();
@@ -235,6 +243,23 @@ public class Stage {
     return commands;
   }
 
+  /**
+   * Returns <Role, RoleCommand> pairs which are in progress.
+   * @return
+   */
+  public Set<RoleCommandPair> getHostRolesInProgress() {
+    Set<RoleCommandPair> commandsToScheduleSet = new HashSet<>();
+    for (Map.Entry<String, Map<String, HostRoleCommand>> hostRoleCommandEntry : hostRoleCommands.entrySet()) {
+      for (Map.Entry<String, HostRoleCommand> roleCommandEntry : hostRoleCommandEntry.getValue().entrySet()) {
+        if (HostRoleStatus.IN_PROGRESS_STATUSES.contains(roleCommandEntry.getValue().getStatus())) {
+          commandsToScheduleSet.add(
+            new RoleCommandPair(roleCommandEntry.getValue().getRole(), roleCommandEntry.getValue().getRoleCommand()));
+        }
+      }
+    }
+    return commandsToScheduleSet;
+  }
+
   public String getClusterHostInfo() {
     return clusterHostInfo;
   }
@@ -259,6 +284,13 @@ public class Stage {
     this.hostParamsStage = hostParamsStage;
   }
 
+  public CommandExecutionType getCommandExecutionType() {
+    return commandExecutionType;
+  }
+
+  public void setCommandExecutionType(CommandExecutionType commandExecutionType) {
+    this.commandExecutionType = commandExecutionType;
+  }
 
   public synchronized void setStageId(long stageId) {
     if (this.stageId != -1) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index cedafb8..a0747d4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -51,6 +51,7 @@ import org.apache.ambari.annotations.Markdown;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.Stage;
+import org.apache.ambari.server.actionmanager.CommandExecutionType;
 import org.apache.ambari.server.controller.spi.PropertyProvider;
 import org.apache.ambari.server.events.listeners.alerts.AlertReceivedListener;
 import org.apache.ambari.server.orm.JPATableGenerationStrategy;
@@ -1797,6 +1798,15 @@ public class Configuration {
       "server.stages.parallel", Boolean.TRUE);
 
   /**
+   * In case this is set to DEPENDENCY_ORDERED one stage is created for each request and command dependencies are
+   * handled directly by ActionScheduler. In case of STAGE (which is the default) one or more stages are
+   * created depending on dependencies.
+   */
+  @Markdown(description = "How to execute commands in one stage")
+  public static final ConfigurationProperty<String> COMMAND_EXECUTION_TYPE = new ConfigurationProperty<>(
+    "server.stage.command.execution_type", CommandExecutionType.STAGE.toString());
+
+  /**
    * The time, in {@link TimeUnit#SECONDS}, before agent commands are killed.
    * This does not include package installation commands.
    */
@@ -2996,6 +3006,10 @@ public class Configuration {
     return getProperty(SYS_PREPPED_HOSTS);
   }
 
+  public CommandExecutionType getStageExecutionType(){
+    return CommandExecutionType.valueOf(getProperty(COMMAND_EXECUTION_TYPE));
+  }
+
   public String getStackAdvisorScript() {
     return getProperty(STACK_ADVISOR_SCRIPT);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/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 92bcb59..9c030a3 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
@@ -82,6 +82,7 @@ import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.RequestFactory;
 import org.apache.ambari.server.actionmanager.Stage;
+import org.apache.ambari.server.actionmanager.CommandExecutionType;
 import org.apache.ambari.server.actionmanager.StageFactory;
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.agent.ExecutionCommand.KeyNames;
@@ -103,6 +104,7 @@ import org.apache.ambari.server.customactions.ActionDefinition;
 import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
 import org.apache.ambari.server.metadata.ActionMetadata;
 import org.apache.ambari.server.metadata.RoleCommandOrder;
+import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
 import org.apache.ambari.server.orm.dao.ClusterDAO;
 import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
 import org.apache.ambari.server.orm.dao.ExtensionDAO;
@@ -238,6 +240,10 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
 
   private final Gson gson;
 
+
+  @Inject
+  private RoleCommandOrderProvider roleCommandOrderProvider;
+
   @Inject
   private ServiceFactory serviceFactory;
   @Inject
@@ -399,10 +405,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
 
   @Override
   public RoleCommandOrder getRoleCommandOrder(Cluster cluster) {
-      RoleCommandOrder rco;
-      rco = injector.getInstance(RoleCommandOrder.class);
-      rco.initialize(cluster);
-      return rco;
+      return roleCommandOrderProvider.getRoleCommandOrder(cluster);
   }
 
   @Override
@@ -2819,6 +2822,12 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
       RoleCommandOrder rco = getRoleCommandOrder(cluster);
       RoleGraph rg = roleGraphFactory.createNew(rco);
 
+
+      if (CommandExecutionType.DEPENDENCY_ORDERED == configs.getStageExecutionType() && "INITIAL_START".equals
+        (requestProperties.get("phase"))) {
+        LOG.info("Set DEPENDENCY_ORDERED CommandExecutionType on stage: {}", stage.getRequestContext());
+        rg.setCommandExecutionType(CommandExecutionType.DEPENDENCY_ORDERED);
+      }
       rg.build(stage);
       requestStages.addStages(rg.getStages());
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/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 48d4e34..78761f5 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
@@ -18,21 +18,6 @@
 
 package org.apache.ambari.server.controller;
 
-import static org.eclipse.persistence.config.PersistenceUnitProperties.CREATE_JDBC_DDL_FILE;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.CREATE_ONLY;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.CREATE_OR_EXTEND;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.DDL_BOTH_GENERATION;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.DDL_GENERATION;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.DDL_GENERATION_MODE;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.DROP_AND_CREATE;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.DROP_JDBC_DDL_FILE;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_DRIVER;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_PASSWORD;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_URL;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_USER;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.NON_JTA_DATASOURCE;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.THROW_EXCEPTIONS;
-
 import java.beans.PropertyVetoException;
 import java.lang.annotation.Annotation;
 import java.security.SecureRandom;
@@ -77,6 +62,8 @@ import org.apache.ambari.server.controller.metrics.timeline.cache.TimelineMetric
 import org.apache.ambari.server.controller.metrics.timeline.cache.TimelineMetricCacheProvider;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.utilities.KerberosChecker;
+import org.apache.ambari.server.metadata.CachedRoleCommandOrderProvider;
+import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
 import org.apache.ambari.server.notifications.DispatchFactory;
 import org.apache.ambari.server.notifications.NotificationDispatcher;
 import org.apache.ambari.server.notifications.dispatchers.SNMPDispatcher;
@@ -94,7 +81,6 @@ import org.apache.ambari.server.security.encryption.CredentialStoreServiceImpl;
 import org.apache.ambari.server.serveraction.kerberos.KerberosOperationHandlerFactory;
 import org.apache.ambari.server.stack.StackManagerFactory;
 import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
@@ -155,6 +141,21 @@ import com.google.inject.persist.PersistModule;
 import com.google.inject.persist.jpa.AmbariJpaPersistModule;
 import com.mchange.v2.c3p0.ComboPooledDataSource;
 
+import static org.eclipse.persistence.config.PersistenceUnitProperties.CREATE_JDBC_DDL_FILE;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.CREATE_ONLY;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.CREATE_OR_EXTEND;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.DDL_BOTH_GENERATION;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.DDL_GENERATION;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.DDL_GENERATION_MODE;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.DROP_AND_CREATE;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.DROP_JDBC_DDL_FILE;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_DRIVER;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_PASSWORD;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_URL;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_USER;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.NON_JTA_DATASOURCE;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.THROW_EXCEPTIONS;
+
 /**
  * Used for injection purposes.
  */
@@ -350,9 +351,6 @@ public class ControllerModule extends AbstractModule {
     bindConstant().annotatedWith(Names.named(HostRoleCommandDAO.HRC_STATUS_SUMMARY_CACHE_EXPIRY_DURATION_MINUTES)).
       to(configuration.getHostRoleCommandStatusSummaryCacheExpiryDuration());
 
-
-
-
     bind(AmbariManagementController.class).to(
         AmbariManagementControllerImpl.class);
     bind(AbstractRootServiceResponseFactory.class).to(RootServiceResponseFactory.class);
@@ -424,7 +422,7 @@ public class ControllerModule extends AbstractModule {
     install(new FactoryModuleBuilder().implement(
         Host.class, HostImpl.class).build(HostFactory.class));
     install(new FactoryModuleBuilder().implement(
-        Service.class, ServiceImpl.class).build(ServiceFactory.class));
+      Service.class, ServiceImpl.class).build(ServiceFactory.class));
 
     install(new FactoryModuleBuilder()
         .implement(ResourceProvider.class, Names.named("host"), HostResourceProvider.class)
@@ -440,8 +438,8 @@ public class ControllerModule extends AbstractModule {
         .build(ResourceProviderFactory.class));
 
     install(new FactoryModuleBuilder().implement(
-        ServiceComponent.class, ServiceComponentImpl.class).build(
-        ServiceComponentFactory.class));
+      ServiceComponent.class, ServiceComponentImpl.class).build(
+      ServiceComponentFactory.class));
     install(new FactoryModuleBuilder().implement(
         ServiceComponentHost.class, ServiceComponentHostImpl.class).build(
         ServiceComponentHostFactory.class));
@@ -450,10 +448,13 @@ public class ControllerModule extends AbstractModule {
     install(new FactoryModuleBuilder().implement(
         ConfigGroup.class, ConfigGroupImpl.class).build(ConfigGroupFactory.class));
     install(new FactoryModuleBuilder().implement(RequestExecution.class,
-        RequestExecutionImpl.class).build(RequestExecutionFactory.class));
+      RequestExecutionImpl.class).build(RequestExecutionFactory.class));
 
     bind(StageFactory.class).to(StageFactoryImpl.class);
-    bind(RoleGraphFactory.class).to(RoleGraphFactoryImpl.class);
+    bind(RoleCommandOrderProvider.class).to(CachedRoleCommandOrderProvider.class);
+
+    install(new FactoryModuleBuilder().build(RoleGraphFactory.class));
+
     install(new FactoryModuleBuilder().build(RequestFactory.class));
     install(new FactoryModuleBuilder().build(StackManagerFactory.class));
     install(new FactoryModuleBuilder().build(ExecutionCommandWrapperFactory.class));

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/java/org/apache/ambari/server/metadata/CachedRoleCommandOrderProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/metadata/CachedRoleCommandOrderProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/metadata/CachedRoleCommandOrderProvider.java
new file mode 100644
index 0000000..e2b44ca
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/metadata/CachedRoleCommandOrderProvider.java
@@ -0,0 +1,112 @@
+/**
+ * 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.metadata;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+
+/**
+ * RoleCommandOrderProvider which caches RoleCommandOrder objects for a cluster to avoid the cost of construction of
+ * RoleCommandOrder objects each time.
+ */
+public class CachedRoleCommandOrderProvider implements RoleCommandOrderProvider {
+
+  private static Logger LOG = LoggerFactory.getLogger(CachedRoleCommandOrderProvider.class);
+
+  @Inject
+  private Injector injector;
+
+  @Inject
+  private Clusters clusters;
+
+  private Map<Integer, RoleCommandOrder> rcoMap = new HashMap<>();
+
+  @Inject
+  public CachedRoleCommandOrderProvider() {
+  }
+
+  @Override
+  public RoleCommandOrder getRoleCommandOrder(Long clusterId) {
+    Cluster cluster = null;
+    try {
+      cluster = clusters.getCluster(clusterId);
+      return getRoleCommandOrder(cluster);
+    } catch (AmbariException e) {
+      return null;
+    }
+
+  }
+
+  @Override
+  public RoleCommandOrder getRoleCommandOrder(Cluster cluster) {
+    boolean hasGLUSTERFS = false;
+    boolean isNameNodeHAEnabled = false;
+    boolean isResourceManagerHAEnabled = false;
+
+    try {
+      if (cluster != null && cluster.getService("GLUSTERFS") != null) {
+        hasGLUSTERFS = true;
+      }
+    } catch (AmbariException e) {
+    }
+
+    try {
+      if (cluster != null &&
+        cluster.getService("HDFS") != null &&
+        cluster.getService("HDFS").getServiceComponent("JOURNALNODE") != null) {
+        isNameNodeHAEnabled = true;
+      }
+    } catch (AmbariException e) {
+    }
+
+    try {
+      if (cluster != null &&
+        cluster.getService("YARN") != null &&
+        cluster.getService("YARN").getServiceComponent("RESOURCEMANAGER").getServiceComponentHosts().size() > 1) {
+        isResourceManagerHAEnabled = true;
+      }
+    } catch (AmbariException e) {
+    }
+
+    int clusterCacheId = new HashCodeBuilder().append(cluster.getClusterId()).append(hasGLUSTERFS).append(isNameNodeHAEnabled).append
+      (isResourceManagerHAEnabled).toHashCode();
+
+    RoleCommandOrder rco = rcoMap.get(clusterCacheId);
+    if (rco == null) {
+      rco = injector.getInstance(RoleCommandOrder.class);
+      rco.setHasGLUSTERFS(hasGLUSTERFS);
+      rco.setIsNameNodeHAEnabled(isNameNodeHAEnabled);
+      rco.setIsResourceManagerHAEnabled(isResourceManagerHAEnabled);
+      rco.initialize(cluster);
+      rcoMap.put(clusterCacheId, rco);
+    }
+    return rco;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java b/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java
index bbdb808..58675ae 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java
@@ -17,25 +17,26 @@
  */
 package org.apache.ambari.server.metadata;
 
-import java.io.*;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 
-import com.google.inject.Inject;
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
-import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.stageplanner.RoleGraphNode;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackInfo;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.type.TypeReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.ambari.server.AmbariException;
+
+import com.google.inject.Inject;
 
 /**
  * This class is used to establish the order between two roles. This class
@@ -43,9 +44,12 @@ import org.apache.ambari.server.AmbariException;
  */
 public class RoleCommandOrder {
 
-  @Inject Configuration configs;
   @Inject AmbariMetaInfo ambariMetaInfo;
 
+  private boolean hasGLUSTERFS;
+  private boolean isNameNodeHAEnabled;
+  private boolean isResourceManagerHAEnabled;
+
   private final static Logger LOG =
 			LoggerFactory.getLogger(RoleCommandOrder.class);
 
@@ -66,50 +70,6 @@ public class RoleCommandOrder {
             add(RoleCommand.SERVICE_CHECK);
           }};
 
-  static class RoleCommandPair {
-    Role role;
-    RoleCommand cmd;
-
-    public RoleCommandPair(Role _role, RoleCommand _cmd) {
-      if (_role == null || _cmd == null) {
-        throw new IllegalArgumentException("role = "+_role+", cmd = "+_cmd);
-      }
-      this.role = _role;
-      this.cmd = _cmd;
-    }
-
-    @Override
-    public int hashCode() {
-      return (role.toString() + cmd.toString()).hashCode();
-    }
-
-    @Override
-    public boolean equals(Object other) {
-      if (other != null && (other instanceof RoleCommandPair)
-          && ((RoleCommandPair) other).role.equals(role)
-          && ((RoleCommandPair) other).cmd.equals(cmd)) {
-        return true;
-      }
-      return false;
-    }
-
-    Role getRole() {
-      return role;
-    }
-
-    RoleCommand getCmd() {
-      return cmd;
-    }
-
-    @Override
-    public String toString() {
-      return "RoleCommandPair{" +
-              "role=" + role +
-              ", cmd=" + cmd +
-              '}';
-    }
-  }
-
   /**
    * key -> blocked role command value -> set of blocker role commands.
    */
@@ -160,40 +120,12 @@ public class RoleCommandOrder {
   }
 
   public void initialize(Cluster cluster) {
-    Boolean hasGLUSTERFS = false;
-    Boolean isNameNodeHAEnabled = false;
-    Boolean isResourceManagerHAEnabled = false;
-
-    try {
-      if (cluster != null && cluster.getService("GLUSTERFS") != null) {
-    	  hasGLUSTERFS = true;
-      } 
-    } catch (AmbariException e) {
-    }
-
-    try {
-      if (cluster != null &&
-              cluster.getService("HDFS") != null &&
-              cluster.getService("HDFS").getServiceComponent("JOURNALNODE") != null) {
-        isNameNodeHAEnabled = true;
-      }
-    } catch (AmbariException e) {
-    }
-
-    try {
-      if (cluster != null &&
-              cluster.getService("YARN") != null &&
-              cluster.getService("YARN").getServiceComponent("RESOURCEMANAGER").getServiceComponentHosts().size() > 1) {
-        isResourceManagerHAEnabled = true;
-      }
-    } catch (AmbariException e) {
-    }
 
     StackId stackId = cluster.getCurrentStackVersion();
     StackInfo stack = null;
     try {
       stack = ambariMetaInfo.getStack(stackId.getStackName(),
-            stackId.getStackVersion());
+        stackId.getStackVersion());
     } catch (AmbariException e) {
     }
 
@@ -399,8 +331,8 @@ public class RoleCommandOrder {
       v2 = rco.dependencies.get(roleCommandPairSetEntry.getKey());
       if (!v1.equals(v2)) {
         LOG.debug("different entry found for key ("
-          + roleCommandPairSetEntry.getKey().role.toString() + ", "
-          + roleCommandPairSetEntry.getKey().cmd.toString() + ")" );
+          + roleCommandPairSetEntry.getKey().getRole().toString() + ", "
+          + roleCommandPairSetEntry.getKey().getCmd().toString() + ")" );
         return 1;
       }
     }
@@ -408,11 +340,34 @@ public class RoleCommandOrder {
     return 0;
   }
 
+  public boolean isHasGLUSTERFS() {
+    return hasGLUSTERFS;
+  }
+
+  public void setHasGLUSTERFS(boolean hasGLUSTERFS) {
+    this.hasGLUSTERFS = hasGLUSTERFS;
+  }
+
+  public boolean isNameNodeHAEnabled() {
+    return isNameNodeHAEnabled;
+  }
+
+  public void setIsNameNodeHAEnabled(boolean isNameNodeHAEnabled) {
+    this.isNameNodeHAEnabled = isNameNodeHAEnabled;
+  }
+
+  public boolean isResourceManagerHAEnabled() {
+    return isResourceManagerHAEnabled;
+  }
+
+  public void setIsResourceManagerHAEnabled(boolean isResourceManagerHAEnabled) {
+    this.isResourceManagerHAEnabled = isResourceManagerHAEnabled;
+  }
 
   /**
    * For test purposes
    */
-  Map<RoleCommandPair, Set<RoleCommandPair>> getDependencies() {
+  public Map<RoleCommandPair, Set<RoleCommandPair>> getDependencies() {
     return dependencies;
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrderProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrderProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrderProvider.java
new file mode 100644
index 0000000..20c7d77
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrderProvider.java
@@ -0,0 +1,30 @@
+/**
+ * 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.metadata;
+
+import org.apache.ambari.server.state.Cluster;
+
+/**
+ * Provider to retrieve RoleCommandOrder objects for a cluster.
+ */
+public interface RoleCommandOrderProvider {
+
+  RoleCommandOrder getRoleCommandOrder(Cluster cluster);
+  RoleCommandOrder getRoleCommandOrder(Long clusterId);
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandPair.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandPair.java b/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandPair.java
new file mode 100644
index 0000000..9b44ae5
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandPair.java
@@ -0,0 +1,68 @@
+/**
+ * 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.metadata;
+
+import java.util.Objects;
+
+import org.apache.ambari.server.Role;
+import org.apache.ambari.server.RoleCommand;
+
+/**
+ * Tuple object containing a Role and RoleCommand.
+ */
+public class RoleCommandPair {
+
+  private final Role role;
+  private final RoleCommand cmd;
+
+  public RoleCommandPair(Role _role, RoleCommand _cmd) {
+    if (_role == null || _cmd == null) {
+      throw new IllegalArgumentException("role = "+_role+", cmd = "+_cmd);
+    }
+    this.role = _role;
+    this.cmd = _cmd;
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hash(role, cmd);
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (other != null && (other instanceof RoleCommandPair)
+      && ((RoleCommandPair) other).role.equals(role)
+      && ((RoleCommandPair) other).cmd.equals(cmd)) {
+      return true;
+    }
+    return false;
+  }
+
+  Role getRole() {
+    return role;
+  }
+
+  RoleCommand getCmd() {
+    return cmd;
+  }
+
+  @Override
+  public String toString() {
+    return "RoleCommandPair{" + "role=" + role + ", cmd=" + cmd + '}';
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
index eaea913..f9c8810 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
@@ -26,6 +26,8 @@ import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 import javax.persistence.FetchType;
 import javax.persistence.Id;
 import javax.persistence.IdClass;
@@ -36,6 +38,8 @@ import javax.persistence.NamedQuery;
 import javax.persistence.OneToMany;
 import javax.persistence.Table;
 
+import org.apache.ambari.server.actionmanager.CommandExecutionType;
+
 @Entity
 @Table(name = "stage")
 @IdClass(org.apache.ambari.server.orm.entities.StageEntityPK.class)
@@ -77,6 +81,11 @@ public class StageEntity {
   @Basic
   private String requestContext = "";
 
+  @Basic
+  @Enumerated(value = EnumType.STRING)
+  @Column(name = "command_execution_type", nullable = false)
+  private CommandExecutionType commandExecutionType = CommandExecutionType.STAGE;
+
   /**
    * On large clusters, this value can be in the 10,000's of kilobytes. During
    * an upgrade, all stages are loaded in memory for every request, which can
@@ -178,6 +187,14 @@ public class StageEntity {
     }
   }
 
+  public CommandExecutionType getCommandExecutionType() {
+    return commandExecutionType;
+  }
+
+  public void setCommandExecutionType(CommandExecutionType commandExecutionType) {
+    this.commandExecutionType = commandExecutionType;
+  }
+
   @Override
   public boolean equals(Object o) {
     if (this == o) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java b/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java
index c9ab6f9..c8a18b6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java
@@ -18,13 +18,18 @@
 package org.apache.ambari.server.stageplanner;
 
 import com.google.inject.Inject;
+import com.google.inject.assistedinject.Assisted;
+import com.google.inject.assistedinject.AssistedInject;
+
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.Stage;
+import org.apache.ambari.server.actionmanager.CommandExecutionType;
 import org.apache.ambari.server.actionmanager.StageFactory;
 import org.apache.ambari.server.metadata.RoleCommandOrder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -33,28 +38,34 @@ import java.util.TreeMap;
 
 public class RoleGraph {
 
-  private static Log LOG = LogFactory.getLog(RoleGraph.class);
+  private static Logger LOG = LoggerFactory.getLogger(RoleGraph.class);
 
-  
   Map<String, RoleGraphNode> graph = null;
   private RoleCommandOrder roleDependencies;
   private Stage initialStage = null;
   private boolean sameHostOptimization = true;
+  private CommandExecutionType commandExecutionType = CommandExecutionType.STAGE;
 
   @Inject
   private StageFactory stageFactory;
 
-  @Inject
-  public RoleGraph(StageFactory stageFactory) {
-    this.stageFactory = stageFactory;
+  @AssistedInject
+  public RoleGraph() {
   }
 
-  @Inject
-  public RoleGraph(RoleCommandOrder rd, StageFactory stageFactory) {
-    this(stageFactory);
+  @AssistedInject
+  public RoleGraph(@Assisted RoleCommandOrder rd) {
     this.roleDependencies = rd;
   }
 
+  public CommandExecutionType getCommandExecutionType() {
+    return commandExecutionType;
+  }
+
+  public void setCommandExecutionType(CommandExecutionType commandExecutionType) {
+    this.commandExecutionType = commandExecutionType;
+  }
+
   /**
    * Given a stage builds a DAG of all execution commands within the stage.
    */
@@ -80,22 +91,28 @@ public class RoleGraph {
       }
     }
 
-    if (null != roleDependencies) {
-      //Add edges
-      for (String roleI : graph.keySet()) {
-        for (String roleJ : graph.keySet()) {
-          if (!roleI.equals(roleJ)) {
-            RoleGraphNode rgnI = graph.get(roleI);
-            RoleGraphNode rgnJ = graph.get(roleJ);
-            int order = roleDependencies.order(rgnI, rgnJ);
-            if (order == -1) {
-              rgnI.addEdge(rgnJ);
-            } else if (order == 1) {
-              rgnJ.addEdge(rgnI);
+    // In case commandExecutionType == DEPENDENCY_ORDERED there will be only one stage, thus no need to add edges to
+    // the graph
+    if (commandExecutionType == CommandExecutionType.STAGE) {
+      if (null != roleDependencies) {
+        //Add edges
+        for (String roleI : graph.keySet()) {
+          for (String roleJ : graph.keySet()) {
+            if (!roleI.equals(roleJ)) {
+              RoleGraphNode rgnI = graph.get(roleI);
+              RoleGraphNode rgnJ = graph.get(roleJ);
+              int order = roleDependencies.order(rgnI, rgnJ);
+              if (order == -1) {
+                rgnI.addEdge(rgnJ);
+              } else if (order == 1) {
+                rgnJ.addEdge(rgnI);
+              }
             }
           }
         }
       }
+    } else {
+      LOG.info("Build stage with DEPENDENCY_ORDERED commandExecutionType: {} ", stage.getRequestContext());
     }
   }
   /**
@@ -166,6 +183,10 @@ public class RoleGraph {
     newStage.setSuccessFactors(origStage.getSuccessFactors());
     newStage.setSkippable(origStage.isSkippable());
     newStage.setAutoSkipFailureSupported(origStage.isAutoSkipOnFailureSupported());
+    if (commandExecutionType != null) {
+      newStage.setCommandExecutionType(commandExecutionType);
+    }
+
     for (RoleGraphNode rgn : stageGraphNodes) {
       for (String host : rgn.getHosts()) {
         newStage.addExecutionCommandWrapper(origStage, host, rgn.getRole());

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactory.java
index 625b168..1ece2c7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactory.java
@@ -24,12 +24,12 @@ public interface RoleGraphFactory {
    *
    * @return
    */
-  public RoleGraph createNew();
+  RoleGraph createNew();
 
   /**
    *
    * @param rd
    * @return
    */
-  public RoleGraph createNew(RoleCommandOrder rd);
+  RoleGraph createNew(RoleCommandOrder rd);
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactoryImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactoryImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactoryImpl.java
deleted file mode 100644
index 5ca4d88..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactoryImpl.java
+++ /dev/null
@@ -1,54 +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.stageplanner;
-
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.google.inject.Singleton;
-import org.apache.ambari.server.actionmanager.StageFactory;
-import org.apache.ambari.server.metadata.RoleCommandOrder;
-
-
-@Singleton
-public class RoleGraphFactoryImpl implements RoleGraphFactory {
-  private Injector injector;
-
-  @Inject
-  public RoleGraphFactoryImpl(Injector injector) {
-    this.injector = injector;
-  }
-
-  /**
-   *
-   * @return
-   */
-  @Override
-  public RoleGraph createNew() {
-    return new RoleGraph(this.injector.getInstance(StageFactory.class));
-  }
-
-  /**
-   *
-   * @param rd
-   * @return
-   */
-  @Override
-  public RoleGraph createNew(RoleCommandOrder rd) {
-    return new RoleGraph(rd, this.injector.getInstance(StageFactory.class));
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
index 3809c0c..ecdd4f3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
@@ -26,8 +26,11 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.actionmanager.CommandExecutionType;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
+import org.apache.ambari.server.orm.DBAccessor;
+
 import org.apache.ambari.server.orm.dao.DaoUtils;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
@@ -104,6 +107,10 @@ public class UpgradeCatalog250 extends AbstractUpgradeCatalog {
   protected void executeDDLUpdates() throws AmbariException, SQLException {
     updateHostVersionTable();
     createComponentVersionTable();
+    dbAccessor.addColumn("stage",
+      new DBAccessor.DBColumnInfo("command_execution_type", String.class, 32, CommandExecutionType.STAGE.toString(),
+        false));
+
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
index 4b64955..ed94c40 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
@@ -356,6 +356,7 @@ CREATE TABLE stage (
   cluster_host_info BLOB NOT NULL,
   command_params BLOB,
   host_params BLOB,
+  command_execution_type VARCHAR(32) NOT NULL DEFAULT 'STAGE',
   CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id),
   CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id));
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index 15a84cd..c8fbaa7 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -356,6 +356,7 @@ CREATE TABLE stage (
   cluster_host_info LONGBLOB,
   command_params LONGBLOB,
   host_params LONGBLOB,
+  command_execution_type VARCHAR(32) NOT NULL DEFAULT 'STAGE',
   CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id),
   CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id));
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index 6c3c036..04473d6 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -347,6 +347,7 @@ CREATE TABLE stage (
   cluster_host_info BLOB NOT NULL,
   command_params BLOB,
   host_params BLOB,
+  command_execution_type VARCHAR2(32) DEFAULT 'STAGE' NOT NULL,
   CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id),
   CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id));
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index 570b684..09ae3b0 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -356,6 +356,7 @@ CREATE TABLE stage (
   cluster_host_info BYTEA NOT NULL,
   command_params BYTEA,
   host_params BYTEA,
+  command_execution_type VARCHAR(32) DEFAULT 'STAGE' NOT NULL,
   CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id),
   CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id));
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
index 170e430..3dbd3fc 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
@@ -345,6 +345,7 @@ CREATE TABLE stage (
   cluster_host_info IMAGE,
   command_params IMAGE,
   host_params IMAGE,
+  command_execution_type VARCHAR(32) NOT NULL DEFAULT 'STAGE',
   CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id),
   CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id));
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
index 1501143..9def741 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -360,6 +360,7 @@ CREATE TABLE stage (
   cluster_host_info VARBINARY(MAX) NOT NULL,
   command_params VARBINARY(MAX),
   host_params VARBINARY(MAX),
+  command_execution_type VARCHAR(32) NOT NULL DEFAULT 'STAGE',
   CONSTRAINT PK_stage PRIMARY KEY CLUSTERED (stage_id, request_id),
   CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id));
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
index c7e0a9c..7dc6425 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
@@ -18,24 +18,6 @@
 
 package org.apache.ambari.server.controller;
 
-import static org.easymock.EasyMock.anyLong;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.anyString;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.getCurrentArguments;
-import static org.easymock.EasyMock.isNull;
-import static org.easymock.EasyMock.newCapture;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.reset;
-import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
 import java.io.File;
 import java.lang.reflect.Method;
 import java.net.InetAddress;
@@ -93,7 +75,6 @@ import org.apache.ambari.server.serveraction.kerberos.KerberosOperationHandler;
 import org.apache.ambari.server.serveraction.kerberos.KerberosOperationHandlerFactory;
 import org.apache.ambari.server.stack.StackManagerFactory;
 import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
@@ -136,6 +117,25 @@ import org.junit.rules.TemporaryFolder;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+
+import static org.easymock.EasyMock.anyLong;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.anyString;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.getCurrentArguments;
+import static org.easymock.EasyMock.isNull;
+import static org.easymock.EasyMock.newCapture;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 
 @SuppressWarnings("unchecked")
@@ -228,8 +228,8 @@ public class KerberosHelperTest extends EasyMockSupport {
         bind(ActionManager.class).toInstance(createNiceMock(ActionManager.class));
         bind(RequestFactory.class).toInstance(createNiceMock(RequestFactory.class));
         bind(StageFactory.class).toInstance(createNiceMock(StageFactory.class));
-        bind(RoleGraphFactory.class).to(RoleGraphFactoryImpl.class);
         bind(Clusters.class).toInstance(createNiceMock(Clusters.class));
+        install(new FactoryModuleBuilder().build(RoleGraphFactory.class));
         bind(ConfigHelper.class).toInstance(createNiceMock(ConfigHelper.class));
         bind(KerberosOperationHandlerFactory.class).toInstance(kerberosOperationHandlerFactory);
         bind(ClusterController.class).toInstance(clusterController);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActiveWidgetLayoutResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActiveWidgetLayoutResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActiveWidgetLayoutResourceProviderTest.java
index 6b371d8..c592a20 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActiveWidgetLayoutResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActiveWidgetLayoutResourceProviderTest.java
@@ -21,6 +21,8 @@ import com.google.gson.Gson;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+
 import org.apache.ambari.server.actionmanager.ActionDBAccessor;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.StageFactory;
@@ -36,6 +38,8 @@ import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.metadata.CachedRoleCommandOrderProvider;
+import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
 import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
 import org.apache.ambari.server.orm.dao.UserDAO;
@@ -53,7 +57,6 @@ import org.apache.ambari.server.security.encryption.CredentialStoreService;
 import org.apache.ambari.server.security.encryption.CredentialStoreServiceImpl;
 import org.apache.ambari.server.stack.StackManagerFactory;
 import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ConfigFactory;
@@ -379,7 +382,7 @@ public class ActiveWidgetLayoutResourceProviderTest extends EasyMockSupport {
         bind(org.apache.ambari.server.actionmanager.RequestFactory.class).toInstance(createNiceMock(org.apache.ambari.server.actionmanager.RequestFactory.class));
         bind(RequestExecutionFactory.class).toInstance(createNiceMock(RequestExecutionFactory.class));
         bind(StageFactory.class).toInstance(createNiceMock(StageFactory.class));
-        bind(RoleGraphFactory.class).to(RoleGraphFactoryImpl.class);
+        install(new FactoryModuleBuilder().build(RoleGraphFactory.class));
         bind(Clusters.class).toInstance(createNiceMock(Clusters.class));
         bind(AbstractRootServiceResponseFactory.class).toInstance(createNiceMock(AbstractRootServiceResponseFactory.class));
         bind(StackManagerFactory.class).toInstance(createNiceMock(StackManagerFactory.class));
@@ -392,6 +395,7 @@ public class ActiveWidgetLayoutResourceProviderTest extends EasyMockSupport {
         bind(KerberosHelper.class).toInstance(createNiceMock(KerberosHelper.class));
         bind(Users.class).toInstance(createMock(Users.class));
         bind(AmbariManagementController.class).to(AmbariManagementControllerImpl.class);
+        bind(RoleCommandOrderProvider.class).to(CachedRoleCommandOrderProvider.class);
         bind(CredentialStoreService.class).to(CredentialStoreServiceImpl.class);
         bind(UserDAO.class).toInstance(createMock(UserDAO.class));
         bind(WidgetLayoutDAO.class).toInstance(createMock(WidgetLayoutDAO.class));

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackUpgradeConfigurationMergeTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackUpgradeConfigurationMergeTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackUpgradeConfigurationMergeTest.java
index 4f2580a..1bc9125 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackUpgradeConfigurationMergeTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackUpgradeConfigurationMergeTest.java
@@ -40,7 +40,6 @@ import org.apache.ambari.server.scheduler.ExecutionScheduler;
 import org.apache.ambari.server.security.authorization.Users;
 import org.apache.ambari.server.stack.StackManagerFactory;
 import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
@@ -71,6 +70,7 @@ import com.google.inject.Binder;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 import com.google.inject.Module;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
 
 import junit.framework.Assert;
 
@@ -279,7 +279,7 @@ public class StackUpgradeConfigurationMergeTest extends EasyMockSupport {
       binder.bind(ExecutionScheduler.class).toInstance(createNiceMock(ExecutionScheduler.class));
       binder.bind(RequestFactory.class).toInstance(createNiceMock(RequestFactory.class));
       binder.bind(StageFactory.class).toInstance(createNiceMock(StageFactory.class));
-      binder.bind(RoleGraphFactory.class).toInstance(createNiceMock(RoleGraphFactoryImpl.class));
+      binder.install(new FactoryModuleBuilder().build(RoleGraphFactory.class));
       binder.bind(AbstractRootServiceResponseFactory.class).toInstance(createNiceMock(AbstractRootServiceResponseFactory.class));
       binder.bind(ConfigFactory.class).toInstance(createNiceMock(ConfigFactory.class));
       binder.bind(ConfigGroupFactory.class).toInstance(createNiceMock(ConfigGroupFactory.class));

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserAuthorizationResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserAuthorizationResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserAuthorizationResourceProviderTest.java
index 3705af1..013d42d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserAuthorizationResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserAuthorizationResourceProviderTest.java
@@ -18,9 +18,15 @@
 
 package org.apache.ambari.server.controller.internal;
 
-import com.google.inject.AbstractModule;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+
 import org.apache.ambari.server.actionmanager.ActionDBAccessor;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.StageFactory;
@@ -37,6 +43,8 @@ import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.metadata.CachedRoleCommandOrderProvider;
+import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
 import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
 import org.apache.ambari.server.orm.dao.PermissionDAO;
@@ -53,7 +61,6 @@ import org.apache.ambari.server.security.encryption.CredentialStoreService;
 import org.apache.ambari.server.security.encryption.CredentialStoreServiceImpl;
 import org.apache.ambari.server.stack.StackManagerFactory;
 import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ConfigFactory;
 import org.apache.ambari.server.state.ServiceComponentFactory;
@@ -71,15 +78,13 @@ import org.springframework.security.core.Authentication;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.crypto.password.PasswordEncoder;
 
-import javax.persistence.EntityManager;
-import java.lang.reflect.Field;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.Set;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
 
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.expect;
 
 
 /**
@@ -389,7 +394,7 @@ public class UserAuthorizationResourceProviderTest extends EasyMockSupport {
         bind(org.apache.ambari.server.actionmanager.RequestFactory.class).toInstance(createNiceMock(org.apache.ambari.server.actionmanager.RequestFactory.class));
         bind(RequestExecutionFactory.class).toInstance(createNiceMock(RequestExecutionFactory.class));
         bind(StageFactory.class).toInstance(createNiceMock(StageFactory.class));
-        bind(RoleGraphFactory.class).to(RoleGraphFactoryImpl.class);
+        install(new FactoryModuleBuilder().build(RoleGraphFactory.class));
         bind(Clusters.class).toInstance(createNiceMock(Clusters.class));
         bind(AbstractRootServiceResponseFactory.class).toInstance(createNiceMock(AbstractRootServiceResponseFactory.class));
         bind(StackManagerFactory.class).toInstance(createNiceMock(StackManagerFactory.class));
@@ -402,6 +407,7 @@ public class UserAuthorizationResourceProviderTest extends EasyMockSupport {
         bind(KerberosHelper.class).toInstance(createNiceMock(KerberosHelper.class));
         bind(Users.class).toInstance(createMock(Users.class));
         bind(AmbariManagementController.class).to(AmbariManagementControllerImpl.class);
+        bind(RoleCommandOrderProvider.class).to(CachedRoleCommandOrderProvider.class);
         bind(CredentialStoreService.class).to(CredentialStoreServiceImpl.class);
         bind(UserDAO.class).toInstance(createMock(UserDAO.class));
         bind(ResourceTypeDAO.class).toInstance(createMock(ResourceTypeDAO.class));

http://git-wip-us.apache.org/repos/asf/ambari/blob/a040cbfc/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java
index 8984342..bed5be3 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java
@@ -21,6 +21,8 @@ package org.apache.ambari.server.controller.internal;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+
 import org.apache.ambari.server.actionmanager.ActionDBAccessor;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.RequestFactory;
@@ -36,6 +38,8 @@ import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.metadata.CachedRoleCommandOrderProvider;
+import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
 import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
 import org.apache.ambari.server.scheduler.ExecutionScheduler;
@@ -48,7 +52,6 @@ import org.apache.ambari.server.security.encryption.CredentialStoreService;
 import org.apache.ambari.server.security.encryption.CredentialStoreServiceImpl;
 import org.apache.ambari.server.stack.StackManagerFactory;
 import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ConfigFactory;
 import org.apache.ambari.server.state.ServiceComponentFactory;
@@ -227,7 +230,7 @@ public class UserResourceProviderTest extends EasyMockSupport {
         bind(RequestFactory.class).toInstance(createNiceMock(RequestFactory.class));
         bind(RequestExecutionFactory.class).toInstance(createNiceMock(RequestExecutionFactory.class));
         bind(StageFactory.class).toInstance(createNiceMock(StageFactory.class));
-        bind(RoleGraphFactory.class).to(RoleGraphFactoryImpl.class);
+        install(new FactoryModuleBuilder().build(RoleGraphFactory.class));
         bind(Clusters.class).toInstance(createNiceMock(Clusters.class));
         bind(AbstractRootServiceResponseFactory.class).toInstance(createNiceMock(AbstractRootServiceResponseFactory.class));
         bind(StackManagerFactory.class).toInstance(createNiceMock(StackManagerFactory.class));
@@ -240,6 +243,7 @@ public class UserResourceProviderTest extends EasyMockSupport {
         bind(KerberosHelper.class).toInstance(createNiceMock(KerberosHelper.class));
         bind(Users.class).toInstance(createMock(Users.class));
         bind(AmbariManagementController.class).to(AmbariManagementControllerImpl.class);
+        bind(RoleCommandOrderProvider.class).to(CachedRoleCommandOrderProvider.class);
         bind(CredentialStoreService.class).to(CredentialStoreServiceImpl.class);
         bind(HostRoleCommandDAO.class).toInstance(createMock(HostRoleCommandDAO.class));
       }


Mime
View raw message