metaInfo.init();
clusters.mapHostToCluster(hostName, clusterName);
Cluster cluster = clusters.getCluster(clusterName);
ServiceComponentHost sch1 = createNewServiceComponentHost(cluster, "HDFS", "NAMENODE", hostName);
ServiceComponentHost sch2 = createNewServiceComponentHost(cluster, "HDFS", "DATANODE", hostName);
ServiceComponentHost sch3 = createNewServiceComponentHost(cluster, "MAPREDUCE2", "HISTORYSERVER", hostName);
sch1.setDesiredState(State.INSTALLED);
sch1.setState(State.INSTALLING);
sch1.setStackVersion(new StackId(stackVersion));
sch2.setDesiredState(State.INSTALLED);
sch2.setState(State.INSTALLING);
sch2.setStackVersion(new StackId(stackVersion));
sch3.setDesiredState(State.INSTALLED);
sch3.setState(State.INSTALLING);
sch3.setStackVersion(new StackId(stackVersion));
Assert.assertFalse(sch1.convertToResponse().isStaleConfig());
Assert.assertFalse(sch2.convertToResponse().isStaleConfig());
makeConfig(cluster, "global", "version1",
new HashMap<String,String>() {{
put("a", "b");
put("dfs_namenode_name_dir", "/foo1"); // HDFS only
put("mapred_log_dir_prefix", "/foo2"); // MR2 only
}});
Map<String, Map<String, String>> actual = new HashMap<String, Map<String, String>>() {{
put("global", new HashMap<String,String>() {{ put("tag", "version1"); }});
}};
sch1.updateActualConfigs(actual);
sch2.updateActualConfigs(actual);
sch3.updateActualConfigs(actual);
makeConfig(cluster, "foo", "version1",
new HashMap<String,String>() {{ put("a", "c"); }});
// HDP-x/HDFS does not define type 'foo', so changes do not count to stale
Assert.assertFalse(sch1.convertToResponse().isStaleConfig());
Assert.assertFalse(sch2.convertToResponse().isStaleConfig());
makeConfig(cluster, "hdfs-site", "version1",
new HashMap<String,String>() {{ put("a", "b"); }});
// HDP-x/HDFS/hdfs-site is not on the actual, but it is defined, so it is stale
Assert.assertTrue(sch1.convertToResponse().isStaleConfig());
Assert.assertTrue(sch2.convertToResponse().isStaleConfig());
actual.put("hdfs-site", new HashMap<String, String>() {{ put ("tag", "version1"); }});
sch1.updateActualConfigs(actual);
// HDP-x/HDFS/hdfs-site up to date, only for sch1
Assert.assertFalse(sch1.convertToResponse().isStaleConfig());
Assert.assertTrue(sch2.convertToResponse().isStaleConfig());
sch2.updateActualConfigs(actual);
// HDP-x/HDFS/hdfs-site up to date for both
Assert.assertFalse(sch1.convertToResponse().isStaleConfig());
Assert.assertFalse(sch2.convertToResponse().isStaleConfig());
makeConfig(cluster, "hdfs-site", "version2",
new HashMap<String, String>() {{ put("dfs.journalnode.http-address", "http://foo"); }});
// HDP-x/HDFS/hdfs-site updated to changed property
Assert.assertTrue(sch1.convertToResponse().isStaleConfig());
Assert.assertTrue(sch2.convertToResponse().isStaleConfig());
actual.get("hdfs-site").put("tag", "version2");
sch1.updateActualConfigs(actual);
sch2.updateActualConfigs(actual);
// HDP-x/HDFS/hdfs-site updated to changed property
Assert.assertFalse(sch1.convertToResponse().isStaleConfig());
Assert.assertFalse(sch2.convertToResponse().isStaleConfig());
// make a host override
final Host host = clusters.getHostsForCluster(cluster.getClusterName()).get(hostName);
Assert.assertNotNull(host);
final Config c = configFactory.createNew(cluster, "hdfs-site",
new HashMap<String, String>() {{ put("dfs.journalnode.http-address", "http://goo"); }});
c.setVersionTag("version3");
c.persist();
cluster.addConfig(c);
//host.addDesiredConfig(cluster.getClusterId(), true, "user", c);
ConfigGroup configGroup = configGroupFactory.createNew(cluster, "g1",
"t1", "", new HashMap<String, Config>() {{ put("hdfs-site", c); }},
new HashMap<String, Host>() {{ put("h3", host); }});
configGroup.persist();
cluster.addConfigGroup(configGroup);
// HDP-x/HDFS/hdfs-site updated host to changed property
Assert.assertTrue(sch1.convertToResponse().isStaleConfig());
Assert.assertTrue(sch2.convertToResponse().isStaleConfig());
actual.get("hdfs-site").put(configGroup.getId().toString(), "version3");
sch2.updateActualConfigs(actual);
// HDP-x/HDFS/hdfs-site updated host to changed property
Assert.assertTrue(sch1.convertToResponse().isStaleConfig());
Assert.assertFalse(sch2.convertToResponse().isStaleConfig());
sch1.updateActualConfigs(actual);
// HDP-x/HDFS/hdfs-site updated host to changed property
Assert.assertFalse(sch1.convertToResponse().isStaleConfig());
Assert.assertFalse(sch2.convertToResponse().isStaleConfig());
// change 'global' property only affecting global/HDFS
makeConfig(cluster, "global", "version2",
new HashMap<String,String>() {{
put("a", "b");
put("dfs_namenode_name_dir", "/foo3"); // HDFS only
put("mapred_log_dir_prefix", "/foo2"); // MR2 only
}});
Assert.assertTrue(sch1.convertToResponse().isStaleConfig());
Assert.assertTrue(sch2.convertToResponse().isStaleConfig());
Assert.assertFalse(sch3.convertToResponse().isStaleConfig());
// Change core-site property, only HDFS property
makeConfig(cluster, "core-site", "version1",
new HashMap<String,String>() {{
put("a", "b");
put("fs.trash.interval", "360"); // HDFS only
}});
Assert.assertTrue(sch1.convertToResponse().isStaleConfig());
Assert.assertTrue(sch2.convertToResponse().isStaleConfig());
Assert.assertTrue(sch3.convertToResponse().isStaleConfig());
actual.put("core-site", new HashMap<String, String>() {{
put("tag", "version1");
}});
sch1.updateActualConfigs(actual);
final Config c1 = configFactory.createNew(cluster, "core-site",
new HashMap<String, String>() {{ put("fs.trash.interval", "400"); }});
c1.setVersionTag("version2");
c1.persist();
cluster.addConfig(c1);
configGroup = configGroupFactory.createNew(cluster, "g2",
"t2", "", new HashMap<String, Config>() {{ put("core-site", c1); }},
new HashMap<String, Host>() {{ put("h3", host); }});
configGroup.persist();
cluster.addConfigGroup(configGroup);
Assert.assertTrue(sch1.convertToResponse().isStaleConfig());
Assert.assertTrue(sch2.convertToResponse().isStaleConfig());
Assert.assertTrue(sch3.convertToResponse().isStaleConfig());
// Test actual configs are updated for deleted config group
Long id = configGroup.getId();
HashMap<String, String> tags = new HashMap<String, String>();
tags.put("tag", "version1");
tags.put(id.toString(), "version2");
actual.put("core-site", tags);
sch3.updateActualConfigs(actual);
Assert.assertFalse(sch3.convertToResponse().isStaleConfig());
cluster.deleteConfigGroup(id);
Assert.assertNull(cluster.getConfigGroups().get(id));
sch3.updateActualConfigs(actual);
Assert.assertTrue(sch3.convertToResponse().isStaleConfig());
tags.remove(id.toString());
sch3.updateActualConfigs(actual);
Assert.assertFalse(sch3.convertToResponse().isStaleConfig());
}