Search in sources :

Example 1 with Tuple

use of com.twitter.heron.api.tuple.Tuple in project heron by twitter.

the class LaunchRunnerTest method createTopology.

public static TopologyAPI.Topology createTopology(com.twitter.heron.api.Config heronConfig) {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout-1", new BaseRichSpout() {

        private static final long serialVersionUID = -762965195665496156L;

        public void declareOutputFields(OutputFieldsDeclarer declarer) {
        }

        public void open(Map<String, Object> conf, TopologyContext context, SpoutOutputCollector collector) {
        }

        public void nextTuple() {
        }
    }, 2);
    builder.setBolt("bolt-1", new BaseBasicBolt() {

        private static final long serialVersionUID = -5738458486388778812L;

        public void execute(Tuple input, BasicOutputCollector collector) {
        }

        public void declareOutputFields(OutputFieldsDeclarer declarer) {
        }
    }, 1);
    HeronTopology heronTopology = builder.createTopology();
    return heronTopology.setName(TOPOLOGY_NAME).setConfig(heronConfig).setState(TopologyAPI.TopologyState.RUNNING).getTopology();
}
Also used : BaseBasicBolt(com.twitter.heron.api.bolt.BaseBasicBolt) TopologyBuilder(com.twitter.heron.api.topology.TopologyBuilder) HeronTopology(com.twitter.heron.api.HeronTopology) OutputFieldsDeclarer(com.twitter.heron.api.topology.OutputFieldsDeclarer) BasicOutputCollector(com.twitter.heron.api.bolt.BasicOutputCollector) SpoutOutputCollector(com.twitter.heron.api.spout.SpoutOutputCollector) TopologyContext(com.twitter.heron.api.topology.TopologyContext) Tuple(com.twitter.heron.api.tuple.Tuple) BaseRichSpout(com.twitter.heron.api.spout.BaseRichSpout)

Example 2 with Tuple

use of com.twitter.heron.api.tuple.Tuple in project heron by twitter.

the class BoltOutputCollectorImpl method admitBoltTuple.

/////////////////////////////////////////////////////////
// Following private methods are internal implementations
/////////////////////////////////////////////////////////
private List<Integer> admitBoltTuple(String streamId, Collection<Tuple> anchors, List<Object> tuple) {
    // First check whether this tuple is sane
    helper.checkOutputSchema(streamId, tuple);
    // customGroupingTargetTaskIds will be null if this stream is not CustomStreamGrouping
    List<Integer> customGroupingTargetTaskIds = helper.chooseTasksForCustomStreamGrouping(streamId, tuple);
    // Invoke user-defined emit task hook
    helper.getTopologyContext().invokeHookEmit(tuple, streamId, customGroupingTargetTaskIds);
    // Start construct the data tuple
    HeronTuples.HeronDataTuple.Builder bldr = HeronTuples.HeronDataTuple.newBuilder();
    // set the key. This is mostly ignored
    bldr.setKey(0);
    if (customGroupingTargetTaskIds != null) {
        // It is a CustomStreamGrouping
        for (Integer taskId : customGroupingTargetTaskIds) {
            bldr.addDestTaskIds(taskId);
        }
    }
    // Set the anchors for a tuple
    if (anchors != null) {
        // This message is rooted
        Set<HeronTuples.RootId> mergedRoots = new HashSet<HeronTuples.RootId>();
        for (Tuple tpl : anchors) {
            if (tpl instanceof TupleImpl) {
                TupleImpl t = (TupleImpl) tpl;
                mergedRoots.addAll(t.getRoots());
            }
        }
        for (HeronTuples.RootId rt : mergedRoots) {
            bldr.addRoots(rt);
        }
    }
    long tupleSizeInBytes = 0;
    long startTime = System.nanoTime();
    // Serialize it
    for (Object obj : tuple) {
        byte[] b = serializer.serialize(obj);
        ByteString bstr = ByteString.copyFrom(b);
        bldr.addValues(bstr);
        tupleSizeInBytes += b.length;
    }
    long latency = System.nanoTime() - startTime;
    boltMetrics.serializeDataTuple(streamId, latency);
    // submit to outputter
    outputter.addDataTuple(streamId, bldr, tupleSizeInBytes);
    // Update metrics
    boltMetrics.emittedTuple(streamId);
    // TODO:- remove this after changing the api
    return null;
}
Also used : ByteString(com.google.protobuf.ByteString) HeronTuples(com.twitter.heron.proto.system.HeronTuples) TupleImpl(com.twitter.heron.common.utils.tuple.TupleImpl) Tuple(com.twitter.heron.api.tuple.Tuple) HashSet(java.util.HashSet)

Example 3 with Tuple

use of com.twitter.heron.api.tuple.Tuple in project incubator-heron by apache.

the class LaunchRunnerTest method createTopology.

public static TopologyAPI.Topology createTopology(com.twitter.heron.api.Config heronConfig) {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout-1", new BaseRichSpout() {

        private static final long serialVersionUID = -762965195665496156L;

        public void declareOutputFields(OutputFieldsDeclarer declarer) {
        }

        public void open(Map<String, Object> conf, TopologyContext context, SpoutOutputCollector collector) {
        }

        public void nextTuple() {
        }
    }, 2);
    builder.setBolt("bolt-1", new BaseBasicBolt() {

        private static final long serialVersionUID = -5738458486388778812L;

        public void execute(Tuple input, BasicOutputCollector collector) {
        }

        public void declareOutputFields(OutputFieldsDeclarer declarer) {
        }
    }, 1);
    HeronTopology heronTopology = builder.createTopology();
    return heronTopology.setName(TOPOLOGY_NAME).setConfig(heronConfig).setState(TopologyAPI.TopologyState.RUNNING).getTopology();
}
Also used : BaseBasicBolt(com.twitter.heron.api.bolt.BaseBasicBolt) TopologyBuilder(com.twitter.heron.api.topology.TopologyBuilder) HeronTopology(com.twitter.heron.api.HeronTopology) OutputFieldsDeclarer(com.twitter.heron.api.topology.OutputFieldsDeclarer) BasicOutputCollector(com.twitter.heron.api.bolt.BasicOutputCollector) SpoutOutputCollector(com.twitter.heron.api.spout.SpoutOutputCollector) TopologyContext(com.twitter.heron.api.topology.TopologyContext) Tuple(com.twitter.heron.api.tuple.Tuple) BaseRichSpout(com.twitter.heron.api.spout.BaseRichSpout)

Example 4 with Tuple

use of com.twitter.heron.api.tuple.Tuple in project incubator-heron by apache.

the class JoinOperatorTest method getJoinOperator.

@SuppressWarnings({ "rawtypes", "unchecked" })
private JoinOperator<String, KeyValue<String, String>, KeyValue<String, String>, String> getJoinOperator(JoinType type) {
    SerializableFunction<KeyValue<String, String>, String> f = x -> x == null ? "null" : x.getKey();
    JoinOperator<String, KeyValue<String, String>, KeyValue<String, String>, String> joinOperator = new JoinOperator(type, "leftComponent", "rightComponent", f, f, (SerializableBiFunction<KeyValue<String, String>, KeyValue<String, String>, String>) (o, o2) -> (o == null ? "null" : o.getValue()) + (o2 == null ? "null" : o2.getValue()));
    joinOperator.prepare(new Config(), PowerMockito.mock(TopologyContext.class), new OutputCollector(new IOutputCollector() {

        @Override
        public void reportError(Throwable error) {
        }

        @Override
        public List<Integer> emit(String streamId, Collection<Tuple> anchors, List<Object> tuple) {
            emittedTuples.addAll(tuple);
            return null;
        }

        @Override
        public void emitDirect(int taskId, String streamId, Collection<Tuple> anchors, List<Object> tuple) {
        }

        @Override
        public void ack(Tuple input) {
        }

        @Override
        public void fail(Tuple input) {
        }
    }));
    return joinOperator;
}
Also used : TopologyBuilder(com.twitter.heron.api.topology.TopologyBuilder) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Config(com.twitter.heron.api.Config) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Values(com.twitter.heron.api.tuple.Values) TupleImpl(com.twitter.heron.common.utils.tuple.TupleImpl) TopologyContextImpl(com.twitter.heron.common.utils.topology.TopologyContextImpl) Map(java.util.Map) Fields(com.twitter.heron.api.tuple.Fields) SerializableFunction(com.twitter.heron.streamlet.SerializableFunction) LinkedList(java.util.LinkedList) PowerMockito(org.powermock.api.mockito.PowerMockito) SerializableBiFunction(com.twitter.heron.streamlet.SerializableBiFunction) TupleWindow(com.twitter.heron.api.windowing.TupleWindow) Before(org.junit.Before) JoinType(com.twitter.heron.streamlet.JoinType) Collection(java.util.Collection) KeyedWindow(com.twitter.heron.streamlet.KeyedWindow) Set(java.util.Set) Tuple(com.twitter.heron.api.tuple.Tuple) Test(org.junit.Test) TopologyContext(com.twitter.heron.api.topology.TopologyContext) Mockito(org.mockito.Mockito) IOutputCollector(com.twitter.heron.api.bolt.IOutputCollector) List(java.util.List) OutputCollector(com.twitter.heron.api.bolt.OutputCollector) KeyValue(com.twitter.heron.streamlet.KeyValue) Assert(org.junit.Assert) Collections(java.util.Collections) TupleWindowImpl(com.twitter.heron.api.windowing.TupleWindowImpl) IOutputCollector(com.twitter.heron.api.bolt.IOutputCollector) OutputCollector(com.twitter.heron.api.bolt.OutputCollector) KeyValue(com.twitter.heron.streamlet.KeyValue) Config(com.twitter.heron.api.Config) IOutputCollector(com.twitter.heron.api.bolt.IOutputCollector) Collection(java.util.Collection) LinkedList(java.util.LinkedList) List(java.util.List) TopologyContext(com.twitter.heron.api.topology.TopologyContext) Tuple(com.twitter.heron.api.tuple.Tuple)

Example 5 with Tuple

use of com.twitter.heron.api.tuple.Tuple in project incubator-heron by apache.

the class JoinOperatorTest method getTupleWindow.

private TupleWindow getTupleWindow() {
    TopologyAPI.StreamId leftComponentStreamId = TopologyAPI.StreamId.newBuilder().setComponentName("leftComponent").setId("s1").build();
    TopologyAPI.StreamId rightComponentStreamId = TopologyAPI.StreamId.newBuilder().setComponentName("rightComponent").setId("s1").build();
    List<Tuple> tuples = new LinkedList<>();
    for (int i = 0; i < 5; i++) {
        Tuple tuple;
        if (i % 2 == 0) {
            tuple = getTuple(leftComponentStreamId, new Fields("a"), new Values(new KeyValue<String, String>("key1", String.valueOf(i))));
        } else {
            tuple = getTuple(rightComponentStreamId, new Fields("a"), new Values(new KeyValue<String, String>("key1", String.valueOf(i))));
        }
        tuples.add(tuple);
    }
    for (int i = 5; i < 8; i++) {
        Tuple tuple = getTuple(leftComponentStreamId, new Fields("a"), new Values(new KeyValue<String, String>("key2", String.valueOf(i))));
        tuples.add(tuple);
    }
    for (int i = 8; i < 12; i++) {
        Tuple tuple = getTuple(rightComponentStreamId, new Fields("a"), new Values(new KeyValue<String, String>("key3", String.valueOf(i))));
        tuples.add(tuple);
    }
    TupleWindow tupleWindow = new TupleWindowImpl(tuples, new LinkedList<>(), new LinkedList<>(), startTime, endTime);
    return tupleWindow;
}
Also used : KeyValue(com.twitter.heron.streamlet.KeyValue) Values(com.twitter.heron.api.tuple.Values) TupleWindow(com.twitter.heron.api.windowing.TupleWindow) LinkedList(java.util.LinkedList) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Fields(com.twitter.heron.api.tuple.Fields) TupleWindowImpl(com.twitter.heron.api.windowing.TupleWindowImpl) Tuple(com.twitter.heron.api.tuple.Tuple)

Aggregations

Tuple (com.twitter.heron.api.tuple.Tuple)23 TopologyContext (com.twitter.heron.api.topology.TopologyContext)11 Fields (com.twitter.heron.api.tuple.Fields)10 Values (com.twitter.heron.api.tuple.Values)8 BasicOutputCollector (com.twitter.heron.api.bolt.BasicOutputCollector)7 OutputFieldsDeclarer (com.twitter.heron.api.topology.OutputFieldsDeclarer)7 TopologyBuilder (com.twitter.heron.api.topology.TopologyBuilder)7 HashMap (java.util.HashMap)7 BaseBasicBolt (com.twitter.heron.api.bolt.BaseBasicBolt)6 BaseRichSpout (com.twitter.heron.api.spout.BaseRichSpout)6 SpoutOutputCollector (com.twitter.heron.api.spout.SpoutOutputCollector)6 TupleWindow (com.twitter.heron.api.windowing.TupleWindow)6 KeyValue (com.twitter.heron.streamlet.KeyValue)6 LinkedList (java.util.LinkedList)6 Config (com.twitter.heron.api.Config)5 HeronTopology (com.twitter.heron.api.HeronTopology)4 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)4 TupleWindowImpl (com.twitter.heron.api.windowing.TupleWindowImpl)4 TupleImpl (com.twitter.heron.common.utils.tuple.TupleImpl)4 HashSet (java.util.HashSet)4