Bladeren bron

AMBARI-2458. Add ability to change UNKOWN to MAINTENANCE for host_components (ncole)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1495444 13f79535-47bb-0310-9956-ffa450edef68
Nate Cole 12 jaren geleden
bovenliggende
commit
561006e243

+ 9 - 3
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -2041,6 +2041,7 @@ public class AmbariManagementControllerImpl implements
                     || oldSchState == State.UNINSTALLED
                     || oldSchState == State.INSTALLED
                     || oldSchState == State.INSTALLING
+                    || oldSchState == State.UNKNOWN
                     || oldSchState == State.INSTALL_FAILED) {
                   roleCommand = RoleCommand.INSTALL;
                   event = new ServiceComponentHostInstallEvent(
@@ -2283,6 +2284,7 @@ public class AmbariManagementControllerImpl implements
             || oldState == State.INSTALL_FAILED
             || oldState == State.UPGRADING
             || oldState == State.STOPPING
+            || oldState == State.UNKNOWN
             || oldState == State.MAINTENANCE) {
           return true;
         }
@@ -2307,7 +2309,8 @@ public class AmbariManagementControllerImpl implements
           return true;
         }
       case MAINTENANCE:
-        if (oldState == State.INSTALLED) {
+        if (oldState == State.INSTALLED
+            || oldState == State.UNKNOWN) {
           return true;
         }
     }
@@ -3138,7 +3141,7 @@ public class AmbariManagementControllerImpl implements
       // If upgrade request comes without state information then its an error
       boolean upgradeRequest = checkIfUpgradeRequestAndValidate(request, cluster, s, sc, sch);
 
-      if (newState == null || oldState.equals(State.UNKNOWN)) {
+      if (newState == null) {
         if (LOG.isDebugEnabled()) {
           LOG.debug("Nothing to do for new updateServiceComponentHost request"
               + ", clusterName=" + request.getClusterName()
@@ -3373,10 +3376,13 @@ public class AmbariManagementControllerImpl implements
         }
         break;
       case MAINTENANCE:
-        if (oldState == State.INSTALLED) {
+        if (oldState == State.INSTALLED ||
+          oldState == State.UNKNOWN) {
           return true;
         }
         break;
+      default:
+        break;
     }
     return false;
   }

+ 5 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java

@@ -332,6 +332,11 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
           State.INSTALLED,
           ServiceComponentHostEventType.HOST_SVCCOMP_RESTORE,
           new ServiceComponentHostOpCompletedTransition())
+      
+      .addTransition(State.UNKNOWN,
+          State.MAINTENANCE,
+          ServiceComponentHostEventType.HOST_SVCCOMP_MAINTENANCE,
+          new ServiceComponentHostOpCompletedTransition())
 
      .installTopology();
 

+ 31 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java

@@ -1669,6 +1669,37 @@ public class AmbariManagementControllerImplTest {
     amc.createHostComponents(componentHostRequests);
     namenodes = cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
     assertEquals(2, namenodes.size());
+    
+    
+    // make unknown
+    ServiceComponentHost sch = null;
+    for (ServiceComponentHost tmp : cluster.getServiceComponentHosts("host2")) {
+      if (tmp.getServiceComponentName().equals("DATANODE")) {
+        tmp.setState(State.UNKNOWN);
+        sch = tmp;
+      }
+    }
+    assertNotNull(sch);
+
+    // make maintenance
+    componentHostRequests.clear();
+    componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "DATANODE", "host2", null, "MAINTENANCE"));
+    amc.updateHostComponents(componentHostRequests, mapRequestProps, false);
+    assertEquals(State.MAINTENANCE, sch.getState ());
+    
+    // confirm delete
+    componentHostRequests.clear();
+    componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "DATANODE", "host2", null, null));
+    amc.deleteHostComponents(componentHostRequests);
+    
+    sch = null;
+    for (ServiceComponentHost tmp : cluster.getServiceComponentHosts("host2")) {
+      if (tmp.getServiceComponentName().equals("DATANODE")) {
+        sch = tmp;
+      }
+    }
+    assertNull(sch);
+    
   }
 
   private void testRunSmokeTestFlag(Map<String, String> mapRequestProps,