sch1.refresh();
Assert.assertTrue(sch1.getDesiredStackVersion().compareTo(newStack) == 0);
sch2.refresh();
Assert.assertTrue(sch2.getDesiredStackVersion().compareTo(newStack) == 0);
for (HostRoleCommand command : stages.get(0).getOrderedHostRoleCommands()) {
ExecutionCommand execCommand = command.getExecutionCommandWrapper().getExecutionCommand();
Assert.assertTrue(execCommand.getCommandParams().containsKey("source_stack_version"));
Assert.assertTrue(execCommand.getCommandParams().containsKey("target_stack_version"));
Assert.assertEquals(RoleCommand.UPGRADE, execCommand.getRoleCommand());
}
sch1.setState(State.INSTALLED);
sch1.setDesiredState(State.INSTALLED);
sch2.setState(State.UPGRADING);
sch2.setDesiredState(State.INSTALLED);
sch3.setState(State.UPGRADING);
sch3.setDesiredState(State.INSTALLED);
sch3.setStackVersion(oldStack);
sch3.setDesiredStackVersion(newStack);
reqs.clear();
req1 = new ServiceComponentHostRequest(clusterName, serviceName1,
componentName1, host1,
State.INSTALLED.toString());
req1.setDesiredStackId("HDP-0.2");
reqs.add(req1);
req2 = new ServiceComponentHostRequest(clusterName, serviceName1,
componentName1, host2,
State.INSTALLED.toString());
req2.setDesiredStackId("HDP-0.2");
reqs.add(req2);
req3 = new ServiceComponentHostRequest(clusterName, serviceName1,
componentName2, host1,
State.INSTALLED.toString());
req3.setDesiredStackId("HDP-0.2");
reqs.add(req3);
resp = controller.updateHostComponents(reqs, Collections.<String, String>emptyMap(), true);
stages = actionDB.getAllStages(resp.getRequestId());
Assert.assertEquals(2, stages.size());
Assert.assertEquals(2, stages.get(0).getOrderedHostRoleCommands().size());
Assert.assertEquals("", stages.get(0).getRequestContext());
Assert.assertEquals(State.UPGRADING, sch1.getState());
Assert.assertEquals(State.UPGRADING, sch2.getState());
Assert.assertEquals(State.UPGRADING, sch3.getState());
sch1.refresh();
Assert.assertTrue(sch1.getDesiredStackVersion().compareTo(newStack) == 0);
sch2.refresh();
Assert.assertTrue(sch2.getDesiredStackVersion().compareTo(newStack) == 0);
sch3.refresh();
Assert.assertTrue(sch3.getDesiredStackVersion().compareTo(newStack) == 0);
for (Stage stage : stages) {
for (HostRoleCommand command : stage.getOrderedHostRoleCommands()) {
ExecutionCommand execCommand = command.getExecutionCommandWrapper().getExecutionCommand();
Assert.assertTrue(execCommand.getCommandParams().containsKey("source_stack_version"));
Assert.assertTrue(execCommand.getCommandParams().containsKey("target_stack_version"));
Assert.assertEquals("{\"stackName\":\"HDP\",\"stackVersion\":\"0.2\"}",
execCommand.getCommandParams().get("target_stack_version"));
Assert.assertEquals(RoleCommand.UPGRADE, execCommand.getRoleCommand());
}
}
}