set1.add(r5);
controller.createHostComponents(set1);
Cluster c1 = clusters.getCluster(clusterName);
Service s1 = c1.getService(serviceName1);
ServiceComponent sc1 = s1.getServiceComponent(componentName1);
ServiceComponent sc2 = s1.getServiceComponent(componentName2);
ServiceComponent sc3 = s1.getServiceComponent(componentName3);
ServiceComponentHost sch1 = sc1.getServiceComponentHost(host1);
ServiceComponentHost sch2 = sc2.getServiceComponentHost(host1);
ServiceComponentHost sch3 = sc1.getServiceComponentHost(host2);
ServiceComponentHost sch4 = sc2.getServiceComponentHost(host2);
ServiceComponentHost sch5 = sc3.getServiceComponentHost(host1);
s1.setDesiredState(State.INSTALLED);
sc1.setDesiredState(State.INIT);
sc2.setDesiredState(State.INIT);
sc3.setDesiredState(State.STARTED);
sch1.setDesiredState(State.INSTALLED);
sch2.setDesiredState(State.INSTALLED);
sch3.setDesiredState(State.STARTED);
sch4.setDesiredState(State.INSTALLED);
sch5.setDesiredState(State.INSTALLED);
sch1.setState(State.INSTALLED);
sch2.setState(State.INSTALLED);
sch3.setState(State.STARTED);
sch4.setState(State.INSTALLED);
sch5.setState(State.UNKNOWN);
Set<ServiceComponentRequest> reqs =
new HashSet<ServiceComponentRequest>();
ServiceComponentRequest req1, req2, req3;
// confirm an UNKOWN doesn't fail
req1 = new ServiceComponentRequest(clusterName, serviceName1,
sc3.getName(), State.INSTALLED.toString());
reqs.add(req1);
ComponentResourceProviderTest.updateComponents(controller, reqs, Collections.<String, String>emptyMap(), true);
try {
reqs.clear();
req1 = new ServiceComponentRequest(clusterName, serviceName1,
sc1.getName(), State.INIT.toString());
reqs.add(req1);
ComponentResourceProviderTest.updateComponents(controller, reqs, Collections.<String, String>emptyMap(), true);
fail("Expected failure for invalid state update");
} catch (Exception e) {
// Expected
}
s1.setDesiredState(State.INSTALLED);
sc1.setDesiredState(State.STARTED);
sc2.setDesiredState(State.INSTALLED);
sc3.setDesiredState(State.STARTED);
sch1.setDesiredState(State.INIT);
sch2.setDesiredState(State.INIT);
sch3.setDesiredState(State.INIT);
sch4.setDesiredState(State.INIT);
sch5.setDesiredState(State.INIT);
sch1.setState(State.INIT);
sch2.setState(State.INSTALLED);
sch3.setState(State.INIT);
sch4.setState(State.INSTALLED);
sch5.setState(State.INSTALLED);
try {
reqs.clear();
req1 = new ServiceComponentRequest(clusterName, serviceName1,
sc1.getName(), State.STARTED.toString());
reqs.add(req1);
ComponentResourceProviderTest.updateComponents(controller, reqs, Collections.<String, String>emptyMap(), true);
fail("Expected failure for invalid state update");
} catch (Exception e) {
// Expected
}
s1.setDesiredState(State.INSTALLED);
sc1.setDesiredState(State.STARTED);
sc2.setDesiredState(State.INIT);
sc3.setDesiredState(State.STARTED);
sch1.setDesiredState(State.INIT);
sch2.setDesiredState(State.INIT);
sch3.setDesiredState(State.INIT);
sch4.setDesiredState(State.INIT);
sch5.setDesiredState(State.INIT);
sch1.setState(State.STARTED);
sch2.setState(State.INIT);
sch3.setState(State.INSTALLED);
sch4.setState(State.STARTED);
sch5.setState(State.INIT);
reqs.clear();
req1 = new ServiceComponentRequest(clusterName, serviceName1,
sc1.getName(), State.INSTALLED.toString());
req2 = new ServiceComponentRequest(clusterName, serviceName1,
sc2.getName(), State.INSTALLED.toString());
req3 = new ServiceComponentRequest(clusterName, serviceName1,
sc3.getName(), State.INSTALLED.toString());
reqs.add(req1);
reqs.add(req2);
reqs.add(req3);
RequestStatusResponse trackAction = ComponentResourceProviderTest.updateComponents(controller, reqs, Collections.<String, String>emptyMap(), true);
Assert.assertEquals(State.INSTALLED, s1.getDesiredState());
Assert.assertEquals(State.INSTALLED, sc1.getDesiredState());
Assert.assertEquals(State.INSTALLED, sc2.getDesiredState());
Assert.assertEquals(State.INSTALLED, sc3.getDesiredState());
Assert.assertEquals(State.INSTALLED, sch1.getDesiredState());
Assert.assertEquals(State.INSTALLED, sch2.getDesiredState());
Assert.assertEquals(State.INSTALLED, sch3.getDesiredState());
Assert.assertEquals(State.INSTALLED, sch4.getDesiredState());
Assert.assertEquals(State.INSTALLED, sch5.getDesiredState());