ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject [33/50] [abbrv] ambari git commit: AMBARI-22246 Restart HDFS/JOURNALNODE failed on revert patch upgrade(dgrinenko)
Date Thu, 19 Oct 2017 12:55:19 GMT
AMBARI-22246 Restart HDFS/JOURNALNODE failed on revert patch upgrade(dgrinenko)


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

Branch: refs/heads/branch-3.0-perf
Commit: ce29f8ce7762ed6c6d5c2f50d882b6e03b23acfc
Parents: d6cd303
Author: Dmytro Grinenko <hapylestat@apache.org>
Authored: Tue Oct 17 16:53:47 2017 +0300
Committer: Dmytro Grinenko <hapylestat@apache.org>
Committed: Tue Oct 17 16:53:47 2017 +0300

----------------------------------------------------------------------
 .../ambari/server/state/UpgradeContext.java     | 55 ++++++++++++++------
 .../ambari/server/state/UpgradeContextTest.java | 38 +++++++++++++-
 2 files changed, 75 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/ce29f8ce/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 de0f868..cb44adb 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
@@ -261,6 +261,38 @@ public class UpgradeContext {
    */
   private RepositoryType m_orchestration = RepositoryType.STANDARD;
 
+  /**
+   * Reading upgrade type from provided request  or if nothing were provided,
+   * from previous upgrade for downgrade direction.
+   *
+   * @param upgradeRequestMap arguments provided for current upgrade request
+   * @param upgradeEntity previous upgrade entity, should be passed only for downgrade direction
+   *
+   * @return
+   * @throws AmbariException
+   */
+  private UpgradeType calculateUpgradeType(Map<String, Object> upgradeRequestMap,
+                                           UpgradeEntity upgradeEntity) throws AmbariException{
+
+    UpgradeType upgradeType = UpgradeType.ROLLING;
+
+    String upgradeTypeProperty = (String) upgradeRequestMap.get(UPGRADE_TYPE);
+    boolean upgradeTypePassed = StringUtils.isNotBlank(upgradeTypeProperty);
+
+    if (upgradeTypePassed){
+      try {
+        upgradeType = UpgradeType.valueOf(upgradeRequestMap.get(UPGRADE_TYPE).toString());
+      } catch (Exception e) {
+        throw new AmbariException(String.format("Property %s has an incorrect value of %s.",
+          UPGRADE_TYPE, upgradeTypeProperty));
+      }
+    } else if (upgradeEntity != null){
+      upgradeType = upgradeEntity.getUpgradeType();
+    }
+
+    return upgradeType;
+  }
+
   @AssistedInject
   public UpgradeContext(@Assisted Cluster cluster,
       @Assisted Map<String, Object> upgradeRequestMap, Gson gson, UpgradeHelper upgradeHelper,
@@ -271,23 +303,7 @@ public class UpgradeContext {
     m_upgradeHelper = upgradeHelper;
     m_upgradeDAO = upgradeDAO;
     m_repoVersionDAO = repoVersionDAO;
-
     m_cluster = cluster;
-
-    // determine upgrade type (default is ROLLING)
-    String upgradeTypeProperty = (String) upgradeRequestMap.get(UPGRADE_TYPE);
-    if (StringUtils.isNotBlank(upgradeTypeProperty)) {
-      try {
-        m_type = UpgradeType.valueOf(upgradeRequestMap.get(UPGRADE_TYPE).toString());
-      } catch (Exception e) {
-        throw new AmbariException(String.format("Property %s has an incorrect value of %s.",
-            UPGRADE_TYPE, upgradeTypeProperty));
-      }
-    } else {
-      // default type
-      m_type= UpgradeType.ROLLING;
-    }
-
     m_isRevert = upgradeRequestMap.containsKey(UPGRADE_REVERT_UPGRADE_ID);
 
     if (m_isRevert) {
@@ -316,13 +332,15 @@ public class UpgradeContext {
             "Only successfully completed upgrades can be reverted. Downgrades cannot be reverted.");
       }
 
-      if (revertableUpgrade.getId() != revertUpgrade.getId()) {
+      if (!revertableUpgrade.getId().equals(revertUpgrade.getId())) {
         throw new AmbariException(String.format(
             "The only upgrade which is currently allowed to be reverted for cluster %s is
upgrade ID %s which was an upgrade to %s",
             cluster.getClusterName(), revertableUpgrade.getId(),
             revertableUpgrade.getRepositoryVersion().getVersion()));
       }
 
+      m_type = calculateUpgradeType(upgradeRequestMap, revertUpgrade);
+
       // !!! build all service-specific reversions
       Set<RepositoryVersionEntity> priors = new HashSet<>();
       Map<String, Service> clusterServices = cluster.getServices();
@@ -382,6 +400,8 @@ public class UpgradeContext {
                     UPGRADE_REPO_VERSION_ID, m_direction));
           }
 
+          m_type = calculateUpgradeType(upgradeRequestMap, null);
+
           // depending on the repository, add services
           m_repositoryVersion = m_repoVersionDAO.findByPK(Long.valueOf(repositoryVersionId));
           m_orchestration = m_repositoryVersion.getType();
@@ -396,6 +416,7 @@ public class UpgradeContext {
 
           m_repositoryVersion = upgrade.getRepositoryVersion();
           m_orchestration = upgrade.getOrchestration();
+          m_type = calculateUpgradeType(upgradeRequestMap, upgrade);
 
           // populate the repository maps for all services in the upgrade
           for (UpgradeHistoryEntity history : upgrade.getHistory()) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/ce29f8ce/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 5176ffe..b38b272 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
@@ -317,7 +317,6 @@ public class UpgradeContextTest extends EasyMockSupport {
         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();
 
     Map<String, Object> requestMap = new HashMap<>();
@@ -337,6 +336,43 @@ public class UpgradeContextTest extends EasyMockSupport {
     verifyAll();
   }
 
+
+  /**
+   * Tests that the {@link UpgradeContext} for a EU reversion has the correct
+   * parameters set.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testRevertEU() throws Exception {
+    ConfigHelper configHelper = createNiceMock(ConfigHelper.class);
+    UpgradeHelper upgradeHelper = createNiceMock(UpgradeHelper.class);
+    UpgradePack upgradePack = createNiceMock(UpgradePack.class);
+
+    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();
+    expect(m_completedRevertableUpgrade.getUpgradeType()).andReturn(UpgradeType.NON_ROLLING);
+
+    Map<String, Object> requestMap = new HashMap<>();
+    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(UpgradeType.NON_ROLLING, context.getType());
+    assertEquals(1, context.getSupportedServices().size());
+    assertTrue(context.isPatchRevert());
+
+    verifyAll();
+  }
+
   /**
    * Tests that the {@link UpgradeContext} for a reversion has the correct
    * services included in the reversion if one of the services in the original


Mime
View raw message