Explorar o código

AMBARI-3191. Cannot delete a stopped host_component in INSTALLED state.

Sumit Mohanty %!s(int64=11) %!d(string=hai) anos
pai
achega
acfbf348a7

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

@@ -3705,9 +3705,9 @@ public class AmbariManagementControllerImpl implements
       // generation.
       // Clients may be removed without a state check.
       if (!component.isClientComponent() &&
-          !componentHost.getState().isHardDeletableState()) {
+          !componentHost.getState().isRemovableState()) {
         throw new AmbariException("To remove master or slave components they must be in " +
-            "MAINTENANCE/INIT/INSTALL_FAILED/UNKNOWN state. Current=" + componentHost.getState() + ".");
+            "MAINTENANCE/INIT/INSTALLED/INSTALL_FAILED/UNKNOWN state. Current=" + componentHost.getState() + ".");
       }
 
       if (!safeToRemoveSCHs.containsKey(component)) {

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

@@ -150,22 +150,4 @@ public enum State {
         return false;
     }
   }
-
-  /**
-   * Indicates whether or not the resource with this state can be hard-deleted.
-   *
-   * @return true if this is a hard-deletable state
-   */
-  public boolean isHardDeletableState() {
-    switch (State.values()[this.state]) {
-      case INIT:
-      case INSTALLING:
-      case INSTALL_FAILED:
-      case UNKNOWN:
-      case MAINTENANCE:
-        return true;
-      default:
-        return false;
-    }
-  }
 }

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

@@ -6911,7 +6911,7 @@ public class AmbariManagementControllerTest {
     Service s1 = cluster.getService(serviceName);
     Service s2 = cluster.getService(mapred);
     ServiceComponent sc1 = s1.getServiceComponent(componentName1);
-    sc1.getServiceComponentHosts().values().iterator().next().setState(State.INSTALLED);
+    sc1.getServiceComponentHosts().values().iterator().next().setState(State.STARTED);
 
     Set<ServiceComponentHostRequest> schRequests = new HashSet<ServiceComponentHostRequest>();
     // delete HC
@@ -6922,7 +6922,7 @@ public class AmbariManagementControllerTest {
       Assert.fail("Expect failure while deleting.");
     } catch (Exception ex) {
       Assert.assertTrue(ex.getMessage().contains(
-          "remove master or slave components they must be in MAINTENANCE/INIT/INSTALL_FAILED/UNKNOWN"));
+          "Host Component cannot be removed"));
     }
 
     sc1.getServiceComponentHosts().values().iterator().next().setDesiredState(State.STARTED);
@@ -6935,7 +6935,7 @@ public class AmbariManagementControllerTest {
     sc4.getServiceComponentHosts().values().iterator().next().setDesiredState(State.INSTALLED);
     sc4.getServiceComponentHosts().values().iterator().next().setState(State.MAINTENANCE);
     ServiceComponent sc5 = s2.getServiceComponent(componentName5);
-    sc5.getServiceComponentHosts().values().iterator().next().setState(State.INSTALL_FAILED);
+    sc5.getServiceComponentHosts().values().iterator().next().setState(State.INSTALLED);
     ServiceComponent sc6 = s2.getServiceComponent(componentName6);
     sc6.getServiceComponentHosts().values().iterator().next().setState(State.INIT);