use of com.alibaba.jstorm.flux.model.TopologyDef in project jstorm by alibaba.
the class FluxParser method parseInputStream.
public static TopologyDef parseInputStream(InputStream inputStream, boolean dumpYaml, boolean processIncludes, String propertiesFile, boolean envSub) throws IOException {
Yaml yaml = yaml();
if (inputStream == null) {
LOG.error("Unable to load input stream");
System.exit(1);
}
TopologyDef topology = loadYaml(yaml, inputStream, propertiesFile, envSub);
if (dumpYaml) {
dumpYaml(topology, yaml);
}
if (processIncludes) {
return processIncludes(yaml, topology, propertiesFile, envSub);
} else {
return topology;
}
}
use of com.alibaba.jstorm.flux.model.TopologyDef in project jstorm by alibaba.
the class FluxParser method parseResource.
public static TopologyDef parseResource(String resource, boolean dumpYaml, boolean processIncludes, String propertiesFile, boolean envSub) throws IOException {
InputStream in = FluxParser.class.getResourceAsStream(resource);
TopologyDef topology = parseInputStream(in, dumpYaml, processIncludes, propertiesFile, envSub);
in.close();
return topology;
}
use of com.alibaba.jstorm.flux.model.TopologyDef in project jstorm by alibaba.
the class FluxParser method parseFile.
// TODO refactor input stream processing (see parseResource() method).
public static TopologyDef parseFile(String inputFile, boolean dumpYaml, boolean processIncludes, String propertiesFile, boolean envSub) throws IOException {
FileInputStream in = new FileInputStream(inputFile);
TopologyDef topology = parseInputStream(in, dumpYaml, processIncludes, propertiesFile, envSub);
in.close();
return topology;
}
use of com.alibaba.jstorm.flux.model.TopologyDef in project jstorm by alibaba.
the class TCKTest method testTopologySourceWithConfigMethods.
@Test
public void testTopologySourceWithConfigMethods() throws Exception {
TopologyDef topologyDef = FluxParser.parseResource("/configs/config-methods-test.yaml", false, true, null, false);
assertTrue(topologyDef.validate());
Config conf = FluxBuilder.buildConfig(topologyDef);
ExecutionContext context = new ExecutionContext(topologyDef, conf);
StormTopology topology = FluxBuilder.buildTopology(context);
assertNotNull(topology);
topology.validate();
// make sure the property was actually set
TestBolt bolt = (TestBolt) context.getBolt("bolt-1");
assertTrue(bolt.getFoo().equals("foo"));
assertTrue(bolt.getBar().equals("bar"));
assertTrue(bolt.getFooBar().equals("foobar"));
}
use of com.alibaba.jstorm.flux.model.TopologyDef in project jstorm by alibaba.
the class FluxParser method loadYaml.
private static TopologyDef loadYaml(Yaml yaml, InputStream in, String propsFile, boolean envSubstitution) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
LOG.info("loading YAML from input stream...");
int b = -1;
while ((b = in.read()) != -1) {
bos.write(b);
}
// TODO substitution implementation is not exactly efficient or kind to memory...
String str = bos.toString();
// properties file substitution
if (propsFile != null) {
LOG.info("Performing property substitution.");
InputStream propsIn = new FileInputStream(propsFile);
Properties props = new Properties();
props.load(propsIn);
for (Object key : props.keySet()) {
str = str.replace("${" + key + "}", props.getProperty((String) key));
}
} else {
LOG.info("Not performing property substitution.");
}
// environment variable substitution
if (envSubstitution) {
LOG.info("Performing environment variable substitution...");
Map<String, String> envs = System.getenv();
for (String key : envs.keySet()) {
str = str.replace("${ENV-" + key + "}", envs.get(key));
}
} else {
LOG.info("Not performing environment variable substitution.");
}
return (TopologyDef) yaml.load(str);
}
Aggregations