Search in sources :

Example 11 with StreamInfo

use of org.apache.storm.generated.StreamInfo in project storm by apache.

the class StormCommon method addMetricStreams.

public static void addMetricStreams(StormTopology topology) {
    for (Object component : allComponents(topology).values()) {
        ComponentCommon common = getComponentCommon(component);
        StreamInfo streamInfo = Thrift.outputFields(Arrays.asList("task-info", "data-points"));
        common.put_to_streams(Constants.METRICS_STREAM_ID, streamInfo);
    }
}
Also used : ComponentCommon(org.apache.storm.generated.ComponentCommon) StreamInfo(org.apache.storm.generated.StreamInfo)

Example 12 with StreamInfo

use of org.apache.storm.generated.StreamInfo in project storm by apache.

the class StormCommon method validateStructure.

public static void validateStructure(StormTopology topology) throws InvalidTopologyException {
    Map<String, Object> componentMap = allComponents(topology);
    for (Map.Entry<String, Object> entry : componentMap.entrySet()) {
        String componentId = entry.getKey();
        ComponentCommon common = getComponentCommon(entry.getValue());
        Map<GlobalStreamId, Grouping> inputs = common.get_inputs();
        for (Map.Entry<GlobalStreamId, Grouping> input : inputs.entrySet()) {
            String sourceStreamId = input.getKey().get_streamId();
            String sourceComponentId = input.getKey().get_componentId();
            if (!componentMap.keySet().contains(sourceComponentId)) {
                throw new InvalidTopologyException("Component: [" + componentId + "] subscribes from non-existent component [" + sourceComponentId + "]");
            }
            ComponentCommon sourceComponent = getComponentCommon(componentMap.get(sourceComponentId));
            if (!sourceComponent.get_streams().containsKey(sourceStreamId)) {
                throw new InvalidTopologyException("Component: [" + componentId + "] subscribes from non-existent stream: " + "[" + sourceStreamId + "] of component [" + sourceComponentId + "]");
            }
            Grouping grouping = input.getValue();
            if (Thrift.groupingType(grouping) == Grouping._Fields.FIELDS) {
                List<String> fields = new ArrayList<>(grouping.get_fields());
                Map<String, StreamInfo> streams = sourceComponent.get_streams();
                Set<String> sourceOutputFields = getStreamOutputFields(streams);
                fields.removeAll(sourceOutputFields);
                if (fields.size() != 0) {
                    throw new InvalidTopologyException("Component: [" + componentId + "] subscribes from stream: [" + sourceStreamId + "] of component " + "[" + sourceComponentId + "] + with non-existent fields: " + fields);
                }
            }
        }
    }
}
Also used : ComponentCommon(org.apache.storm.generated.ComponentCommon) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) ArrayList(java.util.ArrayList) Grouping(org.apache.storm.generated.Grouping) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) StreamInfo(org.apache.storm.generated.StreamInfo) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 13 with StreamInfo

use of org.apache.storm.generated.StreamInfo in project flink by apache.

the class WrapperSetupHelper method processSingleOperator.

/**
	 * Sets up {@code taskToComponents}, {@code componentToSortedTasks}, and {@code componentToStreamToFields} for a
	 * single instance of a Spout or Bolt (ie, task or executor). Furthermore, is computes the unique task-id.
	 * 
	 * @param componentId
	 *            The ID of the Spout/Bolt in the topology.
	 * @param common
	 *            The common operator object (that is all Spouts and Bolts have).
	 * @param operatorName
	 *            The Flink operator name.
	 * @param index
	 *            The index of the currently processed tasks with its operator.
	 * @param dop
	 *            The parallelism of the operator.
	 * @param taskToComponents
	 *            OUTPUT: A map from all task IDs of the topology to their component IDs.
	 * @param componentToSortedTasks
	 *            OUTPUT: A map from all component IDs to their sorted list of corresponding task IDs.
	 * @param componentToStreamToFields
	 *            OUTPUT: A map from all component IDs to there output streams and output fields.
	 * 
	 * @return A unique task ID if the currently processed Spout or Bolt ({@code componentId}) is equal to the current
	 *         Flink operator {@code operatorName} -- {@code null} otherwise.
	 */
private static Integer processSingleOperator(final String componentId, final ComponentCommon common, final String operatorName, final int index, final int dop, final Map<Integer, String> taskToComponents, final Map<String, List<Integer>> componentToSortedTasks, final Map<String, Map<String, Fields>> componentToStreamToFields) {
    final int parallelism_hint = common.get_parallelism_hint();
    Integer taskId = null;
    if (componentId.equals(operatorName)) {
        taskId = tid + index;
    }
    List<Integer> sortedTasks = new ArrayList<Integer>(dop);
    for (int i = 0; i < parallelism_hint; ++i) {
        taskToComponents.put(tid, componentId);
        sortedTasks.add(tid);
        ++tid;
    }
    componentToSortedTasks.put(componentId, sortedTasks);
    Map<String, Fields> outputStreams = new HashMap<String, Fields>();
    for (Entry<String, StreamInfo> outStream : common.get_streams().entrySet()) {
        outputStreams.put(outStream.getKey(), new Fields(outStream.getValue().get_output_fields()));
    }
    componentToStreamToFields.put(componentId, outputStreams);
    return taskId;
}
Also used : Fields(org.apache.storm.tuple.Fields) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StreamInfo(org.apache.storm.generated.StreamInfo)

Example 14 with StreamInfo

use of org.apache.storm.generated.StreamInfo in project storm by apache.

the class ClojureBolt method declareOutputFields.

@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
    for (String stream : _fields.keySet()) {
        StreamInfo info = _fields.get(stream);
        declarer.declareStream(stream, info.is_direct(), new Fields(info.get_output_fields()));
    }
}
Also used : Fields(org.apache.storm.tuple.Fields) StreamInfo(org.apache.storm.generated.StreamInfo)

Aggregations

StreamInfo (org.apache.storm.generated.StreamInfo)14 HashMap (java.util.HashMap)7 Fields (org.apache.storm.tuple.Fields)7 ComponentCommon (org.apache.storm.generated.ComponentCommon)5 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)4 Grouping (org.apache.storm.generated.Grouping)4 OutputFieldsGetter (org.apache.storm.topology.OutputFieldsGetter)4 Map (java.util.Map)3 Bolt (org.apache.storm.generated.Bolt)3 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 SpoutSpec (org.apache.storm.generated.SpoutSpec)2 EventLoggerBolt (org.apache.storm.metric.EventLoggerBolt)2 MetricsConsumerBolt (org.apache.storm.metric.MetricsConsumerBolt)2 SystemBolt (org.apache.storm.metric.SystemBolt)2 IBolt (org.apache.storm.task.IBolt)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CoordinatedBolt (org.apache.storm.coordination.CoordinatedBolt)1 FinishedCallback (org.apache.storm.coordination.CoordinatedBolt.FinishedCallback)1 IdStreamSpec (org.apache.storm.coordination.CoordinatedBolt.IdStreamSpec)1