Java Code Examples for backtype.storm.task.TopologyContext#getComponentTasks()
The following examples show how to use
backtype.storm.task.TopologyContext#getComponentTasks() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Worker.java From jstorm with Apache License 2.0 | 6 votes |
/** * 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; }
Example 2
Source File: CoordinatedBolt.java From jstorm with Apache License 2.0 | 6 votes |
public void prepare(Map config, TopologyContext context, OutputCollector collector) { TimeCacheMap.ExpiredCallback<Object, TrackingInfo> callback = null; if (_delegate instanceof TimeoutCallback) { callback = new TimeoutItems(); } _tracked = new TimeCacheMap<>(context.maxTopologyMessageTimeout(), callback); _collector = collector; _delegate.prepare(config, context, new OutputCollector(new CoordinatedOutputCollector(collector))); for (String component : Utils.get(context.getThisTargets(), Constants.COORDINATED_STREAM_ID, new HashMap<String, Grouping>()).keySet()) { for (Integer task : context.getComponentTasks(component)) { _countOutTasks.add(task); } } if (!_sourceArgs.isEmpty()) { _numSourceReports = 0; for (Entry<String, SourceArgs> entry : _sourceArgs.entrySet()) { if (entry.getValue().singleCount) { _numSourceReports += 1; } else { _numSourceReports += context.getComponentTasks(entry.getKey()).size(); } } } }
Example 3
Source File: FixedTupleSpout.java From jstorm with Apache License 2.0 | 6 votes |
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { _context = context; List<Integer> tasks = context.getComponentTasks(context.getThisComponentId()); int startIndex; for (startIndex = 0; startIndex < tasks.size(); startIndex++) { if (tasks.get(startIndex) == context.getThisTaskId()) { break; } } _collector = collector; _pending = new HashMap<String, FixedTuple>(); _serveTuples = new ArrayList<FixedTuple>(); for (int i = startIndex; i < _tuples.size(); i += tasks.size()) { _serveTuples.add(_tuples.get(i)); } }
Example 4
Source File: JobRunningSpout.java From Eagle with Apache License 2.0 | 5 votes |
/** * TODO: just copy this part from jobHistorySpout, need to move it to a common place * @param context * @return */ private int calculatePartitionId(TopologyContext context){ int thisGlobalTaskId = context.getThisTaskId(); String componentName = context.getComponentId(thisGlobalTaskId); List<Integer> globalTaskIds = context.getComponentTasks(componentName); int index = 0; for(Integer id : globalTaskIds){ if(id == thisGlobalTaskId){ return index; } index++; } throw new IllegalStateException(); }
Example 5
Source File: JobHistorySpout.java From eagle with Apache License 2.0 | 5 votes |
private int calculatePartitionId(TopologyContext context) { int thisGlobalTaskId = context.getThisTaskId(); String componentName = context.getComponentId(thisGlobalTaskId); List<Integer> globalTaskIds = context.getComponentTasks(componentName); numTotalPartitions = globalTaskIds.size(); int index = 0; for (Integer id : globalTaskIds) { if (id == thisGlobalTaskId) { return index; } index++; } throw new IllegalStateException(); }
Example 6
Source File: HiveJobFetchSpout.java From eagle with Apache License 2.0 | 5 votes |
private int calculatePartitionId(TopologyContext context) { int thisGlobalTaskId = context.getThisTaskId(); String componentName = context.getComponentId(thisGlobalTaskId); List<Integer> globalTaskIds = context.getComponentTasks(componentName); int index = 0; for (Integer id : globalTaskIds) { if (id == thisGlobalTaskId) { return index; } index++; } throw new IllegalStateException(); }
Example 7
Source File: Common.java From jstorm with Apache License 2.0 | 5 votes |
/** * get current task's output <Stream_id, <componentId, MkGrouper>> */ public static Map<String, Map<String, MkGrouper>> outbound_components( TopologyContext topology_context, WorkerData workerData) { Map<String, Map<String, MkGrouper>> rr = new HashMap<>(); // <Stream_id,<component,Grouping>> Map<String, Map<String, Grouping>> output_groupings = topology_context.getThisTargets(); for (Entry<String, Map<String, Grouping>> entry : output_groupings.entrySet()) { String stream_id = entry.getKey(); Map<String, Grouping> component_grouping = entry.getValue(); Fields out_fields = topology_context.getThisOutputFields(stream_id); Map<String, MkGrouper> componentGrouper = new HashMap<>(); for (Entry<String, Grouping> cg : component_grouping.entrySet()) { String component = cg.getKey(); Grouping tgrouping = cg.getValue(); List<Integer> outTasks = topology_context.getComponentTasks(component); // ATTENTION: If topology set one component parallelism as 0 // so we don't need send tuple to it if (outTasks.size() > 0) { MkGrouper grouper = new MkGrouper( topology_context, out_fields, tgrouping, component, stream_id, workerData); componentGrouper.put(component, grouper); } LOG.info("outbound_components, {}-{} for task-{} on {}", component, outTasks, topology_context.getThisTaskId(), stream_id); } if (componentGrouper.size() > 0) { rr.put(stream_id, componentGrouper); } } return rr; }
Example 8
Source File: TMUdfHandler.java From jstorm with Apache License 2.0 | 4 votes |
@Override public void init(TopologyMasterContext tmContext) { TopologyContext context = tmContext.getContext(); boltTasks = context.getComponentTasks("TMUdfBolt"); collector = tmContext.getCollector(); }