Search in sources :

Example 1 with Grouping

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

the class Worker method worker_output_tasks.

/**
     * get current task's output task list
     */
public static Set<Integer> worker_output_tasks(WorkerData workerData) {
    ContextMaker context_maker = workerData.getContextMaker();
    Set<Integer> taskIds = workerData.getTaskids();
    StormTopology topology = workerData.getSysTopology();
    Set<Integer> rtn = new HashSet<>();
    for (Integer taskId : taskIds) {
        TopologyContext context = context_maker.makeTopologyContext(topology, taskId, null);
        // <StreamId, <ComponentId, Grouping>>
        Map<String, Map<String, Grouping>> targets = context.getThisTargets();
        for (Map<String, Grouping> e : targets.values()) {
            for (String componentId : e.keySet()) {
                List<Integer> tasks = context.getComponentTasks(componentId);
                rtn.addAll(tasks);
            }
        }
    }
    return rtn;
}
Also used : StormTopology(backtype.storm.generated.StormTopology) Grouping(backtype.storm.generated.Grouping) TopologyContext(backtype.storm.task.TopologyContext)

Example 2 with Grouping

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

the class TopologyContext method toJSONString.

@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<String>();
    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<String, Map>();
    for (Map.Entry<String, Map<String, Grouping>> entry : this.getThisTargets().entrySet()) {
        Map stringTargetMap = new HashMap<String, Object>();
        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<String, Map<String, Object>>();
    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<String, Object>();
            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 : Grouping(backtype.storm.generated.Grouping) GlobalStreamId(backtype.storm.generated.GlobalStreamId)

Example 3 with Grouping

use of backtype.storm.generated.Grouping 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)

Example 4 with Grouping

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

the class GeneralTopologyContext method getTargets.

/**
     * Gets information about who is consuming the outputs of the specified component, and how.
     *
     * @return Map from stream id to component id to the Grouping used.
     */
public Map<String, Map<String, Grouping>> getTargets(String componentId) {
    Map<String, Map<String, Grouping>> ret = new HashMap<String, Map<String, Grouping>>();
    for (String otherComponentId : getComponentIds()) {
        Map<GlobalStreamId, Grouping> inputs = getComponentCommon(otherComponentId).get_inputs();
        for (GlobalStreamId id : inputs.keySet()) {
            if (id.get_componentId().equals(componentId)) {
                Map<String, Grouping> curr = ret.get(id.get_streamId());
                if (curr == null)
                    curr = new HashMap<String, Grouping>();
                curr.put(otherComponentId, inputs.get(id));
                ret.put(id.get_streamId(), curr);
            }
        }
    }
    return ret;
}
Also used : GlobalStreamId(backtype.storm.generated.GlobalStreamId) Grouping(backtype.storm.generated.Grouping)

Example 5 with Grouping

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

the class TopologyContext method getThisSourceComponentTasks.

public Map<String, List<Integer>> getThisSourceComponentTasks() {
    Map<String, List<Integer>> ret = new HashMap<>();
    Map<GlobalStreamId, Grouping> sources = getThisSources();
    Set<String> sourceComponents = new HashSet<>();
    if (sources != null) {
        for (GlobalStreamId globalStreamId : sources.keySet()) {
            sourceComponents.add(globalStreamId.get_componentId());
        }
    }
    for (String component : sourceComponents) {
        ret.put(component, getComponentTasks(component));
    }
    return ret;
}
Also used : GlobalStreamId(backtype.storm.generated.GlobalStreamId) Grouping(backtype.storm.generated.Grouping)

Aggregations

Grouping (backtype.storm.generated.Grouping)7 GlobalStreamId (backtype.storm.generated.GlobalStreamId)6 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ComponentCommon (backtype.storm.generated.ComponentCommon)2 CustomStreamGrouping (backtype.storm.grouping.CustomStreamGrouping)2 StormTopology (backtype.storm.generated.StormTopology)1 PartialKeyGrouping (backtype.storm.grouping.PartialKeyGrouping)1 TopologyContext (backtype.storm.task.TopologyContext)1