ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alejan...@apache.org
Subject [3/9] ambari git commit: AMBARI-13392. Stop-and-Start Upgrade: Merge branch branch-dev-stop-all-upgrade to branch-2.1 for feature Stop-the-World Upgrade, aka Express Upgrade (alejandro, dlysnichenko, Dmytro Grinenko)
Date Mon, 12 Oct 2015 21:07:36 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheckTest.java
index 947121a..5713f59 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheckTest.java
@@ -65,14 +65,18 @@ public class ServicesNamenodeHighAvailabilityCheckTest {
   @Test
   public void testIsApplicable() throws Exception {
     final Cluster cluster = Mockito.mock(Cluster.class);
+    final Map<String, Service> services = new HashMap<>();
+    final Service service = Mockito.mock(Service.class);
+
+    services.put("HDFS", service);
+
+    Mockito.when(cluster.getServices()).thenReturn(services);
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
     Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
 
-    final Service service = Mockito.mock(Service.class);
-    Mockito.when(cluster.getService("HDFS")).thenReturn(service);
     Assert.assertTrue(servicesNamenodeHighAvailabilityCheck.isApplicable(new PrereqCheckRequest("cluster")));
 
-    Mockito.when(cluster.getService("HDFS")).thenThrow(new ServiceNotFoundException("no", "service"));
+    services.remove("HDFS");
     Assert.assertFalse(servicesNamenodeHighAvailabilityCheck.isApplicable(new PrereqCheckRequest("cluster")));
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java
index 07d17d8..ef39e9e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java
@@ -40,6 +40,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 import com.google.inject.Provider;
+import org.mockito.Mockito;
 
 /**
  * Unit tests for ServicesUpCheck
@@ -56,9 +57,14 @@ public class ServicesNamenodeTruncateCheckTest {
     Cluster cluster = EasyMock.createMock(Cluster.class);
 
     Config config = EasyMock.createMock(Config.class);
+    final Map<String, Service> services = new HashMap<>();
+    final Service service = Mockito.mock(Service.class);
 
+    services.put("HDFS", service);
+
+    expect(cluster.getServices()).andReturn(services).anyTimes();
     expect(config.getProperties()).andReturn(m_configMap).anyTimes();
-    expect(cluster.getService("HDFS")).andReturn(EasyMock.createMock(Service.class));
+    expect(cluster.getService("HDFS")).andReturn(service);
     expect(cluster.getDesiredConfigByType("hdfs-site")).andReturn(config).anyTimes();
     expect(m_clusters.getCluster((String) anyObject())).andReturn(cluster).anyTimes();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheckTest.java
index d732302..d70d575 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheckTest.java
@@ -65,27 +65,28 @@ public class ServicesTezDistributedCacheCheckTest {
   @Test
   public void testIsApplicable() throws Exception {
     final Cluster cluster = Mockito.mock(Cluster.class);
+    final Map<String, Service> services = new HashMap<>();
+    final Service service = Mockito.mock(Service.class);
+
+    services.put("TEZ", service);
+
+    Mockito.when(cluster.getServices()).thenReturn(services);
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
     Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
 
-    final Service service = Mockito.mock(Service.class);
-    Mockito.when(cluster.getService("TEZ")).thenReturn(service);
+
     Assert.assertTrue(servicesTezDistributedCacheCheck.isApplicable(new PrereqCheckRequest("cluster")));
 
     PrereqCheckRequest req = new PrereqCheckRequest("cluster");
     req.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.FAIL);
-    Mockito.when(cluster.getService("TEZ")).thenReturn(service);
     Assert.assertFalse(servicesTezDistributedCacheCheck.isApplicable(req));
 
     req.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.PASS);
-    Mockito.when(cluster.getService("TEZ")).thenReturn(service);
     Assert.assertTrue(servicesTezDistributedCacheCheck.isApplicable(req));
 
 
-    Mockito.when(cluster.getService("TEZ")).thenThrow(new ServiceNotFoundException("no", "service"));
+    services.remove("TEZ");
     Assert.assertFalse(servicesTezDistributedCacheCheck.isApplicable(new PrereqCheckRequest("cluster")));
-
-
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheckTest.java
index 135c9c9..5658f17 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheckTest.java
@@ -65,14 +65,18 @@ public class ServicesYarnWorkPreservingCheckTest {
   @Test
   public void testIsApplicable() throws Exception {
     final Cluster cluster = Mockito.mock(Cluster.class);
+    final Map<String, Service> services = new HashMap<>();
+    final Service service = Mockito.mock(Service.class);
+
+    services.put("YARN", service);
+
+    Mockito.when(cluster.getServices()).thenReturn(services);
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
     Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
 
-    final Service service = Mockito.mock(Service.class);
-    Mockito.when(cluster.getService("YARN")).thenReturn(service);
     Assert.assertTrue(servicesYarnWorkPreservingCheck.isApplicable(new PrereqCheckRequest("cluster")));
 
-    Mockito.when(cluster.getService("YARN")).thenThrow(new ServiceNotFoundException("no", "service"));
+   services.remove("YARN");
     Assert.assertFalse(servicesYarnWorkPreservingCheck.isApplicable(new PrereqCheckRequest("cluster")));
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/checks/UpgradeCheckStackVersionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/UpgradeCheckStackVersionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/UpgradeCheckStackVersionTest.java
deleted file mode 100644
index 8d8b08f..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/UpgradeCheckStackVersionTest.java
+++ /dev/null
@@ -1,170 +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.checks;
-
-import junit.framework.Assert;
-
-import org.apache.ambari.server.controller.PrereqCheckRequest;
-import org.apache.ambari.server.state.StackId;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-
-/**
- * Tests that the {@link AbstractCheckDescriptor} instances will return the
- * correct values for
- * {@link AbstractCheckDescriptor#isApplicable(org.apache.ambari.server.controller.PrereqCheckRequest)}
- * when different stack versions are present.
- */
-public class UpgradeCheckStackVersionTest {
-
-  @Test
-  public void testUpgradeCheckForMoreRecentStack() throws Exception {
-    AbstractCheckDescriptor invalidCheck = EasyMock.createMockBuilder(AbstractCheckDescriptor.class).addMockedMethods(
-        "getSourceStack", "getTargetStack").createMock();
-
-    EasyMock.expect(invalidCheck.getSourceStack()).andReturn(new StackId("HDP-2.3"));
-    EasyMock.expect(invalidCheck.getTargetStack()).andReturn(new StackId("HDP-2.3"));
-
-    EasyMock.replay(invalidCheck);
-
-    PrereqCheckRequest checkRequest = new PrereqCheckRequest("c1");
-    checkRequest.setRepositoryVersion("HDP-2.2.0.0");
-    checkRequest.setSourceStackId(new StackId("HDP", "2.2"));
-    checkRequest.setTargetStackId(new StackId("HDP", "2.2"));
-
-    // false because the upgrade is for 2.2->2.2 and the check starts at 2.3
-    Assert.assertFalse(invalidCheck.isApplicable(checkRequest));
-
-    EasyMock.verify(invalidCheck);
-  }
-
-  @Test
-  public void testUpgradeCheckForOlderStack() throws Exception {
-    AbstractCheckDescriptor invalidCheck = EasyMock.createMockBuilder(AbstractCheckDescriptor.class).addMockedMethods(
-        "getSourceStack", "getTargetStack").createMock();
-
-    EasyMock.expect(invalidCheck.getSourceStack()).andReturn(new StackId("HDP-2.2"));
-    EasyMock.expect(invalidCheck.getTargetStack()).andReturn(new StackId("HDP-2.2"));
-
-    EasyMock.replay(invalidCheck);
-
-    PrereqCheckRequest checkRequest = new PrereqCheckRequest("c1");
-    checkRequest.setRepositoryVersion("HDP-2.3.0.0");
-    checkRequest.setSourceStackId(new StackId("HDP", "2.3"));
-    checkRequest.setTargetStackId(new StackId("HDP", "2.3"));
-
-    // false because the upgrade is for 2.3->2.3 and the check is only for 2.2
-    Assert.assertFalse(invalidCheck.isApplicable(checkRequest));
-
-    EasyMock.verify(invalidCheck);
-  }
-
-  @Test
-  public void testUpgradeCheckForWithinStackOnly() throws Exception {
-    AbstractCheckDescriptor invalidCheck = EasyMock.createMockBuilder(AbstractCheckDescriptor.class).addMockedMethods(
-        "getSourceStack", "getTargetStack").createMock();
-
-    EasyMock.expect(invalidCheck.getSourceStack()).andReturn(new StackId("HDP-2.2"));
-    EasyMock.expect(invalidCheck.getTargetStack()).andReturn(new StackId("HDP-2.2"));
-
-    EasyMock.replay(invalidCheck);
-
-    PrereqCheckRequest checkRequest = new PrereqCheckRequest("c1");
-    checkRequest.setRepositoryVersion("HDP-2.3.0.0");
-    checkRequest.setSourceStackId(new StackId("HDP", "2.2"));
-    checkRequest.setTargetStackId(new StackId("HDP", "2.3"));
-
-    // false because the upgrade is for 2.2->2.3 and the check is only for 2.2
-    // to 2.2
-    Assert.assertFalse(invalidCheck.isApplicable(checkRequest));
-
-    EasyMock.verify(invalidCheck);
-  }
-
-  @Test
-  public void testUpgradeCheckMatchesExactly() throws Exception {
-    AbstractCheckDescriptor invalidCheck = EasyMock.createMockBuilder(AbstractCheckDescriptor.class).addMockedMethods(
-        "getSourceStack", "getTargetStack").createMock();
-
-    EasyMock.expect(invalidCheck.getSourceStack()).andReturn(new StackId("HDP-2.2"));
-    EasyMock.expect(invalidCheck.getTargetStack()).andReturn(new StackId("HDP-2.2"));
-
-    EasyMock.replay(invalidCheck);
-
-    PrereqCheckRequest checkRequest = new PrereqCheckRequest("c1");
-    checkRequest.setRepositoryVersion("HDP-2.2.0.0");
-    checkRequest.setSourceStackId(new StackId("HDP", "2.2"));
-    checkRequest.setTargetStackId(new StackId("HDP", "2.2"));
-
-    // pass because the upgrade is for 2.2->2.2 and the check is only for 2.2
-    // to 2.2
-    Assert.assertTrue(invalidCheck.isApplicable(checkRequest));
-
-    EasyMock.verify(invalidCheck);
-  }
-
-  @Test
-  public void testNoUpgradeStacksDefined() throws Exception {
-    AbstractCheckDescriptor invalidCheck = EasyMock.createMockBuilder(AbstractCheckDescriptor.class).addMockedMethods(
-        "getSourceStack", "getTargetStack").createMock();
-
-    EasyMock.expect(invalidCheck.getSourceStack()).andReturn(null);
-    EasyMock.expect(invalidCheck.getTargetStack()).andReturn(null);
-
-    EasyMock.replay(invalidCheck);
-
-    PrereqCheckRequest checkRequest = new PrereqCheckRequest("c1");
-    checkRequest.setRepositoryVersion("HDP-2.3.0.0");
-    checkRequest.setSourceStackId(new StackId("HDP", "2.2"));
-    checkRequest.setTargetStackId(new StackId("HDP", "2.3"));
-
-    // pass because there are no restrictions
-    Assert.assertTrue(invalidCheck.isApplicable(checkRequest));
-
-    EasyMock.verify(invalidCheck);
-  }
-
-  @Test
-  public void testUpgradeStartsAtSpecifiedStackVersion() throws Exception {
-    AbstractCheckDescriptor invalidCheck = EasyMock.createMockBuilder(AbstractCheckDescriptor.class).addMockedMethods(
-        "getSourceStack", "getTargetStack").createMock();
-
-    EasyMock.expect(invalidCheck.getSourceStack()).andReturn(new StackId("HDP-2.3")).atLeastOnce();
-    EasyMock.expect(invalidCheck.getTargetStack()).andReturn(null).atLeastOnce();
-
-    EasyMock.replay(invalidCheck);
-
-    PrereqCheckRequest checkRequest = new PrereqCheckRequest("c1");
-    checkRequest.setRepositoryVersion("HDP-2.2.0.0");
-    checkRequest.setSourceStackId(new StackId("HDP", "2.2"));
-    checkRequest.setTargetStackId(new StackId("HDP", "2.2"));
-
-    // false because this check starts at 2.3 and the upgrade is 2.2 -> 2.2
-    Assert.assertFalse(invalidCheck.isApplicable(checkRequest));
-
-    checkRequest.setRepositoryVersion("HDP-2.3.0.0");
-    checkRequest.setSourceStackId(new StackId("HDP", "2.2"));
-    checkRequest.setTargetStackId(new StackId("HDP", "2.3"));
-
-    // false because this check starts at 2.3 and the upgrade is 2.2 -> 2.3
-    Assert.assertFalse(invalidCheck.isApplicable(checkRequest));
-
-    EasyMock.verify(invalidCheck);
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index d1e58a1..eed4379 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -7189,7 +7189,7 @@ public class AmbariManagementControllerTest {
     Assert.assertEquals(1, responsesWithParams.size());
     StackVersionResponse resp = responsesWithParams.iterator().next();
     assertNotNull(resp.getUpgradePacks());
-    assertEquals(5, resp.getUpgradePacks().size());
+    assertEquals(6, resp.getUpgradePacks().size());
     assertTrue(resp.getUpgradePacks().contains("upgrade_test"));
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java
index ea6e56e..ab06a5c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java
@@ -102,6 +102,12 @@ public class CompatibleRepositoryVersionResourceProviderTest {
         Map<String, UpgradePack> map = new HashMap<String, UpgradePack>();
 
         UpgradePack pack1 = new UpgradePack() {
+
+          @Override
+          public String getName() {
+            return "pack1";
+          }
+
           @Override
           public String getTarget() {
             return "1.1.*.*";
@@ -110,6 +116,11 @@ public class CompatibleRepositoryVersionResourceProviderTest {
 
         final UpgradePack pack2 = new UpgradePack() {
           @Override
+          public String getName() {
+            return "pack2";
+          }
+
+          @Override
           public String getTarget() {
             return "2.2.*.*";
           }
@@ -133,6 +144,11 @@ public class CompatibleRepositoryVersionResourceProviderTest {
 
         UpgradePack pack = new UpgradePack() {
           @Override
+          public String getName() {
+            return "pack2";
+          }
+
+          @Override
           public String getTarget() {
             return "2.2.*.*";
           }

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
index 442bcb2..493cfbb 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
@@ -42,11 +42,14 @@ import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
 import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
+import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
+import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.OperatingSystemInfo;
 import org.apache.ambari.server.state.RepositoryVersionState;
+import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.stack.UpgradePack;
 import org.junit.After;
@@ -67,16 +70,43 @@ import com.google.inject.persist.PersistService;
  */
 public class RepositoryVersionResourceProviderTest {
 
+  private ClusterVersionDAO clusterVersionDAO;
+
   private static Injector injector;
 
   private static String jsonStringRedhat6 = "[{\"OperatingSystems\":{\"os_type\":\"redhat6\"},\"repositories\":[]}]";
   private static String jsonStringRedhat7 = "[{\"OperatingSystems\":{\"os_type\":\"redhat7\"},\"repositories\":[]}]";
 
+  private List<ClusterVersionEntity> getNoClusterVersions() {
+    final List<ClusterVersionEntity> emptyList = new ArrayList<ClusterVersionEntity>();
+    return emptyList;
+  }
+
+  private List<ClusterVersionEntity> getInstallFailedClusterVersions() {
+    ClusterEntity cluster = new ClusterEntity();
+    cluster.setClusterName("c1");
+    cluster.setClusterId(1L);
+
+    final List<ClusterVersionEntity> clusterVersions = new ArrayList<ClusterVersionEntity>();
+    final RepositoryVersionEntity repositoryVersion = new RepositoryVersionEntity();
+    repositoryVersion.setId(1L);
+    final ClusterVersionEntity installFailedVersion = new ClusterVersionEntity();
+    installFailedVersion.setState(RepositoryVersionState.INSTALL_FAILED);
+    installFailedVersion.setRepositoryVersion(repositoryVersion);
+    installFailedVersion.setClusterEntity(cluster);
+    clusterVersions.add(installFailedVersion);
+    cluster.setClusterVersionEntities(clusterVersions);
+    return clusterVersions;
+  }
+
   @Before
   public void before() throws Exception {
     final Set<String> validVersions = Sets.newHashSet("1.1", "1.1-17", "1.1.1.1", "1.1.343432.2", "1.1.343432.2-234234324");
+    final Set<StackInfo> stacks = new HashSet<StackInfo>();
+
     final AmbariMetaInfo ambariMetaInfo = Mockito.mock(AmbariMetaInfo.class);
-    final ClusterVersionDAO clusterVersionDAO = Mockito.mock(ClusterVersionDAO.class);
+    clusterVersionDAO = Mockito.mock(ClusterVersionDAO.class);
+
     final InMemoryDefaultTestModule injectorModule = new InMemoryDefaultTestModule() {
       @Override
       protected void configure() {
@@ -93,12 +123,22 @@ public class RepositoryVersionResourceProviderTest {
         final Map<String, UpgradePack> map = new HashMap<String, UpgradePack>();
         final UpgradePack pack1 = new UpgradePack() {
           @Override
+          public String getName() {
+            return "pack1";
+          }
+
+          @Override
           public String getTarget() {
             return "1.1.*.*";
           }
         };
         final UpgradePack pack2 = new UpgradePack() {
           @Override
+          public String getName() {
+            return "pack2";
+          }
+
+          @Override
           public String getTarget() {
             return "1.1.*.*";
           }
@@ -108,6 +148,9 @@ public class RepositoryVersionResourceProviderTest {
         return map;
       }
     };
+    stackInfo.setName("HDP");
+    stackInfo.setVersion("1.1");
+    stacks.add(stackInfo);
     Mockito.when(ambariMetaInfo.getStack(Mockito.anyString(), Mockito.anyString())).thenAnswer(new Answer<StackInfo>() {
 
       @Override
@@ -122,7 +165,7 @@ public class RepositoryVersionResourceProviderTest {
       }
 
     });
-
+    Mockito.when(ambariMetaInfo.getStacks()).thenReturn(stacks);
     Mockito.when(ambariMetaInfo.getUpgradePacks(Mockito.anyString(), Mockito.anyString())).thenAnswer(new Answer<Map<String, UpgradePack>>() {
 
       @Override
@@ -151,29 +194,17 @@ public class RepositoryVersionResourceProviderTest {
       }
     });
 
-    Mockito.when(
-        clusterVersionDAO.findByStackAndVersion(Mockito.anyString(),
-            Mockito.anyString(), Mockito.anyString())).thenAnswer(
+    Mockito.when(clusterVersionDAO.findByStackAndVersion(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenAnswer(
         new Answer<List<ClusterVersionEntity>>() {
-
       @Override
-      public List<ClusterVersionEntity> answer(InvocationOnMock invocation)
-          throws Throwable {
+      public List<ClusterVersionEntity> answer(InvocationOnMock invocation) throws Throwable {
         final String stack = invocation.getArguments()[0].toString();
         final String version = invocation.getArguments()[1].toString();
+
         if (stack.equals("HDP-1.1") && version.equals("1.1.1.1")) {
-          final List<ClusterVersionEntity> notEmptyList = new ArrayList<ClusterVersionEntity>();
-          notEmptyList.add(null);
-          return notEmptyList;
+          return getNoClusterVersions();
         } else {
-          final List<ClusterVersionEntity> clusterVersions = new ArrayList<ClusterVersionEntity>();
-          final RepositoryVersionEntity repositoryVersion = new RepositoryVersionEntity();
-          repositoryVersion.setId(1L);
-          final ClusterVersionEntity installFailedVersion = new ClusterVersionEntity();
-          installFailedVersion.setState(RepositoryVersionState.INSTALL_FAILED);
-          installFailedVersion.setRepositoryVersion(repositoryVersion);
-          clusterVersions.add(installFailedVersion);
-          return clusterVersions;
+          return getInstallFailedClusterVersions();
         }
       }
     });
@@ -187,6 +218,9 @@ public class RepositoryVersionResourceProviderTest {
     stackEntity.setStackName("HDP");
     stackEntity.setStackVersion("1.1");
     stackDAO.create(stackEntity);
+
+    Clusters clusters = injector.getInstance(Clusters.class);
+    clusters.addCluster("c1", new StackId("HDP", "1.1"));
   }
 
   @Test
@@ -198,7 +232,6 @@ public class RepositoryVersionResourceProviderTest {
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID, "name");
     properties.put(RepositoryVersionResourceProvider.SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID, new Gson().fromJson("[{\"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"1\",\"Repositories/repo_name\":\"1\",\"Repositories/base_url\":\"1\"}]}]", Object.class));
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID, "HDP");
-    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID, "pack1");
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID, "1.1");
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID, "1.1.1.1");
     propertySet.add(properties);
@@ -251,7 +284,6 @@ public class RepositoryVersionResourceProviderTest {
     final RepositoryVersionEntity entity = new RepositoryVersionEntity();
     entity.setDisplayName("name");
     entity.setStack(stackEntity);
-    entity.setUpgradePackage("pack1");
     entity.setVersion("1.1");
     entity.setOperatingSystems("[{\"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"1\",\"Repositories/repo_name\":\"1\",\"Repositories/base_url\":\"http://example.com/repo1\"}]}]");
 
@@ -281,13 +313,6 @@ public class RepositoryVersionResourceProviderTest {
     } catch (Exception ex) {
     }
 
-    entity.setUpgradePackage("pack2");
-    try {
-      provider.validateRepositoryVersion(entity);
-      Assert.fail("Should throw exception");
-    } catch (Exception ex) {
-    }
-
     StackEntity bigtop = new StackEntity();
     stackEntity.setStackName("BIGTOP");
     entity.setStack(bigtop);
@@ -300,7 +325,6 @@ public class RepositoryVersionResourceProviderTest {
     final RepositoryVersionDAO repositoryVersionDAO = injector.getInstance(RepositoryVersionDAO.class);
     entity.setDisplayName("name");
     entity.setStack(stackEntity);
-    entity.setUpgradePackage("pack1");
     entity.setVersion("1.1");
     entity.setOperatingSystems("[{\"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"1\",\"Repositories/repo_name\":\"1\",\"Repositories/base_url\":\"http://example.com/repo1\"}]}]");
     repositoryVersionDAO.create(entity);
@@ -309,7 +333,6 @@ public class RepositoryVersionResourceProviderTest {
     entity2.setId(2l);
     entity2.setDisplayName("name2");
     entity2.setStack(stackEntity);
-    entity2.setUpgradePackage("pack1");
     entity2.setVersion("1.2");
     entity2.setOperatingSystems("[{\"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"1\",\"Repositories/repo_name\":\"1\",\"Repositories/base_url\":\"http://example.com/repo1\"}]}]");
 
@@ -330,7 +353,6 @@ public class RepositoryVersionResourceProviderTest {
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID, "name");
     properties.put(RepositoryVersionResourceProvider.SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID, new Gson().fromJson("[{\"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"1\",\"Repositories/repo_name\":\"1\",\"Repositories/base_url\":\"1\"}]}]", Object.class));
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID, "HDP");
-    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID, "pack1");
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID, "1.1");
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID, "1.1.1.2");
     propertySet.add(properties);
@@ -355,12 +377,19 @@ public class RepositoryVersionResourceProviderTest {
   public void testUpdateResources() throws Exception {
     final ResourceProvider provider = injector.getInstance(ResourceProviderFactory.class).getRepositoryVersionResourceProvider();
 
+    Mockito.when(clusterVersionDAO.findByStackAndVersion(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenAnswer(
+        new Answer<List<ClusterVersionEntity>>() {
+          @Override
+          public List<ClusterVersionEntity> answer(InvocationOnMock invocation) throws Throwable {
+            return getNoClusterVersions();
+          }
+        });
+
     final Set<Map<String, Object>> propertySet = new LinkedHashSet<Map<String, Object>>();
     final Map<String, Object> properties = new LinkedHashMap<String, Object>();
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID, "name");
     properties.put(RepositoryVersionResourceProvider.SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID, new Gson().fromJson("[{\"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"1\",\"Repositories/repo_name\":\"1\",\"Repositories/base_url\":\"http://example.com/repo1\"}]}]", Object.class));
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID, "HDP");
-    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID, "pack1");
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID, "1.1");
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID, "1.1.1.1");
     propertySet.add(properties);
@@ -368,9 +397,8 @@ public class RepositoryVersionResourceProviderTest {
     final Predicate predicateStackName = new PredicateBuilder().property(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID).equals("HDP").toPredicate();
     final Predicate predicateStackVersion = new PredicateBuilder().property(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID).equals("1.1").toPredicate();
     final Request getRequest = PropertyHelper.getReadRequest(
-        RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID,
-        RepositoryVersionResourceProvider.SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID,
-        RepositoryVersionResourceProvider.REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID);
+      RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID,
+      RepositoryVersionResourceProvider.SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID);
     Assert.assertEquals(0, provider.getResources(getRequest, new AndPredicate(predicateStackName, predicateStackVersion)).size());
 
     final Request createRequest = PropertyHelper.getCreateRequest(propertySet, null);
@@ -379,8 +407,6 @@ public class RepositoryVersionResourceProviderTest {
     Assert.assertEquals(1, provider.getResources(getRequest, new AndPredicate(predicateStackName, predicateStackVersion)).size());
     Assert.assertEquals("name", provider.getResources(getRequest, new AndPredicate(predicateStackName, predicateStackVersion)).iterator().next().getPropertyValue(RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID));
 
-    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID, null);
-
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_ID_PROPERTY_ID, "1");
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID, "name2");
     final Request updateRequest = PropertyHelper.getUpdateRequest(properties, null);
@@ -391,7 +417,15 @@ public class RepositoryVersionResourceProviderTest {
     properties.put(RepositoryVersionResourceProvider.SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID, new Gson().fromJson("[{\"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"2\",\"Repositories/repo_name\":\"2\",\"Repositories/base_url\":\"2\"}]}]", Object.class));
     provider.updateResources(updateRequest, new AndPredicate(predicateStackName, predicateStackVersion));
 
-    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID, "pack2");
+    // Now, insert a cluster version whose state is INSTALL_FAILED, so the operation will not be permitted.
+    Mockito.when(clusterVersionDAO.findByStackAndVersion(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenAnswer(
+      new Answer<List<ClusterVersionEntity>>() {
+        @Override
+        public List<ClusterVersionEntity> answer(InvocationOnMock invocation) throws Throwable {
+          return getInstallFailedClusterVersions();
+        }
+      });
+
     try {
       provider.updateResources(updateRequest, new AndPredicate(predicateStackName, predicateStackVersion));
       Assert.fail("Update of upgrade pack should not be allowed when repo version is installed on any cluster");

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java
index f786445..8997f58 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java
@@ -178,7 +178,6 @@ public class UpgradeResourceProviderHDP22Test {
     repoVersionEntity.setDisplayName("For Stack Version 2.2.0");
     repoVersionEntity.setOperatingSystems("");
     repoVersionEntity.setStack(stackEntity);
-    repoVersionEntity.setUpgradePackage("upgrade_test");
     repoVersionEntity.setVersion("2.2.0.0");
     repoVersionDao.create(repoVersionEntity);
 
@@ -186,7 +185,6 @@ public class UpgradeResourceProviderHDP22Test {
     repoVersionEntity.setDisplayName("For Stack Version 2.2.4.2");
     repoVersionEntity.setOperatingSystems("");
     repoVersionEntity.setStack(stackEntity);
-    repoVersionEntity.setUpgradePackage("upgrade_test");
     repoVersionEntity.setVersion("2.2.4.2");
     repoVersionDao.create(repoVersionEntity);
 
@@ -270,6 +268,7 @@ public class UpgradeResourceProviderHDP22Test {
     Map<String, Object> requestProps = new HashMap<String, Object>();
     requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
     requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.4.2");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test");
     requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true");
 
     ResourceProvider upgradeResourceProvider = createProvider(amc);
@@ -281,6 +280,7 @@ public class UpgradeResourceProviderHDP22Test {
     assertEquals(1, upgrades.size());
 
     UpgradeEntity upgrade = upgrades.get(0);
+    assertEquals("upgrade_test", upgrade.getUpgradePackage());
     assertEquals(3, upgrade.getUpgradeGroups().size());
 
     UpgradeGroupEntity group = upgrade.getUpgradeGroups().get(2);

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/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 9873104..066c0e6 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
@@ -23,6 +23,7 @@ import static org.easymock.EasyMock.replay;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.lang.reflect.Field;
@@ -33,6 +34,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.ambari.server.Role;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.HostRoleStatus;
@@ -80,6 +82,7 @@ import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.stack.UpgradePack;
 import org.apache.ambari.server.state.stack.upgrade.Direction;
+import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
 import org.apache.ambari.server.topology.TopologyManager;
 import org.apache.ambari.server.utils.StageUtils;
 import org.apache.ambari.server.view.ViewRegistry;
@@ -88,6 +91,7 @@ import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import com.google.gson.Gson;
@@ -163,41 +167,42 @@ public class UpgradeResourceProviderTest {
     replay(publisher);
     ViewRegistry.initInstance(new ViewRegistry(publisher));
 
-    StackEntity stackEntity = stackDAO.find("HDP", "2.1.1");
+    StackEntity stackEntity211 = stackDAO.find("HDP", "2.1.1");
+    StackEntity stackEntity220 = stackDAO.find("HDP", "2.2.0");
+    StackId stack211 = new StackId("HDP-2.1.1");
+    StackId stack220 = new StackId("HDP-2.2.0");
 
     RepositoryVersionEntity repoVersionEntity = new RepositoryVersionEntity();
     repoVersionEntity.setDisplayName("My New Version 1");
     repoVersionEntity.setOperatingSystems("");
-    repoVersionEntity.setStack(stackEntity);
-    repoVersionEntity.setUpgradePackage("upgrade_test");
+    repoVersionEntity.setStack(stackEntity211);
     repoVersionEntity.setVersion("2.1.1.0");
     repoVersionDao.create(repoVersionEntity);
 
     repoVersionEntity = new RepositoryVersionEntity();
-    repoVersionEntity.setDisplayName("My New Version 2");
+    repoVersionEntity.setDisplayName("My New Version 2 for patch upgrade");
     repoVersionEntity.setOperatingSystems("");
-    repoVersionEntity.setStack(stackEntity);
-    repoVersionEntity.setUpgradePackage("upgrade_test");
+    repoVersionEntity.setStack(stackEntity211);
     repoVersionEntity.setVersion("2.1.1.1");
     repoVersionDao.create(repoVersionEntity);
 
     repoVersionEntity = new RepositoryVersionEntity();
-    repoVersionEntity.setDisplayName("For Stack Version 2.2.0");
+    repoVersionEntity.setDisplayName("My New Version 3 for major upgrade");
     repoVersionEntity.setOperatingSystems("");
-    repoVersionEntity.setStack(stackDAO.find("HDP", "2.2.0"));
-    repoVersionEntity.setUpgradePackage("upgrade_test");
+    repoVersionEntity.setStack(stackEntity220);
     repoVersionEntity.setVersion("2.2.0.0");
     repoVersionDao.create(repoVersionEntity);
 
     clusters = injector.getInstance(Clusters.class);
 
-    StackId stackId = new StackId("HDP-2.1.1");
-    clusters.addCluster("c1", stackId);
+    clusters.addCluster("c1", stack211);
     Cluster cluster = clusters.getCluster("c1");
 
-    helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
-    cluster.createClusterVersion(stackId, stackId.getStackVersion(), "admin", RepositoryVersionState.UPGRADING);
-    cluster.transitionClusterVersion(stackId, stackId.getStackVersion(), RepositoryVersionState.CURRENT);
+    helper.getOrCreateRepositoryVersion(stack211, stack211.getStackVersion());
+    helper.getOrCreateRepositoryVersion(stack220, stack220.getStackVersion());
+
+    cluster.createClusterVersion(stack211, stack211.getStackVersion(), "admin", RepositoryVersionState.UPGRADING);
+    cluster.transitionClusterVersion(stack211, stack211.getStackVersion(), RepositoryVersionState.CURRENT);
 
     clusters.addHost(s_serverHostName);
     Host host = clusters.getHost(s_serverHostName);
@@ -388,6 +393,8 @@ public class UpgradeResourceProviderTest {
     upgradeEntity.setDirection(Direction.UPGRADE);
     upgradeEntity.setFromVersion("2.1.1.1");
     upgradeEntity.setToVersion("2.2.2.2");
+    upgradeEntity.setUpgradePackage("upgrade_test");
+    upgradeEntity.setUpgradeType(UpgradeType.ROLLING);
     upgradeEntity.setRequestId(1L);
 
     upgradeDao.create(upgradeEntity);
@@ -432,6 +439,7 @@ public class UpgradeResourceProviderTest {
     Map<String, Object> requestProps = new HashMap<String, Object>();
     requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
     requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.1.1.1");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test");
 
     ResourceProvider upgradeResourceProvider = createProvider(amc);
 
@@ -445,6 +453,7 @@ public class UpgradeResourceProviderTest {
     requestProps = new HashMap<String, Object>();
     requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
     requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test");
     request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);
     try {
       status = upgradeResourceProvider.createResources(request);
@@ -454,7 +463,8 @@ public class UpgradeResourceProviderTest {
     }
 
     requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
-    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.0.0");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test");
     requestProps.put(UpgradeResourceProvider.UPGRADE_FROM_VERSION, "2.1.1.0");
 
     Map<String, String> requestInfoProperties = new HashMap<String, String>();
@@ -469,7 +479,7 @@ public class UpgradeResourceProviderTest {
     UpgradeEntity entity = upgradeDao.findUpgrade(Long.parseLong(id));
     assertNotNull(entity);
     assertEquals("2.1.1", entity.getFromVersion());
-    assertEquals("2.2", entity.getToVersion());
+    assertEquals("2.2.0.0", entity.getToVersion());
     assertEquals(Direction.DOWNGRADE, entity.getDirection());
 
     StageDAO dao = injector.getInstance(StageDAO.class);
@@ -531,6 +541,16 @@ public class UpgradeResourceProviderTest {
 
     List<HostRoleCommand> commands = am.getRequestTasks(id);
 
+    boolean foundOne = false;
+    for (HostRoleCommand hrc : commands) {
+      if (hrc.getRole().equals(Role.AMBARI_SERVER_ACTION)) {
+        assertEquals(-1L, hrc.getHostId());
+        assertNull(hrc.getHostName());
+        foundOne = true;
+      }
+    }
+    assertTrue("Expected at least one server-side action", foundOne);
+
     HostRoleCommand cmd = commands.get(commands.size()-1);
 
     HostRoleCommandDAO dao = injector.getInstance(HostRoleCommandDAO.class);
@@ -549,6 +569,7 @@ public class UpgradeResourceProviderTest {
 
 
   @Test
+  @Ignore
   public void testDirectionUpgrade() throws Exception {
     Cluster cluster = clusters.getCluster("c1");
 
@@ -557,7 +578,6 @@ public class UpgradeResourceProviderTest {
     repoVersionEntity.setDisplayName("My New Version 3");
     repoVersionEntity.setOperatingSystems("");
     repoVersionEntity.setStack(stackEntity);
-    repoVersionEntity.setUpgradePackage("upgrade_direction");
     repoVersionEntity.setVersion("2.2.2.3");
     repoVersionDao.create(repoVersionEntity);
 
@@ -576,12 +596,20 @@ public class UpgradeResourceProviderTest {
     UpgradeEntity upgrade = upgrades.get(0);
     Long id = upgrade.getRequestId();
     assertEquals(3, upgrade.getUpgradeGroups().size());
+    // Ensure that there are no items related to downgrade in the upgrade direction
     UpgradeGroupEntity group = upgrade.getUpgradeGroups().get(2);
-    assertEquals(1, group.getItems().size());
+    Assert.assertEquals("POST_CLUSTER", group.getName());
+    Assert.assertTrue(!group.getItems().isEmpty());
+    for (UpgradeItemEntity item : group.getItems()) {
+      Assert.assertFalse(item.getText().toLowerCase().contains("downgrade"));
+    }
+
 
     requestProps.clear();
+    // Now perform a downgrade
     requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
     requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_direction");
     requestProps.put(UpgradeResourceProvider.UPGRADE_FROM_VERSION, "2.2.2.3");
 
     Map<String, String> requestInfoProps = new HashMap<String, String>();
@@ -695,10 +723,10 @@ public class UpgradeResourceProviderTest {
     assertEquals(1, upgrades.size());
 
     UpgradeEntity upgrade = upgrades.get(0);
-    assertEquals(3, upgrade.getUpgradeGroups().size());
+    assertEquals(5, upgrade.getUpgradeGroups().size());
 
     UpgradeGroupEntity group = upgrade.getUpgradeGroups().get(2);
-    assertEquals(2, group.getItems().size());
+    assertEquals(1, group.getItems().size());
 
     group = upgrade.getUpgradeGroups().get(0);
     assertEquals(2, group.getItems().size());
@@ -815,7 +843,8 @@ public class UpgradeResourceProviderTest {
     UpgradeResourceProvider upgradeResourceProvider = createProvider(amc);
 
     Map<String, UpgradePack> upgradePacks = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1");
-    upgradeResourceProvider.processConfigurations(stack211.getStackName(), cluster, "2.2.0.0", Direction.UPGRADE, upgradePacks.get("upgrade_to_new_stack"));
+    UpgradePack upgrade = upgradePacks.get("upgrade_to_new_stack");
+    upgradeResourceProvider.applyStackAndProcessConfigurations(stack211.getStackName(), cluster, "2.2.0.0", Direction.UPGRADE, upgrade);
 
     Map<String, Map<String, String>> expectedConfigurations = expectedConfigurationsCapture.getValue();
     Map<String, String> expectedFooType = expectedConfigurations.get("foo-site");

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
index b36480f..c5bb6e6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
@@ -614,7 +614,7 @@ public class OrmTestHelper {
     if (repositoryVersion == null) {
       try {
         repositoryVersion = repositoryVersionDAO.create(stackEntity, version,
-            String.valueOf(System.currentTimeMillis()), "pack", "");
+            String.valueOf(System.currentTimeMillis()), "");
       } catch (Exception ex) {
         Assert.fail(MessageFormat.format("Unable to create Repo Version for Stack {0} and version {1}",
             stackEntity.getStackName() + "-" + stackEntity.getStackVersion(), version));

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/CrudDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/CrudDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/CrudDAOTest.java
index 8777d33..6b5b297 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/CrudDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/CrudDAOTest.java
@@ -69,7 +69,6 @@ public class CrudDAOTest {
     entity.setDisplayName("display name" + uniqueCounter);
     entity.setOperatingSystems("repositories");
     entity.setStack(stackEntity);
-    entity.setUpgradePackage("upgrade package");
     entity.setVersion("version");
     repositoryVersionDAO.create(entity);
     uniqueCounter++;

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java
index adda018..9d390a9 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java
@@ -81,7 +81,6 @@ public class RepositoryVersionDAOTest {
     entity.setDisplayName("display name");
     entity.setOperatingSystems("repositories");
     entity.setStack(stackEntity);
-    entity.setUpgradePackage("upgrade package");
     entity.setVersion("version");
     repositoryVersionDAO.create(entity);
 
@@ -103,12 +102,11 @@ public class RepositoryVersionDAOTest {
     dupVersion.setDisplayName("display name " + uuid.toString());
     dupVersion.setOperatingSystems("repositories");
     dupVersion.setStack(stackEntity);
-    dupVersion.setUpgradePackage("upgrade package");
     dupVersion.setVersion(first.getVersion());
 
     boolean exceptionThrown = false;
     try {
-      repositoryVersionDAO.create(stackEntity, dupVersion.getVersion(), dupVersion.getDisplayName(), dupVersion.getUpgradePackage(), dupVersion.getOperatingSystemsJson());
+      repositoryVersionDAO.create(stackEntity, dupVersion.getVersion(), dupVersion.getDisplayName(), dupVersion.getOperatingSystemsJson());
     } catch (AmbariException e) {
       exceptionThrown = true;
       Assert.assertTrue(e.getMessage().contains("already exists"));
@@ -121,7 +119,7 @@ public class RepositoryVersionDAOTest {
     // The version must belong to the stack
     dupVersion.setVersion("2.3-1234");
     try {
-      repositoryVersionDAO.create(stackEntity, dupVersion.getVersion(), dupVersion.getDisplayName(), dupVersion.getUpgradePackage(), dupVersion.getOperatingSystemsJson());
+      repositoryVersionDAO.create(stackEntity, dupVersion.getVersion(), dupVersion.getDisplayName(), dupVersion.getOperatingSystemsJson());
     } catch (AmbariException e) {
       exceptionThrown = true;
       Assert.assertTrue(e.getMessage().contains("needs to belong to stack"));
@@ -132,7 +130,7 @@ public class RepositoryVersionDAOTest {
     // Success
     dupVersion.setVersion(stackEntity.getStackVersion() + "-1234");
     try {
-      repositoryVersionDAO.create(stackEntity, dupVersion.getVersion(), dupVersion.getDisplayName(), dupVersion.getUpgradePackage(), dupVersion.getOperatingSystemsJson());
+      repositoryVersionDAO.create(stackEntity, dupVersion.getVersion(), dupVersion.getDisplayName(), dupVersion.getOperatingSystemsJson());
     } catch (AmbariException e) {
       Assert.fail("Did not expect a failure creating the Repository Version");
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/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 0b12e97..f6d1acf 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
@@ -35,6 +35,7 @@ import org.apache.ambari.server.orm.entities.UpgradeGroupEntity;
 import org.apache.ambari.server.orm.entities.UpgradeItemEntity;
 import org.apache.ambari.server.state.UpgradeState;
 import org.apache.ambari.server.state.stack.upgrade.Direction;
+import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -69,13 +70,14 @@ public class UpgradeDAOTest {
     helper = injector.getInstance(OrmTestHelper.class);
     clusterId = helper.createCluster();
 
-
     // create upgrade entities
     UpgradeEntity entity = new UpgradeEntity();
     entity.setClusterId(Long.valueOf(1));
     entity.setRequestId(Long.valueOf(1));
     entity.setFromVersion("");
     entity.setToVersion("");
+    entity.setUpgradeType(UpgradeType.ROLLING);
+    entity.setUpgradePackage("test-upgrade");
 
     UpgradeGroupEntity group = new UpgradeGroupEntity();
     group.setName("group_name");
@@ -144,6 +146,8 @@ public class UpgradeDAOTest {
     entity1.setRequestId(Long.valueOf(1));
     entity1.setFromVersion("2.2.0.0-1234");
     entity1.setToVersion("2.3.0.0-4567");
+    entity1.setUpgradeType(UpgradeType.ROLLING);
+    entity1.setUpgradePackage("test-upgrade");
     dao.create(entity1);
     UpgradeEntity entity2 = new UpgradeEntity();
     entity2.setId(22L);
@@ -152,6 +156,8 @@ public class UpgradeDAOTest {
     entity2.setRequestId(Long.valueOf(1));
     entity2.setFromVersion("2.3.0.0-4567");
     entity2.setToVersion("2.2.0.0-1234");
+    entity2.setUpgradeType(UpgradeType.ROLLING);
+    entity2.setUpgradePackage("test-upgrade");
     dao.create(entity2);
     UpgradeEntity entity3 = new UpgradeEntity();
     entity3.setId(33L);
@@ -160,6 +166,8 @@ public class UpgradeDAOTest {
     entity3.setRequestId(Long.valueOf(1));
     entity3.setFromVersion("2.2.0.0-1234");
     entity3.setToVersion("2.3.1.1-4567");
+    entity3.setUpgradeType(UpgradeType.ROLLING);
+    entity3.setUpgradePackage("test-upgrade");
     dao.create(entity3);
     UpgradeEntity lastUpgradeForCluster = dao.findLastUpgradeForCluster(1);
     assertNotNull(lastUpgradeForCluster);

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java
index 93e29b5..d1d783c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java
@@ -56,7 +56,7 @@ import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceFactory;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.stack.upgrade.ConfigureTask;
-import org.apache.ambari.server.state.stack.upgrade.ConfigureTask.ConfigurationKeyValue;
+import org.apache.ambari.server.state.stack.upgrade.ConfigUpgradeChangeDefinition.*;
 import org.apache.ambari.server.state.stack.upgrade.TransferCoercionType;
 import org.apache.ambari.server.state.stack.upgrade.TransferOperation;
 import org.junit.After;
@@ -131,7 +131,7 @@ public class ConfigureActionTest {
     c.addDesiredConfig("user", Collections.singleton(config));
     assertEquals(2, c.getConfigsByType("zoo.cfg").size());
 
-    List<ConfigurationKeyValue> configurations = new ArrayList<ConfigureTask.ConfigurationKeyValue>();
+    List<ConfigurationKeyValue> configurations = new ArrayList<ConfigurationKeyValue>();
     ConfigurationKeyValue keyValue = new ConfigurationKeyValue();
     configurations.add(keyValue);
     keyValue.key = "initLimit";
@@ -206,8 +206,8 @@ public class ConfigureActionTest {
     commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg");
 
     // delete all keys, preserving edits or additions
-    List<ConfigureTask.Transfer> transfers = new ArrayList<ConfigureTask.Transfer>();
-    ConfigureTask.Transfer transfer = new ConfigureTask.Transfer();
+    List<Transfer> transfers = new ArrayList<>();
+    Transfer transfer = new Transfer();
     transfer.operation = TransferOperation.DELETE;
     transfer.deleteKey = "*";
     transfer.preserveEdits = true;
@@ -266,7 +266,7 @@ public class ConfigureActionTest {
     c.addDesiredConfig("user", Collections.singleton(config));
     assertEquals(2, c.getConfigsByType("zoo.cfg").size());
 
-    List<ConfigurationKeyValue> configurations = new ArrayList<ConfigureTask.ConfigurationKeyValue>();
+    List<ConfigurationKeyValue> configurations = new ArrayList<>();
     ConfigurationKeyValue keyValue = new ConfigurationKeyValue();
     configurations.add(keyValue);
     keyValue.key = "initLimit";
@@ -280,15 +280,15 @@ public class ConfigureActionTest {
     commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations));
 
     // normal copy
-    List<ConfigureTask.Transfer> transfers = new ArrayList<ConfigureTask.Transfer>();
-    ConfigureTask.Transfer transfer = new ConfigureTask.Transfer();
+    List<Transfer> transfers = new ArrayList<>();
+    Transfer transfer = new Transfer();
     transfer.operation = TransferOperation.COPY;
     transfer.fromKey = "copyIt";
     transfer.toKey = "copyKey";
     transfers.add(transfer);
 
     // copy with default
-    transfer = new ConfigureTask.Transfer();
+    transfer = new Transfer();
     transfer.operation = TransferOperation.COPY;
     transfer.fromKey = "copiedFromMissingKeyWithDefault";
     transfer.toKey = "copiedToMissingKeyWithDefault";
@@ -296,14 +296,14 @@ public class ConfigureActionTest {
     transfers.add(transfer);
 
     // normal move
-    transfer = new ConfigureTask.Transfer();
+    transfer = new Transfer();
     transfer.operation = TransferOperation.MOVE;
     transfer.fromKey = "moveIt";
     transfer.toKey = "movedKey";
     transfers.add(transfer);
 
     // move with default
-    transfer = new ConfigureTask.Transfer();
+    transfer = new Transfer();
     transfer.operation = TransferOperation.MOVE;
     transfer.fromKey = "movedFromKeyMissingWithDefault";
     transfer.toKey = "movedToMissingWithDefault";
@@ -311,7 +311,7 @@ public class ConfigureActionTest {
     transfer.mask = true;
     transfers.add(transfer);
 
-    transfer = new ConfigureTask.Transfer();
+    transfer = new Transfer();
     transfer.operation = TransferOperation.DELETE;
     transfer.deleteKey = "deleteIt";
     transfers.add(transfer);
@@ -357,7 +357,7 @@ public class ConfigureActionTest {
     assertEquals("defaultValue2", map.get("movedToMissingWithDefault"));
 
     transfers.clear();
-    transfer = new ConfigureTask.Transfer();
+    transfer = new Transfer();
     transfer.operation = TransferOperation.DELETE;
     transfer.deleteKey = "*";
     transfer.preserveEdits = true;
@@ -404,8 +404,8 @@ public class ConfigureActionTest {
     commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg");
 
     // copy with coerce
-    List<ConfigureTask.Transfer> transfers = new ArrayList<ConfigureTask.Transfer>();
-    ConfigureTask.Transfer transfer = new ConfigureTask.Transfer();
+    List<Transfer> transfers = new ArrayList<Transfer>();
+    Transfer transfer = new Transfer();
     transfer.operation = TransferOperation.COPY;
     transfer.coerceTo = TransferCoercionType.YAML_ARRAY;
     transfer.fromKey = "zoo.server.csv";
@@ -472,14 +472,14 @@ public class ConfigureActionTest {
     commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg");
 
     // Replacement task
-    List<ConfigureTask.Replace> replacements = new ArrayList<ConfigureTask.Replace>();
-    ConfigureTask.Replace replace = new ConfigureTask.Replace();
+    List<Replace> replacements = new ArrayList<Replace>();
+    Replace replace = new Replace();
     replace.key = "key_to_replace";
     replace.find = "New Cat";
     replace.replaceWith = "Wet Dog";
     replacements.add(replace);
 
-    replace = new ConfigureTask.Replace();
+    replace = new Replace();
     replace.key = "key_with_no_match";
     replace.find = "abc";
     replace.replaceWith = "def";
@@ -538,7 +538,7 @@ public class ConfigureActionTest {
     assertEquals(2, c.getConfigsByType("zoo.cfg").size());
 
     // create several configurations
-    List<ConfigurationKeyValue> configurations = new ArrayList<ConfigureTask.ConfigurationKeyValue>();
+    List<ConfigurationKeyValue> configurations = new ArrayList<ConfigurationKeyValue>();
     ConfigurationKeyValue fooKey2 = new ConfigurationKeyValue();
     configurations.add(fooKey2);
     fooKey2.key = "fooKey2";
@@ -633,8 +633,7 @@ public class ConfigureActionTest {
     String urlInfo = "[{'repositories':["
         + "{'Repositories/base_url':'http://foo1','Repositories/repo_name':'HDP','Repositories/repo_id':'HDP-2.2.0'}"
         + "], 'OperatingSystems/os_type':'redhat6'}]";
-    repoVersionDAO.create(stackEntity, HDP_2_2_0_1, String.valueOf(System.currentTimeMillis()),
-        "pack", urlInfo);
+    repoVersionDAO.create(stackEntity, HDP_2_2_0_1, String.valueOf(System.currentTimeMillis()), urlInfo);
 
 
     c.createClusterVersion(HDP_220_STACK, HDP_2_2_0_1, "admin", RepositoryVersionState.INSTALLING);

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
index 5f65e2d..a8c361a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
@@ -214,8 +214,7 @@ public class UpgradeActionTest {
     String urlInfo = "[{'repositories':["
         + "{'Repositories/base_url':'http://foo1','Repositories/repo_name':'HDP','Repositories/repo_id':'" + targetStack.getStackId() + "'}"
         + "], 'OperatingSystems/os_type':'redhat6'}]";
-    repoVersionDAO.create(stackEntityTarget, targetRepo, String.valueOf(System.currentTimeMillis()),
-        "pack", urlInfo);
+    repoVersionDAO.create(stackEntityTarget, targetRepo, String.valueOf(System.currentTimeMillis()), urlInfo);
 
     // Start upgrading the newer repo
     c.createClusterVersion(targetStack, targetRepo, "admin", RepositoryVersionState.INSTALLING);
@@ -275,8 +274,7 @@ public class UpgradeActionTest {
     String urlInfo = "[{'repositories':["
         + "{'Repositories/base_url':'http://foo1','Repositories/repo_name':'HDP','Repositories/repo_id':'" + targetRepo + "'}"
         + "], 'OperatingSystems/os_type':'redhat6'}]";
-    repoVersionDAO.create(stackEntityTarget, targetRepo, String.valueOf(System.currentTimeMillis()),
-        "pack", urlInfo);
+    repoVersionDAO.create(stackEntityTarget, targetRepo, String.valueOf(System.currentTimeMillis()), urlInfo);
 
     // Start upgrading the newer repo
     c.createClusterVersion(targetStack, targetRepo, "admin", RepositoryVersionState.INSTALLING);

http://git-wip-us.apache.org/repos/asf/ambari/blob/ff8a56af/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
index 7077f4c..483a024 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
@@ -36,6 +36,7 @@ import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import com.google.gson.reflect.TypeToken;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.AmbariManagementController;
@@ -44,19 +45,19 @@ import org.apache.ambari.server.controller.ConfigurationRequest;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.OrmTestHelper;
+import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
+import org.apache.ambari.server.orm.dao.StackDAO;
+import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.stack.HostsType;
 import org.apache.ambari.server.stack.MasterHostResolver;
 import org.apache.ambari.server.state.UpgradeHelper.UpgradeGroupHolder;
+import org.apache.ambari.server.state.stack.ConfigUpgradePack;
 import org.apache.ambari.server.state.stack.UpgradePack;
-import org.apache.ambari.server.state.stack.upgrade.ConfigureTask;
-import org.apache.ambari.server.state.stack.upgrade.Direction;
-import org.apache.ambari.server.state.stack.upgrade.ManualTask;
-import org.apache.ambari.server.state.stack.upgrade.StageWrapper;
-import org.apache.ambari.server.state.stack.upgrade.Task;
-import org.apache.ambari.server.state.stack.upgrade.TaskWrapper;
+import org.apache.ambari.server.state.stack.upgrade.*;
 import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import com.google.gson.Gson;
@@ -65,6 +66,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.persist.PersistService;
 import com.google.inject.util.Modules;
 
@@ -93,24 +95,54 @@ public class UpgradeHelperTest {
     m_configHelper = EasyMock.createNiceMock(ConfigHelper.class);
 
     expect(
-        m_configHelper.getPlaceholderValueFromDesiredConfigurations(
-            EasyMock.anyObject(Cluster.class), EasyMock.eq("{{foo/bar}}"))).andReturn(
+      m_configHelper.getPlaceholderValueFromDesiredConfigurations(
+        EasyMock.anyObject(Cluster.class), EasyMock.eq("{{foo/bar}}"))).andReturn(
         "placeholder-rendered-properly").anyTimes();
 
+    expect(
+        m_configHelper.getEffectiveDesiredTags(
+            EasyMock.anyObject(Cluster.class), EasyMock.anyObject(String.class))).
+        andReturn(new HashMap<String, Map<String, String>>()).anyTimes();
+
     replay(m_configHelper);
 
-    // create an injector which will inject the mocks
-    injector = Guice.createInjector(Modules.override(
-        new InMemoryDefaultTestModule()).with(new MockModule()));
+    final InMemoryDefaultTestModule injectorModule = new InMemoryDefaultTestModule() {
+      @Override
+      protected void configure() {
+        super.configure();
+      }
+    };
 
+    MockModule mockModule = new MockModule();
+    // create an injector which will inject the mocks
+    injector = Guice.createInjector(Modules.override(injectorModule).with(mockModule));
     injector.getInstance(GuiceJpaInitializer.class);
 
     helper = injector.getInstance(OrmTestHelper.class);
     ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
-
     m_upgradeHelper = injector.getInstance(UpgradeHelper.class);
     m_masterHostResolver = EasyMock.createMock(MasterHostResolver.class);
     m_managementController = injector.getInstance(AmbariManagementController.class);
+
+//    StackDAO stackDAO = injector.getInstance(StackDAO.class);
+//    StackEntity stackEntity = new StackEntity();
+//    stackEntity.setStackName("HDP");
+//    stackEntity.setStackVersion("2.1");
+//    stackDAO.create(stackEntity);
+//
+//    StackEntity stackEntityTo = new StackEntity();
+//    stackEntityTo.setStackName("HDP");
+//    stackEntityTo.setStackVersion("2.2");
+//    stackDAO.create(stackEntityTo);
+//
+//    Clusters clusters = injector.getInstance(Clusters.class);
+//    clusters.addCluster("c1", new StackId("HDP", "2.1"));
+//
+//    RepositoryVersionDAO repositoryVersionDAO = injector.getInstance(RepositoryVersionDAO.class);
+//    repositoryVersionDAO.create(stackEntity, "2.1.1", "2.1.1", "");
+//    repositoryVersionDAO.create(stackEntityTo, "2.2.0", "2.2.0", "");
+//
+//    replay(m_configHelper);
   }
 
   @After
@@ -119,6 +151,23 @@ public class UpgradeHelperTest {
   }
 
   @Test
+  public void testSuggestUpgradePack() throws Exception{
+    final String clusterName = "c1";
+    final String upgradeFromVersion = "2.1.1";
+    final String upgradeToVersion = "2.2.0";
+    final Direction upgradeDirection = Direction.UPGRADE;
+    final UpgradeType upgradeType = UpgradeType.ROLLING;
+
+    makeCluster();
+    try {
+      UpgradePack up = m_upgradeHelper.suggestUpgradePack(clusterName, upgradeFromVersion, upgradeToVersion, upgradeDirection, upgradeType);
+      assertEquals(upgradeType, up.getType());
+    } catch (AmbariException e){
+      assertTrue(false);
+    }
+  }
+
+  @Test
   public void testUpgradeOrchestration() throws Exception {
     Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("foo", "bar");
     assertTrue(upgrades.isEmpty());
@@ -130,7 +179,6 @@ public class UpgradeHelperTest {
     ComponentInfo ci = si.getComponentByName("ZOOKEEPER_SERVER");
     ci.setDisplayName("ZooKeeper1 Server2");
 
-
     assertTrue(upgrades.containsKey("upgrade_test"));
     UpgradePack upgrade = upgrades.get("upgrade_test");
     assertNotNull(upgrade);
@@ -138,7 +186,7 @@ public class UpgradeHelperTest {
     makeCluster();
 
     UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21,
-        HDP_21, UPGRADE_VERSION, Direction.UPGRADE);
+        HDP_21, UPGRADE_VERSION, Direction.UPGRADE, UpgradeType.ROLLING);
 
     List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
 
@@ -194,50 +242,6 @@ public class UpgradeHelperTest {
   }
 
   /**
-   * Tests that hosts in MM are not included in the upgrade.
-   *
-   * @throws Exception
-   */
-  @Test
-  public void testUpgradeOrchestrationWithHostsInMM() throws Exception {
-    Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("foo", "bar");
-    assertTrue(upgrades.isEmpty());
-
-    upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1");
-
-    ServiceInfo si = ambariMetaInfo.getService("HDP", "2.1.1", "ZOOKEEPER");
-    si.setDisplayName("Zk");
-
-    ComponentInfo ci = si.getComponentByName("ZOOKEEPER_SERVER");
-    ci.setDisplayName("ZooKeeper1 Server2");
-
-    assertTrue(upgrades.containsKey("upgrade_test"));
-    UpgradePack upgrade = upgrades.get("upgrade_test");
-    assertNotNull(upgrade);
-
-    // turn on MM for the first host
-    Cluster cluster = makeCluster();
-    Host hostInMaintenanceMode = cluster.getHosts().iterator().next();
-    hostInMaintenanceMode.setMaintenanceState(cluster.getClusterId(), MaintenanceState.ON);
-
-    // use a "real" master host resolver here so that we can actually test MM
-    MasterHostResolver masterHostResolver = new MasterHostResolver(null, cluster, "");
-
-    UpgradeContext context = new UpgradeContext(masterHostResolver, HDP_21, HDP_21,
-        UPGRADE_VERSION, Direction.UPGRADE);
-
-    List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
-    assertEquals(6, groups.size());
-
-    for (UpgradeGroupHolder group : groups) {
-      for (StageWrapper stageWrapper : group.items) {
-        Set<String> hosts = stageWrapper.getHosts();
-        assertFalse(hosts.contains(hostInMaintenanceMode.getHostName()));
-      }
-    }
-  }
-
-  /**
    * Verify that a Rolling Upgrades restarts the NameNodes in the following order: standby, active.
    * @throws Exception
    */
@@ -251,7 +255,7 @@ public class UpgradeHelperTest {
     makeCluster();
 
     UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21,
-        HDP_21, UPGRADE_VERSION, Direction.UPGRADE);
+        HDP_21, UPGRADE_VERSION, Direction.UPGRADE, UpgradeType.ROLLING);
 
     List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
 
@@ -262,7 +266,7 @@ public class UpgradeHelperTest {
 
     List<String> orderedNameNodes = new LinkedList<String>();
     for (StageWrapper sw : mastersGroup.items) {
-      if (sw.getType().equals(StageWrapper.Type.RESTART)) {
+      if (sw.getType().equals(StageWrapper.Type.RESTART) && sw.getText().toLowerCase().contains("NameNode".toLowerCase())) {
         for (TaskWrapper tw : sw.getTasks()) {
           for (String hostName : tw.getHosts()) {
             orderedNameNodes.add(hostName);
@@ -300,7 +304,7 @@ public class UpgradeHelperTest {
     assertEquals(HostState.HEARTBEAT_LOST, schs.get(0).getHostState());
 
     UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21,
-        HDP_21, UPGRADE_VERSION, Direction.UPGRADE);
+        HDP_21, UPGRADE_VERSION, Direction.UPGRADE, UpgradeType.ROLLING);
 
     List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
 
@@ -336,7 +340,7 @@ public class UpgradeHelperTest {
     makeCluster();
 
     UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21,
-        HDP_21, DOWNGRADE_VERSION, Direction.DOWNGRADE);
+        HDP_21, DOWNGRADE_VERSION, Direction.DOWNGRADE, UpgradeType.ROLLING);
 
     List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
 
@@ -376,7 +380,7 @@ public class UpgradeHelperTest {
     makeCluster();
 
     UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21,
-        HDP_21, UPGRADE_VERSION, Direction.UPGRADE);
+        HDP_21, UPGRADE_VERSION, Direction.UPGRADE, UpgradeType.ROLLING);
 
     List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
 
@@ -396,7 +400,7 @@ public class UpgradeHelperTest {
     makeCluster();
 
     UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21,
-        HDP_21, UPGRADE_VERSION, Direction.UPGRADE);
+        HDP_21, UPGRADE_VERSION, Direction.UPGRADE, UpgradeType.ROLLING);
 
     List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
 
@@ -415,20 +419,18 @@ public class UpgradeHelperTest {
 
   @Test
   public void testConditionalDeleteTask() throws Exception {
-    Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP",
-                                                                       "2.1.1");
-
+    Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1");
     assertTrue(upgrades.containsKey("upgrade_test"));
     UpgradePack upgrade = upgrades.get("upgrade_test");
+    ConfigUpgradePack cup = ambariMetaInfo.getConfigUpgradePack("HDP", "2.1.1");
     assertNotNull(upgrade);
 
     Cluster cluster = makeCluster();
 
     UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21,
-                                                HDP_21, UPGRADE_VERSION, Direction.UPGRADE);
+                                                HDP_21, UPGRADE_VERSION, Direction.UPGRADE, UpgradeType.ROLLING);
 
-    List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade,
-                                                                     context);
+    List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
 
     assertEquals(6, groups.size());
 
@@ -459,16 +461,15 @@ public class UpgradeHelperTest {
       }
     }, null);
 
-    Map<String, String> configProperties = configureTask.getConfigurationChanges(cluster);
+    Map<String, String> configProperties = configureTask.getConfigurationChanges(cluster, cup);
     assertFalse(configProperties.isEmpty());
     assertEquals(configProperties.get(ConfigureTask.PARAMETER_CONFIG_TYPE), "hive-site");
 
     String configurationJson = configProperties.get(ConfigureTask.PARAMETER_TRANSFERS);
     assertNotNull(configurationJson);
 
-    List<ConfigureTask.Transfer> transfers = m_gson.fromJson(configurationJson,
-                                                                              new TypeToken<List<ConfigureTask.Transfer>>() {
-                                                                              }.getType());
+    List<ConfigUpgradeChangeDefinition.Transfer> transfers = m_gson.fromJson(configurationJson,
+            new TypeToken<List<ConfigUpgradeChangeDefinition.Transfer>>() { }.getType());
 
     assertEquals(8, transfers.size());
     assertEquals("copy-key", transfers.get(0).fromKey);
@@ -489,17 +490,16 @@ public class UpgradeHelperTest {
 
   @Test
   public void testConfigureTask() throws Exception {
-    Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP",
-        "2.1.1");
-
+    Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1");
     assertTrue(upgrades.containsKey("upgrade_test"));
     UpgradePack upgrade = upgrades.get("upgrade_test");
+    ConfigUpgradePack cup = ambariMetaInfo.getConfigUpgradePack("HDP", "2.1.1");
     assertNotNull(upgrade);
 
     Cluster cluster = makeCluster();
 
     UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21,
-        HDP_21, UPGRADE_VERSION, Direction.UPGRADE);
+        HDP_21, UPGRADE_VERSION, Direction.UPGRADE, UpgradeType.ROLLING);
 
     List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade,
         context);
@@ -512,15 +512,15 @@ public class UpgradeHelperTest {
     ConfigureTask configureTask = (ConfigureTask) hiveGroup.items.get(1).getTasks().get(
         0).getTasks().get(0);
 
-    Map<String, String> configProperties = configureTask.getConfigurationChanges(cluster);
+    Map<String, String> configProperties = configureTask.getConfigurationChanges(cluster, cup);
     assertFalse(configProperties.isEmpty());
     assertEquals(configProperties.get(ConfigureTask.PARAMETER_CONFIG_TYPE), "hive-site");
 
     String configurationJson = configProperties.get(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS);
     assertNotNull(configurationJson);
 
-    List<ConfigureTask.ConfigurationKeyValue> keyValuePairs = m_gson.fromJson(configurationJson,
-        new TypeToken<List<ConfigureTask.ConfigurationKeyValue>>() {
+    List<ConfigUpgradeChangeDefinition.ConfigurationKeyValue> keyValuePairs = m_gson.fromJson(configurationJson,
+        new TypeToken<List<ConfigUpgradeChangeDefinition.ConfigurationKeyValue>>() {
         }.getType());
 
     assertEquals("hive.server2.thrift.port", keyValuePairs.get(0).key);
@@ -548,7 +548,7 @@ public class UpgradeHelperTest {
     }, null);
 
     // the configure task should now return different properties
-    configProperties = configureTask.getConfigurationChanges(cluster);
+    configProperties = configureTask.getConfigurationChanges(cluster, cup);
     assertFalse(configProperties.isEmpty());
     assertEquals( configProperties.get(ConfigureTask.PARAMETER_CONFIG_TYPE), "hive-site");
 
@@ -556,7 +556,7 @@ public class UpgradeHelperTest {
     assertNotNull(configurationJson);
 
     keyValuePairs = m_gson.fromJson(configurationJson,
-        new TypeToken<List<ConfigureTask.ConfigurationKeyValue>>() {
+        new TypeToken<List<ConfigUpgradeChangeDefinition.ConfigurationKeyValue>>() {
         }.getType());
 
     assertEquals("hive.server2.http.port", keyValuePairs.get(0).key);
@@ -566,15 +566,14 @@ public class UpgradeHelperTest {
   @Test
   public void testConfigureTaskWithMultipleConfigurations() throws Exception {
     Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1");
-
     assertTrue(upgrades.containsKey("upgrade_test"));
     UpgradePack upgrade = upgrades.get("upgrade_test");
+    ConfigUpgradePack cup = ambariMetaInfo.getConfigUpgradePack("HDP", "2.1.1");
     assertNotNull(upgrade);
-
     Cluster cluster = makeCluster();
 
     UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21, HDP_21,
-        UPGRADE_VERSION, Direction.UPGRADE);
+        UPGRADE_VERSION, Direction.UPGRADE, UpgradeType.ROLLING);
 
     List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
 
@@ -585,7 +584,7 @@ public class UpgradeHelperTest {
     assertEquals("HIVE", hiveGroup.name);
     ConfigureTask configureTask = (ConfigureTask) hiveGroup.items.get(1).getTasks().get(1).getTasks().get(0);
 
-    Map<String, String> configProperties = configureTask.getConfigurationChanges(cluster);
+    Map<String, String> configProperties = configureTask.getConfigurationChanges(cluster, cup);
     assertFalse(configProperties.isEmpty());
     assertEquals(configProperties.get(ConfigureTask.PARAMETER_CONFIG_TYPE), "hive-site");
 
@@ -594,12 +593,12 @@ public class UpgradeHelperTest {
     assertNotNull(configurationJson);
     assertNotNull(transferJson);
 
-    List<ConfigureTask.ConfigurationKeyValue> keyValuePairs = m_gson.fromJson(configurationJson,
-        new TypeToken<List<ConfigureTask.ConfigurationKeyValue>>() {
+    List<ConfigUpgradeChangeDefinition.ConfigurationKeyValue> keyValuePairs = m_gson.fromJson(configurationJson,
+        new TypeToken<List<ConfigUpgradeChangeDefinition.ConfigurationKeyValue>>() {
         }.getType());
 
-    List<ConfigureTask.Transfer> transfers = m_gson.fromJson(transferJson,
-        new TypeToken<List<ConfigureTask.Transfer>>() {
+    List<ConfigUpgradeChangeDefinition.Transfer> transfers = m_gson.fromJson(transferJson,
+        new TypeToken<List<ConfigUpgradeChangeDefinition.Transfer>>() {
         }.getType());
 
     assertEquals("fooKey", keyValuePairs.get(0).key);
@@ -616,7 +615,6 @@ public class UpgradeHelperTest {
     assertEquals("move-key-to", transfers.get(1).toKey);
   }
 
-
   @Test
   public void testServiceCheckUpgradeStages() throws Exception {
     Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.2.0");
@@ -651,7 +649,7 @@ public class UpgradeHelperTest {
     }
 
     UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21,
-        HDP_22, UPGRADE_VERSION, Direction.UPGRADE);
+        HDP_22, UPGRADE_VERSION, Direction.UPGRADE, UpgradeType.ROLLING);
 
     List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
 
@@ -695,7 +693,7 @@ public class UpgradeHelperTest {
     makeCluster();
 
     UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21,
-        HDP_21, DOWNGRADE_VERSION, Direction.DOWNGRADE);
+        HDP_21, DOWNGRADE_VERSION, Direction.DOWNGRADE, UpgradeType.ROLLING);
 
     List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
 
@@ -713,6 +711,7 @@ public class UpgradeHelperTest {
         manualTask.message);
   }
 
+  @Ignore
   @Test
   public void testUpgradeOrchestrationFullTask() throws Exception {
     Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1");
@@ -729,7 +728,7 @@ public class UpgradeHelperTest {
     makeCluster();
 
     UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21,
-        HDP_21, UPGRADE_VERSION, Direction.UPGRADE);
+        HDP_21, UPGRADE_VERSION, Direction.UPGRADE, UpgradeType.ROLLING);
 
     List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
 
@@ -807,11 +806,13 @@ public class UpgradeHelperTest {
     String clusterName = "c1";
 
     StackId stackId = new StackId("HDP-2.1.1");
+    StackId stackId2 = new StackId("HDP-2.2.0");
     clusters.addCluster(clusterName, stackId);
     Cluster c = clusters.getCluster(clusterName);
 
     helper.getOrCreateRepositoryVersion(stackId,
         c.getDesiredStackVersion().getStackVersion());
+    helper.getOrCreateRepositoryVersion(stackId2,"2.2.0");
 
     c.createClusterVersion(stackId,
         c.getDesiredStackVersion().getStackVersion(), "admin",
@@ -977,9 +978,11 @@ public class UpgradeHelperTest {
     expect(m_masterHostResolver.getCluster()).andReturn(c).anyTimes();
     replay(m_masterHostResolver);
 
-    UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21, HDP_21, DOWNGRADE_VERSION, Direction.DOWNGRADE);
+    UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21, HDP_21, DOWNGRADE_VERSION,
+        Direction.DOWNGRADE, UpgradeType.ROLLING);
 
     Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1");
+    assertTrue(upgrades.containsKey("upgrade_direction"));
     UpgradePack upgrade = upgrades.get("upgrade_direction");
     assertNotNull(upgrade);
 
@@ -1004,13 +1007,8 @@ public class UpgradeHelperTest {
 
 
 
-  /**
-   *
-   */
   private class MockModule implements Module {
-    /**
-    *
-    */
+
     @Override
     public void configure(Binder binder) {
       binder.bind(ConfigHelper.class).toInstance(m_configHelper);


Mime
View raw message