ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlun...@apache.org
Subject [19/31] ambari git commit: AMBARI-22166 - Not able to perform revert after deleting the upgraded service (jonathanhurley)
Date Wed, 11 Oct 2017 05:25:15 GMT
AMBARI-22166 - Not able to perform revert after deleting the upgraded service (jonathanhurley)


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

Branch: refs/heads/branch-feature-AMBARI-14714
Commit: 8cffd72227c22da2bc3bad30f1c3e877bd26cad4
Parents: 4242225
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Mon Oct 9 13:21:40 2017 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Mon Oct 9 16:40:45 2017 -0400

----------------------------------------------------------------------
 .../ambari/server/state/UpgradeContext.java     | 24 ++++++--
 .../ambari/server/state/UpgradeContextTest.java | 60 +++++++++++++++++++-
 2 files changed, 76 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8cffd722/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeContext.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeContext.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeContext.java
index 67a8950..de0f868 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeContext.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeContext.java
@@ -304,8 +304,8 @@ public class UpgradeContext {
         throw new AmbariException(
             String.format("There are no upgrades for cluster %s which are marked as revertable",
                 cluster.getClusterName()));
-      }      
-      
+      }
+
       if (!revertUpgrade.getOrchestration().isRevertable()) {
         throw new AmbariException(String.format("The %s repository type is not revertable",
             revertUpgrade.getOrchestration()));
@@ -323,14 +323,26 @@ public class UpgradeContext {
             revertableUpgrade.getRepositoryVersion().getVersion()));
       }
 
+      // !!! build all service-specific reversions
       Set<RepositoryVersionEntity> priors = new HashSet<>();
+      Map<String, Service> clusterServices = cluster.getServices();
       for (UpgradeHistoryEntity history : revertUpgrade.getHistory()) {
+        String serviceName = history.getServiceName();
+        String componentName = history.getComponentName();
+
         priors.add(history.getFromReposistoryVersion());
 
-        // !!! build all service-specific
-        m_services.add(history.getServiceName());
-        m_sourceRepositoryMap.put(history.getServiceName(), history.getTargetRepositoryVersion());
-        m_targetRepositoryMap.put(history.getServiceName(), history.getFromReposistoryVersion());
+        // if the service is no longer installed, do nothing
+        if (!clusterServices.containsKey(serviceName)) {
+          LOG.warn("{}/{} will not be reverted since it is no longer installed in the cluster",
+              serviceName, componentName);
+
+          continue;
+        }
+
+        m_services.add(serviceName);
+        m_sourceRepositoryMap.put(serviceName, history.getTargetRepositoryVersion());
+        m_targetRepositoryMap.put(serviceName, history.getFromReposistoryVersion());
       }
 
       if (priors.size() != 1) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/8cffd722/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeContextTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeContextTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeContextTest.java
index dc77fa6..5176ffe 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeContextTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeContextTest.java
@@ -23,6 +23,7 @@ import static junit.framework.Assert.assertTrue;
 import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -111,6 +112,11 @@ public class UpgradeContextTest extends EasyMockSupport {
   private VersionDefinitionXml m_vdfXml;
 
   /**
+   * The upgrade history to return for the completed upgrade.
+   */
+  private List<UpgradeHistoryEntity> m_upgradeHistory = new ArrayList<>();
+
+  /**
    * The cluster services.
    */
   private Map<String, Service> m_services = new HashMap<>();
@@ -128,7 +134,7 @@ public class UpgradeContextTest extends EasyMockSupport {
     expect(upgradeHistoryEntity.getServiceName()).andReturn(HDFS_SERVICE_NAME).anyTimes();
     expect(upgradeHistoryEntity.getFromReposistoryVersion()).andReturn(m_sourceRepositoryVersion).anyTimes();
     expect(upgradeHistoryEntity.getTargetRepositoryVersion()).andReturn(m_targetRepositoryVersion).anyTimes();
-    List<UpgradeHistoryEntity> upgradeHistory = Lists.newArrayList(upgradeHistoryEntity);
+    m_upgradeHistory = Lists.newArrayList(upgradeHistoryEntity);
 
     expect(m_repositoryVersionDAO.findByPK(1L)).andReturn(m_sourceRepositoryVersion).anyTimes();
     expect(m_repositoryVersionDAO.findByPK(99L)).andReturn(m_targetRepositoryVersion).anyTimes();
@@ -143,12 +149,13 @@ public class UpgradeContextTest extends EasyMockSupport {
     expect(m_completedRevertableUpgrade.getDirection()).andReturn(Direction.UPGRADE).anyTimes();
     expect(m_completedRevertableUpgrade.getRepositoryVersion()).andReturn(m_targetRepositoryVersion).anyTimes();
     expect(m_completedRevertableUpgrade.getOrchestration()).andReturn(RepositoryType.PATCH).anyTimes();
-    expect(m_completedRevertableUpgrade.getHistory()).andReturn(upgradeHistory).anyTimes();
+    expect(m_completedRevertableUpgrade.getHistory()).andReturn(m_upgradeHistory).anyTimes();
     expect(m_completedRevertableUpgrade.getUpgradePackage()).andReturn(null).anyTimes();
 
     RepositoryVersionEntity hdfsRepositoryVersion = createNiceMock(RepositoryVersionEntity.class);
 
     expect(m_hdfsService.getDesiredRepositoryVersion()).andReturn(hdfsRepositoryVersion).anyTimes();
+    expect(m_zookeeperService.getDesiredRepositoryVersion()).andReturn(hdfsRepositoryVersion).anyTimes();
     expect(m_cluster.getService(HDFS_SERVICE_NAME)).andReturn(m_hdfsService).anyTimes();
     m_services.put(HDFS_SERVICE_NAME, m_hdfsService);
 
@@ -331,6 +338,55 @@ public class UpgradeContextTest extends EasyMockSupport {
   }
 
   /**
+   * Tests that the {@link UpgradeContext} for a reversion has the correct
+   * services included in the reversion if one of the services in the original
+   * upgrade has since been deleted.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testRevertWithDeletedService() throws Exception {
+    UpgradeHelper upgradeHelper = createNiceMock(UpgradeHelper.class);
+    ConfigHelper configHelper = createNiceMock(ConfigHelper.class);
+    UpgradePack upgradePack = createNiceMock(UpgradePack.class);
+
+    // give the completed upgrade 2 services which can be reverted
+    UpgradeHistoryEntity upgradeHistoryEntity = createNiceMock(UpgradeHistoryEntity.class);
+    expect(upgradeHistoryEntity.getServiceName()).andReturn(ZOOKEEPER_SERVICE_NAME).anyTimes();
+    expect(upgradeHistoryEntity.getFromReposistoryVersion()).andReturn(m_sourceRepositoryVersion).anyTimes();
+    expect(upgradeHistoryEntity.getTargetRepositoryVersion()).andReturn(m_targetRepositoryVersion).anyTimes();
+    m_upgradeHistory.add(upgradeHistoryEntity);
+
+    expect(upgradeHelper.suggestUpgradePack(EasyMock.anyString(), EasyMock.anyObject(StackId.class),
+        EasyMock.anyObject(StackId.class), EasyMock.anyObject(Direction.class),
+        EasyMock.anyObject(UpgradeType.class), EasyMock.anyString())).andReturn(upgradePack).once();
+
+    expect(m_upgradeDAO.findRevertable(1L)).andReturn(m_completedRevertableUpgrade).once();
+
+    // remove HDFS, add ZK
+    m_services.remove(HDFS_SERVICE_NAME);
+    expect(m_cluster.getService(ZOOKEEPER_SERVICE_NAME)).andReturn(m_zookeeperService).anyTimes();
+    m_services.put(ZOOKEEPER_SERVICE_NAME, m_zookeeperService);
+    assertEquals(1, m_services.size());
+
+    Map<String, Object> requestMap = new HashMap<>();
+    requestMap.put(UpgradeResourceProvider.UPGRADE_TYPE, UpgradeType.ROLLING.name());
+    requestMap.put(UpgradeResourceProvider.UPGRADE_REVERT_UPGRADE_ID, "1");
+
+    replayAll();
+
+    UpgradeContext context = new UpgradeContext(m_cluster, requestMap, null, upgradeHelper,
+        m_upgradeDAO, m_repositoryVersionDAO, configHelper);
+
+    assertEquals(Direction.DOWNGRADE, context.getDirection());
+    assertEquals(RepositoryType.PATCH, context.getOrchestrationType());
+    assertEquals(1, context.getSupportedServices().size());
+    assertTrue(context.isPatchRevert());
+
+    verifyAll();
+  }
+
+  /**
    * Tests that if a different {@link UpgradeEntity} is returned instead of the one
    * specified by the
    *


Mime
View raw message