ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smoha...@apache.org
Subject ambari git commit: AMBARI-16080. Delete Service: Deleting Hive fails with 500 error (smohanty)
Date Sun, 24 Apr 2016 14:12:54 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 3ea71e333 -> 3024c43bd


AMBARI-16080. Delete Service: Deleting Hive fails with 500 error (smohanty)


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

Branch: refs/heads/trunk
Commit: 3024c43bdfe437ad3db7970ed3d2a779668f21cb
Parents: 3ea71e3
Author: Sumit Mohanty <smohanty@hortonworks.com>
Authored: Sun Apr 24 07:12:41 2016 -0700
Committer: Sumit Mohanty <smohanty@hortonworks.com>
Committed: Sun Apr 24 07:12:41 2016 -0700

----------------------------------------------------------------------
 .../server/state/ServiceComponentImpl.java      |  9 +--
 .../server/state/ServiceComponentTest.java      | 84 ++++++++++++++++++--
 2 files changed, 81 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3024c43b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
index 93e7222..9283e38 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
@@ -678,10 +678,9 @@ public class ServiceComponentImpl implements ServiceComponent {
     try {
       readWriteLock.readLock().lock();
       try {
-        if (!getDesiredState().isRemovableState()) {
-          return false;
-        }
-
+        // A component can be deleted if all it's host components
+        // can be removed, irrespective of the state of
+        // the component itself
         for (ServiceComponentHost sch : hostComponents.values()) {
           if (!sch.canBeRemoved()) {
             LOG.warn("Found non removable hostcomponent when trying to"
@@ -689,7 +688,7 @@ public class ServiceComponentImpl implements ServiceComponent {
                 + ", clusterName=" + getClusterName()
                 + ", serviceName=" + getServiceName()
                 + ", componentName=" + getName()
-                + ", recoveryEnabled=" + isRecoveryEnabled()
+                + ", state=" + sch.getState()
                 + ", hostname=" + sch.getHostName());
             return false;
           }

http://git-wip-us.apache.org/repos/asf/ambari/blob/3024c43b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
index 0adac80..6b00616 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
@@ -341,19 +341,26 @@ public class ServiceComponentTest {
   }
 
   @Test
-  public void testCanBeRemoved() throws Exception{
+  public void testCanBeRemoved() throws Exception {
     String componentName = "NAMENODE";
     ServiceComponent component = serviceComponentFactory.createNew(service,
-        componentName);
+                                                                   componentName);
+    addHostToCluster("h1", service.getCluster().getClusterName());
+    ServiceComponentHost sch = serviceComponentHostFactory.createNew(component, "h1");
+    component.addServiceComponentHost(sch);
 
     for (State state : State.values()) {
       component.setDesiredState(state);
 
-      if (state.isRemovableState()) {
-        org.junit.Assert.assertTrue(component.canBeRemoved());
-      }
-      else {
-        org.junit.Assert.assertFalse(component.canBeRemoved());
+      for (State hcState : State.values()) {
+        sch.setDesiredState(hcState);
+        sch.setState(hcState);
+
+        if (hcState.isRemovableState()) {
+          org.junit.Assert.assertTrue(component.canBeRemoved());
+        } else {
+          org.junit.Assert.assertFalse(component.canBeRemoved());
+        }
       }
     }
   }
@@ -399,6 +406,69 @@ public class ServiceComponentTest {
     Assert.assertEquals(history, serviceComponentDesiredStateEntity.getHistory().iterator().next());
   }
 
+
+  @Test
+  public void testServiceComponentRemove() throws AmbariException {
+    ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = injector.getInstance(
+        ServiceComponentDesiredStateDAO.class);
+
+    String componentName = "NAMENODE";
+    ServiceComponent component = serviceComponentFactory.createNew(service, componentName);
+    service.addServiceComponent(component);
+    component.persist();
+
+    ServiceComponent sc = service.getServiceComponent(componentName);
+    Assert.assertNotNull(sc);
+
+    sc.setDesiredState(State.STARTED);
+    Assert.assertEquals(State.STARTED, sc.getDesiredState());
+
+    ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName(
+        cluster.getClusterId(), serviceName, componentName);
+
+    Assert.assertNotNull(serviceComponentDesiredStateEntity);
+
+    Assert.assertTrue(sc.getServiceComponentHosts().isEmpty());
+
+    addHostToCluster("h1", service.getCluster().getClusterName());
+    addHostToCluster("h2", service.getCluster().getClusterName());
+
+    HostEntity hostEntity1 = hostDAO.findByName("h1");
+    assertNotNull(hostEntity1);
+
+    ServiceComponentHost sch1 =
+        serviceComponentHostFactory.createNew(sc, "h1");
+    ServiceComponentHost sch2 =
+        serviceComponentHostFactory.createNew(sc, "h2");
+
+    Map<String, ServiceComponentHost> compHosts =
+        new HashMap<String, ServiceComponentHost>();
+    compHosts.put("h1", sch1);
+    compHosts.put("h2", sch2);
+    sc.addServiceComponentHosts(compHosts);
+
+    sch1.setState(State.STARTED);
+    sch2.setState(State.STARTED);
+
+    try {
+      // delete the SC
+      sc.delete();
+      Assert.assertTrue("Delete must fail as some SCH are in STARTED state", false);
+    }catch(AmbariException e) {
+      // expected
+    }
+
+    sch1.setState(State.INSTALLED);
+    sch2.setState(State.INSTALL_FAILED);
+    sc.delete();
+
+    // verify history is gone, too
+    serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName(
+        cluster.getClusterId(), serviceName, componentName);
+
+    Assert.assertNull(serviceComponentDesiredStateEntity);
+ }
+
   /**
    * Tests the CASCADE nature of removing a service component also removes the
    * history.


Mime
View raw message