Search in sources :

Example 1 with Config

use of com.twitter.heron.streamlet.Config in project incubator-heron by apache.

the class StreamletImplTest method testConfigBuilder.

@Test
public void testConfigBuilder() {
    Config defaultConfig = Config.defaultConfig();
    assertEquals(defaultConfig.getSerializer(), Config.Serializer.KRYO);
    assertEquals(0, Double.compare(defaultConfig.getPerContainerCpu(), 1.0));
    assertEquals(defaultConfig.getPerContainerRam(), ByteAmount.fromMegabytes(100).asBytes());
    assertEquals(defaultConfig.getDeliverySemantics(), Config.DeliverySemantics.ATMOST_ONCE);
    Config nonDefaultConfig = Config.newBuilder().setDeliverySemantics(Config.DeliverySemantics.EFFECTIVELY_ONCE).setSerializer(Config.Serializer.JAVA).setPerContainerCpu(3.5).setPerContainerRamInGigabytes(10).build();
    assertEquals(nonDefaultConfig.getDeliverySemantics(), Config.DeliverySemantics.EFFECTIVELY_ONCE);
    assertEquals(nonDefaultConfig.getSerializer(), Config.Serializer.JAVA);
    assertEquals(nonDefaultConfig.getPerContainerRamAsGigabytes(), 10);
    assertEquals(nonDefaultConfig.getPerContainerRamAsMegabytes(), 1024 * 10);
    assertEquals(0, Double.compare(nonDefaultConfig.getPerContainerCpu(), 3.5));
}
Also used : Config(com.twitter.heron.streamlet.Config) WindowConfig(com.twitter.heron.streamlet.WindowConfig) Test(org.junit.Test)

Example 2 with Config

use of com.twitter.heron.streamlet.Config in project incubator-heron by apache.

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);
}
Also used : Runner(com.twitter.heron.streamlet.Runner) Config(com.twitter.heron.streamlet.Config) Builder(com.twitter.heron.streamlet.Builder)

Example 3 with Config

use of com.twitter.heron.streamlet.Config in project incubator-heron by apache.

the class SmartWatchTopology method main.

public static void main(String[] args) throws Exception {
    Builder processingGraphBuilder = Builder.newBuilder();
    processingGraphBuilder.newSource(SmartWatchReading::new).setName("incoming-watch-readings").reduceByKeyAndWindow(// Key extractor
    reading -> reading.getJoggerId(), // Value extractor
    reading -> reading.getFeetRun(), // The time window (1 minute of clock time)
    WindowConfig.TumblingTimeWindow(Duration.ofSeconds(10)), // The reduce function (produces a cumulative sum)
    (cumulative, incoming) -> cumulative + incoming).setName("reduce-to-total-distance-per-jogger").map(keyWindow -> {
        // The per-key result of the previous reduce step
        long totalFeetRun = keyWindow.getValue();
        // The amount of time elapsed
        long startTime = keyWindow.getKey().getWindow().getStartTime();
        long endTime = keyWindow.getKey().getWindow().getEndTime();
        // Cast to float to use as denominator
        long timeLengthMillis = endTime - startTime;
        // The feet-per-minute calculation
        float feetPerMinute = totalFeetRun / (float) (timeLengthMillis / 1000);
        // Reduce to two decimal places
        String paceString = new DecimalFormat("#.##").format(feetPerMinute);
        // Return a per-jogger average pace
        return new KeyValue<>(keyWindow.getKey().getKey(), paceString);
    }).setName("calculate-average-speed").consume(kv -> {
        String logMessage = String.format("(runner: %s, avgFeetPerMinute: %s)", kv.getKey(), kv.getValue());
        LOG.info(logMessage);
    });
    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);
}
Also used : Runner(com.twitter.heron.streamlet.Runner) KeyValue(com.twitter.heron.streamlet.KeyValue) Config(com.twitter.heron.streamlet.Config) WindowConfig(com.twitter.heron.streamlet.WindowConfig) Builder(com.twitter.heron.streamlet.Builder) DecimalFormat(java.text.DecimalFormat)

Example 4 with Config

use of com.twitter.heron.streamlet.Config in project incubator-heron by apache.

the class SimplePulsarSourceTopology 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 Pulsar source is constructed for a specific Pulsar installation, topic, and
     * subsecription.
     */
    Source<String> pulsarSource = new PulsarSource(// Pulsar connection URL
    "pulsar://localhost:6650", // Pulsar topic
    "persistent://sample/standalone/ns1/heron-pulsar-test-topic", // Subscription name for the Pulsar topic
    "subscription-1");
    /**
     * In this processing graph, the source streamlet consists of messages on a
     * Pulsar topic. Those messages are simply logged without any processing logic
     * applied to them.
     */
    processingGraphBuilder.newSource(pulsarSource).setName("incoming-pulsar-messages").consume(s -> LOG.info(String.format("Message received from Pulsar: \"%s\"", s)));
    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);
}
Also used : Runner(com.twitter.heron.streamlet.Runner) Config(com.twitter.heron.streamlet.Config) Builder(com.twitter.heron.streamlet.Builder)

Example 5 with Config

use of com.twitter.heron.streamlet.Config in project incubator-heron by apache.

the class WindowedWordCountTopology method main.

public static void main(String[] args) throws Exception {
    Builder processingGraphBuilder = Builder.newBuilder();
    processingGraphBuilder.newSource(() -> StreamletUtils.randomFromList(SENTENCES)).setName("random-sentences-source").flatMap(sentence -> Arrays.asList(sentence.toLowerCase().split("\\s+"))).setName("flatten-into-individual-words").reduceByKeyAndWindow(// The key extractor (the word is left unchanged)
    word -> word, // Value extractor (the value is always 1)
    word -> 1, WindowConfig.TumblingCountWindow(50), (x, y) -> x + y).setName("reduce-operation").consume(kv -> {
        String logMessage = String.format("(word: %s, count: %d)", kv.getKey().getKey(), kv.getValue());
        LOG.info(logMessage);
    });
    // The topology's parallelism (the number of containers across which the topology's
    // processing instance will be split) can be defined via the second command-line
    // argument (or else the default of 2 will be used).
    int topologyParallelism = StreamletUtils.getParallelism(args, 2);
    Config config = Config.newBuilder().setNumContainers(topologyParallelism).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, processingGraphBuilder);
}
Also used : Runner(com.twitter.heron.streamlet.Runner) Config(com.twitter.heron.streamlet.Config) WindowConfig(com.twitter.heron.streamlet.WindowConfig) Builder(com.twitter.heron.streamlet.Builder)

Aggregations

Config (com.twitter.heron.streamlet.Config)12 Builder (com.twitter.heron.streamlet.Builder)11 Runner (com.twitter.heron.streamlet.Runner)11 WindowConfig (com.twitter.heron.streamlet.WindowConfig)4 StreamletUtils (com.twitter.heron.examples.streamlet.utils.StreamletUtils)2 Streamlet (com.twitter.heron.streamlet.Streamlet)2 Serializable (java.io.Serializable)2 List (java.util.List)2 Logger (java.util.logging.Logger)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 JoinType (com.twitter.heron.streamlet.JoinType)1 KeyValue (com.twitter.heron.streamlet.KeyValue)1 File (java.io.File)1 DecimalFormat (java.text.DecimalFormat)1 Arrays (java.util.Arrays)1 Random (java.util.Random)1 UUID (java.util.UUID)1 Test (org.junit.Test)1