Map<String, String> requestProperties = new HashMap<String, String>();
requestProperties.put("context", "Called from a test");
Cluster cluster = clusters.getCluster(clusterName);
Service service = cluster.getService(serviceName);
Map<String, Host> hosts = clusters.getHostsForCluster(clusterName);
// test updating a service
ServiceRequest sr = new ServiceRequest(clusterName, serviceName, null);
sr.setMaintenanceState(MaintenanceState.ON.name());
ServiceResourceProviderTest.updateServices(controller, Collections.singleton(sr),
requestProperties, false, false);
Assert.assertEquals(MaintenanceState.ON, service.getMaintenanceState());
// check the host components implied state vs desired state
for (ServiceComponent sc : service.getServiceComponents().values()) {
for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
Assert.assertEquals(MaintenanceState.IMPLIED_FROM_SERVICE,
controller.getEffectiveMaintenanceState(sch));
Assert.assertEquals(MaintenanceState.OFF, sch.getMaintenanceState());
}
}
// reset
sr.setMaintenanceState(MaintenanceState.OFF.name());
ServiceResourceProviderTest.updateServices(controller, Collections.singleton(sr),
requestProperties, false, false);
Assert.assertEquals(MaintenanceState.OFF, service.getMaintenanceState());
// check the host components implied state vs desired state
for (ServiceComponent sc : service.getServiceComponents().values()) {
for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
Assert.assertEquals(MaintenanceState.OFF,
controller.getEffectiveMaintenanceState(sch));
Assert.assertEquals(MaintenanceState.OFF, sch.getMaintenanceState());
}
}
// passivate a host
HostRequest hr = new HostRequest(host1, clusterName, requestProperties);
hr.setMaintenanceState(MaintenanceState.ON.name());
HostResourceProviderTest.updateHosts(controller, Collections.singleton(hr),
new HashMap<String, String>());
Host host = hosts.get(host1);
Assert.assertEquals(MaintenanceState.ON, host.getMaintenanceState(cluster.getClusterId()));
// check the host components implied state vs desired state, only for affected hosts
for (ServiceComponent sc : service.getServiceComponents().values()) {
for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
MaintenanceState implied = controller.getEffectiveMaintenanceState(sch);
if (sch.getHostName().equals(host1)) {
Assert.assertEquals(MaintenanceState.IMPLIED_FROM_HOST, implied);
} else {
Assert.assertEquals(MaintenanceState.OFF, implied);
}
Assert.assertEquals(MaintenanceState.OFF, sch.getMaintenanceState());
}
}
// reset
hr.setMaintenanceState(MaintenanceState.OFF.name());
HostResourceProviderTest.updateHosts(controller, Collections.singleton(hr),
new HashMap<String, String>());
host = hosts.get(host1);
Assert.assertEquals(MaintenanceState.OFF, host.getMaintenanceState(cluster.getClusterId()));
// check the host components active state vs desired state
for (ServiceComponent sc : service.getServiceComponents().values()) {
for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
Assert.assertEquals(MaintenanceState.OFF,
controller.getEffectiveMaintenanceState(sch));
Assert.assertEquals(MaintenanceState.OFF, sch.getMaintenanceState());
}
}
// passivate several hosts
HostRequest hr1 = new HostRequest(host1, clusterName, requestProperties);
hr1.setMaintenanceState(MaintenanceState.ON.name());
HostRequest hr2 = new HostRequest(host2, clusterName, requestProperties);
hr2.setMaintenanceState(MaintenanceState.ON.name());
Set<HostRequest> set = new HashSet<HostRequest>();
set.add(hr1);
set.add(hr2);
HostResourceProviderTest.updateHosts(controller, set, new HashMap<String, String>());
host = hosts.get(host1);
Assert.assertEquals(MaintenanceState.ON, host.getMaintenanceState(cluster.getClusterId()));
host = hosts.get(host2);
Assert.assertEquals(MaintenanceState.ON, host.getMaintenanceState(cluster.getClusterId()));
// reset
hr1 = new HostRequest(host1, clusterName, requestProperties);
hr1.setMaintenanceState(MaintenanceState.OFF.name());
hr2 = new HostRequest(host2, clusterName, requestProperties);
hr2.setMaintenanceState(MaintenanceState.OFF.name());
set = new HashSet<HostRequest>();
set.add(hr1);
set.add(hr2);
HostResourceProviderTest.updateHosts(controller, set, new HashMap<String, String>());
host = hosts.get(host1);
Assert.assertEquals(MaintenanceState.OFF, host.getMaintenanceState(cluster.getClusterId()));
host = hosts.get(host2);
Assert.assertEquals(MaintenanceState.OFF, host.getMaintenanceState(cluster.getClusterId()));
// only do one SCH
ServiceComponentHost targetSch = service.getServiceComponent(
componentName2).getServiceComponentHosts().get(host2);
Assert.assertNotNull(targetSch);
targetSch.setMaintenanceState(MaintenanceState.ON);
// check the host components active state vs desired state
Assert.assertEquals(MaintenanceState.ON, controller.getEffectiveMaintenanceState(targetSch));
// update the service
service.setMaintenanceState(MaintenanceState.ON);
Assert.assertEquals(MaintenanceState.ON, controller.getEffectiveMaintenanceState(targetSch));
// make SCH active
targetSch.setMaintenanceState(MaintenanceState.OFF);
Assert.assertEquals(MaintenanceState.IMPLIED_FROM_SERVICE,
controller.getEffectiveMaintenanceState(targetSch));
// update the service
service.setMaintenanceState(MaintenanceState.OFF);
Assert.assertEquals(MaintenanceState.OFF, controller.getEffectiveMaintenanceState(targetSch));
host = hosts.get(host2);
// update host
host.setMaintenanceState(cluster.getClusterId(), MaintenanceState.ON);
Assert.assertEquals(MaintenanceState.IMPLIED_FROM_HOST,
controller.getEffectiveMaintenanceState(targetSch));
targetSch.setMaintenanceState(MaintenanceState.ON);
Assert.assertEquals(MaintenanceState.ON, controller.getEffectiveMaintenanceState(targetSch));
// check the host components active state vs desired state
for (ServiceComponent sc : service.getServiceComponents().values()) {
for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
Assert.assertEquals(State.INIT, sch.getState());
}
}
long id1 = installService(clusterName, serviceName, false, false);
long id2 = installService(clusterName, nagiosService, false, false);
List<HostRoleCommand> hdfsCmds = actionDB.getRequestTasks(id1);
List<HostRoleCommand> nagiosCmds = actionDB.getRequestTasks(id2);
Assert.assertNotNull(hdfsCmds);
Assert.assertNotNull(nagiosCmds);
HostRoleCommand datanodeCmd = null;
HostRoleCommand nagiosCmd = null;
for (HostRoleCommand cmd : hdfsCmds) {
if (cmd.getRole().equals(Role.DATANODE)) {
datanodeCmd = cmd;
}
}
for (HostRoleCommand cmd : nagiosCmds) {
if (cmd.getRole().equals(Role.NAGIOS_SERVER)) {
nagiosCmd = cmd;
}
}
Assert.assertNotNull(datanodeCmd);
Assert.assertNotNull(nagiosCmd);
Assert.assertNotNull(nagiosCmd.getExecutionCommandWrapper()
.getExecutionCommand().getPassiveInfo());
Assert.assertEquals(Integer.valueOf(1),
Integer.valueOf(nagiosCmd.getExecutionCommandWrapper()
.getExecutionCommand().getPassiveInfo().size()));
// verify passive sch was skipped
for (ServiceComponent sc : service.getServiceComponents().values()) {
if (!sc.getName().equals(componentName2))
continue;
for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
Assert.assertEquals(sch == targetSch ? State.INIT : State.INSTALLED, sch.getState());