Clusters fsm = clusters;
Cluster cluster = getDummyCluster();
Host hostObject = clusters.getHost(DummyHostname1);
clusters.mapHostToCluster(hostObject.getHostName(), cluster.getClusterName());
Service hdfs = cluster.addService(HDFS);
hdfs.persist();
hdfs.addServiceComponent(DATANODE).persist();
hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
hdfs.addServiceComponent(NAMENODE).persist();
hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1).persist();
hdfs.getServiceComponent(NAMENODE).getServiceComponentHost(DummyHostname1).setState(State.STARTED);
hdfs.getServiceComponent(DATANODE).getServiceComponentHost(DummyHostname1).setState(State.STARTED);
ActionQueue aq = new ActionQueue();
HeartBeatHandler handler = new HeartBeatHandler(fsm, aq, am, injector);
Register reg = new Register();
HostInfo hi = new HostInfo();
hi.setHostName(DummyHostname1);
hi.setOS(DummyOs);
hi.setOSRelease(DummyOSRelease);
reg.setHostname(DummyHostname1);
reg.setHardwareProfile(hi);
reg.setAgentVersion(metaInfo.getServerVersion());
handler.handleRegistration(reg);
hostObject.setState(HostState.UNHEALTHY);
aq.enqueue(DummyHostname1, new StatusCommand());
//All components are up
HeartBeat hb1 = new HeartBeat();
hb1.setResponseId(0);
hb1.setNodeStatus(new HostStatus(Status.HEALTHY, DummyHostStatus));
hb1.setHostname(DummyHostname1);
List<ComponentStatus> componentStatus = new ArrayList<ComponentStatus>();
ComponentStatus dataNodeStatus = new ComponentStatus();
dataNodeStatus.setClusterName(cluster.getClusterName());
dataNodeStatus.setServiceName(HDFS);
dataNodeStatus.setComponentName(DATANODE);
dataNodeStatus.setStatus("STARTED");
componentStatus.add(dataNodeStatus);
ComponentStatus nameNodeStatus = new ComponentStatus();
nameNodeStatus.setClusterName(cluster.getClusterName());
nameNodeStatus.setServiceName(HDFS);
nameNodeStatus.setComponentName(NAMENODE);
nameNodeStatus.setStatus("STARTED");
componentStatus.add(nameNodeStatus);
hb1.setComponentStatus(componentStatus);
handler.handleHeartBeat(hb1);
assertEquals(HostHealthStatus.HealthStatus.HEALTHY.name(), hostObject.getStatus());
//Some slaves are down, masters are up
HeartBeat hb2 = new HeartBeat();
hb2.setResponseId(1);
hb2.setNodeStatus(new HostStatus(Status.HEALTHY, DummyHostStatus));
hb2.setHostname(DummyHostname1);
componentStatus = new ArrayList<ComponentStatus>();
dataNodeStatus = new ComponentStatus();
dataNodeStatus.setClusterName(cluster.getClusterName());
dataNodeStatus.setServiceName(HDFS);
dataNodeStatus.setComponentName(DATANODE);
dataNodeStatus.setStatus("INSTALLED");
componentStatus.add(dataNodeStatus);
nameNodeStatus = new ComponentStatus();
nameNodeStatus.setClusterName(cluster.getClusterName());
nameNodeStatus.setServiceName(HDFS);
nameNodeStatus.setComponentName(NAMENODE);
nameNodeStatus.setStatus("STARTED");
componentStatus.add(nameNodeStatus);
hb2.setComponentStatus(componentStatus);
handler.handleHeartBeat(hb2);
assertEquals(HostHealthStatus.HealthStatus.ALERT.name(), hostObject.getStatus());
// mark the installed DN as maintenance
hdfs.getServiceComponent(DATANODE).getServiceComponentHost(
DummyHostname1).setMaintenanceState(MaintenanceState.ON);
HeartBeat hb2a = new HeartBeat();
hb2a.setResponseId(2);
hb2a.setNodeStatus(new HostStatus(Status.HEALTHY, DummyHostStatus));
hb2a.setHostname(DummyHostname1);
componentStatus = new ArrayList<ComponentStatus>();
dataNodeStatus = new ComponentStatus();
dataNodeStatus.setClusterName(cluster.getClusterName());
dataNodeStatus.setServiceName(HDFS);
dataNodeStatus.setComponentName(DATANODE);
dataNodeStatus.setStatus("INSTALLED");
componentStatus.add(dataNodeStatus);
nameNodeStatus = new ComponentStatus();
nameNodeStatus.setClusterName(cluster.getClusterName());
nameNodeStatus.setServiceName(HDFS);
nameNodeStatus.setComponentName(NAMENODE);
nameNodeStatus.setStatus("STARTED");
componentStatus.add(nameNodeStatus);
hb2a.setComponentStatus(componentStatus);
handler.handleHeartBeat(hb2a);
assertEquals(HostHealthStatus.HealthStatus.HEALTHY.name(), hostObject.getStatus());
hdfs.getServiceComponent(DATANODE).getServiceComponentHost(
DummyHostname1).setMaintenanceState(MaintenanceState.OFF);
//Some masters are down
HeartBeat hb3 = new HeartBeat();
hb3.setResponseId(3);
hb3.setNodeStatus(new HostStatus(Status.HEALTHY, DummyHostStatus));
hb3.setHostname(DummyHostname1);
componentStatus = new ArrayList<ComponentStatus>();
dataNodeStatus = new ComponentStatus();
dataNodeStatus.setClusterName(cluster.getClusterName());
dataNodeStatus.setServiceName(HDFS);
dataNodeStatus.setComponentName(DATANODE);
dataNodeStatus.setStatus("INSTALLED");
componentStatus.add(dataNodeStatus);
nameNodeStatus = new ComponentStatus();
nameNodeStatus.setClusterName(cluster.getClusterName());
nameNodeStatus.setServiceName(HDFS);
nameNodeStatus.setComponentName(NAMENODE);
nameNodeStatus.setStatus("INSTALLED");
componentStatus.add(nameNodeStatus);
hb3.setComponentStatus(componentStatus);
handler.handleHeartBeat(hb3);
assertEquals(HostHealthStatus.HealthStatus.UNHEALTHY.name(), hostObject.getStatus());
//All are up
hb1.setResponseId(4);
handler.handleHeartBeat(hb1);
assertEquals(HostHealthStatus.HealthStatus.HEALTHY.name(), hostObject.getStatus());
//Only one component reported status
hdfs.getServiceComponent(NAMENODE).getServiceComponentHost(DummyHostname1).setState(State.INSTALLED);
HeartBeat hb4 = new HeartBeat();
hb4.setResponseId(5);
hb4.setNodeStatus(new HostStatus(Status.HEALTHY, DummyHostStatus));
hb4.setHostname(DummyHostname1);
componentStatus = new ArrayList<ComponentStatus>();