Package storm.trident

Examples of storm.trident.TridentTopology


    }

  }

  public static StormTopology buildTopology(LocalDRPC drpc) {
    TridentTopology topology = new TridentTopology();
    TridentState urlToTweeters = topology.newStaticState(new StaticSingleKeyMapState.Factory(TWEETERS_DB));
    TridentState tweetersToFollowers = topology.newStaticState(new StaticSingleKeyMapState.Factory(FOLLOWERS_DB));


    topology.newDRPCStream("reach", drpc).stateQuery(urlToTweeters, new Fields("args"), new MapGet(), new Fields(
        "tweeters")).each(new Fields("tweeters"), new ExpandList(), new Fields("tweeter")).shuffle().stateQuery(
        tweetersToFollowers, new Fields("tweeter"), new MapGet(), new Fields("followers")).each(new Fields("followers"),
        new ExpandList(), new Fields("follower")).groupBy(new Fields("follower")).aggregate(new One(), new Fields(
        "one")).aggregate(new Fields("one"), new Sum(), new Fields("reach"));
    return topology.build();
  }
View Full Code Here


                .withRowToStormValueMapper(rowToStormValueMapper)
                .withTableName("WordCount");

        StateFactory factory = new HBaseStateFactory(options);

        TridentTopology topology = new TridentTopology();
        Stream stream = topology.newStream("spout1", spout);

        stream.partitionPersist(factory, fields,  new HBaseUpdater(), new Fields());

        TridentState state = topology.newStaticState(factory);
        stream = stream.stateQuery(state, new Fields("word"), new HBaseQuery(), new Fields("columnName","columnValue"));
        stream.each(new Fields("word","columnValue"), new PrintFunction(), new Fields());
        return topology.build();
    }
View Full Code Here

  private final static DateTimeFormatter DAY_FORMAT = DateTimeFormat.forPattern("yyyyMMdd");

  public static StormTopology buildTopology(LocalDRPC drpc) {

    TridentTopology topology = new TridentTopology();

    String now = DAY_FORMAT.print(new Date().getTime());

    // This is just a dummy cyclic spout that only emits two tweets
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("tweet", "date"), 3,
        new Values("#california is cool", now),
        new Values("I like #california", now)
    );
    spout.setCycle(true);

    // In this state we will save the real-time counts per date for each hashtag
    StateFactory mapState = new MemoryMapState.Factory();

    // Real-time part of the system: a Trident topology that groups by hashtag and stores per-date counts
    TridentState hashTagCounts = topology
        .newStream("spout1", spout)
        // note how we carry the date around
        .each(new Fields("tweet", "date"), new Split(), new Fields("word"))
        .each(new Fields("word", "date"), new HashTagFilter(), new Fields("hashtag"))
        .groupBy(new Fields("hashtag"))
        .persistentAggregate(mapState, new Fields("hashtag", "date"), new CountByDate(),
            new Fields("datecount"));

    // Batch part of the system:
    // We instantiate a Splout connector that doesn't fail fast so we can work without the batch layer.
    // This TridentState can be used to query Splout.
    TridentState sploutState = topology.newStaticState(new SploutState.Factory(false,
        "http://localhost:4412"));

    // DRPC service:
    // Accepts a "hashtag" argument and queries first the real-time view and then the batch-view. Finally,
    // it uses a custom Function "LambdaMerge" for merging the results and projects the results back to the user.
    topology
        .newDRPCStream("hashtags", drpc)
        .each(new Fields("args"), new Split(), new Fields("hashtag"))
        .groupBy(new Fields("hashtag"))
        .stateQuery(hashTagCounts, new Fields("hashtag"), new MapGet(), new Fields("resultrt"))
        .stateQuery(sploutState, new Fields("hashtag", "resultrt"), new HashTagsSploutQuery(),
            new Fields("resultbatch"))
        .each(new Fields("hashtag", "resultrt", "resultbatch"), new LambdaMerge(), new Fields("result"))
        // Project allows us to keep only the interesting results
        .project(new Fields("result"));

    return topology.build();
  }
View Full Code Here

    FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3, new Values("the cow jumped over the moon"),
        new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"),
        new Values("how many apples can you eat"), new Values("to be or not to be the person"));
    spout.setCycle(true);

    TridentTopology topology = new TridentTopology();
    TridentState wordCounts = topology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"),
        new Split(), new Fields("word")).groupBy(new Fields("word")).persistentAggregate(new MemoryMapState.Factory(),
        new Count(), new Fields("count")).parallelismHint(16);

    topology.newDRPCStream("words", drpc).each(new Fields("args"), new Split(), new Fields("word")).groupBy(new Fields(
        "word")).stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count")).each(new Fields("count"),
        new FilterNull()).aggregate(new Fields("count"), new Sum(), new Fields("sum"));
    return topology.build();
  }
View Full Code Here

    }

  }

  public static StormTopology buildTopology(LocalDRPC drpc) {
    TridentTopology topology = new TridentTopology();
    TridentState urlToTweeters = topology.newStaticState(new StaticSingleKeyMapState.Factory(TWEETERS_DB));
    TridentState tweetersToFollowers = topology.newStaticState(new StaticSingleKeyMapState.Factory(FOLLOWERS_DB));


    topology.newDRPCStream("reach", drpc).stateQuery(urlToTweeters, new Fields("args"), new MapGet(), new Fields(
        "tweeters")).each(new Fields("tweeters"), new ExpandList(), new Fields("tweeter")).shuffle().stateQuery(
        tweetersToFollowers, new Fields("tweeter"), new MapGet(), new Fields("followers")).each(new Fields("followers"),
        new ExpandList(), new Fields("follower")).groupBy(new Fields("follower")).aggregate(new One(), new Fields(
        "one")).aggregate(new Fields("one"), new Sum(), new Fields("reach"));
    return topology.build();
  }
View Full Code Here

    LocalCluster cluster = new LocalCluster();
    LocalDRPC localDRPC = new LocalDRPC();

    try {
      // Build topology
      TridentTopology toppology = new TridentTopology();

      // Classification stream
      toppology.newDRPCStream("classify", localDRPC)
        // Query classifier with text instance
        .each(new Fields("args"), new TwitterSentimentClassifier(), new Fields("sentiment")).project(new Fields("sentiment"));

      cluster.submitTopology(this.getClass().getSimpleName(), new Config(), toppology.build());
      Thread.sleep(4000);

      // Query with DRPC
      test(false, "RT @JazminBianca: I hate Windows 8. I hate Windows 8. I hate Windows 8.", localDRPC);
      test(false, "I don't like Windows 8, I think it's overrated =))", localDRPC);
View Full Code Here

    LocalCluster cluster = new LocalCluster();
    LocalDRPC localDRPC = new LocalDRPC();

    try {
      // Build topology
      TridentTopology toppology = new TridentTopology();

      // "Training" stream
      TridentState classifierState = toppology.newStream("reutersData", new ReutersBatchSpout())
      // Transform raw data to text instance
          .each(new Fields("label", "text"), new TextInstanceCreator<Integer>(), new Fields("instance"))

          // Update text classifier
          .partitionPersist(new MemoryMapState.Factory(), new Fields("instance"), new TextClassifierUpdater<Integer>("newsClassifier", new KLDClassifier(9)));

      // Classification stream
      toppology.newDRPCStream("classify", localDRPC)
      // Convert DRPC args to text instance
          .each(new Fields("args"), new TextInstanceCreator<Integer>(false), new Fields("instance"))

          // Query classifier with text instance
          .stateQuery(classifierState, new Fields("instance"), new ClassifyTextQuery<Integer>("newsClassifier"), new Fields("prediction")).project(new Fields("prediction"));

      cluster.submitTopology(this.getClass().getSimpleName(), new Config(), toppology.build());
      Thread.sleep(4000);

      // Query with DRPC
      for (Integer realClass : ReutersBatchSpout.REUTEURS_EVAL_SAMPLES.keySet()) {
        Integer prediction = extractPrediction(localDRPC.execute("classify", ReutersBatchSpout.REUTEURS_EVAL_SAMPLES.get(realClass)));
View Full Code Here

    LocalCluster cluster = new LocalCluster();
    LocalDRPC localDRPC = new LocalDRPC();

    try {
      // Build topology
      TridentTopology toppology = new TridentTopology();

      // Training stream
      TridentState kmeansState = toppology
        // Emit tuples with a instance containing an integer as label and 3
        // double features named (x0, x1 and x2)
        .newStream("samples", new RandomFeaturesForClusteringSpout())

        // Convert trident tuple to instance
        .each(new Fields("label", "x0", "x1", "x2"), new InstanceCreator<Integer>(), new Fields("instance"))

        // Update a 3 classes kmeans
        .partitionPersist(new MemoryMapState.Factory(), new Fields("instance"), new ClusterUpdater("kmeans", new KMeans(3)));

      // Cluster stream
      toppology.newDRPCStream("predict", localDRPC)
        // Convert DRPC args to instance
        .each(new Fields("args"), new DRPCArgsToInstance(), new Fields("instance"))

        // Query kmeans to classify instance
        .stateQuery(kmeansState, new Fields("instance"), new ClusterQuery("kmeans"), new Fields("prediction"))
         
        .project(new Fields("prediction"));

      cluster.submitTopology(this.getClass().getSimpleName(), new Config(), toppology.build());

      Thread.sleep(10000);

      Integer result11 = extractPrediction(localDRPC.execute("predict", "1.0 1.0 1.0"));
      Integer result12 = extractPrediction(localDRPC.execute("predict", "0.8 1.1 0.9"));
View Full Code Here

    // Start local cluster
    LocalCluster cluster = new LocalCluster();
    LocalDRPC localDRPC = new LocalDRPC();

    try {
      TridentTopology toppology = new TridentTopology();
      MemoryMapState.Factory evaluationStateFactory = new MemoryMapState.Factory();
      MemoryMapState.Factory perceptronModelStateFactory = new MemoryMapState.Factory();
      TridentState perceptronModel = toppology.newStaticState(perceptronModelStateFactory);
      TridentState perceptronEvaluation = toppology.newStaticState(evaluationStateFactory);

      // Predict
      Stream predictionStream = toppology.newStream("nandsamples", new NANDSpout()) //
          .stateQuery(perceptronModel, new Fields("instance"), new ClassifyQuery<Boolean>("perceptron"), new Fields("prediction"));

      // Update evaluation
      predictionStream //
          .persistentAggregate(evaluationStateFactory, new Fields("instance", "prediction"), new AccuracyAggregator<Boolean>(), new Fields("accuracy"));

      // Update model
      predictionStream.partitionPersist(perceptronModelStateFactory, new Fields("instance"), new ClassifierUpdater<Boolean>("perceptron", new PerceptronClassifier()));

      // Classification stream
      toppology.newDRPCStream("predict", localDRPC)
      // convert DRPC args to instance
          .each(new Fields("args"), new DRPCArgsToInstance(), new Fields("instance"))

          // Query classifier to classify instance
          .stateQuery(perceptronModel, new Fields("instance"), new ClassifyQuery<Boolean>("perceptron"), new Fields("prediction")).project(new Fields("prediction"));

      // Evaluation stream
      toppology.newDRPCStream("evaluate", localDRPC) //
          .stateQuery(perceptronEvaluation, new EvaluationQuery<Boolean>(), new Fields("eval")) //
          .project(new Fields("eval"));

      cluster.submitTopology(this.getClass().getSimpleName(), new Config(), toppology.build());
      Thread.sleep(4000);

      assertEquals(Boolean.TRUE, extractPrediction(localDRPC.execute("predict", "1.0 0.0 0.0")));
      assertEquals(Boolean.TRUE, extractPrediction(localDRPC.execute("predict", "1.0 0.0 1.0")));
      assertEquals(Boolean.TRUE, extractPrediction(localDRPC.execute("predict", "1.0 1.0 0.0")));
View Full Code Here

    LocalDRPC localDRPC = new LocalDRPC();

    try {

      // Build topology
      TridentTopology toppology = new TridentTopology();

      TridentState scaledStreamStatistics = toppology
      // emit tuples with random features
          .newStream("originalStream", new RandomFeaturesSpout(false, 2, 3.0))

          // Transform trident tupl to instance
          .each(new Fields("x0", "x1"), new InstanceCreator(false), new Fields("instance"))

          // Update original stream statistics
          .partitionPersist(new MemoryMapState.Factory(), new Fields("instance"), new StreamStatisticsUpdater("originalStreamStats", new StreamStatistics()),
              new Fields("instance", "originalStreamStats")).newValuesStream()

          // Standardized stream using original stream statistics
          .each(new Fields("instance", "originalStreamStats"), new StandardScaler(), new Fields("scaledInstance"))

          // Update scaled stream statistics
          .partitionPersist(new MemoryMapState.Factory(), new Fields("scaledInstance"), new StreamStatisticsUpdater("scaledStreamStats", new StreamStatistics()));

      toppology.newDRPCStream("queryStats", localDRPC)
          // Convert DRPC args to stat query
          .each(new Fields("args"), new TuplifyArgs(), new Fields("featureIndex", "queryType"))

          // Query scaled stream statistics
          .stateQuery(scaledStreamStatistics, new Fields("featureIndex", "queryType"), new StreamFeatureStatisticsQuery("scaledStreamStats"), new Fields("stats"))
          .project(new Fields("stats"));

      cluster.submitTopology("testStandardScaler", new Config(), toppology.build());

      Thread.sleep(8000);

      double mean0 = extractDouble(localDRPC.execute("queryStats", "[[0, \"MEAN\"]]"));
      double mean1 = extractDouble(localDRPC.execute("queryStats", "[[1, \"MEAN\"]]"));
View Full Code Here

TOP

Related Classes of storm.trident.TridentTopology

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.