//
// jsanda
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(options);
Map cassandraConfig = (Map) yaml.load(new FileInputStream(yamlFile));
List seedProviderList = (List) cassandraConfig.get("seed_provider");
Map seedProvider = (Map) seedProviderList.get(0);
List paramsList = (List) seedProvider.get("parameters");
Map params = (Map) paramsList.get(0);
params.put("seeds", StringUtil.listToString(seeds));
// create a backup of the configuration file in preparation of writing out the changes
File yamlFileBackup = new File(yamlProp + ".bak" + new Date().getTime());
StreamUtil.copy(new FileInputStream(yamlFile), new FileOutputStream(yamlFileBackup), true);
if (!yamlFile.delete()) {
String msg = "Failed to delete [" + yamlFile + "] in preparation of writing updated configuration. The " +
"changes will be aborted.";
log.error(msg);
deleteYamlBackupFile(yamlFileBackup);
throw new IOException(msg);
}
FileWriter writer = new FileWriter(yamlFile);
try {
yaml.dump(cassandraConfig, writer);
deleteYamlBackupFile(yamlFileBackup);
} catch (Exception e) {
log.error("An error occurred while trying to write the updated configuration back to " + yamlFile, e);
log.error("Reverting changes to " + yamlFile);