Search in sources :

Example 1 with StormTopologyFluxGenerator

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();
        }
    }
}
Also used : Config(com.hortonworks.streamline.common.Config) ClientConfig(org.glassfish.jersey.client.ClientConfig) StormTopologyFluxGenerator(com.hortonworks.streamline.streams.layout.storm.StormTopologyFluxGenerator) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) IOException(java.io.IOException) Yaml(org.yaml.snakeyaml.Yaml) FileOutputStream(java.io.FileOutputStream) DumperOptions(org.yaml.snakeyaml.DumperOptions) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag)

Aggregations

Config (com.hortonworks.streamline.common.Config)1 TopologyNotAliveException (com.hortonworks.streamline.streams.exception.TopologyNotAliveException)1 TopologyDag (com.hortonworks.streamline.streams.layout.component.TopologyDag)1 StormTopologyFluxGenerator (com.hortonworks.streamline.streams.layout.storm.StormTopologyFluxGenerator)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ClientConfig (org.glassfish.jersey.client.ClientConfig)1 DumperOptions (org.yaml.snakeyaml.DumperOptions)1 Yaml (org.yaml.snakeyaml.Yaml)1