/** * SpoutSpec may be changed, this class will respond to changes on tuple2StreamMetadataMap and streamRepartitionMetadataMap. * * @param spoutSpec * @param sds */ @Override public void update(SpoutSpec spoutSpec, Map<String, StreamDefinition> sds) { this.streamRepartitionMetadataList = spoutSpec.getStreamRepartitionMetadataMap().get(topic); this.converter = new Tuple2StreamConverter(spoutSpec.getTuple2StreamMetadataMap().get(topic)); this.sds = sds; }
@SuppressWarnings( {"unchecked", "rawtypes"}) @Test public void test() { Tuple2StreamMetadata metadata = new Tuple2StreamMetadata(); Set activeStreamNames = new HashSet<>(); activeStreamNames.add("defaultStringStream"); metadata.setStreamNameSelectorCls("org.apache.eagle.alert.engine.scheme.PlainStringStreamNameSelector"); metadata.setStreamNameSelectorProp(new Properties()); metadata.getStreamNameSelectorProp().put("userProvidedStreamName", "defaultStringStream"); metadata.setActiveStreamNames(activeStreamNames); metadata.setTimestampColumn("timestamp"); Tuple2StreamConverter convert = new Tuple2StreamConverter(metadata); String topic = "testTopic"; Map m = new HashMap<>(); m.put("value", "IAmPlainString"); long t = System.currentTimeMillis(); m.put("timestamp", t); List<Object> ret = convert.convert(Arrays.asList(topic, m)); Assert.assertEquals(topic, ret.get(0)); Assert.assertEquals("defaultStringStream", ret.get(1)); Assert.assertEquals(t, ret.get(2)); Assert.assertEquals(m, ret.get(3)); } }
List<Object> convertedTuple = converter.convert(tuple); if (convertedTuple == null) { LOG.debug("source data {} can't be converted to a stream, ignore this message", tuple);
/** * @param delegate actual SpoutOutputCollector to send data to following bolts * @param topic topic for this KafkaSpout to handle * @param numGroupbyBolts bolts following this spout. * @param serializer */ public SpoutOutputCollectorWrapper(CorrelationSpout spout, ISpoutOutputCollector delegate, String topic, SpoutSpec spoutSpec, int numGroupbyBolts, Map<String, StreamDefinition> sds, PartitionedEventSerializer serializer, boolean logEventEnabled) { super(delegate); this.spout = spout; this.delegate = delegate; this.topic = topic; this.streamRepartitionMetadataList = spoutSpec.getStreamRepartitionMetadataMap().get(topic); this.converter = new Tuple2StreamConverter(spoutSpec.getTuple2StreamMetadataMap().get(topic)); this.numOfRouterBolts = numGroupbyBolts; this.sds = sds; this.serializer = serializer; this.logEventEnabled = logEventEnabled; }