ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [48/50] [abbrv] ambari git commit: AMBARI-19347 - Previous Upgrade In Progress Pre-Req Check Incorrectly Detects ABORTED Upgrade (jonathanhurley)
Date Thu, 05 Jan 2017 00:05:29 GMT
AMBARI-19347 - Previous Upgrade In Progress Pre-Req Check Incorrectly Detects ABORTED Upgrade
(jonathanhurley)


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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: f207b95f586a5d218d0059c767825d1baa6bd856
Parents: e3eef3c
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Tue Jan 3 17:06:44 2017 -0500
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Wed Jan 4 16:18:05 2017 -0500

----------------------------------------------------------------------
 .../server/checks/PreviousUpgradeCompleted.java |  81 +--
 .../internal/UpgradeResourceProvider.java       |   4 +-
 .../ambari/server/orm/dao/UpgradeDAO.java       |   9 +-
 .../server/state/cluster/ClusterImpl.java       |   4 +-
 .../HDP/2.6/upgrades/host-ordered-upgrade.xml   | 573 +++++++++++++++++++
 .../checks/PreviousUpgradeCompletedTest.java    | 171 +-----
 .../internal/UpgradeResourceProviderTest.java   |   2 +-
 .../ambari/server/orm/dao/UpgradeDAOTest.java   |   6 +-
 8 files changed, 625 insertions(+), 225 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f207b95f/ambari-server/src/main/java/org/apache/ambari/server/checks/PreviousUpgradeCompleted.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/PreviousUpgradeCompleted.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/PreviousUpgradeCompleted.java
index ff82750..fe57ae4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/checks/PreviousUpgradeCompleted.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/PreviousUpgradeCompleted.java
@@ -19,17 +19,9 @@ package org.apache.ambari.server.checks;
 
 import java.text.MessageFormat;
 import java.util.LinkedHashSet;
-import java.util.List;
-
-import javax.inject.Provider;
 
 import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.actionmanager.HostRoleStatus;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
-import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
-import org.apache.ambari.server.orm.dao.RequestDAO;
-import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
-import org.apache.ambari.server.orm.entities.RequestEntity;
 import org.apache.ambari.server.orm.entities.UpgradeEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.stack.PrereqCheckStatus;
@@ -37,11 +29,12 @@ import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.apache.ambari.server.state.stack.upgrade.Direction;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
 
-import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
 /**
- * Checks if Install Packages needs to be re-run
+ * The {@link PreviousUpgradeCompleted} class is used to determine if there is a
+ * prior upgrade or downgrade which has not completed. If the most recent
+ * upgrade/downgrade is in a non-completed state, then this check will fail.
  */
 @Singleton
 @UpgradeCheck(
@@ -51,16 +44,9 @@ import com.google.inject.Singleton;
 public class PreviousUpgradeCompleted extends AbstractCheckDescriptor {
 
   /**
-   * If this ever changes, we will need to keep the historic name.
+   * The message displayed as part of this pre-upgrade check.
    */
-  public static final String FINALIZE_ACTION_CLASS_NAME = "org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction";
-  public static final String SET_CURRENT_COMMAND = "ambari-server set-current --cluster-name=$CLUSTERNAME
--version-display-name=$VERSION_NAME";
-
-  @Inject
-  Provider<RequestDAO> requestDaoProvider;
-
-  @Inject
-  Provider<HostRoleCommandDAO> hostRoleCommandDaoProvider;
+  public static final String ERROR_MESSAGE = "There is an existing {0} from {1} to {2} which
has not completed. This {3} must be completed before a new upgrade or downgrade can begin.";
 
   /**
    * Constructor.
@@ -75,58 +61,13 @@ public class PreviousUpgradeCompleted extends AbstractCheckDescriptor
{
     final Cluster cluster = clustersProvider.get().getCluster(clusterName);
 
     String errorMessage = null;
+    UpgradeEntity upgradeInProgress = cluster.getUpgradeInProgress();
+    if (null != upgradeInProgress) {
+      Direction direction = upgradeInProgress.getDirection();
+      String directionText = direction.getText(false);
 
-    List<UpgradeEntity> upgrades= upgradeDaoProvider.get().findAll();
-    if (upgrades != null) {
-      Long lastStartTime = 0L;
-      UpgradeEntity mostRecentUpgrade = null;
-      UpgradeEntity correspondingDowngrade = null;
-      for (UpgradeEntity upgrade : upgrades) {
-        // Find the most recent upgrade for this cluster
-        if (upgrade.getClusterId() == cluster.getClusterId() && upgrade.getDirection()
== Direction.UPGRADE) {
-          Long requestId = upgrade.getRequestId();
-          RequestEntity upgradeRequest = requestDaoProvider.get().findByPK(requestId);
-          if (upgradeRequest != null && upgradeRequest.getStartTime() > lastStartTime)
{
-            mostRecentUpgrade = upgrade;
-            lastStartTime = upgradeRequest.getStartTime();
-          }
-        }
-      }
-
-      // Check for the corresponding downgrade.
-      if (mostRecentUpgrade != null) {
-        for (UpgradeEntity downgrade : upgrades) {
-          // Surprisingly, a Downgrade's from and to version are identical.
-          if (downgrade.getClusterId() == cluster.getClusterId() && downgrade.getDirection()
== Direction.DOWNGRADE &&
-              downgrade.getFromVersion().equals(mostRecentUpgrade.getFromVersion())) {
-            correspondingDowngrade = downgrade;
-            break;
-          }
-        }
-
-        // If it has no downgrade, then the "Save Cluster State" step should have COMPLETED.
-        if (correspondingDowngrade == null) {
-          // Should have only 1 element.
-          List<HostRoleCommandEntity> finalizeCommandList = hostRoleCommandDaoProvider.get().
-              findSortedCommandsByRequestIdAndCustomCommandName(mostRecentUpgrade.getRequestId(),
FINALIZE_ACTION_CLASS_NAME);
-
-          // If the action is not COMPLETED, then something went wrong.
-          if (finalizeCommandList != null) {
-            for (HostRoleCommandEntity command : finalizeCommandList) {
-              if (command.getStatus() != HostRoleStatus.COMPLETED) {
-                errorMessage = MessageFormat.format("Upgrade attempt (id: {0}, request id:
{1}, from version: {2}, " +
-                    "to version: {3}) did not complete task with id {4} since its state is
{5} instead of COMPLETED.",
-                    mostRecentUpgrade.getId(), mostRecentUpgrade.getRequestId(), mostRecentUpgrade.getFromVersion(),
-                    mostRecentUpgrade.getToVersion(), command.getTaskId(), command.getStatus());
-                errorMessage += " Please ensure that you called:\n" + SET_CURRENT_COMMAND;
-                errorMessage += MessageFormat.format("\nFurther, change the status of host_role_command
with " +
-                    "id {0} to COMPLETED", mostRecentUpgrade.getId());
-                break;
-              }
-            }
-          }
-        }
-      }
+      errorMessage = MessageFormat.format(ERROR_MESSAGE, directionText,
+          upgradeInProgress.getFromVersion(), upgradeInProgress.getToVersion(), directionText);
     }
 
     if (null != errorMessage) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/f207b95f/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
index 67be152..5191e83 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
@@ -764,7 +764,9 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
       if (requestMap.containsKey(UPGRADE_FROM_VERSION)) {
         downgradeFromVersion = (String) requestMap.get(UPGRADE_FROM_VERSION);
       } else {
-        UpgradeEntity lastUpgradeItemForCluster = s_upgradeDAO.findLastUpgradeForCluster(cluster.getClusterId());
+        UpgradeEntity lastUpgradeItemForCluster = s_upgradeDAO.findLastUpgradeForCluster(
+            cluster.getClusterId(), Direction.UPGRADE);
+
         downgradeFromVersion = lastUpgradeItemForCluster.getToVersion();
       }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f207b95f/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java
index 2d0a4d7..bf9c650 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java
@@ -175,16 +175,19 @@ public class UpgradeDAO {
   }
 
   /**
-   * @param clusterId the cluster id
+   * @param clusterId
+   *          the cluster id
+   * @param direction
+   *          the direction (not {@code null}).
    * @return the upgrade entity, or {@code null} if not found
    */
   @RequiresSession
-  public UpgradeEntity findLastUpgradeForCluster(long clusterId) {
+  public UpgradeEntity findLastUpgradeForCluster(long clusterId, Direction direction) {
     TypedQuery<UpgradeEntity> query = entityManagerProvider.get().createNamedQuery(
         "UpgradeEntity.findLatestForClusterInDirection", UpgradeEntity.class);
     query.setMaxResults(1);
     query.setParameter("clusterId", clusterId);
-    query.setParameter("direction", Direction.UPGRADE);
+    query.setParameter("direction", direction);
 
     query.setHint(QueryHints.REFRESH, HintValues.TRUE);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f207b95f/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index 86ba1a1..46e2f8e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
@@ -3409,7 +3409,9 @@ public class ClusterImpl implements Cluster {
    */
   @Override
   public boolean isUpgradeSuspended() {
-    UpgradeEntity lastUpgradeItemForCluster = upgradeDAO.findLastUpgradeForCluster(clusterId);
+    UpgradeEntity lastUpgradeItemForCluster = upgradeDAO.findLastUpgradeForCluster(clusterId,
+        Direction.UPGRADE);
+
     if (null != lastUpgradeItemForCluster) {
       return lastUpgradeItemForCluster.isSuspended();
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f207b95f/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/host-ordered-upgrade.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/host-ordered-upgrade.xml
b/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/host-ordered-upgrade.xml
new file mode 100644
index 0000000..1b29af3
--- /dev/null
+++ b/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/host-ordered-upgrade.xml
@@ -0,0 +1,573 @@
+<?xml version="1.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.
+-->
+
+<upgrade xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="upgrade-pack.xsd">
+  <target>2.6.*.*</target>
+  <target-stack>HDP-2.6</target-stack>
+  <skip-failures>false</skip-failures>
+  <skip-service-check-failures>false</skip-service-check-failures>
+  <type>HOST_ORDERED</type>
+  <prerequisite-checks>
+    <!-- List of additional pre-req checks to run in addition to the required pre-reqs
-->
+    <check>org.apache.ambari.server.checks.MapReduce2JobHistoryStatePreservingCheck</check>
+    <check>org.apache.ambari.server.checks.ServicesMapReduceDistributedCacheCheck</check>
+    <check>org.apache.ambari.server.checks.ServicesTezDistributedCacheCheck</check>
+    <check>org.apache.ambari.server.checks.ServicesYarnWorkPreservingCheck</check>
+    <check>org.apache.ambari.server.checks.YarnTimelineServerStatePreservingCheck</check>
+  </prerequisite-checks>
+
+  <order>
+    <group xsi:type="cluster" name="PRE_CLUSTER" title="Prepare Upgrade">
+      <direction>UPGRADE</direction>
+      <execute-stage service="HDFS" component="NAMENODE" title="Pre Upgrade HDFS">
+        <task xsi:type="execute" hosts="master">
+          <script>scripts/namenode.py</script>
+          <function>prepare_rolling_upgrade</function>
+        </task>
+      </execute-stage>
+
+      <execute-stage service="TEZ" component="TEZ_CLIENT" title="Check Tez Tarball">
+        <task xsi:type="execute" hosts="any">
+          <script>scripts/pre_upgrade.py</script>
+          <function>prepare</function>
+        </task>
+      </execute-stage>
+    </group>
+
+    <group xsi:type="cluster" name="PREPARE_BACKUPS" title="Prepare Backups">
+      <direction>UPGRADE</direction>
+      <skippable>true</skippable>
+      <supports-auto-skip-failure>false</supports-auto-skip-failure>
+
+      <execute-stage service="HBASE" component="HBASE_MASTER" title="Pre Upgrade HBase
Backup">
+        <task xsi:type="execute" hosts="master">
+          <script>scripts/hbase_upgrade.py</script>
+          <function>take_snapshot</function>
+        </task>
+      </execute-stage>
+
+    </group>
+     
+    <!--
+    In a HOST_ORDERED upgrade, this placeholder group is expanded by the number of hosts
passed
+    when creating the upgrade.  For starters, this will include "stop" commands, a manual
+    verification task, and the "start" commands as indicated by the processing element.
+    If we get to the point where we need additional flexibility, it will get added at that
time.
+    -->
+    <group xsi:type="host-order" name="HOST_ORDER" title="Upgrade All Hosts">
+      <skippable>true</skippable>
+    </group>
+    
+    <!--
+    After processing this group, the user-specified Kerberos descriptor will be updated to
work with
+    the new stack-level Kerberos descriptor.
+    -->
+    <group xsi:type="cluster" name="UPDATE_KERBEROS_DESCRIPTORS" title="Update Kerberos
Descriptors">
+      <condition xsi:type="security" type="kerberos"/>
+      <execute-stage title="Update the user-specified Kerberos descriptor">
+        <task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.UpgradeUserKerberosDescriptor"/>
+      </execute-stage>
+    </group>
+
+    <group xsi:type="cluster" name="ALL_HOST_OPS" title="Finalize Hosts">
+      <scope>COMPLETE</scope>
+      <execute-stage title="Update remaining HDP stack to {{version}}">
+        <task xsi:type="execute">
+          <script>scripts/ru_set_all.py</script>
+          <function>actionexecute</function>
+        </task>
+      </execute-stage>
+    </group>
+
+    <group xsi:type="cluster" name="FINALIZE_PRE_CHECK" title="Finalize {{direction.text.proper}}
Pre-Check">
+      <direction>UPGRADE</direction>
+      
+      <execute-stage title="Check Component Versions">
+        <task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.ComponentVersionCheckAction"
/>
+      </execute-stage>
+    </group>
+
+    <group xsi:type="cluster" name="POST_CLUSTER" title="Finalize {{direction.text.proper}}">
+      <skippable>true</skippable>
+      <supports-auto-skip-failure>false</supports-auto-skip-failure>
+
+      <execute-stage title="Confirm Finalize">
+        <direction>UPGRADE</direction>
+        <task xsi:type="manual">
+          <message>Please confirm you are ready to finalize.</message>
+        </task>
+      </execute-stage>
+
+      <execute-stage service="HDFS" component="NAMENODE" title="Execute HDFS Finalize">
+        <task xsi:type="execute" hosts="master">
+          <script>scripts/namenode.py</script>
+          <function>finalize_rolling_upgrade</function>
+        </task>
+      </execute-stage>
+
+      <execute-stage title="Save Cluster State">
+        <task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction">
+        </task>
+      </execute-stage>
+    </group>
+  </order>
+
+  <processing>
+    <service name="ZOOKEEPER">
+      <component name="ZOOKEEPER_SERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="ZOOKEEPER_CLIENT">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="RANGER">
+      <component name="RANGER_ADMIN">
+        <pre-upgrade>
+
+          <task xsi:type="execute" hosts="all">
+            <script>scripts/ranger_admin.py</script>
+            <function>set_pre_start</function>
+          </task>
+
+          <task xsi:type="execute" hosts="any">
+            <summary>Upgrading Ranger database schema</summary>
+            <script>scripts/ranger_admin.py</script>
+            <function>setup_ranger_database</function>
+          </task>
+
+          <task xsi:type="configure_function" hosts="all" />
+
+          <task xsi:type="execute" hosts="any">
+            <summary>Applying Ranger java patches</summary>
+            <script>scripts/ranger_admin.py</script>
+            <function>setup_ranger_java_patches</function>
+          </task>
+        </pre-upgrade>
+
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+
+      </component>
+
+      <component name="RANGER_USERSYNC">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="RANGER_TAGSYNC">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="RANGER_KMS">
+      <component name="RANGER_KMS_SERVER">
+        <pre-upgrade>
+          <task xsi:type="execute" hosts="any" sequential="true">
+            <summary>Upgrading Ranger KMS database schema</summary>
+            <script>scripts/kms_server.py</script>
+            <function>setup_ranger_kms_database</function>
+          </task>
+        </pre-upgrade>
+
+        <pre-downgrade>
+          <task xsi:type="execute" hosts="any" sequential="true">
+            <summary>Downgrading Ranger KMS database schema</summary>
+            <script>scripts/kms_server.py</script>
+            <function>setup_ranger_kms_database</function>
+          </task>
+        </pre-downgrade>
+
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="HDFS">
+      <component name="NAMENODE">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="SECONDARY_NAMENODE">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="DATANODE">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="HDFS_CLIENT">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="JOURNALNODE">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="ZKFC">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="NFS_GATEWAY">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="MAPREDUCE2">
+      <component name="HISTORYSERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="MAPREDUCE2_CLIENT">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="YARN">
+      <component name="APP_TIMELINE_SERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="RESOURCEMANAGER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="NODEMANAGER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="YARN_CLIENT">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="KAFKA">
+      <component name="KAFKA_BROKER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="HBASE">
+      <component name="HBASE_MASTER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="HBASE_REGIONSERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="HBASE_CLIENT">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="TEZ">
+      <component name="TEZ_CLIENT">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="MAHOUT">
+      <component name="MAHOUT">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="PIG">
+      <component name="PIG">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="SQOOP">
+      <component name="SQOOP">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="HIVE">
+      <component name="HIVE_METASTORE">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="HIVE_SERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="HIVE_SERVER_INTERACTIVE">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="WEBHCAT_SERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="HIVE_CLIENT">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="HCAT">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="SPARK">
+      <component name="SPARK_JOBHISTORYSERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+      <component name="SPARK_THRIFTSERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+      <component name="LIVY_SERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+      <component name="SPARK_CLIENT">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="ZEPPELIN">
+      <component name="ZEPPELIN_MASTER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="OOZIE">
+      <component name="OOZIE_SERVER">
+        <pre-upgrade>
+          <!-- It is extremely important that both of these tasks run on the exact same
host. Hence, pick the first alphabetically. -->
+          <task xsi:type="configure_function" hosts="first" />
+
+          <task xsi:type="execute" hosts="first" sequential="true">
+            <summary>Upgrading the Oozie database and creating a new sharelib</summary>
+            <script>scripts/oozie_server_upgrade.py</script>
+            <function>upgrade_oozie_database_and_sharelib</function>
+          </task>
+        </pre-upgrade>
+
+        <pre-downgrade>
+          <task xsi:type="execute" hosts="any" sequential="true">
+            <summary>Create a new sharelib</summary>
+            <script>scripts/oozie_server_upgrade.py</script>
+            <function>create_sharelib</function>
+          </task>
+        </pre-downgrade>
+
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="OOZIE_CLIENT">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="FALCON">
+      <component name="FALCON_SERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+      <component name="FALCON_CLIENT">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="KNOX">
+      <component name="KNOX_GATEWAY">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="STORM">
+      <component name="NIMBUS">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="SUPERVISOR">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="STORM_UI_SERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="DRPC_SERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="ACCUMULO">
+      <component name="ACCUMULO_MASTER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="ACCUMULO_TSERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="ACCUMULO_MONITOR">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="ACCUMULO_GC">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="ACCUMULO_TRACER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="ACCUMULO_CLIENT">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="SLIDER">
+      <component name="SLIDER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="FLUME">
+      <component name="FLUME_HANDLER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+
+    <service name="ATLAS">
+      <component name="ATLAS_SERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+
+      <component name="ATLAS_CLIENT">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+  </processing>
+</upgrade>

http://git-wip-us.apache.org/repos/asf/ambari/blob/f207b95f/ambari-server/src/test/java/org/apache/ambari/server/checks/PreviousUpgradeCompletedTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/PreviousUpgradeCompletedTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/checks/PreviousUpgradeCompletedTest.java
index ab8da1b..4bfa8d4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/PreviousUpgradeCompletedTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/PreviousUpgradeCompletedTest.java
@@ -17,19 +17,7 @@
  */
 package org.apache.ambari.server.checks;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.ambari.server.actionmanager.HostRoleStatus;
-import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
-import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
-import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
-import org.apache.ambari.server.orm.dao.RequestDAO;
-import org.apache.ambari.server.orm.dao.UpgradeDAO;
-import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
-import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
-import org.apache.ambari.server.orm.entities.RequestEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.orm.entities.UpgradeEntity;
 import org.apache.ambari.server.state.Cluster;
@@ -45,7 +33,6 @@ import org.mockito.Mockito;
 
 import com.google.inject.Provider;
 
-
 /**
  * Unit tests for PreviousUpgradeCompleted
  *
@@ -53,167 +40,59 @@ import com.google.inject.Provider;
 public class PreviousUpgradeCompletedTest {
 
   private final Clusters clusters = Mockito.mock(Clusters.class);
-  private final ClusterVersionDAO clusterVersionDAO = Mockito.mock(ClusterVersionDAO.class);
-  private AmbariMetaInfo ambariMetaInfo = Mockito.mock(AmbariMetaInfo.class);
-  private final RequestDAO requestDAO = Mockito.mock(RequestDAO.class);
-  private HostRoleCommandDAO hrcDAO = Mockito.mock(HostRoleCommandDAO.class);
-  private UpgradeDAO upgradeDAO = Mockito.mock(UpgradeDAO.class);
-
+  private final Cluster cluster = Mockito.mock(Cluster.class);
   private StackId sourceStackId = new StackId("HDP", "2.2");
   private StackId targetStackId = new StackId("HDP", "2.2");
   private String sourceRepositoryVersion = "2.2.6.0-1234";
   private String destRepositoryVersion = "2.2.8.0-5678";
   private String clusterName = "cluster";
+  private PrereqCheckRequest checkRequest = new PrereqCheckRequest(clusterName);
+  private PreviousUpgradeCompleted puc = new PreviousUpgradeCompleted();
 
-  private PreviousUpgradeCompleted puc;
   /**
    *
    */
   @Before
-  public void setup() {
-    puc = new PreviousUpgradeCompleted();
-    puc.clustersProvider = new Provider<Clusters>() {
-      @Override
-      public Clusters get() {
-        return clusters;
-      }
-    };
-
-    puc.ambariMetaInfo = new Provider<AmbariMetaInfo>() {
-      @Override
-      public AmbariMetaInfo get() {
-        return ambariMetaInfo;
-      }
-    };
-
-    puc.clusterVersionDAOProvider = new Provider<ClusterVersionDAO>() {
-      @Override
-      public ClusterVersionDAO get() {
-        return clusterVersionDAO;
-      }
-    };
-
-    puc.requestDaoProvider = new Provider<RequestDAO>() {
-      @Override
-      public RequestDAO get() {
-        return requestDAO;
-      }
-    };
-
-    puc.hostRoleCommandDaoProvider = new Provider<HostRoleCommandDAO>() {
-      @Override
-      public HostRoleCommandDAO get() {
-        return hrcDAO;
-      }
-    };
-
-    puc.upgradeDaoProvider = new Provider<UpgradeDAO>() {
-      @Override
-      public UpgradeDAO get() {
-        return upgradeDAO;
-      }
-    };
-  }
+  public void setup() throws Exception {
+    Mockito.when(cluster.getClusterId()).thenReturn(1L);
+    Mockito.when(cluster.getClusterName()).thenReturn(clusterName);
+    Mockito.when(clusters.getCluster(clusterName)).thenReturn(cluster);
 
-  @Test
-  public void testPerform() throws Exception {
     StackId stackId = new StackId("HDP", "2.2");
 
     StackEntity stack = new StackEntity();
     stack.setStackName(stackId.getStackName());
     stack.setStackVersion(stackId.getStackVersion());
-    RepositoryVersionEntity rve = new RepositoryVersionEntity(stack, sourceRepositoryVersion,
sourceRepositoryVersion, "rhel6");
-    final Cluster cluster = Mockito.mock(Cluster.class);
-    Mockito.when(cluster.getClusterName()).thenReturn(clusterName);
-    final long clusterId = 1L;
-    Mockito.when(cluster.getClusterId()).thenReturn(clusterId);
 
-    PrereqCheckRequest checkRequest = new PrereqCheckRequest(clusterName);
     checkRequest.setRepositoryVersion(sourceRepositoryVersion);
     checkRequest.setSourceStackId(sourceStackId);
     checkRequest.setTargetStackId(targetStackId);
 
-    List<UpgradeEntity> upgrades = new ArrayList<>();
-    Mockito.when(upgradeDAO.findAll()).thenReturn(upgrades);
+    puc.clustersProvider = new Provider<Clusters>() {
+      @Override
+      public Clusters get() {
+        return clusters;
+      }
+    };
 
-    Mockito.when(clusters.getCluster(clusterName)).thenReturn(cluster);
+  }
 
-    
-    // Case 1. No previous upgrades
+  @Test
+  public void testPerform() throws Exception {
+    // no existing upgrades
+    Mockito.when(cluster.getUpgradeInProgress()).thenReturn(null);
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
     puc.perform(check, checkRequest);
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
+    // existing upgrade
+    UpgradeEntity upgradeInProgress = Mockito.mock(UpgradeEntity.class);
+    Mockito.when(upgradeInProgress.getDirection()).thenReturn(Direction.UPGRADE);
+    Mockito.when(upgradeInProgress.getClusterId()).thenReturn(1L);
+    Mockito.when(upgradeInProgress.getFromVersion()).thenReturn(sourceRepositoryVersion);
+    Mockito.when(upgradeInProgress.getToVersion()).thenReturn(destRepositoryVersion);
 
-    // Case 2. Initialize with only one completed upgrade
-    final long upgradeRequestId = 1L;
-    RequestEntity upgradeRequest = Mockito.mock(RequestEntity.class);
-    Mockito.when(upgradeRequest.getRequestId()).thenReturn(upgradeRequestId);
-    Mockito.when(upgradeRequest.getStartTime()).thenReturn(System.currentTimeMillis() - 1000);
-    Mockito.when(requestDAO.findByPK(upgradeRequestId)).thenReturn(upgradeRequest);
-
-    UpgradeEntity upgrade = Mockito.mock(UpgradeEntity.class);
-    Mockito.when(upgrade.getClusterId()).thenReturn(clusterId);
-    Mockito.when(upgrade.getRequestId()).thenReturn(upgradeRequestId);
-    Mockito.when(upgrade.getDirection()).thenReturn(Direction.UPGRADE);
-    Mockito.when(upgrade.getFromVersion()).thenReturn(sourceRepositoryVersion);
-    Mockito.when(upgrade.getToVersion()).thenReturn(destRepositoryVersion);
-
-    upgrades.add(upgrade);
-    Mockito.when(upgradeDAO.findAll()).thenReturn(upgrades);
-
-    check = new PrerequisiteCheck(null, null);
-    puc.perform(check, checkRequest);
-    Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
-
-
-    // Case 3. Initialize with a successful downgrade.
-    final long downgradeRequestId = 2L;
-    RequestEntity downgradeRequest = Mockito.mock(RequestEntity.class);
-    Mockito.when(downgradeRequest.getRequestId()).thenReturn(downgradeRequestId);
-    Mockito.when(downgradeRequest.getStartTime()).thenReturn(System.currentTimeMillis() -
500);
-    Mockito.when(requestDAO.findByPK(downgradeRequestId)).thenReturn(downgradeRequest);
-
-    UpgradeEntity downgrade = Mockito.mock(UpgradeEntity.class);
-    Mockito.when(downgrade.getClusterId()).thenReturn(clusterId);
-    Mockito.when(downgrade.getRequestId()).thenReturn(downgradeRequestId);
-    Mockito.when(downgrade.getDirection()).thenReturn(Direction.DOWNGRADE);
-    Mockito.when(downgrade.getFromVersion()).thenReturn(sourceRepositoryVersion);
-    Mockito.when(downgrade.getToVersion()).thenReturn(sourceRepositoryVersion);
-
-    upgrades.clear();
-    upgrades.add(upgrade);
-    upgrades.add(downgrade);
-    Mockito.when(upgradeDAO.findAll()).thenReturn(upgrades);
-
-    check = new PrerequisiteCheck(null, null);
-    puc.perform(check, checkRequest);
-    Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
-
-
-    // Case 4. The upgrade has no downgrade, and it has a COMPLETED "Save Cluster State"
step, so it should pass.
-    HostRoleCommandEntity finalizeCommand = Mockito.mock(HostRoleCommandEntity.class);
-    Mockito.when(finalizeCommand.getStatus()).thenReturn(HostRoleStatus.COMPLETED);
-    Mockito.when(finalizeCommand.getTaskId()).thenReturn(1000L);
-    List<HostRoleCommandEntity> commands = new ArrayList<>();
-    commands.add(finalizeCommand);
-    Mockito.when(hrcDAO.findSortedCommandsByRequestIdAndCustomCommandName(upgradeRequestId,
PreviousUpgradeCompleted.FINALIZE_ACTION_CLASS_NAME)).thenReturn(commands);
-
-    upgrades.clear();
-    upgrades.add(upgrade);
-    Mockito.when(upgradeDAO.findAll()).thenReturn(upgrades);
-
-    check = new PrerequisiteCheck(null, null);
-    puc.perform(check, checkRequest);
-    Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
-
-
-    // Case 5. The upgrade has no downgrade, and it has an ABORTED "Save Cluster State" step,
so it should fail.
-    Mockito.when(finalizeCommand.getStatus()).thenReturn(HostRoleStatus.ABORTED);
-    upgrades.clear();
-    upgrades.add(upgrade);
-    Mockito.when(upgradeDAO.findAll()).thenReturn(upgrades);
-
+    Mockito.when(cluster.getUpgradeInProgress()).thenReturn(upgradeInProgress);
     check = new PrerequisiteCheck(null, null);
     puc.perform(check, checkRequest);
     Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());

http://git-wip-us.apache.org/repos/asf/ambari/blob/f207b95f/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
index 1861c0e..92e4a49 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
@@ -629,7 +629,7 @@ public class UpgradeResourceProviderTest {
     upgrades = upgradeDao.findUpgrades(cluster.getClusterId());
     assertEquals(1, upgrades.size());
 
-    UpgradeEntity lastUpgrade = upgradeDao.findLastUpgradeForCluster(cluster.getClusterId());
+    UpgradeEntity lastUpgrade = upgradeDao.findLastUpgradeForCluster(cluster.getClusterId(),
Direction.UPGRADE);
     assertNotNull(lastUpgrade);
 
     Map<String, Object> requestProps = new HashMap<String, Object>();

http://git-wip-us.apache.org/repos/asf/ambari/blob/f207b95f/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/UpgradeDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/UpgradeDAOTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/UpgradeDAOTest.java
index cc49cbd..ae85241 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/UpgradeDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/UpgradeDAOTest.java
@@ -185,7 +185,7 @@ public class UpgradeDAOTest {
     entity3.setUpgradePackage("test-upgrade");
     entity3.setDowngradeAllowed(true);
     dao.create(entity3);
-    UpgradeEntity lastUpgradeForCluster = dao.findLastUpgradeForCluster(1);
+    UpgradeEntity lastUpgradeForCluster = dao.findLastUpgradeForCluster(1, Direction.UPGRADE);
     assertNotNull(lastUpgradeForCluster);
     assertEquals(33L, (long)lastUpgradeForCluster.getId());
   }
@@ -215,7 +215,7 @@ public class UpgradeDAOTest {
     upgradeEntity.setUpgradePackage("test-upgrade");
     dao.create(upgradeEntity);
 
-    UpgradeEntity lastUpgradeForCluster = dao.findLastUpgradeForCluster(1);
+    UpgradeEntity lastUpgradeForCluster = dao.findLastUpgradeForCluster(1, Direction.UPGRADE);
     Assert.assertFalse(lastUpgradeForCluster.isComponentFailureAutoSkipped());
     Assert.assertFalse(lastUpgradeForCluster.isServiceCheckFailureAutoSkipped());
 
@@ -223,7 +223,7 @@ public class UpgradeDAOTest {
     lastUpgradeForCluster.setAutoSkipServiceCheckFailures(true);
     dao.merge(lastUpgradeForCluster);
 
-    lastUpgradeForCluster = dao.findLastUpgradeForCluster(1);
+    lastUpgradeForCluster = dao.findLastUpgradeForCluster(1, Direction.UPGRADE);
     Assert.assertTrue(lastUpgradeForCluster.isComponentFailureAutoSkipped());
     Assert.assertTrue(lastUpgradeForCluster.isServiceCheckFailureAutoSkipped());
   }


Mime
View raw message