use of org.apache.storm.generated.GlobalStreamId 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);
}
}
}
}
}
use of org.apache.storm.generated.GlobalStreamId in project storm by apache.
the class StormCommon method metricsConsumerBoltSpecs.
@SuppressWarnings("unchecked")
public static Map<String, Bolt> metricsConsumerBoltSpecs(Map conf, StormTopology topology) {
Map<String, Bolt> metricsConsumerBolts = new HashMap<>();
Set<String> componentIdsEmitMetrics = new HashSet<>();
componentIdsEmitMetrics.addAll(allComponents(topology).keySet());
componentIdsEmitMetrics.add(Constants.SYSTEM_COMPONENT_ID);
Map<GlobalStreamId, Grouping> inputs = new HashMap<>();
for (String componentId : componentIdsEmitMetrics) {
inputs.put(Utils.getGlobalStreamId(componentId, Constants.METRICS_STREAM_ID), Thrift.prepareShuffleGrouping());
}
List<Map<String, Object>> registerInfo = (List<Map<String, Object>>) conf.get(Config.TOPOLOGY_METRICS_CONSUMER_REGISTER);
if (registerInfo != null) {
Map<String, Integer> classOccurrencesMap = new HashMap<String, Integer>();
for (Map<String, Object> info : registerInfo) {
String className = (String) info.get(TOPOLOGY_METRICS_CONSUMER_CLASS);
Object argument = info.get(TOPOLOGY_METRICS_CONSUMER_ARGUMENT);
Integer maxRetainMetricTuples = Utils.getInt(info.get(TOPOLOGY_METRICS_CONSUMER_MAX_RETAIN_METRIC_TUPLES), 100);
Integer phintNum = Utils.getInt(info.get(TOPOLOGY_METRICS_CONSUMER_PARALLELISM_HINT), 1);
Map<String, Object> metricsConsumerConf = new HashMap<String, Object>();
metricsConsumerConf.put(Config.TOPOLOGY_TASKS, phintNum);
List<String> whitelist = (List<String>) info.get(TOPOLOGY_METRICS_CONSUMER_WHITELIST);
List<String> blacklist = (List<String>) info.get(TOPOLOGY_METRICS_CONSUMER_BLACKLIST);
FilterByMetricName filterPredicate = new FilterByMetricName(whitelist, blacklist);
Boolean expandMapType = Utils.getBoolean(info.get(TOPOLOGY_METRICS_CONSUMER_EXPAND_MAP_TYPE), false);
String metricNameSeparator = Utils.getString(info.get(TOPOLOGY_METRICS_CONSUMER_METRIC_NAME_SEPARATOR), ".");
DataPointExpander expander = new DataPointExpander(expandMapType, metricNameSeparator);
MetricsConsumerBolt boltInstance = new MetricsConsumerBolt(className, argument, maxRetainMetricTuples, filterPredicate, expander);
Bolt metricsConsumerBolt = Thrift.prepareSerializedBoltDetails(inputs, boltInstance, null, phintNum, metricsConsumerConf);
String id = className;
if (classOccurrencesMap.containsKey(className)) {
// e.g. [\"a\", \"b\", \"a\"]) => [\"a\", \"b\", \"a#2\"]"
int occurrenceNum = classOccurrencesMap.get(className);
occurrenceNum++;
classOccurrencesMap.put(className, occurrenceNum);
id = Constants.METRICS_COMPONENT_ID_PREFIX + className + "#" + occurrenceNum;
} else {
classOccurrencesMap.put(className, 1);
}
metricsConsumerBolts.put(id, metricsConsumerBolt);
}
}
return metricsConsumerBolts;
}
use of org.apache.storm.generated.GlobalStreamId in project storm by apache.
the class GzipBridgeThriftSerializationDelegateTest method testDeserialize_readingFromGzip.
@Test
public void testDeserialize_readingFromGzip() throws Exception {
GlobalStreamId id = new GlobalStreamId("first", "second");
byte[] serialized = new GzipThriftSerializationDelegate().serialize(id);
GlobalStreamId id2 = testDelegate.deserialize(serialized, GlobalStreamId.class);
assertEquals(id2.get_componentId(), id.get_componentId());
assertEquals(id2.get_streamId(), id.get_streamId());
}
use of org.apache.storm.generated.GlobalStreamId in project storm by apache.
the class GzipBridgeThriftSerializationDelegateTest method testDeserialize_readingFromDefault.
@Test
public void testDeserialize_readingFromDefault() throws Exception {
GlobalStreamId id = new GlobalStreamId("A", "B");
byte[] serialized = new ThriftSerializationDelegate().serialize(id);
GlobalStreamId id2 = testDelegate.deserialize(serialized, GlobalStreamId.class);
assertEquals(id2.get_componentId(), id.get_componentId());
assertEquals(id2.get_streamId(), id.get_streamId());
}
use of org.apache.storm.generated.GlobalStreamId in project storm by apache.
the class GzipBridgeThriftSerializationDelegateTest method testDeserialize_readingFromGzipBridge.
@Test
public void testDeserialize_readingFromGzipBridge() throws Exception {
GlobalStreamId id = new GlobalStreamId("first", "second");
byte[] serialized = new GzipBridgeThriftSerializationDelegate().serialize(id);
GlobalStreamId id2 = testDelegate.deserialize(serialized, GlobalStreamId.class);
assertEquals(id2.get_componentId(), id.get_componentId());
assertEquals(id2.get_streamId(), id.get_streamId());
}
Aggregations