incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject svn commit: r1453707 - in /incubator/ambari/trunk: ./ ambari-server/src/main/java/org/apache/ambari/server/controller/ ambari-server/src/main/java/org/apache/ambari/server/state/ ambari-server/src/test/java/org/apache/ambari/server/controller/ ambari-s...
Date Thu, 07 Mar 2013 06:35:21 GMT
Author: swagle
Date: Thu Mar  7 06:35:21 2013
New Revision: 1453707

URL: http://svn.apache.org/r1453707
Log:
AMBARI-1555. Upgrade should validate that the from->to version is an allowed combination
(Sumit Mohanty via swagle)

Added:
    incubator/ambari/trunk/ambari-server/src/test/resources/stacks/HDP/0.2/metainfo.xml
Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/StackId.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1453707&r1=1453706&r2=1453707&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Thu Mar  7 06:35:21 2013
@@ -12,6 +12,9 @@ Trunk (unreleased changes):
 
  NEW FEATURES
 
+ AMBARI-1555. Upgrade should validate that the from->to version is an allowed 
+ combination. (Sumit Mohanty via swagle)
+
  AMBARI-1568. Update the version of ambari artifacts to 1.3.0 snapshot (ncole)
 
  AMBARI-1563. API Support:  Host-component resource should include its current 

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1453707&r1=1453706&r2=1453707&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
Thu Mar  7 06:35:21 2013
@@ -1424,6 +1424,7 @@ public class AmbariManagementControllerI
     // Set the current version value if its not already set
     if (currentVersion == null) {
       cluster.setCurrentStackVersion(desiredVersion);
+      cluster.refresh();
       currentVersion = cluster.getCurrentStackVersion();
     }
 
@@ -1465,12 +1466,11 @@ public class AmbariManagementControllerI
             throw new AmbariException("Target version : " + requestedVersion
                 + " is not a recognized version");
           }
-          // TODO Ensure its an allowed upgrade using AmbariMetaInfo
-          //if(!upgradeAllowed(stackInfo, requestedVersion))
-          //{
-          //  throw new AmbariException("Upgrade is not allowed from " + currentVersion
-          //      + " to the target version " + requestedVersion);
-          //}
+          if(!isUpgradeAllowed(stackInfo, currentVersion))
+          {
+            throw new AmbariException("Upgrade is not allowed from " + currentVersion
+                + " to the target version " + requestedVersion);
+          }
         }
       } else {
         retry = true;
@@ -1528,6 +1528,19 @@ public class AmbariManagementControllerI
     return null;
   }
 
+  private boolean isUpgradeAllowed(StackInfo requestedStackInfo, StackId currentStackId)
{
+    String minUpgradeVersion = requestedStackInfo.getMinUpgradeVersion();
+    if (minUpgradeVersion != null && !minUpgradeVersion.isEmpty()) {
+      StackId minUpgradeStackId =
+          new StackId(currentStackId.getStackName(), minUpgradeVersion);
+      if (currentStackId.compareTo(minUpgradeStackId) >= 0) {
+        return true;
+      }
+    }
+
+    return false;
+  }
+
   private void fillComponentsToUpgrade(ClusterRequest request, Cluster cluster,
            Map<State, List<Service>> changedServices, Map<State, List<ServiceComponent>>
changedComps,
            Map<String, Map<State, List<ServiceComponentHost>>> changedScHosts)
throws AmbariException {
@@ -1574,7 +1587,7 @@ public class AmbariManagementControllerI
           State currSchState = sch.getState();
           if (sch.getStackVersion().equals(sch.getDesiredStackVersion())
               && newState == currSchState) {
-            LOG.info("Ignoring ServiceComponentHost"
+            LOG.info("Requesting upgrade for already upgraded ServiceComponentHost"
                 + ", clusterName=" + request.getClusterName()
                 + ", serviceName=" + service.getName()
                 + ", componentName=" + sc.getName()
@@ -1583,8 +1596,6 @@ public class AmbariManagementControllerI
                 + ", newDesiredState=" + newState
                 + ", currentDesiredState=" + sch.getStackVersion()
                 + ", newDesiredVersion=" + sch.getDesiredStackVersion());
-            //TODO Create NOP tasks for progress tracking
-            continue;
           }
 
           sch.setState(State.UPGRADING);

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/StackId.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/StackId.java?rev=1453707&r1=1453706&r2=1453707&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/StackId.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/StackId.java
Thu Mar  7 06:35:21 2013
@@ -19,17 +19,18 @@
 package org.apache.ambari.server.state;
 
 public class StackId implements Comparable<StackId> {
+
+  private static final String NAME_SEPARATOR = "-";
+
   private String stackName;
   private String stackVersion;
 
   public StackId() {
-    super();
     this.stackName = "";
     this.stackVersion = "";
   }
 
   public StackId(String stackId) {
-    super();
     parseStackIdHelper(this, stackId);
   }
 
@@ -38,6 +39,10 @@ public class StackId implements Comparab
     this.stackVersion = stackInfo.getVersion();
   }
 
+  public StackId(String stackName, String stackVersion) {
+    this(stackName + NAME_SEPARATOR + stackVersion);
+  }
+
   /**
    * @return the stackName
    */
@@ -60,7 +65,7 @@ public class StackId implements Comparab
         && stackVersion.isEmpty()) {
       return "";
     }
-    return stackName + "-" + stackVersion;
+    return stackName + NAME_SEPARATOR + stackVersion;
   }
 
   /**

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java?rev=1453707&r1=1453706&r2=1453707&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
Thu Mar  7 06:35:21 2013
@@ -3975,9 +3975,6 @@ public class AmbariManagementControllerT
     
     
   }
-  
-  
-  
 
   @Test
   public void testUpdateClusterVersionBasic() throws AmbariException {
@@ -4091,6 +4088,33 @@ public class AmbariManagementControllerT
   }
 
   @Test
+  public void testUpdateClusterUpgradabilityCheck() throws AmbariException {
+    String clusterName = "foo1";
+    StackId currentStackId = new StackId("HDP-0.2");
+
+    createCluster(clusterName);
+    Cluster c = clusters.getCluster(clusterName);
+    c.setDesiredStackVersion(currentStackId);
+    ClusterRequest r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.3", null);
+    try {
+      controller.updateCluster(r);
+    } catch (AmbariException e) {
+      Assert.assertTrue(e.getMessage().contains("Illegal request to upgrade to"));
+    }
+
+    StackId unsupportedStackId = new StackId("HDP-0.0.1");
+    c.setDesiredStackVersion(unsupportedStackId);
+    c.setCurrentStackVersion(unsupportedStackId);
+    c.refresh();
+    r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.2", null);
+    try {
+      controller.updateCluster(r);
+    } catch (AmbariException e) {
+      Assert.assertTrue(e.getMessage().contains("Upgrade is not allowed from"));
+    }
+  }
+
+  @Test
   public void testUpdateClusterVersionCombinations() throws AmbariException {
     String clusterName = "foo1";
     String pigServiceName = "PIG";
@@ -4184,11 +4208,7 @@ public class AmbariManagementControllerT
 
     trackAction = controller.updateCluster(r);
     stages = actionDB.getAllStages(trackAction.getRequestId());
-    expectedTasks.resetAll();
-    expectedTasks.expectTask(Role.JOBTRACKER, host1);
-    expectedTasks.expectTask(Role.TASKTRACKER, host2);
-    expectedTasks.expectTask(Role.MAPREDUCE_CLIENT, host2);
-    validateGeneratedStages(stages, 3, expectedTasks);
+    validateGeneratedStages(stages, 4, expectedTasks);
 
     c.getService(mrServiceName).getServiceComponent(mrJobTrackerComp).getServiceComponentHost(host1)
         .setState(State.UPGRADE_FAILED);
@@ -4196,7 +4216,7 @@ public class AmbariManagementControllerT
         .setState(State.UPGRADE_FAILED);
     trackAction = controller.updateCluster(r);
     stages = actionDB.getAllStages(trackAction.getRequestId());
-    validateGeneratedStages(stages, 3, expectedTasks);
+    validateGeneratedStages(stages, 4, expectedTasks);
 
     // Add HDFS and upgrade
     createService(clusterName, hdfsService, State.INIT);

Added: incubator/ambari/trunk/ambari-server/src/test/resources/stacks/HDP/0.2/metainfo.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/resources/stacks/HDP/0.2/metainfo.xml?rev=1453707&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/resources/stacks/HDP/0.2/metainfo.xml (added)
+++ incubator/ambari/trunk/ambari-server/src/test/resources/stacks/HDP/0.2/metainfo.xml Thu
Mar  7 06:35:21 2013
@@ -0,0 +1,22 @@
+<?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.
+-->
+<metainfo>
+    <versions>
+	  <upgrade>0.1</upgrade>
+    </versions>
+</metainfo>



Mime
View raw message