ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smn...@apache.org
Subject ambari git commit: AMBARI-15549: Delete service - Unable to delete a service even when it's host components are in a removable state.
Date Fri, 25 Mar 2016 17:59:53 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk f151a43b4 -> eec5fc309


AMBARI-15549: Delete service - Unable to delete a service even when it's host components are
in a removable state.


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/eec5fc30
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/eec5fc30
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/eec5fc30

Branch: refs/heads/trunk
Commit: eec5fc3092ac2900d2adde505ed983db72b378f0
Parents: f151a43
Author: Nahappan Somasundaram <nsomasundaram@hortonworks.com>
Authored: Thu Mar 24 11:18:50 2016 -0700
Committer: Nahappan Somasundaram <nsomasundaram@hortonworks.com>
Committed: Fri Mar 25 10:55:44 2016 -0700

----------------------------------------------------------------------
 .../internal/ServiceResourceProvider.java       | 25 ++++++--
 .../internal/ServiceResourceProviderTest.java   | 60 ++++++++++++++++----
 2 files changed, 70 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/eec5fc30/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
index ed7659f..adfac0c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
@@ -776,17 +776,32 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
                 serviceRequest.getServiceName());
 
         //
-        // Run through the list of service components. If all components are in removable
state,
+        // Run through the list of service component hosts. If all host components are in
removable state,
         // the service can be deleted, irrespective of it's state.
         //
+        boolean isServiceRemovable = true;
+
         for (ServiceComponent sc : service.getServiceComponents().values()) {
-          if (!sc.canBeRemoved()) {
-            throw new AmbariException ("Cannot remove " +
-                    serviceRequest.getClusterName() + "/" + serviceRequest.getServiceName()
+
-                    ". " + sc.getName() + " is in a non-removable state.");
+          Map<String, ServiceComponentHost> schHostMap = sc.getServiceComponentHosts();
+
+          for (Map.Entry<String, ServiceComponentHost> entry : schHostMap.entrySet())
{
+            ServiceComponentHost sch = entry.getValue();
+            if (!sch.canBeRemoved()) {
+              String msg = "Cannot remove " + serviceRequest.getClusterName() + "/" + serviceRequest.getServiceName()
+
+                      ". " + sch.getServiceComponentName() + "on " + sch.getHost() + " is
in " +
+                      String.valueOf(sch.getDesiredState()) + " state.";
+              LOG.error(msg);
+              isServiceRemovable = false;
+            }
           }
         }
 
+        if (!isServiceRemovable) {
+          throw new AmbariException ("Cannot remove " +
+                  serviceRequest.getClusterName() + "/" + serviceRequest.getServiceName()
+
+                    ". " + "One or more host components are in a non-removable state.");
+        }
+
         removable.add(service);
       }
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/eec5fc30/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
index 0cc03b8..e113347 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
@@ -58,6 +58,7 @@ import org.springframework.security.core.Authentication;
 import org.springframework.security.core.context.SecurityContextHolder;
 
 import java.lang.reflect.Field;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -924,6 +925,10 @@ public class ServiceResourceProviderTest {
     Map<String, ServiceComponent> scMap = new HashMap<String, ServiceComponent>();
     scMap.put("Component100", sc);
     State componentState = State.STARTED;
+    ServiceComponentHost sch = createNiceMock(ServiceComponentHost.class);
+    Map<String, ServiceComponentHost> schMap = new HashMap<>();
+    schMap.put("Host1", sch);
+    State schState = State.STARTED;
 
     String serviceName = "Service100";
 
@@ -937,9 +942,12 @@ public class ServiceResourceProviderTest {
     expect(sc.getDesiredState()).andReturn(componentState).anyTimes();
     expect(sc.getName()).andReturn("Component100").anyTimes();
     expect(sc.canBeRemoved()).andReturn(componentState.isRemovableState()).anyTimes();
+    expect(sc.getServiceComponentHosts()).andReturn(schMap).anyTimes();
+    expect(sch.getDesiredState()).andReturn(schState).anyTimes();
+    expect(sch.canBeRemoved()).andReturn(schState.isRemovableState()).anyTimes();
 
     // replay
-    replay(managementController, clusters, cluster, service, sc);
+    replay(managementController, clusters, cluster, service, sc, sch);
 
     SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
 
@@ -962,10 +970,10 @@ public class ServiceResourceProviderTest {
   }
 
   /*
-  If the components of a service are in a removable state, the service should be removable
even if it's state is non-removable
+  If the host components of a service are in a removable state, the service should be removable
even if it's state is non-removable
  */
   @Test
-  public void testDeleteResourcesStoppedComponentState() throws Exception {
+  public void testDeleteResourcesStoppedHostComponentState() throws Exception {
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
     Clusters clusters = createNiceMock(Clusters.class);
     Cluster cluster = createNiceMock(Cluster.class);
@@ -987,17 +995,29 @@ public class ServiceResourceProviderTest {
     }
 
     //
-    // Set up three components in INSTALLED state, so that the service can be deleted, no
matter what state the service is in
+    // Set up three components in STARTED state.
     //
-    TestComponent component1 = new TestComponent("Component100", createNiceMock(ServiceComponent.class),
State.INSTALLED);
-    TestComponent component2 = new TestComponent("Component101", createNiceMock(ServiceComponent.class),
State.INSTALLED);
-    TestComponent component3 = new TestComponent("Component102", createNiceMock(ServiceComponent.class),
State.INSTALLED);
-    Map<String, ServiceComponent> scMap = new HashMap<String, ServiceComponent>();
+    TestComponent component1 = new TestComponent("Component100", createNiceMock(ServiceComponent.class),
State.STARTED);
+    TestComponent component2 = new TestComponent("Component101", createNiceMock(ServiceComponent.class),
State.STARTED);
+    TestComponent component3 = new TestComponent("Component102", createNiceMock(ServiceComponent.class),
State.STARTED);
 
+    Map<String, ServiceComponent> scMap = new HashMap<String, ServiceComponent>();
     scMap.put(component1.Name, component1.Component);
     scMap.put(component2.Name, component2.Component);
     scMap.put(component3.Name, component3.Component);
 
+    Map<String, ServiceComponentHost> schMap1 = new HashMap<>();
+    ServiceComponentHost sch1 = createNiceMock(ServiceComponentHost.class);
+    schMap1.put("Host1", sch1);
+
+    Map<String, ServiceComponentHost> schMap2 = new HashMap<>();
+    ServiceComponentHost sch2 = createNiceMock(ServiceComponentHost.class);
+    schMap2.put("Host2", sch2);
+
+    Map<String, ServiceComponentHost> schMap3 = new HashMap<>();
+    ServiceComponentHost sch3 = createNiceMock(ServiceComponentHost.class);
+    schMap3.put("Host3", sch3);
+
     String clusterName = "Cluster100";
     String serviceName = "Service100";
 
@@ -1014,11 +1034,30 @@ public class ServiceResourceProviderTest {
     expect(component1.Component.canBeRemoved()).andReturn(component1.DesiredState.isRemovableState()).anyTimes();
     expect(component2.Component.canBeRemoved()).andReturn(component2.DesiredState.isRemovableState()).anyTimes();
     expect(component3.Component.canBeRemoved()).andReturn(component3.DesiredState.isRemovableState()).anyTimes();
+    expect(component1.Component.getServiceComponentHosts()).andReturn(schMap1).anyTimes();
+    expect(component2.Component.getServiceComponentHosts()).andReturn(schMap2).anyTimes();
+    expect(component3.Component.getServiceComponentHosts()).andReturn(schMap3).anyTimes();
+
+    // Put the SCH in INSTALLED state so that the service can be deleted,
+    // no matter what state the service component is in.
+    State sch1State = State.INSTALLED;
+    expect(sch1.getDesiredState()).andReturn(sch1State).anyTimes();
+    expect(sch1.canBeRemoved()).andReturn(sch1State.isRemovableState()).anyTimes();
+
+    State sch2State = State.INSTALLED;
+    expect(sch2.getDesiredState()).andReturn(sch2State).anyTimes();
+    expect(sch2.canBeRemoved()).andReturn(sch2State.isRemovableState()).anyTimes();
+
+    State sch3State = State.INSTALLED;
+    expect(sch3.getDesiredState()).andReturn(sch3State).anyTimes();
+    expect(sch3.canBeRemoved()).andReturn(sch3State.isRemovableState()).anyTimes();
+
     expect(service.getCluster()).andReturn(cluster);
     cluster.deleteService(serviceName);
 
     // replay
-    replay(managementController, clusters, cluster, service, component1.Component, component2.Component,
component3.Component);
+    replay(managementController, clusters, cluster, service,
+            component1.Component, component2.Component, component3.Component, sch1, sch2,
sch3);
 
     SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
 
@@ -1042,7 +1081,8 @@ public class ServiceResourceProviderTest {
     Assert.assertNull(lastEvent.getRequest());
 
     // verify
-    verify(managementController, clusters, cluster, service, component1.Component, component2.Component,
component3.Component);
+    verify(managementController, clusters, cluster, service,
+            component1.Component, component2.Component, component3.Component, sch1, sch2,
sch3);
   }
 
   @Test


Mime
View raw message