You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2013/02/01 08:38:03 UTC

svn commit: r1441324 - in /incubator/ambari/trunk: CHANGES.txt ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java

Author: mahadev
Date: Fri Feb  1 07:38:03 2013
New Revision: 1441324

URL: http://svn.apache.org/viewvc?rev=1441324&view=rev
Log:
AMBARI-1330. Cluster missing hosts after successful install and restart. (mahadev)

Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1441324&r1=1441323&r2=1441324&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Fri Feb  1 07:38:03 2013
@@ -379,6 +379,9 @@ Trunk (unreleased changes):
  AMBARI-1314. Hostname test is failing in some environments. (Nate Cole via
  mahadev) 
 
+ AMBARI-1330. Cluster missing hosts after successful install and restart.
+ (mahadev)
+
 AMBARI-1.2.0 branch:
 
  INCOMPATIBLE CHANGES

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java?rev=1441324&r1=1441323&r2=1441324&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java Fri Feb  1 07:38:03 2013
@@ -103,6 +103,8 @@ public class ClusterImpl implements Clus
   private ConfigFactory configFactory;
   @Inject
   private Gson gson;
+  
+  private volatile boolean svcHostsLoaded = false;
 
   @Inject
   public ClusterImpl(@Assisted ClusterEntity clusterEntity,
@@ -116,7 +118,6 @@ public class ClusterImpl implements Clus
         List<ServiceComponentHost>>();
     this.desiredStackVersion = gson.fromJson(
         clusterEntity.getDesiredStackVersion(), StackId.class);
-    loadServiceHostComponents();
     configs = new HashMap<String, Map<String, Config>>();
     if (!clusterEntity.getClusterConfigEntities().isEmpty()) {
       for (ClusterConfigEntity entity : clusterEntity.getClusterConfigEntities()) {
@@ -137,9 +138,10 @@ public class ClusterImpl implements Clus
    * Make sure we load all the service host components.
    * We need this for live status checks.
    */
-  public void loadServiceHostComponents() {
+  public synchronized void loadServiceHostComponents() {
     loadServices();
     LOG.info("Loading Service Host Components");
+    if (svcHostsLoaded) return;
     if (services != null) {
       for (Map.Entry<String, Service> serviceKV: services.entrySet()) {
         /* get all the service component hosts **/
@@ -177,6 +179,7 @@ public class ClusterImpl implements Clus
         }
       }
     }
+    svcHostsLoaded = true;
   }
 
   private void loadServices() {
@@ -197,6 +200,7 @@ public class ClusterImpl implements Clus
 
   public ServiceComponentHost getServiceComponentHost(String serviceName,
       String serviceComponentName, String hostname) throws AmbariException {
+    loadServiceHostComponents();
     if (!serviceComponentHosts.containsKey(serviceName)
         || !serviceComponentHosts.get(serviceName)
             .containsKey(serviceComponentName)
@@ -234,6 +238,7 @@ public class ClusterImpl implements Clus
 
   public synchronized void addServiceComponentHost(
       ServiceComponentHost svcCompHost) throws AmbariException {
+    loadServiceHostComponents();
     if (LOG.isDebugEnabled()) {
       LOG.debug("Trying to add ServiceComponentHost to ClusterHostMap cache"
           + ", serviceName=" + svcCompHost.getServiceName()
@@ -305,6 +310,7 @@ public class ClusterImpl implements Clus
   @Override
   public synchronized List<ServiceComponentHost> getServiceComponentHosts(
       String hostname) {
+    loadServiceHostComponents();
     if (serviceComponentHostsByHost.containsKey(hostname)) {
       return Collections.unmodifiableList(
           serviceComponentHostsByHost.get(hostname));

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java?rev=1441324&r1=1441323&r2=1441324&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java Fri Feb  1 07:38:03 2013
@@ -211,14 +211,20 @@ public class ClustersTest {
 
     clusters.mapHostToCluster(h1, c1);
     clusters.mapHostToCluster(h2, c1);
-
+    
     try {
       clusters.mapHostToCluster(h1, c1);
       fail("Expected exception for duplicate");
     } catch (DuplicateResourceException e) {
       // expected
     }
-
+    
+    /* make sure 2 host mapping to same cluster are the same cluster objects */
+    
+    Cluster c3 = (Cluster) clusters.getClustersForHost(h1).toArray()[0];
+    Cluster c4 = (Cluster) clusters.getClustersForHost(h2).toArray()[0];
+    
+    Assert.assertEquals(c3, c4);
     Set<String> hostnames = new HashSet<String>();
     hostnames.add(h1);
     hostnames.add(h2);
@@ -227,7 +233,7 @@ public class ClustersTest {
 
     c = clusters.getClustersForHost(h1);
     Assert.assertEquals(2, c.size());
-
+    
     c = clusters.getClustersForHost(h2);
     Assert.assertEquals(2, c.size());