You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2013/03/02 00:39:53 UTC

svn commit: r1451778 - in /incubator/ambari/trunk: ./ ambari-server/src/main/java/org/apache/ambari/server/controller/ ambari-server/src/test/java/org/apache/ambari/server/controller/

Author: swagle
Date: Fri Mar  1 23:39:53 2013
New Revision: 1451778

URL: http://svn.apache.org/r1451778
Log:
AMBARI-1485. Server throws exception when trying to stop a service which is in stopping state (Siddharth Wagle)

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/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=1451778&r1=1451777&r2=1451778&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Fri Mar  1 23:39:53 2013
@@ -400,6 +400,9 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
+ AMBARI-1485. Server throws exception when trying to stop a service which is 
+ in stopping state (Siddharth Wagle) 
+
  AMBARI-1526. State fields are not returned by default for services.
  (tbeerbower)
 

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=1451778&r1=1451777&r2=1451778&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 Fri Mar  1 23:39:53 2013
@@ -1789,7 +1789,8 @@ public class AmbariManagementControllerI
                 } else if (oldSchState == State.STARTED
                     || oldSchState == State.START_FAILED
                     || oldSchState == State.INSTALLED
-                    || oldSchState == State.STOP_FAILED) {
+                    || oldSchState == State.STOP_FAILED
+                    || oldSchState == State.STOPPING) {
                   roleCommand = RoleCommand.STOP;
                   event = new ServiceComponentHostStopEvent(
                       scHost.getServiceComponentName(), scHost.getHostName(),
@@ -2025,7 +2026,8 @@ public class AmbariManagementControllerI
             || oldState == State.INSTALL_FAILED
             || oldState == State.STOP_FAILED
             || oldState == State.UPGRADE_FAILED
-            || oldState == State.UPGRADING) {
+            || oldState == State.UPGRADING
+            || oldState == State.STOPPING) {
           return true;
         }
         break;
@@ -2061,7 +2063,8 @@ public class AmbariManagementControllerI
         if (oldState == State.INIT
             || oldState == State.UNINSTALLED
             || oldState == State.INSTALLED
-            || oldState == State.STARTED) {
+            || oldState == State.STARTED
+            || oldState == State.STOPPING) {
           return true;
         }
         break;

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=1451778&r1=1451777&r2=1451778&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 Fri Mar  1 23:39:53 2013
@@ -31,6 +31,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import com.sun.source.tree.AssertTree;
 import junit.framework.Assert;
 
 import org.apache.ambari.server.AmbariException;
@@ -4158,4 +4159,154 @@ public class AmbariManagementControllerT
       this.roleToIndex.put(Role.NAGIOS_SERVER, 23);
     }
   }
+
+  @Test
+  public void testServiceStopWhileStopping() throws AmbariException {
+    String clusterName = "foo1";
+    createCluster(clusterName);
+    clusters.getCluster(clusterName)
+      .setDesiredStackVersion(new StackId("HDP-0.1"));
+    String serviceName = "HDFS";
+    createService(clusterName, serviceName, null);
+    String componentName1 = "NAMENODE";
+    String componentName2 = "DATANODE";
+    String componentName3 = "HDFS_CLIENT";
+    createServiceComponent(clusterName, serviceName, componentName1,
+      State.INIT);
+    createServiceComponent(clusterName, serviceName, componentName2,
+      State.INIT);
+    createServiceComponent(clusterName, serviceName, componentName3,
+      State.INIT);
+
+    String host1 = "h1";
+    clusters.addHost(host1);
+    clusters.getHost("h1").setOsType("centos5");
+    clusters.getHost("h1").persist();
+    String host2 = "h2";
+    clusters.addHost(host2);
+    clusters.getHost("h2").setOsType("centos6");
+    clusters.getHost("h2").persist();
+
+    clusters.mapHostToCluster(host1, clusterName);
+    clusters.mapHostToCluster(host2, clusterName);
+
+
+    // null service should work
+    createServiceComponentHost(clusterName, null, componentName1,
+      host1, null);
+    createServiceComponentHost(clusterName, serviceName, componentName2,
+      host1, null);
+    createServiceComponentHost(clusterName, serviceName, componentName2,
+      host2, null);
+    createServiceComponentHost(clusterName, serviceName, componentName3,
+      host1, null);
+    createServiceComponentHost(clusterName, serviceName, componentName3,
+      host2, null);
+
+    Assert.assertNotNull(clusters.getCluster(clusterName)
+      .getService(serviceName)
+      .getServiceComponent(componentName1)
+      .getServiceComponentHost(host1));
+    Assert.assertNotNull(clusters.getCluster(clusterName)
+      .getService(serviceName)
+      .getServiceComponent(componentName2)
+      .getServiceComponentHost(host1));
+    Assert.assertNotNull(clusters.getCluster(clusterName)
+      .getService(serviceName)
+      .getServiceComponent(componentName2)
+      .getServiceComponentHost(host2));
+    Assert.assertNotNull(clusters.getCluster(clusterName)
+      .getService(serviceName)
+      .getServiceComponent(componentName3)
+      .getServiceComponentHost(host1));
+    Assert.assertNotNull(clusters.getCluster(clusterName)
+      .getService(serviceName)
+      .getServiceComponent(componentName3)
+      .getServiceComponentHost(host2));
+
+    // Install
+    ServiceRequest r = new ServiceRequest(clusterName, serviceName, null,
+      State.INSTALLED.toString());
+    Set<ServiceRequest> requests = new HashSet<ServiceRequest>();
+    requests.add(r);
+
+    RequestStatusResponse trackAction =
+      controller.updateServices(requests);
+    Assert.assertEquals(State.INSTALLED,
+      clusters.getCluster(clusterName).getService(serviceName)
+        .getDesiredState());
+
+    // manually change live state to installed as no running action manager
+    for (ServiceComponent sc :
+      clusters.getCluster(clusterName).getService(serviceName)
+        .getServiceComponents().values()) {
+      for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+        sch.setState(State.INSTALLED);
+      }
+    }
+
+    // Start
+    r = new ServiceRequest(clusterName, serviceName, null,
+      State.STARTED.toString());
+    requests.clear();
+    requests.add(r);
+    trackAction = controller.updateServices(requests);
+
+    // manually change live state to started as no running action manager
+    for (ServiceComponent sc :
+      clusters.getCluster(clusterName).getService(serviceName)
+        .getServiceComponents().values()) {
+      for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+        if (!sch.getServiceComponentName().equals("HDFS_CLIENT"))
+          sch.setState(State.STARTED);
+      }
+    }
+
+    Assert.assertEquals(State.STARTED,
+      clusters.getCluster(clusterName).getService(serviceName)
+        .getDesiredState());
+
+    // Set Current state to stopping
+    clusters.getCluster(clusterName).getService(serviceName).setDesiredState
+      (State.STOPPING);
+    for (ServiceComponent sc :
+      clusters.getCluster(clusterName).getService(serviceName)
+        .getServiceComponents().values()) {
+
+      for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+        if (!sch.getServiceComponentName().equals("HDFS_CLIENT")) {
+          Assert.assertEquals(State.STARTED, sch.getDesiredState());
+          sch.setState(State.STOPPING);
+        } else if (sch.getServiceComponentName().equals("DATANODE")) {
+          ServiceComponentHostRequest r1 = new ServiceComponentHostRequest
+            (clusterName, serviceName, sch.getServiceComponentName(),
+              sch.getHostName(), null, State.INSTALLED.name());
+          Set<ServiceComponentHostRequest> reqs1 = new
+            HashSet<ServiceComponentHostRequest>();
+          reqs1.add(r1);
+          controller.updateHostComponents(reqs1);
+          Assert.assertEquals(State.INSTALLED, sch.getDesiredState());
+        }
+      }
+    }
+
+    // Stop all services
+    r = new ServiceRequest(clusterName, serviceName, null,
+      State.INSTALLED.toString());
+    requests.clear();
+    requests.add(r);
+    controller.updateServices(requests);
+
+    for (ServiceComponent sc :
+      clusters.getCluster(clusterName).getService(serviceName)
+        .getServiceComponents().values()) {
+
+      for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+        if (!sch.getServiceComponentName().equals("HDFS_CLIENT")) {
+          Assert.assertEquals(State.INSTALLED, sch.getDesiredState());
+        }
+      }
+    }
+  }
+
 }