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(); }
/** * Creates a topology with device-id and count (which are whole numbers) as * tuple fields in a stream and it finally generates result stream based on * min amd max with device-id and count values. */ public static StormTopology buildDevicesTopology() { String deviceID = "device-id"; String count = "count"; Fields allFields = new Fields(deviceID, count); RandomNumberGeneratorSpout spout = new RandomNumberGeneratorSpout(allFields, 10, 1000); TridentTopology topology = new TridentTopology(); Stream devicesStream = topology.newStream("devicegen-spout", spout).each(allFields, new Debug("##### devices")); devicesStream.minBy(deviceID).each(allFields, new Debug("#### device with min id")); devicesStream.maxBy(count).each(allFields, new Debug("#### device with max count")); return topology.build(); }
public Stream join(List<Stream> streams, List<Fields> joinFields, Fields outFields) { return join(streams, joinFields, outFields, JoinType.INNER); }
private static void completeDRPC(DefaultDirectedGraph<Node, IndexedEdge> graph, Map<String, List<Node>> colocate, UniqueIdGen gen) { List<Set<Node>> connectedComponents = new ConnectivityInspector<>(graph).connectedSets(); for(Set<Node> g: connectedComponents) { checkValidJoins(g); } TridentTopology helper = new TridentTopology(graph, colocate, gen); for(Set<Node> g: connectedComponents) { SpoutNode drpcNode = getDRPCSpoutNode(g); if(drpcNode!=null) { Stream lastStream = new Stream(helper, null, getLastAddedNode(g)); Stream s = new Stream(helper, null, drpcNode); helper.multiReduce( s.project(new Fields("return-info")) .batchGlobal(), lastStream.batchGlobal(), new ReturnResultsReducer(), new Fields()); } } }
public static StormTopology buildTopology(TransactionalTridentKafkaSpout spout) throws IOException { TridentTopology topology = new TridentTopology(); .newStream("tweets", spout) .each(new Fields("str"), new ParseTweet(), new Fields("text", "content", "user")); topology.join(hashtags, new Fields("tweetId"), urls, new Fields("tweetId"), new Fields("tweetId", "hashtag", "url")) .each(new Fields("tweetId", "hashtag", "url"), new Print()); return topology.build();
stream = tridentTopology.newDRPCStream(drpcFunction); setActiveStream(ActiveStream.STREAM); topology, component, isClusterMode, configuration); stream = tridentTopology.newStream(component.getKey(), richSpoutWrapper); setActiveStream(ActiveStream.STREAM); topology, component, isClusterMode, configuration); stream = tridentTopology.newStream(component.getKey(), tridentSpoutWrapper); setActiveStream(ActiveStream.STREAM); topology, component, isClusterMode, configuration); stream = tridentTopology.newStream(component.getKey(), batchSpoutWrapper); setActiveStream(ActiveStream.STREAM); topology, component, isClusterMode, configuration); stream = tridentTopology.newStream(component.getKey(), batchSpoutWrapper); setActiveStream(ActiveStream.STREAM); stream = tridentTopology.newStream(component.getKey(), batchSpoutWrapper); setActiveStream(ActiveStream.STREAM); return tridentTopology.build();
public Stream newStream(String txId, ITridentDataSource dataSource) { if (dataSource instanceof IBatchSpout) { return newStream(txId, (IBatchSpout) dataSource); } else if (dataSource instanceof ITridentSpout) { return newStream(txId, (ITridentSpout) dataSource); } else if (dataSource instanceof IPartitionedTridentSpout) { return newStream(txId, (IPartitionedTridentSpout) dataSource); } else if (dataSource instanceof IOpaquePartitionedTridentSpout) { return newStream(txId, (IOpaquePartitionedTridentSpout) dataSource); } else { throw new UnsupportedOperationException("Unsupported stream"); } }
public static TridentTopology pageviewsOverTime() { TridentTopology topology = new TridentTopology(); TridentKafkaConfig kafkaConfig = new TridentKafkaConfig( topology.newStream( "pageviewsOverTime", new TransactionalTridentKafkaSpout(
public Stream newDRPCStream(String function) { return newDRPCStream(new DRPCSpout(function)); }
public static LocalCluster runPageviews() { LocalCluster cluster = new LocalCluster(); Config conf = new Config(); cluster.submitTopology("pageviews", conf, pageviewsOverTime().build()); return cluster; }
public TridentState newStaticState(StateFactory factory) { return newStaticState(new StateSpec(factory)); }
public Stream newStream(String txId, IPartitionedTridentSpout spout) { return newStream(txId, new PartitionedTridentSpoutExecutor(spout)); }
private static void completeDRPC(DefaultDirectedGraph<Node, IndexedEdge> graph, Map<String, List<Node>> colocate, UniqueIdGen gen) { List<Set<Node>> connectedComponents = new ConnectivityInspector<>(graph).connectedSets(); for(Set<Node> g: connectedComponents) { checkValidJoins(g); } TridentTopology helper = new TridentTopology(graph, colocate, gen); for(Set<Node> g: connectedComponents) { SpoutNode drpcNode = getDRPCSpoutNode(g); if(drpcNode!=null) { Stream lastStream = new Stream(helper, null, getLastAddedNode(g)); Stream s = new Stream(helper, null, drpcNode); helper.multiReduce( s.project(new Fields("return-info")) .batchGlobal(), lastStream.batchGlobal(), new ReturnResultsReducer(), new Fields()); } } }
public static TridentTopology bounceRateOverTime() { TridentTopology topology = new TridentTopology(); TridentKafkaConfig kafkaConfig = new TridentKafkaConfig( opts.colSerializer = StringSerializer.get(); topology.newStream( "bounceRate", new TransactionalTridentKafkaSpout(kafkaConfig))
public Stream newDRPCStream(String function, ILocalDRPC server) { DRPCSpout spout; if(server==null) { spout = new DRPCSpout(function); } else { spout = new DRPCSpout(function, server); } return newDRPCStream(spout); }
public static LocalCluster runBounces() { LocalCluster cluster = new LocalCluster(); Config conf = new Config(); cluster.submitTopology("bounces", conf, bounceRateOverTime().build()); return cluster; } }
public TridentState newStaticState(StateFactory factory) { return newStaticState(new StateSpec(factory)); }
public static StormTopology buildTopology(LocalDRPC drpc) { FixedBatchSpout spout = new FixedBatchSpout(new Fields("word"), 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).flatMap(split).map(toUpper) .filter(theFilter).peek(new Consumer() { @Override public void accept(TridentTuple input) { System.out.println(input.getString(0)); } }).groupBy(new Fields("word")) .persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")) .parallelismHint(16); topology.newDRPCStream("words", drpc).flatMap(split).groupBy(new Fields("args")) .stateQuery(wordCounts, new Fields("args"), new MapGet(), new Fields("count")).filter(new FilterNull()) .aggregate(new Fields("count"), new Sum(), new Fields("sum")); return topology.build(); }