/** * Gets the declared inputs to the specified component. * * @return A map from subscribed component/stream to the grouping subscribed with. */ public Map<GlobalStreamId, Grouping> getSources(String componentId) { return getComponentCommon(componentId).get_inputs(); }
/** * Gets the declared inputs to the specified component. * * @return A map from subscribed component/stream to the grouping subscribed with. */ public Map<GlobalStreamId, Grouping> getSources(String componentId) { return getComponentCommon(componentId).get_inputs(); }
public static Set<String> getUpstreamComponents(String componentId, TopologyContext context) { Set<String> upstreamComponents = new HashSet<>(); ComponentCommon componentCommon = Utils.getComponentCommon(context.getRawTopology(), componentId); Set<GlobalStreamId> input = componentCommon.get_inputs().keySet(); for (GlobalStreamId stream : input) { upstreamComponents.add(stream.get_componentId()); } return upstreamComponents; }
public static Set<String> getDownstreamComponents(String componentId, StormTopology topology) { Set<String> components = new HashSet<>(); Map<String, Bolt> bolts = topology.get_bolts(); for (Entry<String, Bolt> entry : bolts.entrySet()) { String downstreamComponentId = entry.getKey(); Bolt bolt = entry.getValue(); Set<GlobalStreamId> input = bolt.get_common().get_inputs().keySet(); for (GlobalStreamId stream : input) { String upstreamComponentId = stream.get_componentId(); if (upstreamComponentId.equals(componentId)) { components.add(downstreamComponentId); break; } } } return components; }
private static void validate_component_inputs(Object obj) throws InvalidTopologyException { if (obj instanceof StateSpoutSpec) { StateSpoutSpec spec = (StateSpoutSpec) obj; if (!spec.get_common().get_inputs().isEmpty()) { throw new InvalidTopologyException("May not declare inputs for a spout"); } } if (obj instanceof SpoutSpec) { SpoutSpec spec = (SpoutSpec) obj; if (!spec.get_common().get_inputs().isEmpty()) { throw new InvalidTopologyException("May not declare inputs for a spout"); } } }
public static Set<String> getAllDownstreamComponents(String componentId, StormTopology topology, Set<String> traversedComponents) { Set<String> components = new HashSet<>(); traversedComponents.add(componentId); Map<String, Bolt> bolts = topology.get_bolts(); for (Entry<String, Bolt> entry : bolts.entrySet()) { String downstreamComponentId = entry.getKey(); Bolt bolt = entry.getValue(); Set<GlobalStreamId> input = bolt.get_common().get_inputs().keySet(); for (GlobalStreamId stream : input) { String upstreamComponentId = stream.get_componentId(); if (upstreamComponentId.equals(componentId) && !traversedComponents.contains(downstreamComponentId)) { components.add(downstreamComponentId); components.addAll(getAllDownstreamComponents(downstreamComponentId, topology, traversedComponents)); break; } } } return components; }
public Object getFieldValue(_Fields field) { switch (field) { case INPUTS: return get_inputs(); case STREAMS: return get_streams(); case PARALLELISM_HINT: return Integer.valueOf(get_parallelism_hint()); case JSON_CONF: return get_json_conf(); } throw new IllegalStateException(); }
private static boolean hasDownstreamComponent(StormTopology topology, String outComponentId, String outStreamId) { boolean ret = false; for (String componentId : ThriftTopologyUtils.getComponentIds(topology)) { ComponentCommon componentCommon = Utils.getComponentCommon(topology, componentId); Set<GlobalStreamId> inputs = componentCommon.get_inputs().keySet(); for (GlobalStreamId input : inputs) { if (input.get_componentId().equals(outComponentId) && input.get_streamId().equals(outStreamId)) return true; } } return ret; } }
public Object getFieldValue(_Fields field) { switch (field) { case INPUTS: return get_inputs(); case STREAMS: return get_streams(); case PARALLELISM_HINT: return Integer.valueOf(get_parallelism_hint()); case JSON_CONF: return get_json_conf(); } throw new IllegalStateException(); }
public static Set<Integer> getDownstreamTasks(String componentId, TopologyContext context) { Set<Integer> tasks = new HashSet<>(); StormTopology topology = context.getRawTopology(); Map<String, Bolt> bolts = topology.get_bolts(); for (Entry<String, Bolt> entry : bolts.entrySet()) { String downstreamComponentId = entry.getKey(); Bolt bolt = entry.getValue(); Set<GlobalStreamId> input = bolt.get_common().get_inputs().keySet(); for (GlobalStreamId stream : input) { String upstreamComponentId = stream.get_componentId(); if (upstreamComponentId.equals(componentId)) { tasks.addAll(context.getComponentTasks(downstreamComponentId)); break; } } } return tasks; }
/** * 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<>(); 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<>(); curr.put(otherComponentId, inputs.get(id)); ret.put(id.get_streamId(), curr); } } } return ret; }
static void validate_component_inputs(Object obj) throws InvalidTopologyException { if (obj instanceof StateSpoutSpec) { StateSpoutSpec spec = (StateSpoutSpec) obj; if (!spec.get_common().get_inputs().isEmpty()) { throw new InvalidTopologyException( "May not declare inputs for a spout"); } } if (obj instanceof SpoutSpec) { SpoutSpec spec = (SpoutSpec) obj; if (!spec.get_common().get_inputs().isEmpty()) { throw new InvalidTopologyException( "May not declare inputs for a spout"); } } }
Map<String, Set<String>> relationship = new HashMap<>(); for (Entry<String, Bolt> entry : context.getRawTopology().get_bolts().entrySet()) { Map<GlobalStreamId, Grouping> inputs = entry.getValue().get_common().get_inputs(); Set<String> input = new HashSet<>(); relationship.put(entry.getKey(), input);
/** * 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; }
/** * Add watermark stream to source components of window bolts */ private void maybeAddWatermarkInputs(ComponentCommon common, IRichBolt bolt) { if (bolt instanceof WindowedBoltExecutor) { Set<String> comps = new HashSet<>(); for (GlobalStreamId globalStreamId : common.get_inputs().keySet()) { comps.add(globalStreamId.get_componentId()); } for (String comp : comps) { common.put_to_inputs( new GlobalStreamId(comp, Common.WATERMARK_STREAM_ID), Grouping.all(new NullStruct())); } } }
/** * For bolts that has incoming streams from spouts (the root bolts), * add checkpoint stream from checkpoint spout to its input. For other bolts, * add checkpoint stream from the previous bolt to its input. */ private void addCheckPointInputs(ComponentCommon component) { Set<GlobalStreamId> checkPointInputs = new HashSet<>(); for (GlobalStreamId inputStream : component.get_inputs().keySet()) { String sourceId = inputStream.get_componentId(); if (_spouts.containsKey(sourceId)) { checkPointInputs.add(new GlobalStreamId(CheckpointSpout.CHECKPOINT_COMPONENT_ID, CheckpointSpout.CHECKPOINT_STREAM_ID)); } else { checkPointInputs.add(new GlobalStreamId(sourceId, CheckpointSpout.CHECKPOINT_STREAM_ID)); } } for (GlobalStreamId streamId : checkPointInputs) { component.put_to_inputs(streamId, Grouping.all(new NullStruct())); } } private ComponentCommon getComponentCommon(String id, IComponent component) {
/** * Gets the declared inputs to the specified component. * * @return A map from subscribed component/stream to the grouping subscribed with. */ public Map<GlobalStreamId, Grouping> getSources(String componentId) { return getComponentCommon(componentId).get_inputs(); }
/** * Gets the declared inputs to the specified component. * * @return A map from subscribed component/stream to the grouping subscribed with. */ public Map<GlobalStreamId, Grouping> getSources(String componentId) { return getComponentCommon(componentId).get_inputs(); }
public static Set<String> getUpstreamComponents(String componentId, TopologyContext context) { Set<String> upstreamComponents = new HashSet<String>(); ComponentCommon componentCommon = Utils.getComponentCommon(context.getRawTopology(), componentId); Set<GlobalStreamId> input = componentCommon.get_inputs().keySet(); for (GlobalStreamId stream : input) { upstreamComponents.add(stream.get_componentId()); } return upstreamComponents; }
public Object getFieldValue(_Fields field) { switch (field) { case INPUTS: return get_inputs(); case STREAMS: return get_streams(); case PARALLELISM_HINT: return Integer.valueOf(get_parallelism_hint()); case JSON_CONF: return get_json_conf(); } throw new IllegalStateException(); }