Search in sources :

Example 1 with GlobalStreamId

use of backtype.storm.generated.GlobalStreamId in project storm by nathanmarz.

the class TridentTopologyBuilder method getBoltSubscriptionStreams.

List<GlobalStreamId> getBoltSubscriptionStreams(String id) {
    List<GlobalStreamId> ret = new ArrayList();
    Component c = _bolts.get(id);
    for (InputDeclaration d : c.declarations) {
        ret.add(new GlobalStreamId(d.getComponent(), d.getStream()));
    }
    return ret;
}
Also used : GlobalStreamId(backtype.storm.generated.GlobalStreamId) ArrayList(java.util.ArrayList)

Example 2 with GlobalStreamId

use of backtype.storm.generated.GlobalStreamId in project heron by twitter.

the class CustomStreamGroupingDelegate method prepare.

@Override
public void prepare(com.twitter.heron.api.topology.TopologyContext context, String component, String streamId, List<Integer> targetTasks) {
    TopologyContext c = new TopologyContext(context);
    GlobalStreamId g = new GlobalStreamId(component, streamId);
    delegate.prepare(c, g, targetTasks);
}
Also used : GlobalStreamId(backtype.storm.generated.GlobalStreamId) TopologyContext(backtype.storm.task.TopologyContext)

Example 3 with GlobalStreamId

use of backtype.storm.generated.GlobalStreamId in project jstorm by alibaba.

the class SingleJoinBolt method execute.

@Override
public void execute(Tuple tuple) {
    List<Object> id = tuple.select(_idFields);
    GlobalStreamId streamId = new GlobalStreamId(tuple.getSourceComponent(), tuple.getSourceStreamId());
    if (!_pending.containsKey(id)) {
        _pending.put(id, new HashMap<GlobalStreamId, Tuple>());
    }
    Map<GlobalStreamId, Tuple> parts = _pending.get(id);
    if (parts.containsKey(streamId))
        throw new RuntimeException("Received same side of single join twice");
    parts.put(streamId, tuple);
    if (parts.size() == _numSources) {
        _pending.remove(id);
        List<Object> joinResult = new ArrayList<Object>();
        for (String outField : _outFields) {
            GlobalStreamId loc = _fieldLocations.get(outField);
            joinResult.add(parts.get(loc).getValueByField(outField));
        }
        _collector.emit(new ArrayList<Tuple>(parts.values()), joinResult);
        for (Tuple part : parts.values()) {
            _collector.ack(part);
        }
    }
}
Also used : GlobalStreamId(backtype.storm.generated.GlobalStreamId) ArrayList(java.util.ArrayList) Tuple(backtype.storm.tuple.Tuple)

Example 4 with GlobalStreamId

use of backtype.storm.generated.GlobalStreamId in project jstorm by alibaba.

the class TopologyContext method toJSONString.

@SuppressWarnings("unchecked")
@Override
public String toJSONString() {
    Map obj = new HashMap();
    obj.put("task->component", this.getTaskToComponent());
    obj.put("taskid", this.getThisTaskId());
    obj.put("componentid", this.getThisComponentId());
    List<String> streamList = new ArrayList<>();
    streamList.addAll(this.getThisStreams());
    obj.put("streams", streamList);
    obj.put("stream->outputfields", this.getThisOutputFieldsForStreams());
    // Convert targets to a JSON serializable format
    Map<String, Map> stringTargets = new HashMap<>();
    for (Map.Entry<String, Map<String, Grouping>> entry : this.getThisTargets().entrySet()) {
        Map stringTargetMap = new HashMap<>();
        for (Map.Entry<String, Grouping> innerEntry : entry.getValue().entrySet()) {
            stringTargetMap.put(innerEntry.getKey(), groupingToJSONableMap(innerEntry.getValue()));
        }
        stringTargets.put(entry.getKey(), stringTargetMap);
    }
    obj.put("stream->target->grouping", stringTargets);
    // Convert sources to a JSON serializable format
    Map<String, Map<String, Object>> stringSources = new HashMap<>();
    for (Map.Entry<GlobalStreamId, Grouping> entry : this.getThisSources().entrySet()) {
        GlobalStreamId gid = entry.getKey();
        Map<String, Object> stringSourceMap = stringSources.get(gid.get_componentId());
        if (stringSourceMap == null) {
            stringSourceMap = new HashMap<>();
            stringSources.put(gid.get_componentId(), stringSourceMap);
        }
        stringSourceMap.put(gid.get_streamId(), groupingToJSONableMap(entry.getValue()));
    }
    obj.put("source->stream->grouping", stringSources);
    return JSONValue.toJSONString(obj);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Grouping(backtype.storm.generated.Grouping) GlobalStreamId(backtype.storm.generated.GlobalStreamId) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with GlobalStreamId

use of backtype.storm.generated.GlobalStreamId in project jstorm by alibaba.

the class TopologyBuilder method initCommon.

protected void initCommon(String id, IComponent component, Number parallelism) throws IllegalArgumentException {
    ComponentCommon common = new ComponentCommon();
    common.set_inputs(new HashMap<GlobalStreamId, Grouping>());
    if (parallelism != null) {
        int dop = parallelism.intValue();
        if (dop < 1) {
            throw new IllegalArgumentException("Parallelism must be positive.");
        }
        common.set_parallelism_hint(dop);
    } else {
        common.set_parallelism_hint(1);
    }
    Map conf = component.getComponentConfiguration();
    if (conf != null)
        common.set_json_conf(JSONValue.toJSONString(conf));
    _commons.put(id, common);
}
Also used : ComponentCommon(backtype.storm.generated.ComponentCommon) GlobalStreamId(backtype.storm.generated.GlobalStreamId) PartialKeyGrouping(backtype.storm.grouping.PartialKeyGrouping) Grouping(backtype.storm.generated.Grouping) CustomStreamGrouping(backtype.storm.grouping.CustomStreamGrouping) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

GlobalStreamId (backtype.storm.generated.GlobalStreamId)33 HashMap (java.util.HashMap)13 HashSet (java.util.HashSet)13 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 Grouping (backtype.storm.generated.Grouping)7 ComponentCommon (backtype.storm.generated.ComponentCommon)4 Fields (backtype.storm.tuple.Fields)4 List (java.util.List)4 Set (java.util.Set)4 Bolt (backtype.storm.generated.Bolt)3 CustomStreamGrouping (backtype.storm.grouping.CustomStreamGrouping)3 TopologyContext (backtype.storm.task.TopologyContext)3 BoltDeclarer (backtype.storm.topology.BoltDeclarer)3 ITridentSpout (storm.trident.spout.ITridentSpout)3 Tuple (backtype.storm.tuple.Tuple)2 DefaultDirectedGraph (org.jgrapht.graph.DefaultDirectedGraph)2 GraphGrouper (storm.trident.graph.GraphGrouper)2 Group (storm.trident.graph.Group)2 Node (storm.trident.planner.Node)2