host.persist();
c1.setDesiredStackVersion(new StackId("HDP-0.1"));
clusters.mapHostToCluster("h1", "c1");
ConfigFactory configFactory = injector.getInstance(ConfigFactory.class);
Config config = configFactory.createNew(c1, "global",
new HashMap<String,String>() {{ put("a", "b"); put("x", "y"); }});
try {
host.addDesiredConfig(c1.getClusterId(), true, "_test", config);
Assert.fail("Expect failure when version is not specified.");
}
catch (Exception e) {
// testing exception
}
try {
host.addDesiredConfig(c1.getClusterId(), true, null, config);
Assert.fail("Expect failure when user is not specified.");
}
catch (Exception e) {
// testing exception
}
config.setVersionTag("v1");
host.addDesiredConfig(c1.getClusterId(), true, "_test", config);
Map<String, DesiredConfig> map = host.getDesiredConfigs(c1.getClusterId());
Assert.assertTrue("Expect desired config to contain global", map.containsKey("global"));
Assert.assertEquals("Expect global user to be '_test'", "_test", map.get("global").getUser());
config = configFactory.createNew(c1, "global",
new HashMap<String,String>() {{ put("c", "d"); }});
config.setVersionTag("v2");
host.addDesiredConfig(c1.getClusterId(), true, "_test1", config);
map = host.getDesiredConfigs(c1.getClusterId());