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));