use of com.alibaba.jstorm.flux.model.IncludeDef 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;
}
Aggregations