Search in sources :

Example 1 with TupleDruidEventMapper

use of org.apache.storm.druid.bolt.TupleDruidEventMapper in project storm by apache.

the class SampleDruidBoltTopology method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        throw new IllegalArgumentException("There should be at least one argument. Run as `SampleDruidBoltTopology <zk-url>`");
    }
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    topologyBuilder.setSpout("event-gen", new SimpleSpout(), 5);
    DruidBeamFactory druidBeamFactory = new SampleDruidBeamFactoryImpl(new HashMap<String, Object>());
    DruidConfig.Builder builder = DruidConfig.newBuilder().discardStreamId(DruidConfig.DEFAULT_DISCARD_STREAM_ID);
    ITupleDruidEventMapper<Map<String, Object>> eventMapper = new TupleDruidEventMapper<>(TupleDruidEventMapper.DEFAULT_FIELD_NAME);
    DruidBeamBolt<Map<String, Object>> druidBolt = new DruidBeamBolt<Map<String, Object>>(druidBeamFactory, eventMapper, builder);
    topologyBuilder.setBolt("druid-bolt", druidBolt).shuffleGrouping("event-gen");
    topologyBuilder.setBolt("printer-bolt", new PrinterBolt()).shuffleGrouping("druid-bolt", DruidConfig.DEFAULT_DISCARD_STREAM_ID);
    Config conf = new Config();
    conf.setDebug(true);
    conf.put("druid.tranquility.zk.connect", args[0]);
    if (args.length > 1) {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopologyWithProgressBar(args[1], conf, topologyBuilder.createTopology());
    } else {
        conf.setMaxTaskParallelism(3);
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("druid-test", conf, topologyBuilder.createTopology())) {
            Thread.sleep(30000);
        }
        System.exit(0);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) DruidConfig(org.apache.storm.druid.bolt.DruidConfig) Config(org.apache.storm.Config) DruidBeamFactory(org.apache.storm.druid.bolt.DruidBeamFactory) DruidConfig(org.apache.storm.druid.bolt.DruidConfig) LocalTopology(org.apache.storm.LocalCluster.LocalTopology) DruidBeamBolt(org.apache.storm.druid.bolt.DruidBeamBolt) TupleDruidEventMapper(org.apache.storm.druid.bolt.TupleDruidEventMapper) ITupleDruidEventMapper(org.apache.storm.druid.bolt.ITupleDruidEventMapper) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with TupleDruidEventMapper

use of org.apache.storm.druid.bolt.TupleDruidEventMapper in project storm by apache.

the class SampleDruidBoltTridentTopology method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        throw new IllegalArgumentException("There should be at least one argument. Run as `SampleDruidBoltTridentTopology <zk-url>`");
    }
    TridentTopology tridentTopology = new TridentTopology();
    DruidBeamFactory druidBeamFactory = new SampleDruidBeamFactoryImpl(new HashMap<String, Object>());
    ITupleDruidEventMapper<Map<String, Object>> eventMapper = new TupleDruidEventMapper<>(TupleDruidEventMapper.DEFAULT_FIELD_NAME);
    final Stream stream = tridentTopology.newStream("batch-event-gen", new SimpleBatchSpout(10));
    stream.peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            LOG.info("########### Received tuple: [{}]", input);
        }
    }).partitionPersist(new DruidBeamStateFactory<Map<String, Object>>(druidBeamFactory, eventMapper), new Fields("event"), new DruidBeamStateUpdater());
    Config conf = new Config();
    conf.setDebug(true);
    conf.put("druid.tranquility.zk.connect", args[0]);
    if (args.length > 1) {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopologyWithProgressBar(args[1], conf, tridentTopology.build());
    } else {
        conf.setMaxTaskParallelism(3);
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("druid-test", conf, tridentTopology.build())) {
            Thread.sleep(30000);
        }
        System.exit(0);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Config(org.apache.storm.Config) DruidBeamFactory(org.apache.storm.druid.bolt.DruidBeamFactory) DruidBeamStateUpdater(org.apache.storm.druid.trident.DruidBeamStateUpdater) LocalTopology(org.apache.storm.LocalCluster.LocalTopology) Fields(org.apache.storm.tuple.Fields) Consumer(org.apache.storm.trident.operation.Consumer) TridentTopology(org.apache.storm.trident.TridentTopology) TupleDruidEventMapper(org.apache.storm.druid.bolt.TupleDruidEventMapper) ITupleDruidEventMapper(org.apache.storm.druid.bolt.ITupleDruidEventMapper) Stream(org.apache.storm.trident.Stream) HashMap(java.util.HashMap) Map(java.util.Map) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 Config (org.apache.storm.Config)2 LocalCluster (org.apache.storm.LocalCluster)2 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)2 DruidBeamFactory (org.apache.storm.druid.bolt.DruidBeamFactory)2 ITupleDruidEventMapper (org.apache.storm.druid.bolt.ITupleDruidEventMapper)2 TupleDruidEventMapper (org.apache.storm.druid.bolt.TupleDruidEventMapper)2 DruidBeamBolt (org.apache.storm.druid.bolt.DruidBeamBolt)1 DruidConfig (org.apache.storm.druid.bolt.DruidConfig)1 DruidBeamStateUpdater (org.apache.storm.druid.trident.DruidBeamStateUpdater)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1 Stream (org.apache.storm.trident.Stream)1 TridentTopology (org.apache.storm.trident.TridentTopology)1 Consumer (org.apache.storm.trident.operation.Consumer)1 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)1 Fields (org.apache.storm.tuple.Fields)1