Search in sources :

Example 41 with StormTopology

use of org.apache.storm.generated.StormTopology in project storm by apache.

the class TCKTest method testIncludes.

@Test
public void testIncludes() throws Exception {
    TopologyDef topologyDef = FluxParser.parseResource("/configs/include_test.yaml", false, true, null, false);
    Config conf = FluxBuilder.buildConfig(topologyDef);
    ExecutionContext context = new ExecutionContext(topologyDef, conf);
    StormTopology topology = FluxBuilder.buildTopology(context);
    assertNotNull(topology);
    assertTrue(topologyDef.getName().equals("include-topology"));
    assertTrue(topologyDef.getBolts().size() > 0);
    assertTrue(topologyDef.getSpouts().size() > 0);
    topology.validate();
}
Also used : TopologyDef(org.apache.storm.flux.model.TopologyDef) ExecutionContext(org.apache.storm.flux.model.ExecutionContext) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) Test(org.junit.Test)

Example 42 with StormTopology

use of org.apache.storm.generated.StormTopology in project storm by apache.

the class TCKTest method testDiamondTopology.

@Test
public void testDiamondTopology() throws Exception {
    TopologyDef topologyDef = FluxParser.parseResource("/configs/diamond-topology.yaml", false, true, null, false);
    Config conf = FluxBuilder.buildConfig(topologyDef);
    ExecutionContext context = new ExecutionContext(topologyDef, conf);
    StormTopology topology = FluxBuilder.buildTopology(context);
    assertNotNull(topology);
    topology.validate();
}
Also used : TopologyDef(org.apache.storm.flux.model.TopologyDef) ExecutionContext(org.apache.storm.flux.model.ExecutionContext) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) Test(org.junit.Test)

Example 43 with StormTopology

use of org.apache.storm.generated.StormTopology in project storm by apache.

the class TCKTest method testInvalidTopologySource.

@Test(expected = IllegalArgumentException.class)
public void testInvalidTopologySource() throws Exception {
    TopologyDef topologyDef = FluxParser.parseResource("/configs/invalid-existing-topology.yaml", false, true, null, false);
    assertFalse("Topology config is invalid.", topologyDef.validate());
    Config conf = FluxBuilder.buildConfig(topologyDef);
    ExecutionContext context = new ExecutionContext(topologyDef, conf);
    StormTopology topology = FluxBuilder.buildTopology(context);
}
Also used : TopologyDef(org.apache.storm.flux.model.TopologyDef) ExecutionContext(org.apache.storm.flux.model.ExecutionContext) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) Test(org.junit.Test)

Example 44 with StormTopology

use of org.apache.storm.generated.StormTopology in project storm by apache.

the class TCKTest method testHbase.

@Test
public void testHbase() throws Exception {
    TopologyDef topologyDef = FluxParser.parseResource("/configs/simple_hbase.yaml", false, true, null, false);
    Config conf = FluxBuilder.buildConfig(topologyDef);
    ExecutionContext context = new ExecutionContext(topologyDef, conf);
    StormTopology topology = FluxBuilder.buildTopology(context);
    assertNotNull(topology);
    topology.validate();
}
Also used : TopologyDef(org.apache.storm.flux.model.TopologyDef) ExecutionContext(org.apache.storm.flux.model.ExecutionContext) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) Test(org.junit.Test)

Example 45 with StormTopology

use of org.apache.storm.generated.StormTopology in project storm by apache.

the class FluxBuilder method buildTopology.

/**
     * Given a topology definition, return a Storm topology that can be run either locally or remotely.
     *
     * @param context
     * @return
     * @throws IllegalAccessException
     * @throws InstantiationException
     * @throws ClassNotFoundException
     * @throws NoSuchMethodException
     * @throws InvocationTargetException
     */
public static StormTopology buildTopology(ExecutionContext context) throws IllegalAccessException, InstantiationException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
    StormTopology topology = null;
    TopologyDef topologyDef = context.getTopologyDef();
    if (!topologyDef.validate()) {
        throw new IllegalArgumentException("Invalid topology config. Spouts, bolts and streams cannot be " + "defined in the same configuration as a topologySource.");
    }
    // build components that may be referenced by spouts, bolts, etc.
    // the map will be a String --> Object where the object is a fully
    // constructed class instance
    buildComponents(context);
    if (topologyDef.isDslTopology()) {
        // This is a DSL (YAML, etc.) topology...
        LOG.info("Detected DSL topology...");
        TopologyBuilder builder = new TopologyBuilder();
        // create spouts
        buildSpouts(context, builder);
        // we need to be able to lookup bolts by id, then switch based
        // on whether they are IBasicBolt or IRichBolt instances
        buildBolts(context);
        // process stream definitions
        buildStreamDefinitions(context, builder);
        topology = builder.createTopology();
    } else {
        // user class supplied...
        // this also provides a bridge to Trident...
        LOG.info("A topology source has been specified...");
        ObjectDef def = topologyDef.getTopologySource();
        topology = buildExternalTopology(def, context);
    }
    return topology;
}
Also used : StormTopology(org.apache.storm.generated.StormTopology)

Aggregations

StormTopology (org.apache.storm.generated.StormTopology)76 Test (org.junit.Test)45 Config (org.apache.storm.Config)38 HashMap (java.util.HashMap)31 ExecutionContext (org.apache.storm.flux.model.ExecutionContext)20 TopologyDef (org.apache.storm.flux.model.TopologyDef)20 Map (java.util.Map)17 ArrayList (java.util.ArrayList)14 Bolt (org.apache.storm.generated.Bolt)13 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)13 List (java.util.List)11 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)11 Grouping (org.apache.storm.generated.Grouping)10 SpoutSpec (org.apache.storm.generated.SpoutSpec)10 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)10 NullStruct (org.apache.storm.generated.NullStruct)9 INimbus (org.apache.storm.scheduler.INimbus)9 IRichBolt (org.apache.storm.topology.IRichBolt)9 Cluster (org.apache.storm.scheduler.Cluster)8 ExecutorDetails (org.apache.storm.scheduler.ExecutorDetails)8