Ejemplo n.º 1
0
  public static void main(String[] args) throws Exception {

    TopologyBuilder builder = new TopologyBuilder();

    builder.setSpout("spout", new RandomSentenceSpout(), 5);

    builder.setBolt("split", new SplitSentence(), 8).shuffleGrouping("spout");
    builder.setBolt("count", new WordCount(), 12).fieldsGrouping("split", new Fields("word"));

    Config conf = new Config();
    conf.setDebug(true);

    if (args != null && args.length > 0) {
      conf.setNumWorkers(3);

      StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());
    } else {
      conf.setMaxTaskParallelism(3);

      LocalCluster cluster = new LocalCluster();
      cluster.submitTopology("word-count", conf, builder.createTopology());

      Thread.sleep(10000);

      cluster.shutdown();
    }
  }
  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);

    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("word-count", conf, tridentTopology.build())) {
        Thread.sleep(30000);
      }
      System.exit(0);
    }
  }
  public static void main(String[] args) throws Exception {
    TopologyBuilder builder = new TopologyBuilder();
    BaseWindowedBolt bolt =
        new SlidingWindowSumBolt()
            .withWindow(new Duration(5, TimeUnit.SECONDS), new Duration(3, TimeUnit.SECONDS))
            .withTimestampField("ts")
            .withLag(new Duration(5, TimeUnit.SECONDS));
    builder.setSpout("integer", new RandomIntegerSpout(), 1);
    builder.setBolt("slidingsum", bolt, 1).shuffleGrouping("integer");
    builder.setBolt("printer", new PrinterBolt(), 1).shuffleGrouping("slidingsum");
    Config conf = new Config();
    conf.setDebug(true);

    if (args != null && args.length > 0) {
      conf.setNumWorkers(1);
      StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());
    } else {
      LocalCluster cluster = new LocalCluster();
      cluster.submitTopology("test", conf, builder.createTopology());
      Utils.sleep(40000);
      cluster.killTopology("test");
      cluster.shutdown();
    }
  }