set1.add(r4);
set1.add(r5);
set1.add(r6);
controller.createHostComponents(set1);
Cluster c1 = clusters.getCluster(clusterName);
Service s1 = c1.getService(serviceName1);
Service s2 = c1.getService(serviceName2);
ServiceComponent sc1 = s1.getServiceComponent(componentName1);
ServiceComponent sc2 = s1.getServiceComponent(componentName2);
ServiceComponent sc3 = s2.getServiceComponent(componentName3);
ServiceComponent sc4 = s1.getServiceComponent(componentName4);
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);
ServiceComponentHost sch6 = sc4.getServiceComponentHost(host2);
s1.setDesiredState(State.INSTALLED);
s2.setDesiredState(State.INSTALLED);
sc1.setDesiredState(State.STARTED);
sc2.setDesiredState(State.INIT);
sc3.setDesiredState(State.STARTED);
sc4.setDesiredState(State.INSTALLED);
sch1.setDesiredState(State.INSTALLED);
sch2.setDesiredState(State.INSTALLED);
sch3.setDesiredState(State.INSTALLED);
sch4.setDesiredState(State.INSTALLED);
sch5.setDesiredState(State.INSTALLED);
sch6.setDesiredState(State.INSTALLED);
sch1.setState(State.INSTALLED);
sch2.setState(State.INSTALLED);
sch3.setState(State.INSTALLED);
sch4.setState(State.INSTALLED);
sch5.setState(State.INSTALLED);
sch6.setState(State.INSTALLED);
Set<ServiceRequest> reqs = new HashSet<ServiceRequest>();
ServiceRequest req1, req2;
try {
reqs.clear();
req1 = new ServiceRequest(clusterName, serviceName1,
State.STARTED.toString());
reqs.add(req1);
ServiceResourceProviderTest.updateServices(controller, reqs, mapRequestProps, true, false);
fail("Expected failure for invalid state update");
} catch (Exception e) {
// Expected
}
s1.setDesiredState(State.INSTALLED);
s2.setDesiredState(State.INSTALLED);
sc1.setDesiredState(State.STARTED);
sc2.setDesiredState(State.INSTALLED);
sc3.setDesiredState(State.STARTED);
sch1.setDesiredState(State.INSTALLED);
sch2.setDesiredState(State.INSTALLED);
sch3.setDesiredState(State.INSTALLED);
sch4.setDesiredState(State.INSTALLED);
sch5.setDesiredState(State.INSTALLED);
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 ServiceRequest(clusterName, serviceName1,
State.STARTED.toString());
reqs.add(req1);
ServiceResourceProviderTest.updateServices(controller, reqs, mapRequestProps, true, false);
fail("Expected failure for invalid state update");
} catch (Exception e) {
// Expected
}
s1.setDesiredState(State.INSTALLED);
s2.setDesiredState(State.INSTALLED);
sc1.setDesiredState(State.STARTED);
sc2.setDesiredState(State.INSTALLED);
sc3.setDesiredState(State.STARTED);
sch1.setDesiredState(State.STARTED);
sch2.setDesiredState(State.STARTED);
sch3.setDesiredState(State.STARTED);
sch4.setDesiredState(State.STARTED);
sch5.setDesiredState(State.STARTED);
sch1.setState(State.INSTALLED);
sch2.setState(State.INSTALLED);
sch3.setState(State.INSTALLED);
sch4.setState(State.STARTED);
sch5.setState(State.INSTALLED);
reqs.clear();
req1 = new ServiceRequest(clusterName, serviceName1,
State.STARTED.toString());
req2 = new ServiceRequest(clusterName, serviceName2,
State.STARTED.toString());
reqs.add(req1);
reqs.add(req2);
RequestStatusResponse trackAction = ServiceResourceProviderTest.updateServices(controller, reqs,
mapRequestProps, true, false);
Assert.assertEquals(State.STARTED, s1.getDesiredState());
Assert.assertEquals(State.STARTED, s2.getDesiredState());
Assert.assertEquals(State.STARTED, sc1.getDesiredState());
Assert.assertEquals(State.STARTED, sc2.getDesiredState());
Assert.assertEquals(State.STARTED, sc3.getDesiredState());
Assert.assertEquals(State.INSTALLED, sc4.getDesiredState());
Assert.assertEquals(State.STARTED, sch1.getDesiredState());
Assert.assertEquals(State.STARTED, sch2.getDesiredState());
Assert.assertEquals(State.STARTED, sch3.getDesiredState());
Assert.assertEquals(State.STARTED, sch4.getDesiredState());
Assert.assertEquals(State.STARTED, sch5.getDesiredState());
Assert.assertEquals(State.INSTALLED, sch6.getDesiredState());
Assert.assertEquals(State.INSTALLED, sch1.getState());
Assert.assertEquals(State.INSTALLED, sch2.getState());
Assert.assertEquals(State.INSTALLED, sch3.getState());
Assert.assertEquals(State.STARTED, sch4.getState());
Assert.assertEquals(State.INSTALLED, sch5.getState());
Assert.assertEquals(State.INSTALLED, sch6.getState());
long requestId = trackAction.getRequestId();
List<Stage> stages = actionDB.getAllStages(requestId);
for (Stage stage : stages) {
LOG.debug("Stage dump: " + stage.toString());
}
Assert.assertTrue(!stages.isEmpty());
Assert.assertEquals(3, stages.size());
// expected
// sch1 to start
// sch2 to start
// sch3 to start
// sch5 to start
Stage stage1 = null, stage2 = null, stage3 = null;
for (Stage s : stages) {
if (s.getStageId() == 1) { stage1 = s; }
if (s.getStageId() == 2) { stage2 = s; }
if (s.getStageId() == 3) { stage3 = s; }
}
Assert.assertEquals(2, stage1.getExecutionCommands(host1).size());
Assert.assertEquals(1, stage1.getExecutionCommands(host2).size());
Assert.assertEquals(1, stage2.getExecutionCommands(host1).size());
Assert.assertNotNull(stage1.getExecutionCommandWrapper(host1, "NAMENODE"));
Assert.assertNotNull(stage1.getExecutionCommandWrapper(host1, "DATANODE"));
Assert.assertNotNull(stage1.getExecutionCommandWrapper(host2, "NAMENODE"));
Assert.assertNotNull(stage2.getExecutionCommandWrapper(host1, "HBASE_MASTER"));
Assert.assertNull(stage1.getExecutionCommandWrapper(host2, "DATANODE"));
Assert.assertNotNull(stage3.getExecutionCommandWrapper(host1, "HBASE_SERVICE_CHECK"));
Assert.assertNotNull(stage2.getExecutionCommandWrapper(host2, "HDFS_SERVICE_CHECK"));
for (Stage s : stages) {
for (List<ExecutionCommandWrapper> list : s.getExecutionCommands().values()) {
for (ExecutionCommandWrapper ecw : list) {
if (ecw.getExecutionCommand().getRole().contains("SERVICE_CHECK")) {
Map<String, String> hostParams = ecw.getExecutionCommand().getHostLevelParams();
Assert.assertNotNull(hostParams);
Assert.assertTrue(hostParams.size() > 0);
Assert.assertTrue(hostParams.containsKey("stack_version"));
Assert.assertEquals(hostParams.get("stack_version"), c1.getDesiredStackVersion().getStackVersion());
}
}
}
}