Search in sources :

Example 76 with TopologyBuilder

use of org.apache.storm.topology.TopologyBuilder in project storm by apache.

the class BackPressureTopo method getTopology.

static StormTopology getTopology(Map<String, Object> conf) {
    Long sleepMs = ObjectReader.getLong(conf.get(SLEEP_MS));
    // 1 -  Setup Spout   --------
    ConstSpout spout = new ConstSpout("some data").withOutputFields("string");
    // 2 -  Setup DevNull Bolt   --------
    ThrottledBolt bolt = new ThrottledBolt(sleepMs);
    // 3 - Setup Topology  --------
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(SPOUT_ID, spout, Helper.getInt(conf, SPOUT_COUNT, 1));
    BoltDeclarer bd = builder.setBolt(BOLT_ID, bolt, Helper.getInt(conf, BOLT_COUNT, 1));
    bd.localOrShuffleGrouping(SPOUT_ID);
    return builder.createTopology();
}
Also used : ConstSpout(org.apache.storm.perf.spout.ConstSpout) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) BoltDeclarer(org.apache.storm.topology.BoltDeclarer)

Example 77 with TopologyBuilder

use of org.apache.storm.topology.TopologyBuilder in project storm by apache.

the class HdfsSpoutNullBoltTopo method getTopology.

static StormTopology getTopology(Map<String, Object> config) {
    final int spoutNum = Helper.getInt(config, SPOUT_NUM, DEFAULT_SPOUT_NUM);
    final int boltNum = Helper.getInt(config, BOLT_NUM, DEFAULT_BOLT_NUM);
    final String fileFormat = Helper.getStr(config, "text");
    final String hdfsUri = Helper.getStr(config, HDFS_URI);
    final String sourceDir = Helper.getStr(config, SOURCE_DIR);
    final String archiveDir = Helper.getStr(config, ARCHIVE_DIR);
    final String badDir = Helper.getStr(config, BAD_DIR);
    // 1 -  Setup Hdfs Spout   --------
    HdfsSpout spout = new HdfsSpout().setReaderType(fileFormat).setHdfsUri(hdfsUri).setSourceDir(sourceDir).setArchiveDir(archiveDir).setBadFilesDir(badDir).withOutputFields(TextFileReader.defaultFields);
    // 2 -   DevNull Bolt   --------
    DevNullBolt bolt = new DevNullBolt();
    // 3 - Setup Topology  --------
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(SPOUT_ID, spout, spoutNum);
    builder.setBolt(BOLT_ID, bolt, boltNum).localOrShuffleGrouping(SPOUT_ID);
    return builder.createTopology();
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) DevNullBolt(org.apache.storm.perf.bolt.DevNullBolt) HdfsSpout(org.apache.storm.hdfs.spout.HdfsSpout)

Example 78 with TopologyBuilder

use of org.apache.storm.topology.TopologyBuilder in project storm by apache.

the class SimplifiedWordCountTopo method getTopology.

static StormTopology getTopology(Map<String, Object> config) {
    final int spoutNum = Helper.getInt(config, SPOUT_NUM, DEFAULT_SPOUT_NUM);
    final int cntBoltNum = Helper.getInt(config, BOLT_NUM, DEFAULT_COUNT_BOLT_NUM);
    final String inputFile = Helper.getStr(config, INPUT_FILE);
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(SPOUT_ID, new WordGenSpout(inputFile), spoutNum);
    builder.setBolt(COUNT_ID, new CountBolt(), cntBoltNum).fieldsGrouping(SPOUT_ID, new Fields(WordGenSpout.FIELDS));
    return builder.createTopology();
}
Also used : Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) WordGenSpout(org.apache.storm.perf.spout.WordGenSpout) CountBolt(org.apache.storm.perf.bolt.CountBolt)

Example 79 with TopologyBuilder

use of org.apache.storm.topology.TopologyBuilder in project storm by apache.

the class TestSequenceFileBolt method generateTestTuple.

private Tuple generateTestTuple(Long key, String value) {
    TopologyBuilder builder = new TopologyBuilder();
    GeneralTopologyContext topologyContext = new GeneralTopologyContext(builder.createTopology(), new Config(), new HashMap<>(), new HashMap<>(), new HashMap<>(), "") {

        @Override
        public Fields getComponentOutputFields(String componentId, String streamId) {
            return new Fields("key", "value");
        }
    };
    return new TupleImpl(topologyContext, new Values(key, value), topologyContext.getComponentId(1), 1, "");
}
Also used : Fields(org.apache.storm.tuple.Fields) GeneralTopologyContext(org.apache.storm.task.GeneralTopologyContext) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl)

Example 80 with TopologyBuilder

use of org.apache.storm.topology.TopologyBuilder in project storm by apache.

the class AvroGenericRecordBoltTest method generateTestTuple.

private static Tuple generateTestTuple(GenericRecord record) {
    TopologyBuilder builder = new TopologyBuilder();
    GeneralTopologyContext topologyContext = new GeneralTopologyContext(builder.createTopology(), new Config(), new HashMap(), new HashMap(), new HashMap(), "") {

        @Override
        public Fields getComponentOutputFields(String componentId, String streamId) {
            return new Fields("record");
        }
    };
    return new TupleImpl(topologyContext, new Values(record), topologyContext.getComponentId(1), 1, "");
}
Also used : Fields(org.apache.storm.tuple.Fields) GeneralTopologyContext(org.apache.storm.task.GeneralTopologyContext) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) HashMap(java.util.HashMap) Config(org.apache.storm.Config) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl)

Aggregations

TopologyBuilder (org.apache.storm.topology.TopologyBuilder)266 Config (org.apache.storm.Config)141 Fields (org.apache.storm.tuple.Fields)76 StormTopology (org.apache.storm.generated.StormTopology)47 HashMap (java.util.HashMap)41 LocalCluster (org.apache.storm.LocalCluster)39 TestWordSpout (org.apache.storm.testing.TestWordSpout)34 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)26 Test (org.junit.Test)26 Test (org.junit.jupiter.api.Test)26 Cluster (org.apache.storm.scheduler.Cluster)25 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)25 Topologies (org.apache.storm.scheduler.Topologies)25 Values (org.apache.storm.tuple.Values)25 TestUtilsForResourceAwareScheduler (org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 Map (java.util.Map)23 INimbus (org.apache.storm.scheduler.INimbus)23 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)22 ResourceMetrics (org.apache.storm.scheduler.resource.normalization.ResourceMetrics)22