You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2013/05/07 20:08:33 UTC

svn commit: r1479996 - in /incubator/ambari/trunk: CHANGES.txt ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java

Author: swagle
Date: Tue May  7 18:08:33 2013
New Revision: 1479996

URL: http://svn.apache.org/r1479996
Log:
AMBARI-2086. Agent on host with clients and DATANODE only seems to schedule STATUS commands for several other services. (swagle)

Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1479996&r1=1479995&r2=1479996&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Tue May  7 18:08:33 2013
@@ -830,6 +830,9 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
+ AMBARI-2086. Agent on host with clients and DATANODE only seems to schedule 
+ STATUS commands for several other services. (swagle)
+
  AMBARI-2088. Cluster installation times out at server side too fast. (swagle)
 
  AMBARI-2083. Upgrade fails on Sles. (smohanty)

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java?rev=1479996&r1=1479995&r2=1479996&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java Tue May  7 18:08:33 2013
@@ -178,59 +178,62 @@ public class HeartbeatMonitor implements
     List<StatusCommand> cmds = new ArrayList<StatusCommand>();
     
     for (Cluster cl : fsm.getClustersForHost(hostname)) {
-      
       for (ServiceComponentHost sch : cl.getServiceComponentHosts(hostname)) {
         String serviceName = sch.getServiceName();
-        if (LOG.isDebugEnabled()) {
-          LOG.debug("Live status will include status of service " + serviceName + " of cluster " + cl.getClusterName());
-        }
-        
-        Map<String, Map<String, String>> configurations = new TreeMap<String, Map<String, String>>();
-        
-        // get the cluster config for type 'global'
-        // apply service overrides, if the tag is not the same
-        // apply host overrides, if any
-        
-        Config clusterConfig = cl.getDesiredConfigByType("global");
-        if (null != clusterConfig) {
-          // cluster config for 'global'
-          Map<String,String> props = new HashMap<String, String>(clusterConfig.getProperties());
-
-          // apply service overrides, only if the tag is not the same (for when service configs are overrides)
-          Service service = cl.getService(sch.getServiceName());
-          Config svcConfig = service.getDesiredConfigs().get("global");
-          if (null != svcConfig && !svcConfig.getVersionTag().equals(clusterConfig.getVersionTag())) {
-            props.putAll(svcConfig.getProperties());
+        Service service = cl.getService(sch.getServiceName());
+        ServiceComponent sc = service.getServiceComponent(sch
+          .getServiceComponentName());
+        // Do not send status commands for client components
+        if (!sc.isClientComponent()) {
+          if (LOG.isDebugEnabled()) {
+            LOG.debug("Live status will include status of service " + serviceName + " of cluster " + cl.getClusterName());
           }
-          
+
+          Map<String, Map<String, String>> configurations = new TreeMap<String, Map<String, String>>();
+
+          // get the cluster config for type 'global'
+          // apply service overrides, if the tag is not the same
           // apply host overrides, if any
-          Host host = fsm.getHost(hostname);
-          DesiredConfig dc = host.getDesiredConfigs(cl.getClusterId()).get("global");
-          if (null != dc) {
-            Config hostConfig = cl.getConfig("global", dc.getVersion());
-            if (null != hostConfig) {
-              props.putAll(hostConfig.getProperties());
+
+          Config clusterConfig = cl.getDesiredConfigByType("global");
+          if (null != clusterConfig) {
+            // cluster config for 'global'
+            Map<String, String> props = new HashMap<String, String>(clusterConfig.getProperties());
+
+            // apply service overrides, only if the tag is not the same (for when service configs are overrides)
+            Config svcConfig = service.getDesiredConfigs().get("global");
+            if (null != svcConfig && !svcConfig.getVersionTag().equals(clusterConfig.getVersionTag())) {
+              props.putAll(svcConfig.getProperties());
+            }
+
+            // apply host overrides, if any
+            Host host = fsm.getHost(hostname);
+            DesiredConfig dc = host.getDesiredConfigs(cl.getClusterId()).get("global");
+            if (null != dc) {
+              Config hostConfig = cl.getConfig("global", dc.getVersion());
+              if (null != hostConfig) {
+                props.putAll(hostConfig.getProperties());
+              }
             }
+
+            configurations.put("global", props);
           }
-          
-          configurations.put("global", props);
-        }
-        
-        // HACK - if any service exists with global tag, and we have none, use
-        // that instead
-        if (configurations.isEmpty()) {
-          Service service = cl.getService(sch.getServiceName());
-          Config config = service.getDesiredConfigs().get("global");
-          if (null != config)
-            configurations.put("global", new HashMap<String,String>(config.getProperties()));
+
+          // HACK - if any service exists with global tag, and we have none, use
+          // that instead
+          if (configurations.isEmpty()) {
+            Config config = service.getDesiredConfigs().get("global");
+            if (null != config)
+              configurations.put("global", new HashMap<String, String>(config.getProperties()));
+          }
+
+          StatusCommand statusCmd = new StatusCommand();
+          statusCmd.setClusterName(cl.getClusterName());
+          statusCmd.setServiceName(serviceName);
+          statusCmd.setComponentName(sch.getServiceComponentName());
+          statusCmd.setConfigurations(configurations);
+          cmds.add(statusCmd);
         }
-        
-        StatusCommand statusCmd = new StatusCommand();
-        statusCmd.setClusterName(cl.getClusterName());
-        statusCmd.setServiceName(serviceName);
-        statusCmd.setComponentName(sch.getServiceComponentName());
-        statusCmd.setConfigurations(configurations);
-        cmds.add(statusCmd);
       }
     }
     return cmds;

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java?rev=1479996&r1=1479995&r2=1479996&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java Tue May  7 18:08:33 2013
@@ -18,6 +18,7 @@
 package org.apache.ambari.server.agent;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.Matchers.eq;
@@ -166,6 +167,99 @@ public class TestHeartbeatMonitor {
     assertTrue("HeartbeatMonitor should not generate StatusCommands for host2 because it has no services", cmds.isEmpty());
   }
 
+  @Test
+  public void testNoStatusCommandForClientComponents() throws Exception {
+    Clusters clusters = injector.getInstance(Clusters.class);
+    clusters.addHost(hostname1);
+    clusters.getHost(hostname1).setOsType("centos6");
+    clusters.getHost(hostname1).persist();
+    clusters.addHost(hostname2);
+    clusters.getHost(hostname2).setOsType("centos6");
+    clusters.getHost(hostname2).persist();
+    clusters.addCluster(clusterName);
+    Cluster cluster = clusters.getCluster(clusterName);
+    cluster.setDesiredStackVersion(new StackId("HDP-0.1"));
+    Set<String> hostNames = new HashSet<String>() {{
+      add(hostname1);
+      add(hostname2);
+    }};
+
+    ConfigFactory configFactory = injector.getInstance(ConfigFactory.class);
+    Config config = configFactory.createNew(cluster, "global",
+      new HashMap<String, String>() {{
+        put("a", "b");
+      }});
+    config.setVersionTag("version1");
+    cluster.addConfig(config);
+    cluster.addDesiredConfig(config);
+
+
+    clusters.mapHostsToCluster(hostNames, clusterName);
+    Service hdfs = cluster.addService(serviceName);
+    hdfs.persist();
+    hdfs.addServiceComponent(Role.DATANODE.name()).persist();
+    hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost
+      (hostname1).persist();
+    hdfs.addServiceComponent(Role.NAMENODE.name()).persist();
+    hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost
+      (hostname1).persist();
+    hdfs.addServiceComponent(Role.SECONDARY_NAMENODE.name()).persist();
+    hdfs.getServiceComponent(Role.SECONDARY_NAMENODE.name()).
+      addServiceComponentHost(hostname1).persist();
+    hdfs.addServiceComponent(Role.HDFS_CLIENT.name()).persist();
+    hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost
+      (hostname1).persist();
+    hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost
+      (hostname2).persist();
+
+    ActionQueue aq = new ActionQueue();
+    ActionManager am = mock(ActionManager.class);
+    HeartbeatMonitor hm = new HeartbeatMonitor(clusters, aq, am,
+      heartbeatMonitorWakeupIntervalMS);
+    HeartBeatHandler handler = new HeartBeatHandler(clusters, aq, am, injector);
+    Register reg = new Register();
+    reg.setHostname(hostname1);
+    reg.setResponseId(12);
+    reg.setTimestamp(System.currentTimeMillis() - 300);
+    reg.setAgentVersion(ambariMetaInfo.getServerVersion());
+    HostInfo hi = new HostInfo();
+    hi.setOS("Centos5");
+    reg.setHardwareProfile(hi);
+    handler.handleRegistration(reg);
+
+    HeartBeat hb = new HeartBeat();
+    hb.setHostname(hostname1);
+    hb.setNodeStatus(new HostStatus(HostStatus.Status.HEALTHY, "cool"));
+    hb.setTimestamp(System.currentTimeMillis());
+    hb.setResponseId(12);
+    handler.handleHeartBeat(hb);
+
+    List<StatusCommand> cmds = hm.generateStatusCommands(hostname1);
+    assertTrue("HeartbeatMonitor should generate StatusCommands for host1",
+      cmds.size() == 3);
+    assertEquals("HDFS", cmds.get(0).getServiceName());
+    boolean containsDATANODEStatus = false;
+    boolean containsNAMENODEStatus = false;
+    boolean containsSECONDARY_NAMENODEStatus = false;
+    boolean containsHDFS_CLIENTStatus = false;
+    for (StatusCommand cmd : cmds) {
+      containsDATANODEStatus |= cmd.getComponentName().equals("DATANODE");
+      containsNAMENODEStatus |= cmd.getComponentName().equals("NAMENODE");
+      containsSECONDARY_NAMENODEStatus |= cmd.getComponentName().
+        equals("SECONDARY_NAMENODE");
+      containsHDFS_CLIENTStatus |= cmd.getComponentName().equals
+        ("HDFS_CLIENT");
+      assertTrue(cmd.getConfigurations().size() > 0);
+    }
+    assertTrue(containsDATANODEStatus);
+    assertTrue(containsNAMENODEStatus);
+    assertTrue(containsSECONDARY_NAMENODEStatus);
+    assertFalse(containsHDFS_CLIENTStatus);
+
+    cmds = hm.generateStatusCommands(hostname2);
+    assertTrue("HeartbeatMonitor should not generate StatusCommands for host2" +
+      " because it has only client components", cmds.isEmpty());
+  }
 
   @Test
   public void testHeartbeatStateCommandsEnqueueing() throws AmbariException, InterruptedException,