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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations