ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject ambari git commit: AMBARI-9182. Request to start Downgrade failed (ncole)
Date Fri, 16 Jan 2015 19:06:50 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk c9f875d84 -> c061d7213


AMBARI-9182. Request to start Downgrade failed (ncole)


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

Branch: refs/heads/trunk
Commit: c061d7213172d13f12da597a46db2ccaec1e01c3
Parents: c9f875d
Author: Nate Cole <ncole@hortonworks.com>
Authored: Fri Jan 16 13:01:40 2015 -0500
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Fri Jan 16 13:03:38 2015 -0500

----------------------------------------------------------------------
 .../internal/UpgradeResourceProvider.java       | 18 +++++++--
 .../internal/UpgradeResourceProviderTest.java   | 42 ++++++++++++++++++++
 2 files changed, 57 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c061d721/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 9b17b33..befd014 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
@@ -309,6 +309,10 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
   private UpgradePack validateRequest(Map<String, Object> requestMap) throws AmbariException
{
     String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
     String version = (String) requestMap.get(UPGRADE_VERSION);
+    String forceDowngrade = (String) requestMap.get(UPGRADE_FORCE_DOWNGRADE);
+    String versionForUpgradePack = (String) requestMap.get(UPGRADE_FROM_VERSION);
+
+    boolean forDowngrade = (null != forceDowngrade && Boolean.parseBoolean(forceDowngrade));
 
     if (null == clusterName) {
       throw new AmbariException(String.format("%s is required", UPGRADE_CLUSTER_NAME));
@@ -320,12 +324,19 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
 
     Cluster cluster = getManagementController().getClusters().getCluster(clusterName);
     StackId stack = cluster.getDesiredStackVersion();
+
+    String repoVersion = version;
+
+    if (forDowngrade && null != versionForUpgradePack) {
+      repoVersion = versionForUpgradePack;
+    }
+
     RepositoryVersionEntity versionEntity = m_repoVersionDAO.findByStackAndVersion(
-        stack.getStackId(), version);
+        stack.getStackId(), repoVersion);
 
     if (null == versionEntity) {
       throw new AmbariException(String.format("Version %s for stack %s was not found",
-          version, stack.getStackVersion()));
+          repoVersion, stack.getStackVersion()));
     }
 
     Map<String, UpgradePack> packs = m_metaProvider.get().getUpgradePacks(
@@ -335,7 +346,8 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
 
     if (null == up) {
       throw new AmbariException(String.format(
-          "Upgrade pack %s not found", versionEntity.getUpgradePackage()));
+          "Upgrade pack %s for version %s not found", versionEntity.getUpgradePackage(),
+            repoVersion));
     }
 
     // !!! validate all hosts have the version installed

http://git-wip-us.apache.org/repos/asf/ambari/blob/c061d721/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 bd06c5f..cd5f23e 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
@@ -63,6 +63,7 @@ import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.view.ViewRegistry;
 import org.easymock.EasyMock;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -379,8 +380,49 @@ public class UpgradeResourceProviderTest {
 
   }
 
+  @Test
+  public void testDowngradeToBase() throws Exception {
+    Cluster cluster = clusters.getCluster("c1");
+
+    Map<String, Object> requestProps = new HashMap<String, Object>();
+    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.2.1");
+
+    ResourceProvider upgradeResourceProvider = createProvider(amc);
+
+    Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps),
null);
+    org.apache.ambari.server.controller.spi.RequestStatus status = upgradeResourceProvider.createResources(request);
+
+    List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId());
+    assertEquals(1, upgrades.size());
+
+    requestProps = new HashMap<String, Object>();
+    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2");
+    request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);
+    try {
+      status = upgradeResourceProvider.createResources(request);
+      Assert.fail("Expected an exception going downgrade with no upgrade pack");
+    } catch (Exception e) {
+      // !!! expected
+    }
 
+    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_FORCE_DOWNGRADE, "true");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_FROM_VERSION, "2.2.2.1");
+    request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);
+    status = upgradeResourceProvider.createResources(request);
+    assertEquals(1, status.getAssociatedResources().size());
+    Resource r = status.getAssociatedResources().iterator().next();
+    String id = r.getPropertyValue("Upgrade/request_id").toString();
+
+    UpgradeEntity entity = upgradeDao.findUpgrade(Long.parseLong(id));
+    assertNotNull(entity);
+    assertEquals("2.1.1", entity.getFromVersion());
+    assertEquals("2.2", entity.getToVersion());
 
+  }
 
   /**
    * @param amc


Mime
View raw message