|
@@ -2103,11 +2103,17 @@ public class AmbariManagementControllerTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testGetServiceComponentHostsWithFilter() throws AmbariException {
|
|
|
+ public void testGetServiceComponentHostsWithStaleConfigFilter() throws AmbariException {
|
|
|
+
|
|
|
+ final String host1 = "h1";
|
|
|
+ final String host2 = "h2";
|
|
|
String clusterName = "foo1";
|
|
|
- createCluster(clusterName);
|
|
|
- clusters.getCluster(clusterName)
|
|
|
- .setDesiredStackVersion(new StackId("HDP-2.0.5"));
|
|
|
+ setupClusterWithHosts(clusterName, "HDP-2.0.5",
|
|
|
+ new ArrayList<String>() {{
|
|
|
+ add(host1);
|
|
|
+ add(host2);
|
|
|
+ }},
|
|
|
+ "centos5");
|
|
|
String serviceName = "HDFS";
|
|
|
createService(clusterName, serviceName, null);
|
|
|
String componentName1 = "NAMENODE";
|
|
@@ -2121,20 +2127,16 @@ public class AmbariManagementControllerTest {
|
|
|
createServiceComponent(clusterName, serviceName, componentName3,
|
|
|
State.INIT);
|
|
|
|
|
|
- String host1 = "h1";
|
|
|
- clusters.addHost(host1);
|
|
|
- clusters.getHost("h1").setOsType("centos5");
|
|
|
- clusters.getHost("h1").setState(HostState.HEALTHY);
|
|
|
- clusters.getHost("h1").persist();
|
|
|
-
|
|
|
- clusters.mapHostToCluster(host1, clusterName);
|
|
|
-
|
|
|
createServiceComponentHost(clusterName, serviceName, componentName1,
|
|
|
host1, null);
|
|
|
createServiceComponentHost(clusterName, serviceName, componentName2,
|
|
|
host1, null);
|
|
|
createServiceComponentHost(clusterName, serviceName, componentName3,
|
|
|
host1, null);
|
|
|
+ createServiceComponentHost(clusterName, serviceName, componentName2,
|
|
|
+ host2, null);
|
|
|
+ createServiceComponentHost(clusterName, serviceName, componentName3,
|
|
|
+ host2, null);
|
|
|
|
|
|
// Install
|
|
|
installService(clusterName, serviceName, false, false);
|
|
@@ -2144,7 +2146,7 @@ public class AmbariManagementControllerTest {
|
|
|
configs.put("a", "b");
|
|
|
|
|
|
ConfigurationRequest cr1;
|
|
|
- cr1 = new ConfigurationRequest(clusterName, "hdfs-site","version1",
|
|
|
+ cr1 = new ConfigurationRequest(clusterName, "hdfs-site", "version1",
|
|
|
configs);
|
|
|
ClusterRequest crReq = new ClusterRequest(null, clusterName, null, null);
|
|
|
crReq.setDesiredConfig(cr1);
|
|
@@ -2154,47 +2156,60 @@ public class AmbariManagementControllerTest {
|
|
|
startService(clusterName, serviceName, false, false);
|
|
|
|
|
|
//Update actual config
|
|
|
+ HashMap<String, Map<String, String>> actualConfig = new HashMap<String, Map<String, String>>() {{
|
|
|
+ put("hdfs-site", new HashMap<String, String>() {{
|
|
|
+ put("tag", "version1");
|
|
|
+ }});
|
|
|
+ }};
|
|
|
+ HashMap<String, Map<String, String>> actualConfigOld = new
|
|
|
+ HashMap<String, Map<String, String>>() {{
|
|
|
+ put("hdfs-site", new HashMap<String, String>() {{
|
|
|
+ put("tag", "version0");
|
|
|
+ }});
|
|
|
+ }};
|
|
|
+
|
|
|
Service s1 = clusters.getCluster(clusterName).getService(serviceName);
|
|
|
- ServiceComponentHost sch1 = s1.getServiceComponent(componentName1)
|
|
|
- .getServiceComponentHost(host1);
|
|
|
- ServiceComponentHost sch2 = s1.getServiceComponent(componentName2)
|
|
|
- .getServiceComponentHost(host1);
|
|
|
- ServiceComponentHost sch3 = s1.getServiceComponent(componentName3)
|
|
|
- .getServiceComponentHost(host1);
|
|
|
- sch1.updateActualConfigs(new HashMap<String, Map<String,String>>() {{
|
|
|
- put("hdfs-site", new HashMap<String,String>() {{ put("tag", "version1"); }});
|
|
|
- }});
|
|
|
- sch2.updateActualConfigs(new HashMap<String, Map<String,String>>() {{
|
|
|
- put("hdfs-site", new HashMap<String,String>() {{ put("tag", "version1"); }});
|
|
|
- }});
|
|
|
- sch3.updateActualConfigs(new HashMap<String, Map<String,String>>() {{
|
|
|
- put("hdfs-site", new HashMap<String,String>() {{ put("tag", "version2"); }});
|
|
|
- }});
|
|
|
+ s1.getServiceComponent(componentName1).getServiceComponentHost(host1).updateActualConfigs(actualConfig);
|
|
|
+ s1.getServiceComponent(componentName2).getServiceComponentHost(host1).updateActualConfigs(actualConfig);
|
|
|
+ s1.getServiceComponent(componentName3).getServiceComponentHost(host1).updateActualConfigs(actualConfigOld);
|
|
|
+ s1.getServiceComponent(componentName2).getServiceComponentHost(host2).updateActualConfigs(actualConfigOld);
|
|
|
+ s1.getServiceComponent(componentName3).getServiceComponentHost(host2).updateActualConfigs(actualConfig);
|
|
|
|
|
|
ServiceComponentHostRequest r =
|
|
|
new ServiceComponentHostRequest(clusterName, null, null, null, null);
|
|
|
Set<ServiceComponentHostResponse> resps = controller.getHostComponents(Collections.singleton(r));
|
|
|
- Assert.assertEquals(3, resps.size());
|
|
|
+ Assert.assertEquals(5, resps.size());
|
|
|
|
|
|
//Get all host components with stale config = true
|
|
|
r = new ServiceComponentHostRequest(clusterName, null, null, null, null);
|
|
|
r.setStaleConfig("true");
|
|
|
resps = controller.getHostComponents(Collections.singleton(r));
|
|
|
- Assert.assertEquals(1, resps.size());
|
|
|
+ Assert.assertEquals(2, resps.size());
|
|
|
|
|
|
//Get all host components with stale config = false
|
|
|
r = new ServiceComponentHostRequest(clusterName, null, null, null, null);
|
|
|
r.setStaleConfig("false");
|
|
|
resps = controller.getHostComponents(Collections.singleton(r));
|
|
|
+ Assert.assertEquals(3, resps.size());
|
|
|
+
|
|
|
+ //Get all host components with stale config = false and hostname filter
|
|
|
+ r = new ServiceComponentHostRequest(clusterName, null, null, host1, null);
|
|
|
+ r.setStaleConfig("false");
|
|
|
+ resps = controller.getHostComponents(Collections.singleton(r));
|
|
|
Assert.assertEquals(2, resps.size());
|
|
|
- }
|
|
|
|
|
|
+ //Get all host components with stale config = false and hostname filter
|
|
|
+ r = new ServiceComponentHostRequest(clusterName, null, null, host2, null);
|
|
|
+ r.setStaleConfig("true");
|
|
|
+ resps = controller.getHostComponents(Collections.singleton(r));
|
|
|
+ Assert.assertEquals(1, resps.size());
|
|
|
+ }
|
|
|
|
|
|
private Cluster setupClusterWithHosts(String clusterName, String stackId, List<String> hosts,
|
|
|
- String osType) throws AmbariException {
|
|
|
- clusters.addCluster(clusterName);
|
|
|
+ String osType) throws AmbariException {
|
|
|
+ ClusterRequest r = new ClusterRequest(null, clusterName, stackId, null);
|
|
|
+ controller.createCluster(r);
|
|
|
Cluster c1 = clusters.getCluster(clusterName);
|
|
|
- c1.setDesiredStackVersion(new StackId(stackId));
|
|
|
for (String host : hosts) {
|
|
|
clusters.addHost(host);
|
|
|
clusters.getHost(host).setOsType(osType);
|