Updated Branches:
  refs/heads/trunk e17554c99 -> 7ba1d09a0

AMBARI-2649. After service is deleted, BE gets into inconsistent state when the 
service is added again. (Dmytro Shkvyra via smohanty)


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

Branch: refs/heads/trunk
Commit: 7ba1d09a00faf8613475acdfe6e9b6e409d18363
Parents: e17554c
Author: Sumit Mohanty <[email protected]>
Authored: Tue Jul 16 14:54:09 2013 -0700
Committer: Sumit Mohanty <[email protected]>
Committed: Tue Jul 16 14:54:09 2013 -0700

----------------------------------------------------------------------
 .../org/apache/ambari/server/state/Cluster.java |  7 +++
 .../server/state/ServiceComponentImpl.java      |  3 -
 .../server/state/cluster/ClusterImpl.java       |  1 +
 .../svccomphost/ServiceComponentHostImpl.java   |  6 ++
 .../AmbariManagementControllerImplTest.java     | 66 ++++++++++++++++++++
 5 files changed, 80 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/7ba1d09a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java 
b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
index 5ec59da..3321e48 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
@@ -70,6 +70,13 @@ public interface Cluster {
   public List<ServiceComponentHost> getServiceComponentHosts(String hostname);
 
   /**
+   * Remove ServiceComponentHost from cluster
+   * @param ServiceComponentHost
+   */  
+  public void removeServiceComponentHost(ServiceComponentHost svcCompHost) 
throws AmbariException;
+  
+  
+  /**
    * Get desired stack version
    * @return
    */

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/7ba1d09a/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 3ada22f..b8ebaf8 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
@@ -805,9 +805,6 @@ public class ServiceComponentImpl implements 
ServiceComponent {
         sch.delete();
         hostComponents.remove(hostname);
 
-        // FIXME need a better approach of caching components by host
-        ClusterImpl clusterImpl = (ClusterImpl) service.getCluster();
-        clusterImpl.removeServiceComponentHost(sch);
       } finally {
         readWriteLock.writeLock().unlock();
       }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/7ba1d09a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index aa31347..4e4e666 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
@@ -375,6 +375,7 @@ public class ClusterImpl implements Cluster {
 
   }
 
+  @Override
   public void removeServiceComponentHost(ServiceComponentHost svcCompHost)
       throws AmbariException {
     loadServiceHostComponents();

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/7ba1d09a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
index afdbd78..a6d351a 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
@@ -56,6 +56,7 @@ import com.google.inject.Injector;
 import com.google.inject.assistedinject.Assisted;
 import com.google.inject.assistedinject.AssistedInject;
 import com.google.inject.persist.Transactional;
+import java.util.logging.Level;
 
 public class ServiceComponentHostImpl implements ServiceComponentHost {
 
@@ -1519,7 +1520,12 @@ public class ServiceComponentHostImpl implements 
ServiceComponentHost {
           removeEntities();
           persisted = false;
         }
+        
clusters.getCluster(this.getClusterName()).removeServiceComponentHost(this);
         desiredConfigs.clear();
+      } catch (AmbariException ex) {
+        if (LOG.isDebugEnabled()) {
+          LOG.error(ex.getMessage());
+        }
       } finally {
         writeLock.unlock();
       }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/7ba1d09a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
index ad8eb70..75e03b5 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
@@ -1700,6 +1700,72 @@ public class AmbariManagementControllerImplTest {
     }
     assertNull(sch);
     
+    /*
+    *Test remove service
+    */
+    serviceRequests.clear();
+    serviceRequests.add(new ServiceRequest("c1", "HDFS", null, "INSTALLED"));
+    amc.updateServices(serviceRequests, mapRequestProps, true, false);
+    serviceRequests.clear();
+    serviceRequests.add(new ServiceRequest("c1", null, null, null));
+    assertEquals(1, amc.getServices(serviceRequests).size());
+    serviceRequests.clear();
+    serviceRequests.add(new ServiceRequest("c1", "HDFS", null, null));
+    amc.deleteServices(serviceRequests);
+    serviceRequests.clear();
+    serviceRequests.add(new ServiceRequest("c1", null, null, null));     
+    assertEquals(0, amc.getServices(serviceRequests).size());
+    
+    /*
+    *Test add service again
+    */
+    serviceRequests.clear();
+    serviceRequests.add(new ServiceRequest("c1", "HDFS", null, null));
+    amc.createServices(serviceRequests);
+    assertEquals(1, amc.getServices(serviceRequests).size());
+    //Create new configs
+    configurationRequest = new ConfigurationRequest("c1", "core-site", 
"version2",
+        gson.<Map<String, String>>fromJson("{ \"fs.default.name\" : 
\"localhost:8020\"}", confType)
+    );
+    amc.createConfiguration(configurationRequest);
+    configurationRequest = new ConfigurationRequest("c1", "hdfs-site", 
"version2",
+        gson.<Map<String, String>>fromJson("{ \"dfs.datanode.data.dir.perm\" : 
\"750\"}", confType)
+    );
+    amc.createConfiguration(configurationRequest);
+    configurationRequest = new ConfigurationRequest("c1", "global", "version2",
+        gson.<Map<String, String>>fromJson("{ \"hbase_hdfs_root_dir\" : 
\"/apps/hbase/\"}", confType)
+    );
+    amc.createConfiguration(configurationRequest);    
+    //Add configs to service
+    serviceRequests.clear();
+    serviceRequests.add(new ServiceRequest("c1", "HDFS",
+        gson.<Map<String, String>>fromJson("{\"core-site\": \"version2\", 
\"hdfs-site\": \"version2\", \"global\" : \"version2\" }", confType)
+        , null));
+    amc.updateServices(serviceRequests, mapRequestProps, true, false);
+    //Crate service components
+    serviceComponentRequests = new HashSet<ServiceComponentRequest>();
+    serviceComponentRequests.add(new ServiceComponentRequest("c1", "HDFS", 
"NAMENODE", null, null));
+    serviceComponentRequests.add(new ServiceComponentRequest("c1", "HDFS", 
"SECONDARY_NAMENODE", null, null));
+    serviceComponentRequests.add(new ServiceComponentRequest("c1", "HDFS", 
"DATANODE", null, null));
+    serviceComponentRequests.add(new ServiceComponentRequest("c1", "HDFS", 
"HDFS_CLIENT", null, null));
+    amc.createComponents(serviceComponentRequests);
+    
+    //Create ServiceComponentHosts
+    componentHostRequests = new HashSet<ServiceComponentHostRequest>();
+    componentHostRequests.add(new ServiceComponentHostRequest("c1", null, 
"DATANODE", "host1", null, null));
+    componentHostRequests.add(new ServiceComponentHostRequest("c1", null, 
"NAMENODE", "host1", null, null));
+    componentHostRequests.add(new ServiceComponentHostRequest("c1", null, 
"SECONDARY_NAMENODE", "host1", null, null));
+    componentHostRequests.add(new ServiceComponentHostRequest("c1", null, 
"DATANODE", "host2", null, null));
+    componentHostRequests.add(new ServiceComponentHostRequest("c1", null, 
"DATANODE", "host3", null, null));
+    amc.createHostComponents(componentHostRequests);    
+
+    
+    namenodes = 
cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
+    assertEquals(1, namenodes.size());
+    Map<String, ServiceComponentHost> datanodes = 
cluster.getService("HDFS").getServiceComponent("DATANODE").getServiceComponentHosts();
+    assertEquals(3, datanodes.size());
+    Map<String, ServiceComponentHost> namenodes2 = 
cluster.getService("HDFS").getServiceComponent("SECONDARY_NAMENODE").getServiceComponentHosts();
+    assertEquals(1, namenodes2.size());    
   }
 
   private void testRunSmokeTestFlag(Map<String, String> mapRequestProps,

Reply via email to