org.apache.storm.tuple.Values Java Examples
The following examples show how to use
org.apache.storm.tuple.Values.
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: DbusKafkaSpout.java From DBus with Apache License 2.0 | 6 votes |
private boolean reloadSpout() { // 重新加载配置文件 if (status.isReadyToReload()) { logger.info("Ready to reload spout"); try { reload(); status.reloaded(); logger.info("Spout reloaded!"); // 将reload完成的消息发送到zk CtrlMessagePostOperation oper = CtrlMessagePostOperation.create(zkconnect); oper.spoutReloaded(status.getExtParam("message")); EmitData data = new EmitData(); data.add(EmitData.MESSAGE, status.getExtParam("message")); List<Object> values = new Values(data, Command.APPENDER_RELOAD_CONFIG); this.collector.emit(values); // 不需要跟踪消息的处理状态,即不会调用ack或者fail } catch (Exception e) { logger.error("Spout reload error!", e); } return true; } return true; }
Example #2
Source File: ProfileSplitterBoltTest.java From metron with Apache License 2.0 | 6 votes |
/** * The entity associated with a profile is defined with a Stellar expression. That expression * can refer to any field within the message. * * In this case the entity is defined as 'ip_src_addr' which is resolved to '10.0.0.1' based on * the data contained within the message. */ @Test public void testResolveEntityName() throws Exception { ProfilerConfig config = toProfilerConfig(profileWithOnlyIfTrue); ProfileSplitterBolt bolt = createBolt(config); bolt.execute(tuple); // expected values String expectedEntity = "10.0.0.1"; ProfileConfig expectedConfig = config.getProfiles().get(0); Values expected = new Values(message, timestamp, expectedEntity, expectedConfig); // a tuple should be emitted for the downstream profile builder verify(outputCollector, times(1)) .emit(eq(tuple), eq(expected)); // the original tuple should be ack'd verify(outputCollector, times(1)) .ack(eq(tuple)); }
Example #3
Source File: QuerySpout.java From bullet-storm with Apache License 2.0 | 6 votes |
@Override public void nextTuple() { PubSubMessage message = null; try { message = subscriber.receive(); } catch (Exception e) { log.error(e.getMessage()); } if (message == null) { Utils.sleep(1); return; } String content = message.getContent(); // If no content, it's a metadata only message. Send it on the METADATA_STREAM. if (content == null) { collector.emit(METADATA_STREAM, new Values(message.getId(), message.getMetadata()), message.getId()); } else { collector.emit(QUERY_STREAM, new Values(message.getId(), message.getContent(), message.getMetadata()), message.getId()); } }
Example #4
Source File: RollingCountBoltTest.java From storm-net-adapter with Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") @Test public void shouldEmitSomethingIfAtLeastOneObjectWasCountedAndTickTupleIsReceived() { // given Tuple normalTuple = mockNormalTuple(new Object()); Tuple tickTuple = MockTupleHelpers.mockTickTuple(); RollingCountBolt bolt = new RollingCountBolt(); Map<String, Object> conf = mock(Map.class); TopologyContext context = mock(TopologyContext.class); OutputCollector collector = mock(OutputCollector.class); bolt.prepare(conf, context, collector); // when bolt.execute(normalTuple); bolt.execute(tickTuple); // then verify(collector).emit(any(Values.class)); }
Example #5
Source File: EventProcessingBoltTest.java From monasca-thresh with Apache License 2.0 | 6 votes |
public void testAlarmDeletedEvent() { final AlarmDeletedEvent event = createAlarmDeletedEvent(alarm, alarmDefinition); final Tuple tuple = createTuple(event); bolt.execute(tuple); for (final SubAlarm subAlarm : alarm.getSubAlarms()) { for (final MetricDefinitionAndTenantId mtid : alarm.getAlarmedMetrics()) { // This is not the real check but it is sufficient for this test if (mtid.metricDefinition.name.equals(subAlarm.getExpression().getMetricDefinition().name)) { verifyDeletedSubAlarm(mtid, alarm.getAlarmDefinitionId(), subAlarm); } } } verify(collector, times(1)).emit(EventProcessingBolt.ALARM_EVENT_STREAM_ID, new Values(EventProcessingBolt.DELETED, event.alarmId, event)); verify(collector, times(1)).ack(tuple); }
Example #6
Source File: SlidingWindowTopology.java From storm-net-adapter with Apache License 2.0 | 6 votes |
@Override public void execute(TupleWindow inputWindow) { int sum = 0; List<Tuple> tuplesInWindow = inputWindow.get(); LOG.debug("Events in current window: " + tuplesInWindow.size()); if (tuplesInWindow.size() > 0) { /* * Since this is a tumbling window calculation, * we use all the tuples in the window to compute the avg. */ for (Tuple tuple : tuplesInWindow) { sum += (int) tuple.getValue(0); } collector.emit(new Values(sum / tuplesInWindow.size())); } }
Example #7
Source File: MetricAggregationBoltTest.java From monasca-thresh with Apache License 2.0 | 6 votes |
public void shouldNeverLeaveOkIfThresholdNotExceededForDeterministic() { long t1 = 50000; bolt.setCurrentTime(t1); sendSubAlarmCreated(metricDef4, subAlarm4); bolt.execute(createMetricTuple(metricDef4, new Metric(metricDef4, t1, 1.0, null))); t1 += 1000; bolt.execute(createMetricTuple(metricDef4, new Metric(metricDef4, t1, 1.0, null))); bolt.setCurrentTime(t1 += 60000); sendTickTuple(); assertEquals(subAlarm4.getState(), AlarmState.OK); bolt.setCurrentTime(t1 += 60000); sendTickTuple(); assertEquals(subAlarm4.getState(), AlarmState.OK); verify(collector, times(1)).emit(new Values(subAlarm4.getAlarmId(), subAlarm4)); // Have to reset the mock so it can tell the difference when subAlarm4 is emitted again. reset(collector); bolt.setCurrentTime(t1 += 60000); sendTickTuple(); assertEquals(subAlarm4.getState(), AlarmState.OK); verify(collector, never()).emit(new Values(subAlarm4.getAlarmId(), subAlarm4)); }
Example #8
Source File: MetricFilteringBolt.java From monasca-thresh with Apache License 2.0 | 6 votes |
private boolean checkForMatch(MetricDefinitionAndTenantId metricDefinitionAndTenantId) { final Set<String> alarmDefinitionIds = matcher.match(metricDefinitionAndTenantId); if (alarmDefinitionIds.isEmpty()) { return false; } final Set<String> existing = alreadyFound.matches(metricDefinitionAndTenantId); if (existing != null) { alarmDefinitionIds.removeAll(existing); } if (!alarmDefinitionIds.isEmpty()) { for (final String alarmDefinitionId : alarmDefinitionIds) { final AlarmDefinition alarmDefinition = alarmDefinitions.get(alarmDefinitionId); logger.info("Add metric {} for Alarm Definition id = {} name = {}", metricDefinitionAndTenantId, alarmDefinitionId, alarmDefinition.getName()); collector.emit(NEW_METRIC_FOR_ALARM_DEFINITION_STREAM, new Values(metricDefinitionAndTenantId, alarmDefinitionId)); synchronized (SENTINAL) { alreadyFound.add(metricDefinitionAndTenantId, alarmDefinitionId); } } } return true; }
Example #9
Source File: WordNormalizer.java From java-study with Apache License 2.0 | 6 votes |
/** * *bolt*从单词文件接收到文本行,并标准化它。 文本行会全部转化成小写,并切分它,从中得到所有单词。 */ public void execute(Tuple input) { System.out.println("WordNormalizer.execute()执行次数:"+count); String sentence = input.getString(0); String[] words = sentence.split(" "); for (String word : words) { word = word.trim(); if (!word.isEmpty()) { word = word.toLowerCase(); /* //发布这个单词 */ collector.emit(input, new Values(word)); } } // 对元组做出应答 collector.ack(input); count++; }
Example #10
Source File: SlidingWindowTopology.java From incubator-heron with Apache License 2.0 | 6 votes |
@Override public void execute(TupleWindow inputWindow) { int sum = 0; List<Tuple> tuplesInWindow = inputWindow.get(); LOG.fine("Events in current window: " + tuplesInWindow.size()); if (tuplesInWindow.size() > 0) { /* * Since this is a tumbling window calculation, * we use all the tuples in the window to compute the avg. */ for (Tuple tuple : tuplesInWindow) { sum += (int) tuple.getValue(0); } collector.emit(new Values(sum / tuplesInWindow.size())); } }
Example #11
Source File: JSONScheme.java From nightwatch with GNU Lesser General Public License v3.0 | 6 votes |
@Override public List<Object> deserialize(ByteBuffer ser) { String jsonStr = null; if (ser.hasArray()) { int base = ser.arrayOffset(); jsonStr = new String(ser.array(), base + ser.position(), ser.remaining()); } else { jsonStr = new String(Utils.toByteArray(ser), UTF8_CHARSET); } JSONObject jsonObject = JSONObject.fromObject(jsonStr); Values values = new Values(); for (String outputField : outputFields) { if("jsonBody".equals(outputField)) { values.add(jsonStr); } else { if(!jsonObject.containsKey(outputField)) { JSONObject rcMsgpara = JSONObject.fromObject(jsonObject.get("rc_msg_para")); values.add(rcMsgpara.get(outputField)); } else { values.add(jsonObject.get(outputField)); } } } return values; }
Example #12
Source File: LogProcessorTransformBolt.java From DBus with Apache License 2.0 | 6 votes |
private void emitUmsData(Tuple input, Map<String, List<RecordWrapper>> tableDatasMap) throws Exception { for (Map.Entry<String, List<RecordWrapper>> entry : tableDatasMap.entrySet()) { // vals[0]:host, vals[1]: dsName, vals[2]: schemaName, vals[3]: tableName, vals[4]: version String[] vals = StringUtils.split(entry.getKey(), "|"); String host = vals[0]; if (DbusDatasourceType.stringEqual(inner.logProcessorConf.getProperty("log.type"), DbusDatasourceType.LOG_UMS)) { host = entry.getValue().get(0).getRecordMap().get("umsSource"); } DbusMessage ums = buildUms(entry.getValue(), vals[1], vals[2], vals[3], Long.parseLong(vals[4]), host); String tableKey = StringUtils.joinWith("|", vals[1], vals[2], vals[3], vals[4]); // "outputTopic", "table", "value", "emitDataType" collector.emit("umsStream", input, new Values(inner.activeTableToTopicMap.get(tableKey), tableKey, ums, Constants.EMIT_DATA_TYPE_NORMAL)); } }
Example #13
Source File: ProfileBuilderBoltTest.java From metron with Apache License 2.0 | 6 votes |
/** * Retrieves the ProfileMeasurement(s) (if any) that have been emitted. * * @param collector The Storm output collector. * @param expected The number of measurements expected. * @return A list of ProfileMeasurement(s). */ private List<ProfileMeasurement> getProfileMeasurements(OutputCollector collector, int expected) { // the 'streamId' is defined by the DestinationHandler being used by the bolt final String streamId = emitter.getStreamId(); // capture the emitted tuple(s) ArgumentCaptor<Values> argCaptor = ArgumentCaptor.forClass(Values.class); verify(collector, times(expected)) .emit(eq(streamId), argCaptor.capture()); // return the profile measurements that were emitted return argCaptor.getAllValues() .stream() .map(val -> (ProfileMeasurement) val.get(0)) .collect(Collectors.toList()); }
Example #14
Source File: Utf8StringDeserializerTest.java From storm-dynamic-spout with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Validate that when a message has a null key it doesn't end violently with a NPE. */ @Test public void testDeserializeWithNullKey() { final byte[] expectedKey = null; final String expectedValue = "Value"; final String expectedTopic = "MyTopic"; final int expectedPartition = 34; final long expectedOffset = 31337L; // Attempt to deserialize. final Deserializer deserializer = new Utf8StringDeserializer(); final Values deserializedValues = deserializer.deserialize( expectedTopic, expectedPartition, expectedOffset, expectedKey, expectedValue.getBytes(StandardCharsets.UTF_8) ); assertEquals(2, deserializedValues.size(), "Values has 2 entries"); assertEquals(expectedKey, deserializedValues.get(0), "Got expected key"); assertEquals(expectedValue, deserializedValues.get(1), "Got expected value"); }
Example #15
Source File: SinkerKafkaReadSpout.java From DBus with Apache License 2.0 | 6 votes |
private void reload() { try { for (Map.Entry<String, DBusConsumerRecord<String, byte[]>> entry : reloadCtrlMsg.entrySet()) { String strCtrl = new String(entry.getValue().value(), "UTF-8"); logger.info("[kafka read spout] reload. cmd:{}", strCtrl); JSONObject json = JSONObject.parseObject(strCtrl); // 拖回重跑不提交到bolt,只在spout处理 if (entry.getKey().equals(ControlType.SINKER_DRAG_BACK_RUN_AGAIN.name())) { destroy(); init(json.getJSONObject("payload").getJSONArray("offset")); } if (entry.getKey().equals(ControlType.SINKER_RELOAD_CONFIG.name())) { destroy(); init(null); collector.emit("ctrlStream", new Values(Collections.singletonList(entry.getValue()))); } inner.zkHelper.saveReloadStatus(new String(entry.getValue().value(), "utf-8"), "SinkerKafkaReadSpout-" + context.getThisTaskId(), true); } this.reloadCtrlMsg.clear(); logger.info("[kafka read spout] reload completed."); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { this.reloadCtrlMsg.clear(); } }
Example #16
Source File: DRPCOutputCollectorTest.java From bullet-storm with Apache License 2.0 | 5 votes |
@Test public void testSpoutEmit() { Assert.assertFalse(collector.haveOutput()); Assert.assertFalse(collector.isAcked()); Assert.assertFalse(collector.isFailed()); Assert.assertNull(collector.emit("foo", new Values("bar", 1), "id1")); Assert.assertNull(collector.emit("bar", new Values("baz", 2), "id2")); Assert.assertTrue(collector.haveOutput()); Assert.assertFalse(collector.isAcked()); Assert.assertFalse(collector.isFailed()); List<List<Object>> tuples = collector.reset(); Assert.assertNotNull(tuples); Assert.assertEquals(tuples.size(), 2); List<Object> first = tuples.get(0); Assert.assertEquals(first.get(0), asList("bar", 1)); Assert.assertEquals(first.get(1), "id1"); List<Object> second = tuples.get(1); Assert.assertEquals(second.get(0), asList("baz", 2)); Assert.assertEquals(second.get(1), "id2"); Assert.assertFalse(collector.haveOutput()); Assert.assertFalse(collector.isAcked()); Assert.assertFalse(collector.isFailed()); }
Example #17
Source File: StatefulWindowingTopology.java From storm-net-adapter with Apache License 2.0 | 5 votes |
@Override public void execute(TupleWindow inputWindow) { for (Tuple tuple : inputWindow.get()) { sum += tuple.getIntegerByField("value"); } state.put("sum", sum); collector.emit(new Values(sum)); }
Example #18
Source File: PullHandler.java From DBus with Apache License 2.0 | 5 votes |
public void emitMonitorState(Tuple input, String reqString, String monitorNodePath, long finishedRow, long finishedShardCount) { JSONObject jsonInfo = new JSONObject(); jsonInfo.put(FullPullConstants.FULLPULL_REQ_PARAM, reqString); jsonInfo.put(FullPullConstants.DATA_MONITOR_ZK_PATH, monitorNodePath); jsonInfo.put(FullPullConstants.DB_NAMESPACE_NODE_FINISHED_COUNT, finishedShardCount); jsonInfo.put(FullPullConstants.DB_NAMESPACE_NODE_FINISHED_ROWS, finishedRow); collector.emit(input, new Values(jsonInfo)); }
Example #19
Source File: MessageTest.java From storm-dynamic-spout with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Tests equality when not equal values. */ @Test public void testNotEqualsAgainstNull() { // Define TupleMessageId components final String expectedTopic = "MyTopic"; final int expectedPartition = 2; final long expectedOffset = 31337L; final DefaultVirtualSpoutIdentifier expectedConsumerId = new DefaultVirtualSpoutIdentifier("MyConsumerId"); // Define expected values components final String expectedValue1 = "This is value 1"; final String expectedValue2 = "This is value 2"; final Long expectedValue3 = 42L; // Create messageId final MessageId messageId1 = new MessageId(expectedTopic, expectedPartition, expectedOffset, expectedConsumerId); // Create values final Values values1 = new Values(expectedValue1, expectedValue2, expectedValue3); // Create Message final Message message1 = new Message(messageId1, values1); // Create Message that is null final Message message2 = null; // Validate assertFalse(message1.equals(message2), "Should NOT be equal"); }
Example #20
Source File: ProfileSplitterBoltTest.java From metron with Apache License 2.0 | 5 votes |
/** * What happens when invalid Stella code is used for 'onlyif'? The invalid profile should be ignored. */ @Test public void testOnlyIfInvalid() throws Exception { ProfilerConfig config = toProfilerConfig(profileWithOnlyIfInvalid); ProfileSplitterBolt bolt = createBolt(config); bolt.execute(tuple); // a tuple should NOT be emitted for the downstream profile builder verify(outputCollector, times(0)) .emit(any(Values.class)); }
Example #21
Source File: TumblingWindowTopology.java From twister2 with Apache License 2.0 | 5 votes |
@Override public void nextTuple() { spoutOutputCollector.emit(new Values(counter++)); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } }
Example #22
Source File: TridentWordCount.java From storm-net-adapter with Apache License 2.0 | 5 votes |
@Override public void execute(TridentTuple tuple, TridentCollector collector) { String sentence = tuple.getString(0); for (String word : sentence.split(" ")) { collector.emit(new Values(word)); } }
Example #23
Source File: LambdaTopology.java From storm-net-adapter with Apache License 2.0 | 5 votes |
@Override protected int run(String[] args) throws Exception { TopologyBuilder builder = new TopologyBuilder(); // example. spout1: generate random strings // bolt1: get the first part of a string // bolt2: output the tuple // NOTE: Variable used in lambda expression should be final or effectively final // (or it will cause compilation error), // and variable type should implement the Serializable interface if it isn't primitive type // (or it will cause not serializable exception). Prefix prefix = new Prefix("Hello lambda:"); String suffix = ":so cool!"; int tag = 999; builder.setSpout("spout1", () -> UUID.randomUUID().toString()); builder.setBolt("bolt1", (tuple, collector) -> { String[] parts = tuple.getStringByField("lambda").split("\\-"); collector.emit(new Values(prefix + parts[0] + suffix, tag)); }, "strValue", "intValue").shuffleGrouping("spout1"); builder.setBolt("bolt2", tuple -> System.out.println(tuple)).shuffleGrouping("bolt1"); Config conf = new Config(); conf.setDebug(true); conf.setNumWorkers(2); return submit("lambda-demo", conf, builder); }
Example #24
Source File: EventProcessingBolt.java From monasca-thresh with Apache License 2.0 | 5 votes |
void handle(AlarmUpdatedEvent event) { if (event.oldAlarmState.equals(event.alarmState)) { logger.info("No state change for {}, ignoring", event.alarmId); } logger.info("Received AlarmUpdatedEvent {}", event); processSubAlarms(RESEND, event.tenantId, event.alarmDefinitionId, event.alarmMetrics, event.subAlarms); collector.emit(ALARM_EVENT_STREAM_ID, new Values(UPDATED, event.alarmId, event)); }
Example #25
Source File: RandomSentenceSpout.java From hadoop-mini-clusters with Apache License 2.0 | 5 votes |
@Override public void nextTuple() { Utils.sleep(100); String[] sentences = new String[]{ "the cow jumped over the moon", "an apple a day keeps the doctor away", "four score and seven years ago", "snow white and the seven dwarfs", "i am at two with nature" }; String sentence = sentences[_rand.nextInt(sentences.length)]; _collector.emit(new Values(sentence)); }
Example #26
Source File: TestWordSpout.java From incubator-heron with Apache License 2.0 | 5 votes |
public void nextTuple() { final String word = words[rand.nextInt(words.length)]; collector.emit(new Values(word)); if (!throttleDuration.isZero()) { Utils.sleep(throttleDuration.toMillis()); // sleep to throttle back CPU usage } }
Example #27
Source File: AdvertisingTopology.java From streaming-benchmarks with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple) { String ad_id = tuple.getStringByField("ad_id"); String campaign_id = this.redisAdCampaignCache.execute(ad_id); if(campaign_id == null) { _collector.fail(tuple); return; } _collector.emit(tuple, new Values(campaign_id, tuple.getStringByField("ad_id"), tuple.getStringByField("event_time"))); _collector.ack(tuple); }
Example #28
Source File: DBusRouterEncodeBolt.java From DBus with Apache License 2.0 | 5 votes |
private void emitStatData(EmitWarp<ConsumerRecord<String, byte[]>> data, Tuple input, long offset) { Stat vo = statWindows.poll(data.getNameSpace()); if (vo == null) { collectStat(data, 0); vo = statWindows.poll(data.getNameSpace()); } EmitWarp<Stat> emitData = new EmitWarp<>("stat"); emitData.setNameSpace(data.getNameSpace()); emitData.setHbTime(data.getHbTime()); vo.setTime(data.getHbTime()); vo.setTxTime(data.getHbTime()); emitData.setData(vo); emitData.setOffset(offset); this.collector.emit("statStream", input, new Values(emitData)); }
Example #29
Source File: ReachTopology.java From storm-net-adapter with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple, BasicOutputCollector collector) { Object id = tuple.getValue(0); String tweeter = tuple.getString(1); List<String> followers = FOLLOWERS_DB.get(tweeter); if (followers != null) { for (String follower : followers) { collector.emit(new Values(id, follower)); } } }
Example #30
Source File: RulesBoltConditionTest.java From streamline with Apache License 2.0 | 5 votes |
private Tuple getWeather(String city, long temperature, long humidity) { StreamlineEvent event = StreamlineEventImpl.builder() .fieldsAndValues(ImmutableMap.of("city", city, "temperature", temperature, "humidity", humidity)) .dataSourceId("dsrcid") .build(); return new TupleImpl(mockContext, new Values(event), 1, "inputstream"); }