You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2018/06/26 15:24:39 UTC

[ambari] branch trunk updated: [AMBARI-24193] - Upgrade Packs Do Not Allow Downgrade by Default (#1625)

This is an automated email from the ASF dual-hosted git repository.

jonathanhurley pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 4992284  [AMBARI-24193] - Upgrade Packs Do Not Allow Downgrade by Default (#1625)
4992284 is described below

commit 4992284e956be47272c4a5305ce0bba98b86dd37
Author: Jonathan Hurley <jo...@apache.org>
AuthorDate: Tue Jun 26 11:24:35 2018 -0400

    [AMBARI-24193] - Upgrade Packs Do Not Allow Downgrade by Default (#1625)
---
 .../ambari/server/state/stack/UpgradePack.java     |  2 +-
 .../ambari/server/state/stack/UpgradePackTest.java | 27 ++++++++++++
 .../2.2.0/upgrades/upgrade_test_no_downgrade.xml   | 51 ++++++++++++++++++++++
 3 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/UpgradePack.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/UpgradePack.java
index 33b145a..25778ee 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/UpgradePack.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/UpgradePack.java
@@ -102,7 +102,7 @@ public class UpgradePack {
    * Tag is optional and can be {@code null}, use {@code isDowngradeAllowed} getter instead.
    */
   @XmlElement(name = "downgrade-allowed", required = false, defaultValue = "true")
-  private boolean downgradeAllowed;
+  private boolean downgradeAllowed = true;
 
   /**
    * {@code true} to automatically skip service check failures. The default is
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java
index 0eac2be..534d666 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java
@@ -89,6 +89,33 @@ public class UpgradePackTest {
     H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
+  /**
+   * Tests that boolean values are property serialized in the upgrade pack.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testIsDowngradeAllowed() throws Exception {
+    Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.2.0");
+    assertTrue(upgrades.size() > 0);
+
+    String upgradePackWithoutDowngrade = "upgrade_test_no_downgrade";
+    boolean foundAtLeastOnePackWithoutDowngrade = false;
+
+    for (String key : upgrades.keySet()) {
+      UpgradePack upgradePack = upgrades.get(key);
+      if (upgradePack.getName().equals(upgradePackWithoutDowngrade)) {
+        foundAtLeastOnePackWithoutDowngrade = true;
+        assertFalse(upgradePack.isDowngradeAllowed());
+        continue;
+      }
+
+      assertTrue(upgradePack.isDowngradeAllowed());
+    }
+
+    assertTrue(foundAtLeastOnePackWithoutDowngrade);
+  }
+
   @Test
   public void testExistence() throws Exception {
     Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("foo", "bar");
diff --git a/ambari-server/src/test/resources/stacks/HDP/2.2.0/upgrades/upgrade_test_no_downgrade.xml b/ambari-server/src/test/resources/stacks/HDP/2.2.0/upgrades/upgrade_test_no_downgrade.xml
new file mode 100644
index 0000000..4624828
--- /dev/null
+++ b/ambari-server/src/test/resources/stacks/HDP/2.2.0/upgrades/upgrade_test_no_downgrade.xml
@@ -0,0 +1,51 @@
+<?xml version="1.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.
+-->
+<upgrade xsi:noNamespaceSchemaLocation="upgrade-pack.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <target>2.5.*.*</target>
+  <target-stack>HDP-2.5.0</target-stack>
+  <downgrade-allowed>false</downgrade-allowed>
+  <type>ROLLING</type>  
+
+  <order>
+    <group xsi:type="stop" name="STOP_HIVE" title="Stop Hive Server">
+      <service-check>false</service-check>
+      <skippable>true</skippable>
+      <service name="HIVE">
+        <component>HIVE_SERVER</component>
+      </service>
+    </group>    
+
+    <group xsi:type="restart" name="RESTART_HIVE" title="Restart Hive Server">
+      <service-check>false</service-check>
+      <skippable>true</skippable>
+      <service name="HIVE">
+        <component>HIVE_SERVER</component>
+      </service>
+    </group>    
+  </order>
+  
+  <processing>
+    <service name="HIVE">
+      <component name="HIVE_SERVER">
+        <upgrade>
+          <task xsi:type="restart-task"/>
+        </upgrade>
+      </component>
+    </service>
+  </processing>
+</upgrade>