瀏覽代碼

AMBARI-6361. Component status cannot be changed from INSTALL_FAIL to Disabled state. (Jayush Luniya via mahadev)

Mahadev Konar 11 年之前
父節點
當前提交
fedcbb8a51

+ 1 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -2225,6 +2225,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
         break;
       case DISABLED:
         if (oldState == State.INSTALLED ||
+          oldState == State.INSTALL_FAILED ||
           oldState == State.UNKNOWN) {
           return true;
         }

+ 1 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/State.java

@@ -173,6 +173,7 @@ public enum State {
         }
       case DISABLED:
         if (startState == State.INSTALLED
+            || startState == State.INSTALL_FAILED
             || startState == State.UNKNOWN) {
           return true;
         }

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

@@ -340,15 +340,20 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
           State.DISABLED,
           ServiceComponentHostEventType.HOST_SVCCOMP_DISABLE,
           new ServiceComponentHostOpCompletedTransition())
+      .addTransition(State.UNKNOWN,
+                  State.DISABLED,
+                  ServiceComponentHostEventType.HOST_SVCCOMP_DISABLE,
+                  new ServiceComponentHostOpCompletedTransition())
+      .addTransition(State.INSTALL_FAILED,
+                  State.DISABLED,
+                  ServiceComponentHostEventType.HOST_SVCCOMP_DISABLE,
+                  new ServiceComponentHostOpCompletedTransition())
+
       .addTransition(State.DISABLED,
           State.INSTALLED,
           ServiceComponentHostEventType.HOST_SVCCOMP_RESTORE,
           new ServiceComponentHostOpCompletedTransition())
-      
-      .addTransition(State.UNKNOWN,
-          State.DISABLED,
-          ServiceComponentHostEventType.HOST_SVCCOMP_DISABLE,
-          new ServiceComponentHostOpCompletedTransition())
+
 
      .installTopology();
 

+ 4 - 1
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java

@@ -36,6 +36,7 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.lang.reflect.Type;
+import java.net.ConnectException;
 import java.net.MalformedURLException;
 import java.net.UnknownHostException;
 import java.text.MessageFormat;
@@ -8137,7 +8138,9 @@ public class AmbariManagementControllerTest {
     try {
       controller.updateRespositories(requests);
     } catch (Exception e) {
-      assertTrue(e.getMessage().contains(UnknownHostException.class.getName()));
+      String exceptionMsg = e.getMessage();
+      assertTrue(exceptionMsg.contains(UnknownHostException.class.getName())
+        || exceptionMsg.contains(ConnectException.class.getName()));
     }      
     
     // reset repo

+ 61 - 0
ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java

@@ -19,6 +19,7 @@
 package org.apache.ambari.server.state.svccomphost;
 
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 
 import javax.persistence.EntityManager;
@@ -217,6 +218,9 @@ public class ServiceComponentHostTest {
       case HOST_SVCCOMP_OP_RESTART:
         return new ServiceComponentHostOpRestartedEvent(
             impl.getServiceComponentName(), impl.getHostName(), timestamp);
+      case HOST_SVCCOMP_DISABLE:
+          return new ServiceComponentHostDisableEvent(
+            impl.getServiceComponentName(), impl.getHostName(), timestamp);
       case HOST_SVCCOMP_WIPEOUT:
         return new ServiceComponentHostWipeoutEvent(
             impl.getServiceComponentName(), impl.getHostName(), timestamp);
@@ -611,6 +615,63 @@ public class ServiceComponentHostTest {
         impl.getState());
   }
 
+   @Test
+   public void TestDisableInVariousStates() throws AmbariException,
+           InvalidStateTransitionException {
+       ServiceComponentHost sch =
+               createNewServiceComponentHost("HDFS", "DATANODE", "h1", false);
+       ServiceComponentHostImpl impl =  (ServiceComponentHostImpl) sch;
+
+       // Test valid states in which host component can be disabled
+       long timestamp = 0;
+       HashSet<State> validStates = new HashSet<State>();
+       validStates.add(State.INSTALLED);
+       validStates.add(State.INSTALL_FAILED);
+       validStates.add(State.UNKNOWN);
+       validStates.add(State.DISABLED);
+       for (State state : validStates)
+       {
+         sch.setState(state);
+         ServiceComponentHostEvent disableEvent = createEvent(
+                   impl, ++timestamp, ServiceComponentHostEventType.HOST_SVCCOMP_DISABLE);
+         impl.handleEvent(disableEvent);
+         // TODO: At present operation timestamps are not getting updated.
+         Assert.assertEquals(-1, impl.getLastOpStartTime());
+         Assert.assertEquals(-1, impl.getLastOpLastUpdateTime());
+         Assert.assertEquals(-1, impl.getLastOpEndTime());
+         Assert.assertEquals(State.DISABLED, impl.getState());
+       }
+
+       // Test invalid states in which host component cannot be disabled
+       HashSet<State> invalidStates = new HashSet<State>();
+       invalidStates.add(State.INIT);
+       invalidStates.add(State.INSTALLING);
+       invalidStates.add(State.STARTING);
+       invalidStates.add(State.STARTED);
+       invalidStates.add(State.STOPPING);
+       invalidStates.add(State.UNINSTALLING);
+       invalidStates.add(State.UNINSTALLED);
+       invalidStates.add(State.UPGRADING);
+
+       for(State state : invalidStates)
+       {
+           sch.setState(state);
+           ServiceComponentHostEvent disableEvent = createEvent(
+                   impl, ++timestamp, ServiceComponentHostEventType.HOST_SVCCOMP_DISABLE);
+           boolean exceptionThrown = false;
+           try {
+               impl.handleEvent(disableEvent);
+           } catch (Exception e) {
+               exceptionThrown = true;
+           }
+           Assert.assertTrue("Exception not thrown on invalid event", exceptionThrown);
+           // TODO: At present operation timestamps are not getting updated.
+           Assert.assertEquals(-1, impl.getLastOpStartTime());
+           Assert.assertEquals(-1, impl.getLastOpLastUpdateTime());
+           Assert.assertEquals(-1, impl.getLastOpEndTime());
+       }
+   }
+
   @Test
   public void testCanBeRemoved() throws Exception{
     ServiceComponentHostImpl impl = (ServiceComponentHostImpl)

+ 3 - 2
pom.xml

@@ -173,7 +173,7 @@
             <exclude>derby.log</exclude>
             <exclude>CHANGES.txt</exclude>
             <exclude>pass.txt</exclude>
-                   <exclude>contrib/addons/test/dataServices/jmx/data/cluster_configuration.json.nohbase</exclude>
+            <exclude>contrib/addons/test/dataServices/jmx/data/cluster_configuration.json.nohbase</exclude>
             <exclude>contrib/ambari-scom/msi/src/GUI_Ambari.sln</exclude>
             <exclude>version</exclude>
             <!--IDE and GIT files-->
@@ -222,7 +222,8 @@
             <exclude>contrib/views/*/.classpath</exclude>
             <exclude>contrib/views/*/.project</exclude>
             <exclude>contrib/views/*/.settings/**</exclude>
-			
+            <exclude>contrib/views/jobs/src/main/resources/ui/**</exclude>
+
             <!--Velocity log -->
             <exclude>**/velocity.log*</exclude>
           </excludes>