String clusterName = "foo1";
String serviceName = "MAPREDUCE";
String host1 = "h1";
String host2 = "h2";
String componentName = "JOBTRACKER";
StackId currentStackId = new StackId("HDP-0.1");
Map<String, String> mapRequestProps = new HashMap<String, String>();
mapRequestProps.put("context", "Called from a test");
createCluster(clusterName);
Cluster c = clusters.getCluster(clusterName);
c.setDesiredStackVersion(currentStackId);
createService(clusterName, serviceName, State.INIT);
createServiceComponent(clusterName, serviceName, componentName, null);
clusters.addHost(host1);
clusters.getHost(host1).persist();
clusters.addHost(host2);
clusters.getHost(host2).persist();
clusters.getHost(host1).setOsType("centos5");
clusters.getHost(host2).setOsType("centos6");
clusters.getHost(host1).setState(HostState.HEALTHY);
clusters.getHost(host2).setState(HostState.HEALTHY);
clusters.mapHostToCluster(host1, clusterName);
clusters.mapHostToCluster(host2, clusterName);
createServiceComponentHost(clusterName, null, componentName,
host1, null);
createServiceComponentHost(clusterName, null, componentName,
host2, null);
c.getService(serviceName).setDesiredState(State.INSTALLED);
c.getService(serviceName).getServiceComponent(componentName).setDesiredState(State.INSTALLED);
c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host1)
.setDesiredState(State.INSTALLED);
c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host2)
.setDesiredState(State.STARTED);
c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host1)
.setState(State.INSTALLED);
c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host2)
.setState(State.STARTED);
c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host1)
.setStackVersion(currentStackId);
c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host2)
.setStackVersion(currentStackId);
ClusterRequest r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.0.1", null);
try {
controller.updateClusters(Collections.singleton(r), mapRequestProps);
fail("Update cluster should fail");
} catch (AmbariException e) {
Assert.assertTrue(e.getMessage().contains("must be greater than current version"));
}
r = new ClusterRequest(c.getClusterId(), clusterName, "HDPLocal-1.2.2", null);
try {
controller.updateClusters(Collections.singleton(r), mapRequestProps);
fail("Update cluster should fail");
} catch (AmbariException e) {
Assert.assertTrue(e.getMessage().contains("Upgrade not possible between different stacks"));
}
r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.2", null);
try {
controller.updateClusters(Collections.singleton(r), mapRequestProps);
fail("Update cluster should fail");
} catch (AmbariException e) {
Assert.assertTrue(e.getMessage().contains("Upgrade needs all services to be stopped"));
Assert.assertTrue(e.getMessage().contains(serviceName));
}
c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host2)
.setDesiredState(State.INSTALLED);
r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.2", null);
try {
controller.updateClusters(Collections.singleton(r), mapRequestProps);
fail("Update cluster should fail");
} catch (AmbariException e) {
Assert.assertTrue(e.getMessage().contains("Upgrade needs all services to be stopped"));
Assert.assertTrue(e.getMessage().contains(componentName));
}
c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host2)
.setState(State.INSTALLED);
controller.updateClusters(Collections.singleton(r), mapRequestProps);
StackId expectedStackId = new StackId("HDP-0.2");
Assert.assertTrue(expectedStackId.equals(c.getDesiredStackVersion()));
Assert.assertTrue(expectedStackId.equals(c.getService(serviceName).getDesiredStackVersion()));
Assert.assertTrue(expectedStackId.equals(c.getService(serviceName)
.getServiceComponent(componentName).getDesiredStackVersion()));
Assert.assertTrue(expectedStackId.equals(c.getService(serviceName)
.getServiceComponent(componentName).getServiceComponentHost(host1).getDesiredStackVersion()));
Assert.assertTrue(expectedStackId.equals(c.getService(serviceName)
.getServiceComponent(componentName).getServiceComponentHost(host2).getDesiredStackVersion()));
Assert.assertTrue(currentStackId.equals(c.getService(serviceName)
.getServiceComponent(componentName).getServiceComponentHost(host1).getStackVersion()));
Assert.assertTrue(currentStackId.equals(c.getService(serviceName)
.getServiceComponent(componentName).getServiceComponentHost(host2).getStackVersion()));