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-12314. Downgrade fails with 'Cannot create action for Execute HDFS Finalize with no hosts' (ncole)
Date Tue, 07 Jul 2015 18:31:46 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 ff5599e78 -> 3788777ed


AMBARI-12314. Downgrade fails with 'Cannot create action for Execute HDFS Finalize with no
hosts' (ncole)


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

Branch: refs/heads/branch-2.1
Commit: 3788777edd53ce12773036e5857f4217bbfce30a
Parents: ff5599e
Author: Nate Cole <ncole@hortonworks.com>
Authored: Tue Jul 7 14:25:07 2015 -0400
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Tue Jul 7 14:31:56 2015 -0400

----------------------------------------------------------------------
 .../state/stack/upgrade/ClusterGrouping.java    | 12 +++-
 .../state/stack/upgrade/TaskWrapperBuilder.java |  5 +-
 .../ambari/server/state/UpgradeHelperTest.java  | 73 ++++++++++++++++++++
 .../server/state/stack/UpgradePackTest.java     |  2 +-
 .../HDP/2.1.1/upgrades/upgrade_direction.xml    |  8 +++
 5 files changed, 94 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3788777e/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java
index 0cb0353..5b6bc50 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java
@@ -203,16 +203,22 @@ public class ClusterGrouping extends Grouping {
       HostsType hosts = ctx.getResolver().getMasterAndHosts(service, component);
 
       if (hosts != null) {
-        Set<String> realHosts = new LinkedHashSet<String>(hosts.hosts);
 
-        if (null != et.hosts && "master".equals(et.hosts) && null != hosts.master)
{
+        Set<String> realHosts = new LinkedHashSet<String>(hosts.hosts);
+        if (ExecuteHostType.MASTER == et.hosts && null != hosts.master) {
           realHosts = Collections.singleton(hosts.master);
         }
+
         // Pick a random host.
-        if (null != et.hosts && "any".equals(et.hosts) && !hosts.hosts.isEmpty())
{
+        if (ExecuteHostType.ANY == et.hosts && !hosts.hosts.isEmpty()) {
           realHosts = Collections.singleton(hosts.hosts.iterator().next());
         }
 
+        // !!! cannot execute against empty hosts (safety net)
+        if (realHosts.isEmpty()) {
+          return null;
+        }
+
         return new StageWrapper(
             StageWrapper.Type.RU_TASKS,
             execution.title,

http://git-wip-us.apache.org/repos/asf/ambari/blob/3788777e/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapperBuilder.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapperBuilder.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapperBuilder.java
index 9a5ba8c..a5813e3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapperBuilder.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapperBuilder.java
@@ -48,7 +48,8 @@ public class TaskWrapperBuilder {
     List<TaskWrapper> collection = new ArrayList<TaskWrapper>();
     for (Task t : tasks) {
       if (t.getType().equals(Task.Type.EXECUTE)) {
-        if (((ExecuteTask) t).hosts != null && ((ExecuteTask) t).hosts == ExecuteHostType.MASTER)
{
+        ExecuteTask et = (ExecuteTask) t;
+        if (et.hosts == ExecuteHostType.MASTER) {
           if (hostsType.master != null) {
             collection.add(new TaskWrapper(service, component, Collections.singleton(hostsType.master),
t));
             continue;
@@ -58,7 +59,7 @@ public class TaskWrapperBuilder {
           }
         }
         // Pick a random host.
-        if (((ExecuteTask) t).hosts != null && ((ExecuteTask) t).hosts == ExecuteHostType.ANY)
{
+        if (et.hosts == ExecuteHostType.ANY) {
           if (hostsType.hosts != null && !hostsType.hosts.isEmpty()) {
             collection.add(new TaskWrapper(service, component, Collections.singleton(hostsType.hosts.iterator().next()),
t));
             continue;

http://git-wip-us.apache.org/repos/asf/ambari/blob/3788777e/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
index a63c71e..f5a4a54 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
@@ -879,6 +879,79 @@ public class UpgradeHelperTest {
     return c;
   }
 
+  @Test
+  public void testDowngradeAfterPartialUpgrade() throws Exception {
+
+    Clusters clusters = injector.getInstance(Clusters.class);
+    ServiceFactory serviceFactory = injector.getInstance(ServiceFactory.class);
+
+    String clusterName = "c1";
+
+    StackId stackId = new StackId("HDP-2.1.1");
+    clusters.addCluster(clusterName, stackId);
+    Cluster c = clusters.getCluster(clusterName);
+
+    helper.getOrCreateRepositoryVersion(stackId,
+        c.getDesiredStackVersion().getStackVersion());
+
+    c.createClusterVersion(stackId,
+        c.getDesiredStackVersion().getStackVersion(), "admin",
+        RepositoryVersionState.UPGRADING);
+
+    for (int i = 0; i < 2; i++) {
+      String hostName = "h" + (i+1);
+      clusters.addHost(hostName);
+      Host host = clusters.getHost(hostName);
+
+      Map<String, String> hostAttributes = new HashMap<String, String>();
+      hostAttributes.put("os_family", "redhat");
+      hostAttributes.put("os_release_version", "6");
+
+      host.setHostAttributes(hostAttributes);
+
+      host.persist();
+      clusters.mapHostToCluster(hostName, clusterName);
+    }
+
+    // !!! add services
+    c.addService(serviceFactory.createNew(c, "HDFS"));
+
+    Service s = c.getService("HDFS");
+    ServiceComponent sc = s.addServiceComponent("NAMENODE");
+    sc.addServiceComponentHost("h1");
+    sc.addServiceComponentHost("h2");
+
+    List<ServiceComponentHost> schs = c.getServiceComponentHosts("HDFS", "NAMENODE");
+    assertEquals(2, schs.size());
+
+    HostsType type = new HostsType();
+    type.master = "h1";
+    type.secondary = "h2";
+
+    expect(m_masterHostResolver.getMasterAndHosts("ZOOKEEPER", "ZOOKEEPER_SERVER")).andReturn(null).anyTimes();
+    expect(m_masterHostResolver.getMasterAndHosts("HDFS", "NAMENODE")).andReturn(type).anyTimes();
+    expect(m_masterHostResolver.getCluster()).andReturn(c).anyTimes();
+    replay(m_masterHostResolver);
+
+    UpgradeContext context = new UpgradeContext(m_masterHostResolver, HDP_21, HDP_21, DOWNGRADE_VERSION,
Direction.DOWNGRADE);
+
+    Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1");
+    UpgradePack upgrade = upgrades.get("upgrade_direction");
+    assertNotNull(upgrade);
+
+    List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
+    assertEquals(1, groups.size());
+
+    UpgradeGroupHolder group = groups.get(0);
+    assertEquals(3, group.items.size());
+
+    StageWrapper stage = group.items.get(1);
+    assertEquals("NameNode Finalize", stage.getText());
+    assertEquals(1, stage.getTasks().size());
+    TaskWrapper task = stage.getTasks().get(0);
+    assertEquals(1, task.getHosts().size());
+  }
+
 
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/3788777e/ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java
----------------------------------------------------------------------
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 cdde452..a23713f 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
@@ -243,7 +243,7 @@ public class UpgradePackTest {
 
     ClusterGrouping cluster_group = (ClusterGrouping) groups.get(2);
     List<ExecuteStage> stages = cluster_group.executionStages;
-    assertEquals(2, stages.size());
+    assertEquals(3, stages.size());
     assertNotNull(stages.get(0).intendedDirection);
     assertEquals(Direction.DOWNGRADE, stages.get(0).intendedDirection);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3788777e/ambari-server/src/test/resources/stacks/HDP/2.1.1/upgrades/upgrade_direction.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/stacks/HDP/2.1.1/upgrades/upgrade_direction.xml
b/ambari-server/src/test/resources/stacks/HDP/2.1.1/upgrades/upgrade_direction.xml
index 22a4ea7..538b237 100644
--- a/ambari-server/src/test/resources/stacks/HDP/2.1.1/upgrades/upgrade_direction.xml
+++ b/ambari-server/src/test/resources/stacks/HDP/2.1.1/upgrades/upgrade_direction.xml
@@ -41,6 +41,14 @@
           <message>this is downgrade message</message>
         </task>
       </execute-stage>
+      
+      <execute-stage title="NameNode Finalize" service="HDFS" component="NAMENODE" >
+        <task xsi:type="execute" hosts="master">
+          <script>scripts/namenode.py</script>
+          <function>actionexecute</function>
+        </task>
+      </execute-stage>      
+      
       <execute-stage title="Save Cluster State" service="" component="">
         <task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction">
         </task>


Mime
View raw message