Search in sources :

Example 1 with OpenTsdbStateFactory

use of org.apache.storm.opentsdb.trident.OpenTsdbStateFactory in project storm by apache.

the class SampleOpenTsdbTridentTopology 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 `SampleOpenTsdbTridentTopology <tsdb-url>`");
    }
    String tsdbUrl = args[0];
    final OpenTsdbClient.Builder openTsdbClientBuilder = OpenTsdbClient.newBuilder(tsdbUrl);
    final OpenTsdbStateFactory openTsdbStateFactory = new OpenTsdbStateFactory(openTsdbClientBuilder, Collections.singletonList(TupleOpenTsdbDatapointMapper.DEFAULT_MAPPER));
    TridentTopology tridentTopology = new TridentTopology();
    final Stream stream = tridentTopology.newStream("metric-tsdb-stream", new MetricGenBatchSpout(10));
    stream.peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            LOG.info("########### Received tuple: [{}]", input);
        }
    }).partitionPersist(openTsdbStateFactory, MetricGenSpout.DEFAULT_METRIC_FIELDS, new OpenTsdbStateUpdater());
    Config conf = new Config();
    conf.setDebug(true);
    String topoName = "word-count";
    if (args.length > 1) {
        topoName = args[1];
    }
    conf.setNumWorkers(3);
    StormSubmitter.submitTopologyWithProgressBar(topoName, conf, tridentTopology.build());
}
Also used : OpenTsdbClient(org.apache.storm.opentsdb.client.OpenTsdbClient) Consumer(org.apache.storm.trident.operation.Consumer) TridentTopology(org.apache.storm.trident.TridentTopology) Config(org.apache.storm.Config) OpenTsdbStateUpdater(org.apache.storm.opentsdb.trident.OpenTsdbStateUpdater) OpenTsdbStateFactory(org.apache.storm.opentsdb.trident.OpenTsdbStateFactory) Stream(org.apache.storm.trident.Stream) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Aggregations

Config (org.apache.storm.Config)1 OpenTsdbClient (org.apache.storm.opentsdb.client.OpenTsdbClient)1 OpenTsdbStateFactory (org.apache.storm.opentsdb.trident.OpenTsdbStateFactory)1 OpenTsdbStateUpdater (org.apache.storm.opentsdb.trident.OpenTsdbStateUpdater)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