You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2013/04/25 23:27:12 UTC

svn commit: r1475967 - 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: ncole
Date: Thu Apr 25 21:27:12 2013
New Revision: 1475967

URL: http://svn.apache.org/r1475967
Log:
AMBARI-2025. Fix when UNKNOWN state is applied to host-components

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=1475967&r1=1475966&r2=1475967&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Thu Apr 25 21:27:12 2013
@@ -1293,6 +1293,8 @@ Trunk (unreleased changes):
  AMBARI-1657. User directories on HDFS do not get created with custom names 
  provided from Ambari UI. (swagle)
 
+ AMBARI-2025. Fix to restrict how UNKNOWN is assigned to a host-component. (ncole)
+
  AMBARI-2013. Fix to delete cluster with components in unknown state. (ncole)
 
  AMBARI-1977. Honor service configs when there are no matching cluster configs (ncole)

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=1475967&r1=1475966&r2=1475967&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 Thu Apr 25 21:27:12 2013
@@ -127,7 +127,11 @@ public class HeartbeatMonitor implements
           for (ServiceComponentHost sch : cluster.getServiceComponentHosts(hostObj.getHostName())) {
             Service s = cluster.getService(sch.getServiceName());
             ServiceComponent sc = s.getServiceComponent(sch.getServiceComponentName());
-            if (!sc.isClientComponent()) {
+            if (!sc.isClientComponent() &&
+                !sch.getState().equals(State.INIT) &&
+                !sch.getState().equals(State.INSTALLING) &&
+                !sch.getState().equals(State.INSTALL_FAILED) &&
+                !sch.getState().equals(State.UNINSTALLED)) {
               sch.setState(State.UNKNOWN);
             }
           }

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=1475967&r1=1475966&r2=1475967&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 Thu Apr 25 21:27:12 2013
@@ -25,7 +25,6 @@ import static org.mockito.Mockito.atLeas
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
-import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -38,7 +37,6 @@ import org.apache.ambari.server.orm.Guic
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
-import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
@@ -46,6 +44,9 @@ import org.apache.ambari.server.state.Se
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostInstallEvent;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpSucceededEvent;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartedEvent;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -257,11 +258,11 @@ public class TestHeartbeatMonitor {
   @Test
   public void testHeartbeatLossWithComponent() throws AmbariException, InterruptedException,
           InvalidStateTransitionException {
-    
     Clusters clusters = injector.getInstance(Clusters.class);
     clusters.addHost(hostname1);
     clusters.getHost(hostname1).setOsType("centos5");
     clusters.getHost(hostname1).persist();
+    
     clusters.addCluster(clusterName);
     Cluster cluster = clusters.getCluster(clusterName);
     cluster.setDesiredStackVersion(new StackId("HDP-0.1"));
@@ -293,84 +294,61 @@ public class TestHeartbeatMonitor {
     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);
     
+    cluster = clusters.getClustersForHost(hostname1).iterator().next();
+    for (ServiceComponentHost sch : cluster.getServiceComponentHosts(hostname1)) {
+      if (sch.getServiceComponentName().equals("NAMENODE")) {
+        // installing
+        sch.handleEvent(new ServiceComponentHostInstallEvent(
+            sch.getServiceComponentName(), sch.getHostName(), System.currentTimeMillis(), "HDP-0.1"));
+        
+        // installed
+        sch.handleEvent(new ServiceComponentHostOpSucceededEvent(sch.getServiceComponentName(),
+            sch.getHostName(), System.currentTimeMillis()));
+        
+        // started
+        sch.handleEvent(new ServiceComponentHostStartedEvent(sch.getServiceComponentName(),
+            sch.getHostName(), System.currentTimeMillis()));
+      }
+      else if (sch.getServiceComponentName().equals("DATANODE")) {
+        // installing
+        sch.handleEvent(new ServiceComponentHostInstallEvent(
+            sch.getServiceComponentName(), sch.getHostName(), System.currentTimeMillis(), "HDP-0.1"));
+      }
+    }
+    
     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);
+    
     hm.start();
     aq.enqueue(hostname1, new ExecutionCommand());
     //Heartbeat will expire and action queue will be flushed
     while (aq.size(hostname1) != 0) {
       Thread.sleep(1);
     }
-
-    cluster = clusters.getClustersForHost(hostname1).iterator().next();
-    for (ServiceComponentHost sch : cluster.getServiceComponentHosts(hostname1)) {
-      Service s = cluster.getService(sch.getServiceName());
-      ServiceComponent sc = s.getServiceComponent(sch.getServiceComponentName());
-      if (!sc.isClientComponent())
-        assertEquals(State.UNKNOWN, sch.getState());
-      else
-        assertEquals(State.INIT, sch.getState());
-    }
-
-    // don't keep marking the host as down
     hm.shutdown();
     
-    // try to flip statuses back
-    hb = new HeartBeat();
-    hb.setHostname(hostname1);
-    hb.setNodeStatus(new HostStatus(HostStatus.Status.HEALTHY, "cool"));
-    hb.setTimestamp(System.currentTimeMillis());
-    hb.setResponseId(0);
-    
-    List<ComponentStatus> statuses = new ArrayList<ComponentStatus>();
-    ComponentStatus cs = new ComponentStatus();
-    cs.setClusterName(clusterName);
-    cs.setServiceName(Service.Type.HDFS.name());
-    cs.setStatus(State.STARTED.name());
-    cs.setComponentName(Role.DATANODE.name());
-    statuses.add(cs);
-
-    cs = new ComponentStatus();
-    cs.setClusterName(clusterName);
-    cs.setServiceName(Service.Type.HDFS.name());
-    cs.setStatus(State.STARTED.name());
-    cs.setComponentName(Role.NAMENODE.name());
-    statuses.add(cs);
-    
-    cs = new ComponentStatus();
-    cs.setClusterName(clusterName);
-    cs.setServiceName(Service.Type.HDFS.name());
-    cs.setStatus(State.STARTED.name());
-    cs.setComponentName(Role.SECONDARY_NAMENODE.name());
-    statuses.add(cs);
-    
-    hb.setComponentStatus(statuses);
-    
-    Host host = clusters.getHost(hostname1);
-    host.setState(HostState.HEALTHY);
-    hb.setTimestamp(System.currentTimeMillis() + Integer.MAX_VALUE);
-    host.setLastHeartbeatTime(System.currentTimeMillis() + Integer.MAX_VALUE);
-    handler.handleHeartBeat(hb);
-    
+
     cluster = clusters.getClustersForHost(hostname1).iterator().next();
     for (ServiceComponentHost sch : cluster.getServiceComponentHosts(hostname1)) {
       Service s = cluster.getService(sch.getServiceName());
       ServiceComponent sc = s.getServiceComponent(sch.getServiceComponentName());
-      if (!sc.isClientComponent())
-        assertEquals(State.STARTED, sch.getState());
-      else
-        assertEquals(State.INIT, sch.getState());
+      if (sch.getServiceComponentName().equals("NAMENODE"))
+        assertEquals(sch.getServiceComponentName(), State.UNKNOWN, sch.getState());
+      else if (sch.getServiceComponentName().equals("DATANODE"))
+        assertEquals(sch.getServiceComponentName(), State.INSTALLING, sch.getState());
+      else if (sc.isClientComponent())
+        assertEquals(sch.getServiceComponentName(), State.INIT, sch.getState());
     }
+
     
     
   }