Search in sources :

Example 6 with TopologyDef

use of com.alibaba.jstorm.flux.model.TopologyDef in project jstorm by alibaba.

the class FluxParser method processIncludes.

/**
     *
     * @param yaml the yaml parser for parsing the include file(s)
     * @param topologyDef the topology definition containing (possibly zero) includes
     * @return The TopologyDef with includes resolved.
     */
private static TopologyDef processIncludes(Yaml yaml, TopologyDef topologyDef, String propsFile, boolean envSub) throws IOException {
    //TODO support multiple levels of includes
    if (topologyDef.getIncludes() != null) {
        for (IncludeDef include : topologyDef.getIncludes()) {
            TopologyDef includeTopologyDef = null;
            if (include.isResource()) {
                LOG.info("Loading includes from resource: {}", include.getFile());
                includeTopologyDef = parseResource(include.getFile(), true, false, propsFile, envSub);
            } else {
                LOG.info("Loading includes from file: {}", include.getFile());
                includeTopologyDef = parseFile(include.getFile(), true, false, propsFile, envSub);
            }
            // if overrides are disabled, we won't replace anything that already exists
            boolean override = include.isOverride();
            // name
            if (includeTopologyDef.getName() != null) {
                topologyDef.setName(includeTopologyDef.getName(), override);
            }
            // config
            if (includeTopologyDef.getConfig() != null) {
                //TODO move this logic to the model class
                Map<String, Object> config = topologyDef.getConfig();
                Map<String, Object> includeConfig = includeTopologyDef.getConfig();
                if (override) {
                    config.putAll(includeTopologyDef.getConfig());
                } else {
                    for (String key : includeConfig.keySet()) {
                        if (config.containsKey(key)) {
                            LOG.warn("Ignoring attempt to set topology config property '{}' with override == false", key);
                        } else {
                            config.put(key, includeConfig.get(key));
                        }
                    }
                }
            }
            //component overrides
            if (includeTopologyDef.getComponents() != null) {
                topologyDef.addAllComponents(includeTopologyDef.getComponents(), override);
            }
            //bolt overrides
            if (includeTopologyDef.getBolts() != null) {
                topologyDef.addAllBolts(includeTopologyDef.getBolts(), override);
            }
            //spout overrides
            if (includeTopologyDef.getSpouts() != null) {
                topologyDef.addAllSpouts(includeTopologyDef.getSpouts(), override);
            }
            //TODO streams should be uniquely identifiable
            if (includeTopologyDef.getStreams() != null) {
                topologyDef.addAllStreams(includeTopologyDef.getStreams(), override);
            }
        }
    // end include processing
    }
    return topologyDef;
}
Also used : TopologyDef(com.alibaba.jstorm.flux.model.TopologyDef) IncludeDef(com.alibaba.jstorm.flux.model.IncludeDef)

Aggregations

TopologyDef (com.alibaba.jstorm.flux.model.TopologyDef)6 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)2 Config (backtype.storm.Config)1 StormTopology (backtype.storm.generated.StormTopology)1 ExecutionContext (com.alibaba.jstorm.flux.model.ExecutionContext)1 IncludeDef (com.alibaba.jstorm.flux.model.IncludeDef)1 TestBolt (com.alibaba.jstorm.flux.test.TestBolt)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Properties (java.util.Properties)1 Test (org.junit.Test)1 Yaml (org.yaml.snakeyaml.Yaml)1