use of org.apache.heron.streamlet.Runner in project heron by twitter.
the class FormattedOutputTopology method main.
public static void main(String[] args) throws Exception {
Builder processingGraphBuilder = Builder.newBuilder();
processingGraphBuilder.newSource(SensorReading::new).filter(reading -> reading.getHumidity() < .9 && reading.getTemperature() < 90).consume(reading -> LOG.info(String.format("Reading from device %s: (temp: %f, humidity: %f)", reading.getDeviceId(), reading.getTemperature(), reading.getHumidity())));
// Fetches the topology name from the first command-line argument
String topologyName = StreamletUtils.getTopologyName(args);
Config config = Config.defaultConfig();
// Finally, the processing graph and configuration are passed to the Runner, which converts
// the graph into a Heron topology that can be run in a Heron cluster.
new Runner().run(topologyName, config, processingGraphBuilder);
}
use of org.apache.heron.streamlet.Runner in project heron by twitter.
the class ImpressionsAndClicksTopology method main.
/**
* All Heron topologies require a main function that defines the topology's behavior
* at runtime
*/
public static void main(String[] args) throws Exception {
Builder processingGraphBuilder = Builder.newBuilder();
// A KVStreamlet is produced. Each element is a KeyValue object where the key
// is the impression ID and the user ID is the value.
Streamlet<AdImpression> impressions = processingGraphBuilder.newSource(AdImpression::new);
// A KVStreamlet is produced. Each element is a KeyValue object where the key
// is the ad ID and the user ID is the value.
Streamlet<AdClick> clicks = processingGraphBuilder.newSource(AdClick::new);
/**
* Here, the impressions KVStreamlet is joined to the clicks KVStreamlet.
*/
impressions.join(// The other streamlet that's being joined to
clicks, // Key extractor for the impressions streamlet
impression -> impression.getUserId(), // Key extractor for the clicks streamlet
click -> click.getUserId(), // Window configuration for the join operation
WindowConfig.TumblingCountWindow(25), // Join type (inner join means that all elements from both streams will be included)
JoinType.INNER, // if the ad IDs match between the elements (or a value of 0 if they don't).
(user1, user2) -> (user1.getAdId().equals(user2.getAdId())) ? 1 : 0).reduceByKeyAndWindow(// Key extractor for the reduce operation
kv -> String.format("user-%s", kv.getKey().getKey()), // Value extractor for the reduce operation
kv -> kv.getValue(), // Window configuration for the reduce operation
WindowConfig.TumblingCountWindow(50), // A running cumulative total is calculated for each key
(cumulative, incoming) -> cumulative + incoming).consume(kw -> {
LOG.info(String.format("(user: %s, clicks: %d)", kw.getKey().getKey(), kw.getValue()));
});
Config config = Config.defaultConfig();
// Fetches the topology name from the first command-line argument
String topologyName = StreamletUtils.getTopologyName(args);
// Finally, the processing graph and configuration are passed to the Runner, which converts
// the graph into a Heron topology that can be run in a Heron cluster.
new Runner().run(topologyName, config, processingGraphBuilder);
}
use of org.apache.heron.streamlet.Runner in project heron by twitter.
the class RepartitionTopology method main.
/**
* All Heron topologies require a main function that defines the topology's behavior
* at runtime
*/
public static void main(String[] args) throws Exception {
Builder processingGraphBuilder = Builder.newBuilder();
Streamlet<Integer> randomIntegers = processingGraphBuilder.newSource(() -> {
// Random integers are emitted every 50 milliseconds
StreamletUtils.sleep(50);
return ThreadLocalRandom.current().nextInt(100);
}).setNumPartitions(2).setName("random-integer-source");
randomIntegers.repartition(8, RepartitionTopology::repartitionStreamlet).setName("repartition-incoming-values").repartition(2).setName("reduce-partitions-for-logging-operation").log();
// Fetches the topology name from the first command-line argument
String topologyName = StreamletUtils.getTopologyName(args);
Config config = Config.defaultConfig();
// Finally, the processing graph and configuration are passed to the Runner, which converts
// the graph into a Heron topology that can be run in a Heron cluster.
new Runner().run(topologyName, config, processingGraphBuilder);
}
use of org.apache.heron.streamlet.Runner in project heron by twitter.
the class IntegerProcessingTopology method main.
/**
* All Heron topologies require a main function that defines the topology's behavior
* at runtime
*/
public static void main(String[] args) throws Exception {
Builder builder = Builder.newBuilder();
Streamlet<Integer> zeroes = builder.newSource(() -> 0);
builder.newSource(() -> ThreadLocalRandom.current().nextInt(1, 11)).setName("random-ints").map(i -> i + 1).setName("add-one").union(zeroes).setName("unify-streams").filter(i -> i != 2).setName("remove-twos").log();
Config config = Config.newBuilder().setNumContainers(NUM_CONTAINERS).setPerContainerRamInGigabytes(GIGABYTES_OF_RAM).setPerContainerCpu(CPU).build();
// Fetches the topology name from the first command-line argument
String topologyName = StreamletUtils.getTopologyName(args);
// Finally, the processing graph and configuration are passed to the Runner, which converts
// the graph into a Heron topology that can be run in a Heron cluster.
new Runner().run(topologyName, config, builder);
}
use of org.apache.heron.streamlet.Runner in project heron by twitter.
the class StreamletCloneTopology method main.
/**
* All Heron topologies require a main function that defines the topology's behavior
* at runtime
*/
public static void main(String[] args) throws Exception {
Builder processingGraphBuilder = Builder.newBuilder();
/**
* A supplier streamlet of random GameScore objects is cloned into two
* separate streamlets.
*/
List<Streamlet<GameScore>> splitGameScoreStreamlet = processingGraphBuilder.newSource(GameScore::new).clone(2);
/**
* Elements in the first cloned streamlet go to the database sink.
*/
splitGameScoreStreamlet.get(0).toSink(new DatabaseSink()).setName("sink0");
/**
* Elements in the second cloned streamlet go to the logging sink.
*/
splitGameScoreStreamlet.get(1).toSink(new FormattedLogSink()).setName("sink1");
Config config = Config.defaultConfig();
// Fetches the topology name from the first command-line argument
String topologyName = StreamletUtils.getTopologyName(args);
// Finally, the processing graph and configuration are passed to the Runner, which converts
// the graph into a Heron topology that can be run in a Heron cluster.
new Runner().run(topologyName, config, processingGraphBuilder);
}
Aggregations