use of com.hortonworks.streamline.streams.layout.storm.StormTopologyFluxGenerator in project streamline by hortonworks.
the class StormTopologyActionsImpl method createYamlFile.
private String createYamlFile(TopologyLayout topology, boolean deploy) throws Exception {
Map<String, Object> yamlMap;
File f;
OutputStreamWriter fileWriter = null;
try {
f = new File(this.getFilePath(topology));
if (f.exists()) {
if (!f.delete()) {
throw new Exception("Unable to delete old storm " + "artifact for topology id " + topology.getId());
}
}
yamlMap = new LinkedHashMap<>();
yamlMap.put(StormTopologyLayoutConstants.YAML_KEY_NAME, generateStormTopologyName(topology));
TopologyDag topologyDag = topology.getTopologyDag();
LOG.debug("Initial Topology config {}", topology.getConfig());
StormTopologyFluxGenerator fluxGenerator = new StormTopologyFluxGenerator(topology, conf, getExtraJarsLocation(topology));
topologyDag.traverse(fluxGenerator);
for (Map.Entry<String, Map<String, Object>> entry : fluxGenerator.getYamlKeysAndComponents()) {
addComponentToCollection(yamlMap, entry.getValue(), entry.getKey());
}
Config topologyConfig = fluxGenerator.getTopologyConfig();
putAutoTokenDelegationConfig(topologyConfig, topologyDag);
registerEventLogger(topologyConfig);
Map<String, Object> properties = topologyConfig.getProperties();
if (!deploy) {
LOG.debug("Disabling topology event logger for test mode...");
properties.put("topology.eventlogger.executors", 0);
}
LOG.debug("Final Topology properties {}", properties);
addTopologyConfig(yamlMap, properties);
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setSplitLines(false);
// options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
Yaml yaml = new Yaml(options);
fileWriter = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
yaml.dump(yamlMap, fileWriter);
return f.getAbsolutePath();
} finally {
if (fileWriter != null) {
fileWriter.close();
}
}
}
Aggregations