Cluster cluster = clusters.getCluster("c1");
Map<String, ServiceComponentHost> namenodes = cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
org.junit.Assert.assertEquals(1, namenodes.size());
ServiceComponentHost componentHost = namenodes.get("host1");
Map<String, ServiceComponentHost> hostComponents = cluster.getService("HDFS").getServiceComponent("DATANODE").getServiceComponentHosts();
for (Map.Entry<String, ServiceComponentHost> entry : hostComponents.entrySet()) {
ServiceComponentHost cHost = entry.getValue();
cHost.handleEvent(new ServiceComponentHostInstallEvent(cHost.getServiceComponentName(), cHost.getHostName(), System.currentTimeMillis(), "HDP-1.2.0"));
cHost.handleEvent(new ServiceComponentHostOpSucceededEvent(cHost.getServiceComponentName(), cHost.getHostName(), System.currentTimeMillis()));
}
hostComponents = cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
for (Map.Entry<String, ServiceComponentHost> entry : hostComponents.entrySet()) {
ServiceComponentHost cHost = entry.getValue();
cHost.handleEvent(new ServiceComponentHostInstallEvent(cHost.getServiceComponentName(), cHost.getHostName(), System.currentTimeMillis(), "HDP-1.2.0"));
cHost.handleEvent(new ServiceComponentHostOpSucceededEvent(cHost.getServiceComponentName(), cHost.getHostName(), System.currentTimeMillis()));
}
hostComponents = cluster.getService("HDFS").getServiceComponent("SECONDARY_NAMENODE").getServiceComponentHosts();
for (Map.Entry<String, ServiceComponentHost> entry : hostComponents.entrySet()) {
ServiceComponentHost cHost = entry.getValue();
cHost.handleEvent(new ServiceComponentHostInstallEvent(cHost.getServiceComponentName(), cHost.getHostName(), System.currentTimeMillis(), "HDP-1.2.0"));
cHost.handleEvent(new ServiceComponentHostOpSucceededEvent(cHost.getServiceComponentName(), cHost.getHostName(), System.currentTimeMillis()));
}
componentHostRequests.clear();
componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "NAMENODE", "host1", "DISABLED"));
amc.updateHostComponents(componentHostRequests, mapRequestProps, true);
Assert.assertEquals(State.DISABLED, componentHost.getState());
componentHostRequests.clear();
componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "NAMENODE", "host1", "INSTALLED"));
amc.updateHostComponents(componentHostRequests, mapRequestProps, true);
Assert.assertEquals(State.INSTALLED, componentHost.getState());
componentHostRequests.clear();
componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "NAMENODE", "host1", "DISABLED"));
amc.updateHostComponents(componentHostRequests, mapRequestProps, true);
Assert.assertEquals(State.DISABLED, componentHost.getState());
componentHostRequests.clear();
componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "NAMENODE", "host2", null));
amc.createHostComponents(componentHostRequests);
componentHostRequests.clear();
componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "NAMENODE", "host2", "INSTALLED"));
amc.updateHostComponents(componentHostRequests, mapRequestProps, true);
namenodes = cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
Assert.assertEquals(2, namenodes.size());
componentHost = namenodes.get("host2");
componentHost.handleEvent(new ServiceComponentHostInstallEvent(componentHost.getServiceComponentName(), componentHost.getHostName(), System.currentTimeMillis(), "HDP-1.2.0"));
componentHost.handleEvent(new ServiceComponentHostOpSucceededEvent(componentHost.getServiceComponentName(), componentHost.getHostName(), System.currentTimeMillis()));
serviceRequests.clear();
serviceRequests.add(new ServiceRequest("c1", "HDFS", "STARTED"));
RequestStatusResponse response = ServiceResourceProviderTest.updateServices(amc, serviceRequests,
mapRequestProps, true, false);
for (ShortTaskStatus shortTaskStatus : response.getTasks()) {
assertFalse("host1".equals(shortTaskStatus.getHostName()) && "NAMENODE".equals(shortTaskStatus.getRole()));
}
componentHostRequests.clear();
componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "NAMENODE", "host1", null));
amc.deleteHostComponents(componentHostRequests);
namenodes = cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
org.junit.Assert.assertEquals(1, namenodes.size());
// testing the behavior for runSmokeTest flag
// piggybacking on this test to avoid setting up the mock cluster
testRunSmokeTestFlag(mapRequestProps, amc, serviceRequests);
// should be able to add the host component back
componentHostRequests.clear();
componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "NAMENODE", "host1", null));
amc.createHostComponents(componentHostRequests);
namenodes = cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
assertEquals(2, namenodes.size());
// make INSTALLED again
componentHost = namenodes.get("host1");
componentHost.handleEvent(new ServiceComponentHostInstallEvent(componentHost.getServiceComponentName(), componentHost.getHostName(), System.currentTimeMillis(), "HDP-1.2.0"));
componentHost.handleEvent(new ServiceComponentHostOpSucceededEvent(componentHost.getServiceComponentName(), componentHost.getHostName(), System.currentTimeMillis()));
componentHostRequests.clear();
componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "NAMENODE", "host1", "INSTALLED"));
amc.updateHostComponents(componentHostRequests, mapRequestProps, true);
assertEquals(State.INSTALLED, namenodes.get("host1").getState());
// make unknown
ServiceComponentHost sch = null;
for (ServiceComponentHost tmp : cluster.getServiceComponentHosts("host2")) {
if (tmp.getServiceComponentName().equals("DATANODE")) {
tmp.setState(State.UNKNOWN);
sch = tmp;
}
}
assertNotNull(sch);
// make disabled
componentHostRequests.clear();
componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "DATANODE", "host2", "DISABLED"));
amc.updateHostComponents(componentHostRequests, mapRequestProps, false);
org.junit.Assert.assertEquals(State.DISABLED, sch.getState());
// ServiceComponentHost remains in disabled after service stop
assertEquals(sch.getServiceComponentName(),"DATANODE");
serviceRequests.clear();
serviceRequests.add(new ServiceRequest("c1", "HDFS", "INSTALLED"));
ServiceResourceProviderTest.updateServices(amc, serviceRequests,
mapRequestProps, true, false);
assertEquals(State.DISABLED, sch.getState());
// ServiceComponentHost remains in disabled after service start
serviceRequests.clear();
serviceRequests.add(new ServiceRequest("c1", "HDFS", "STARTED"));
ServiceResourceProviderTest.updateServices(amc, serviceRequests,
mapRequestProps, true, false);
assertEquals(State.DISABLED, sch.getState());
// confirm delete
componentHostRequests.clear();
componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "DATANODE", "host2", null));
amc.deleteHostComponents(componentHostRequests);