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"));
Set<String> hostNames = new HashSet<String>(){{
add(hostname1);
}};
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);
ActionQueue aq = new ActionQueue();
ActionManager am = mock(ActionManager.class);
HeartbeatMonitor hm = new HeartbeatMonitor(clusters, aq, am, 10, injector);
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);
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"));
} else if (sch.getServiceComponentName().equals("SECONDARY_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()));
// disabled
sch.handleEvent(new ServiceComponentHostDisableEvent(sch.getServiceComponentName(),
sch.getHostName(), System.currentTimeMillis()));
}
}
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);
}
hm.shutdown();
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 (sch.getServiceComponentName().equals("NAMENODE"))
assertEquals(sch.getServiceComponentName(), State.UNKNOWN, sch.getState());
else if (sch.getServiceComponentName().equals("DATANODE"))
assertEquals(sch.getServiceComponentName(), State.INSTALLING, sch.getState());