set1.add(r1);
set1.add(r2);
controller.createHostComponents(set1);
Cluster c1 = clusters.getCluster(clusterName);
Service s1 = c1.getService(serviceName1);
ServiceComponent sc1 = s1.getServiceComponent(componentName1);
ServiceComponentHost sch1 = sc1.getServiceComponentHost(host1);
ServiceComponentHost sch2 = sc1.getServiceComponentHost(host2);
s1.setDesiredState(State.INIT);
sc1.setDesiredState(State.INIT);
ServiceComponentHostRequest req1;
ServiceComponentHostRequest req2;
Set<ServiceComponentHostRequest> reqs =
new HashSet<ServiceComponentHostRequest>();
reqs.clear();
req1 = new ServiceComponentHostRequest(clusterName, serviceName1,
componentName1, host1, State.STARTED.toString());
req1.setDesiredStackId("invalid stack id");
reqs.add(req1);
updateHostAndCompareExpectedFailure(reqs, "Invalid desired stack id");
c1.setCurrentStackVersion(null);
sch1.setStackVersion(new StackId("HDP-0.1"));
reqs.clear();
req1 = new ServiceComponentHostRequest(clusterName, serviceName1,
componentName1, host1,
State.STARTED.toString());
req1.setDesiredStackId("HDP-0.2");
reqs.add(req1);
updateHostAndCompareExpectedFailure(reqs, "Cluster has not been upgraded yet");
c1.setCurrentStackVersion(new StackId("HDP2-0.1"));
reqs.clear();
req1 = new ServiceComponentHostRequest(clusterName, serviceName1,
componentName1, host1,
State.STARTED.toString());
req1.setDesiredStackId("HDP-0.2");
reqs.add(req1);
updateHostAndCompareExpectedFailure(reqs, "Deployed stack name and requested stack names");
c1.setCurrentStackVersion(new StackId("HDP-0.2"));
reqs.clear();
req1 = new ServiceComponentHostRequest(clusterName, serviceName1,
componentName1, host1,
State.STARTED.toString());
req1.setDesiredStackId("HDP-0.3");
reqs.add(req1);
updateHostAndCompareExpectedFailure(reqs, "Component host can only be upgraded to the same version");
c1.setCurrentStackVersion(new StackId("HDP-0.2"));
sch1.setState(State.STARTED);
reqs.clear();
req1 = new ServiceComponentHostRequest(clusterName, serviceName1,
componentName1, host1,
State.STARTED.toString());
req1.setDesiredStackId("HDP-0.2");
reqs.add(req1);
updateHostAndCompareExpectedFailure(reqs, "Component host is in an invalid state for upgrade");
c1.setCurrentStackVersion(new StackId("HDP-0.2"));
sch1.setState(State.UPGRADING);
reqs.clear();
req1 = new ServiceComponentHostRequest(clusterName, serviceName1,
componentName1, host1,
State.STARTED.toString());
req1.setDesiredStackId("HDP-0.2");
reqs.add(req1);
updateHostAndCompareExpectedFailure(reqs, "The desired state for an upgrade request must be");
c1.setCurrentStackVersion(new StackId("HDP-0.2"));
sch1.setState(State.UPGRADING);
reqs.clear();
req1 = new ServiceComponentHostRequest(clusterName, serviceName1,
componentName1, host1, null);
req1.setDesiredStackId("HDP-0.2");
reqs.add(req1);
updateHostAndCompareExpectedFailure(reqs, "The desired state for an upgrade request must be");
c1.setCurrentStackVersion(new StackId("HDP-0.2"));
sch1.setState(State.INSTALLED);
sch1.setDesiredState(State.INSTALLED);
sch2.setState(State.INSTALLED);
sch2.setDesiredState(State.INSTALLED);
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.STARTED.toString());
reqs.add(req2);
updateHostAndCompareExpectedFailure(reqs, "An upgrade request cannot be combined with other");
c1.setCurrentStackVersion(new StackId("HDP-0.2"));
sch1.setState(State.INSTALLED);
sch1.setStackVersion(new StackId("HDP-0.2"));
reqs.clear();
req1 = new ServiceComponentHostRequest(clusterName, serviceName1,
componentName1, host1,
null);
req1.setDesiredStackId("HDP-0.2");
reqs.add(req1);
RequestStatusResponse resp = controller.updateHostComponents(reqs,
Collections.<String,String>emptyMap(), true);
Assert.assertNull(resp);
c1.setCurrentStackVersion(new StackId("HDP-0.2"));
sch1.setState(State.INSTALLED);
sch1.setStackVersion(new StackId("HDP-0.2"));
reqs.clear();
req1 = new ServiceComponentHostRequest(clusterName, serviceName1,
componentName1, host1,