ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmitriu...@apache.org
Subject ambari git commit: AMBARI-14242. test-case for EU: Downgrade goes through all steps even if initiated at first prompt, should exit since hasn't changed stack/configs (dlysnichenko)
Date Tue, 08 Dec 2015 13:46:12 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk c776ec588 -> 59b891c60


AMBARI-14242. test-case for EU: Downgrade goes through all steps even if initiated at first
prompt, should exit since hasn't changed stack/configs (dlysnichenko)


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

Branch: refs/heads/trunk
Commit: 59b891c60509ad541d34dd36a7acb7eac9d95697
Parents: c776ec5
Author: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Authored: Tue Dec 8 15:46:39 2015 +0200
Committer: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Committed: Tue Dec 8 15:46:39 2015 +0200

----------------------------------------------------------------------
 .../internal/UpgradeResourceProviderTest.java   | 109 ++++++++++++++++++-
 1 file changed, 103 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/59b891c6/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 6a53076..11c785f 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
@@ -237,6 +237,18 @@ public class UpgradeResourceProviderTest {
     injector = null;
   }
 
+  /**
+   * Obtain request id from the {@code RequestStatus}
+   * @param requestStatus reqult of the {@code createResources}
+   * @return id of the request
+   */
+  private long getRequestId(RequestStatus requestStatus){
+    assertEquals(1, requestStatus.getAssociatedResources().size());
+    Resource r = requestStatus.getAssociatedResources().iterator().next();
+    String id = r.getPropertyValue("Upgrade/request_id").toString();
+    return Long.parseLong(id);
+  }
+
   @Test
   public void testCreateResourcesWithAutoSkipFailures() throws Exception {
     Cluster cluster = clusters.getCluster("c1");
@@ -605,7 +617,7 @@ public class UpgradeResourceProviderTest {
   public void testDowngradeToBase() throws Exception {
     Cluster cluster = clusters.getCluster("c1");
 
-    Map<String, Object> requestProps = new HashMap<String, Object>();
+    Map<String, Object> requestProps = new HashMap<>();
     requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
     requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.1.1.1");
     requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test");
@@ -614,19 +626,19 @@ public class UpgradeResourceProviderTest {
     ResourceProvider upgradeResourceProvider = createProvider(amc);
 
     Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps),
null);
-    RequestStatus status = upgradeResourceProvider.createResources(request);
+    upgradeResourceProvider.createResources(request);
 
     List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId());
     assertEquals(1, upgrades.size());
 
-    requestProps = new HashMap<String, Object>();
+    requestProps = new HashMap<>();
     requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
     requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2");
     requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test");
     requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true");
     request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);
     try {
-      status = upgradeResourceProvider.createResources(request);
+      upgradeResourceProvider.createResources(request);
       Assert.fail("Expected an exception going downgrade with no upgrade pack");
     } catch (Exception e) {
       // !!! expected
@@ -638,11 +650,11 @@ public class UpgradeResourceProviderTest {
     requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true");
     requestProps.put(UpgradeResourceProvider.UPGRADE_FROM_VERSION, "2.1.1.0");
 
-    Map<String, String> requestInfoProperties = new HashMap<String, String>();
+    Map<String, String> requestInfoProperties = new HashMap<>();
     requestInfoProperties.put(UpgradeResourceDefinition.DOWNGRADE_DIRECTIVE, "true");
 
     request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), requestInfoProperties);
-    status = upgradeResourceProvider.createResources(request);
+    RequestStatus status = upgradeResourceProvider.createResources(request);
     assertEquals(1, status.getAssociatedResources().size());
     Resource r = status.getAssociatedResources().iterator().next();
     String id = r.getPropertyValue("Upgrade/request_id").toString();
@@ -665,6 +677,91 @@ public class UpgradeResourceProviderTest {
 
   }
 
+  
+
+  /**
+   * Test Downgrade from the partially completed upgrade
+   */
+  @Test
+  public void testNotFullDowngrade() throws Exception {
+    Cluster cluster = clusters.getCluster("c1");
+
+    // add additional service for the test
+    Service service = cluster.addService("HIVE");
+    service.setDesiredStackVersion(cluster.getDesiredStackVersion());
+    service.persist();
+
+    ServiceComponent component = service.addServiceComponent("HIVE_SERVER");
+    ServiceComponentHost sch = component.addServiceComponentHost("h1");
+    sch.setVersion("2.1.1.0");
+
+    // create upgrade request
+    Map<String, Object> requestProps = new HashMap<>();
+    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.0.0");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_nonrolling_new_stack");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_TYPE, "NON_ROLLING");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true");
+
+    ResourceProvider upgradeResourceProvider = createProvider(amc);
+
+    Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps),
null);
+    upgradeResourceProvider.createResources(request);
+
+    // check that upgrade was created and groups for the tested services are on place
+    List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId());
+    assertEquals(1, upgrades.size());
+
+    List<UpgradeGroupEntity> groups = upgrades.get(0).getUpgradeGroups();
+    boolean isHiveGroupFound = false;
+    boolean isZKGroupFound = false;
+
+    // look only for testing groups
+    for (UpgradeGroupEntity group: groups) {
+      if (group.getName().equalsIgnoreCase("hive")) {
+        isHiveGroupFound = true;
+      } else if (group.getName().equalsIgnoreCase("zookeeper")){
+        isZKGroupFound = true;
+      }
+    }
+
+    assertTrue(isHiveGroupFound);
+    assertTrue(isZKGroupFound);
+
+    isHiveGroupFound = false;
+    isZKGroupFound = false;
+    sch.setVersion("2.2.0.0");
+
+    // create downgrade with one upgraded service
+    StackId stackId = new StackId("HDP", "2.2.0");
+    cluster.setDesiredStackVersion(stackId, true);
+
+    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.1.1.0");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_nonrolling_new_stack");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_FROM_VERSION, "2.2.0.0");
+
+    Map<String, String> requestInfoProperties = new HashMap<>();
+    requestInfoProperties.put(UpgradeResourceDefinition.DOWNGRADE_DIRECTIVE, "true");
+
+    request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), requestInfoProperties);
+    RequestStatus status = upgradeResourceProvider.createResources(request);
+    UpgradeEntity upgradeEntity = upgradeDao.findUpgradeByRequestId(getRequestId(status));
+
+    for (UpgradeGroupEntity group: upgradeEntity.getUpgradeGroups()) {
+      if (group.getName().equalsIgnoreCase("hive")) {
+        isHiveGroupFound = true;
+      } else if (group.getName().equalsIgnoreCase("zookeeper")){
+        isZKGroupFound = true;
+      }
+    }
+
+    // as services not updated, nothing to downgrade
+    assertTrue(isHiveGroupFound);
+    assertFalse(isZKGroupFound);
+  }
+
 
   @Test
   public void testAbort() throws Exception {


Mime
View raw message