Search in sources :

Example 21 with TopologyBuilder

use of org.apache.heron.api.topology.TopologyBuilder in project heron by twitter.

the class EcoBuilder method buildTopologyBuilder.

public TopologyBuilder buildTopologyBuilder(EcoExecutionContext executionContext, ObjectBuilder objectBuilder) throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchFieldException, InvocationTargetException {
    TopologyBuilder builder = new TopologyBuilder();
    LOG.info("Building components");
    componentBuilder.buildComponents(executionContext, objectBuilder);
    LOG.info("Building spouts");
    spoutBuilder.buildSpouts(executionContext, builder, objectBuilder);
    LOG.info("Building bolts");
    boltBuilder.buildBolts(executionContext, objectBuilder);
    LOG.info("Building streams");
    streamBuilder.buildStreams(executionContext, builder, objectBuilder);
    return builder;
}
Also used : TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder)

Example 22 with TopologyBuilder

use of org.apache.heron.api.topology.TopologyBuilder in project heron by twitter.

the class HeronKafkaSpoutSampleTopology method main.

public static void main(String[] args) {
    Map<String, Object> kafkaConsumerConfig = new HashMap<>();
    kafkaConsumerConfig.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
    kafkaConsumerConfig.put(ConsumerConfig.GROUP_ID_CONFIG, "sample-kafka-spout");
    kafkaConsumerConfig.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
    kafkaConsumerConfig.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
    LOG.info("Kafka Consumer Config: {}", kafkaConsumerConfig);
    KafkaConsumerFactory<String, String> kafkaConsumerFactory = new DefaultKafkaConsumerFactory<>(kafkaConsumerConfig);
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    topologyBuilder.setSpout(KAFKA_SPOUT_NAME, new KafkaSpout<>(kafkaConsumerFactory, Collections.singletonList("test-topic")));
    topologyBuilder.setBolt(LOGGING_BOLT_NAME, new LoggingBolt()).shuffleGrouping(KAFKA_SPOUT_NAME);
    Config config = new Config();
    config.setNumStmgrs(1);
    config.setContainerCpuRequested(1);
    config.setContainerRamRequested(ByteAmount.fromGigabytes(1));
    config.setContainerDiskRequested(ByteAmount.fromGigabytes(1));
    config.setComponentCpu(KAFKA_SPOUT_NAME, 0.25);
    config.setComponentRam(KAFKA_SPOUT_NAME, ByteAmount.fromMegabytes(256));
    config.setComponentDisk(KAFKA_SPOUT_NAME, ByteAmount.fromMegabytes(512));
    config.setComponentCpu(LOGGING_BOLT_NAME, 0.25);
    config.setComponentRam(LOGGING_BOLT_NAME, ByteAmount.fromMegabytes(256));
    config.setComponentDisk(LOGGING_BOLT_NAME, ByteAmount.fromMegabytes(256));
    Simulator simulator = new Simulator();
    simulator.submitTopology("heron-kafka-spout-sample-topology", config, topologyBuilder.createTopology());
}
Also used : HashMap(java.util.HashMap) TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) Config(org.apache.heron.api.Config) DefaultKafkaConsumerFactory(org.apache.heron.spouts.kafka.DefaultKafkaConsumerFactory) Simulator(org.apache.heron.simulator.Simulator)

Example 23 with TopologyBuilder

use of org.apache.heron.api.topology.TopologyBuilder in project heron by twitter.

the class AbstractTupleRoutingTest method constructPhysicalPlan.

private PhysicalPlans.PhysicalPlan constructPhysicalPlan() {
    PhysicalPlans.PhysicalPlan.Builder physicalPlanBuilder = PhysicalPlans.PhysicalPlan.newBuilder();
    // Set topology protobuf
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    initSpout(topologyBuilder, Component.SPOUT.getName());
    initBoltA(topologyBuilder, Component.BOLT_A.getName(), Component.SPOUT.getName());
    initBoltB(topologyBuilder, Component.BOLT_B.getName(), Component.BOLT_A.getName());
    Config conf = new Config();
    conf.setTeamEmail("some-team@company.com");
    conf.setTeamName("some-team");
    conf.setTopologyProjectName("heron-integration-test");
    conf.setNumStmgrs(1);
    conf.setMaxSpoutPending(100);
    conf.setTopologyReliabilityMode(Config.TopologyReliabilityMode.ATMOST_ONCE);
    TopologyAPI.Topology topology = topologyBuilder.createTopology().setName("topology-name").setConfig(conf).setState(TopologyAPI.TopologyState.RUNNING).getTopology();
    physicalPlanBuilder.setTopology(topology);
    // Set instances
    int taskId = 0;
    for (Component component : Component.values()) {
        addComponent(physicalPlanBuilder, component, taskId++);
    }
    // Set stream mgr
    PhysicalPlans.StMgr.Builder stmgr = PhysicalPlans.StMgr.newBuilder();
    stmgr.setId("stream-manager-id");
    stmgr.setHostName("127.0.0.1");
    stmgr.setDataPort(8888);
    stmgr.setLocalEndpoint("endpoint");
    physicalPlanBuilder.addStmgrs(stmgr);
    return physicalPlanBuilder.build();
}
Also used : TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) Config(org.apache.heron.api.Config) TopologyAPI(org.apache.heron.api.generated.TopologyAPI)

Example 24 with TopologyBuilder

use of org.apache.heron.api.topology.TopologyBuilder in project heron by twitter.

the class ExclamationTopology method main.

public static void main(String[] args) throws Exception {
    TopologyBuilder builder = new TopologyBuilder();
    int parallelism = 2;
    int spouts = parallelism;
    builder.setSpout("word", new TestWordSpout(Duration.ofMillis(0)), spouts);
    int bolts = 2 * parallelism;
    builder.setBolt("exclaim1", new ExclamationBolt(), bolts).shuffleGrouping("word");
    Config conf = new Config();
    conf.setDebug(true);
    conf.setMaxSpoutPending(10);
    conf.setMessageTimeoutSecs(600);
    conf.put(Config.TOPOLOGY_WORKER_CHILDOPTS, "-XX:+HeapDumpOnOutOfMemoryError");
    // resources configuration
    conf.setComponentRam("word", ExampleResources.getComponentRam());
    conf.setComponentRam("exclaim1", ExampleResources.getComponentRam());
    conf.setContainerDiskRequested(ExampleResources.getContainerDisk(spouts + bolts, parallelism));
    conf.setContainerRamRequested(ExampleResources.getContainerRam(spouts + bolts, parallelism));
    conf.setContainerCpuRequested(ExampleResources.getContainerCpu(spouts + bolts, parallelism));
    if (args != null && args.length > 0) {
        conf.setNumStmgrs(parallelism);
        HeronSubmitter.submitTopology(args[0], conf, builder.createTopology());
    } else {
        System.out.println("Topology name not provided as an argument, running in simulator mode.");
        Simulator simulator = new Simulator();
        simulator.submitTopology("test", conf, builder.createTopology());
        Utils.sleep(10000);
        simulator.killTopology("test");
        simulator.shutdown();
    }
}
Also used : TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) Config(org.apache.heron.api.Config) TestWordSpout(org.apache.heron.examples.api.spout.TestWordSpout) Simulator(org.apache.heron.simulator.Simulator)

Example 25 with TopologyBuilder

use of org.apache.heron.api.topology.TopologyBuilder in project heron by twitter.

the class SlidingWindowTopology method main.

public static void main(String[] args) throws Exception {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("integer", new RandomIntegerSpout(), 1);
    builder.setBolt("slidingsum", new SlidingWindowSumBolt().withWindow(BaseWindowedBolt.Count.of(30), BaseWindowedBolt.Count.of(10)), 1).shuffleGrouping("integer");
    builder.setBolt("tumblingavg", new TumblingWindowAvgBolt().withTumblingWindow(BaseWindowedBolt.Count.of(3)), 1).shuffleGrouping("slidingsum");
    builder.setBolt("printer", new PrinterBolt(), 1).shuffleGrouping("tumblingavg");
    Config conf = new Config();
    conf.setDebug(true);
    String topoName = "test";
    conf.setComponentRam("integer", ByteAmount.fromGigabytes(1));
    conf.setComponentRam("slidingsum", ByteAmount.fromGigabytes(1));
    conf.setComponentRam("tumblingavg", ByteAmount.fromGigabytes(1));
    conf.setComponentRam("printer", ByteAmount.fromGigabytes(1));
    conf.setContainerDiskRequested(ByteAmount.fromGigabytes(5));
    conf.setContainerCpuRequested(4);
    if (args != null && args.length > 0) {
        topoName = args[0];
    }
    HeronSubmitter.submitTopology(topoName, conf, builder.createTopology());
}
Also used : TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) Config(org.apache.heron.api.Config) RandomIntegerSpout(org.apache.heron.examples.api.spout.RandomIntegerSpout) SlidingWindowSumBolt(org.apache.heron.examples.api.bolt.SlidingWindowSumBolt) PrinterBolt(org.apache.heron.examples.api.bolt.PrinterBolt)

Aggregations

TopologyBuilder (org.apache.heron.api.topology.TopologyBuilder)41 Config (org.apache.heron.api.Config)19 Test (org.junit.Test)15 HashMap (java.util.HashMap)8 Fields (org.apache.heron.api.tuple.Fields)6 Simulator (org.apache.heron.simulator.Simulator)6 TestWordSpout (org.apache.heron.examples.api.spout.TestWordSpout)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Duration (java.time.Duration)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 List (java.util.List)3 Set (java.util.Set)3 Consumer (java.util.function.Consumer)3 Function (java.util.function.Function)3 HeronTopology (org.apache.heron.api.HeronTopology)3 ShuffleStreamGrouping (org.apache.heron.api.grouping.ShuffleStreamGrouping)3 Utils (org.apache.heron.api.utils.Utils)3