Search in sources :

Example 1 with TopologyDef

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;
    }
}
Also used : TopologyDef(com.alibaba.jstorm.flux.model.TopologyDef) Yaml(org.yaml.snakeyaml.Yaml)

Example 2 with TopologyDef

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;
}
Also used : TopologyDef(com.alibaba.jstorm.flux.model.TopologyDef) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream)

Example 3 with TopologyDef

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;
}
Also used : TopologyDef(com.alibaba.jstorm.flux.model.TopologyDef) FileInputStream(java.io.FileInputStream)

Example 4 with TopologyDef

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"));
}
Also used : TestBolt(com.alibaba.jstorm.flux.test.TestBolt) TopologyDef(com.alibaba.jstorm.flux.model.TopologyDef) ExecutionContext(com.alibaba.jstorm.flux.model.ExecutionContext) Config(backtype.storm.Config) StormTopology(backtype.storm.generated.StormTopology) Test(org.junit.Test)

Example 5 with TopologyDef

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);
}
Also used : TopologyDef(com.alibaba.jstorm.flux.model.TopologyDef) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

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