@Override public void execute(Tuple tuple) { try { client = Utils.buildClient(this.uiEndpoint, 3000, 3000); HttpPut put = new HttpPut(this.uiEndpoint + "/" + tuple.getShortByField(Constants.FIELD_ALERT_TEMPLATE_ID) + "/" + tuple.getBooleanByField(Constants.SUPRESSION_STATE)); client.execute(put); client.close(); } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException | IOException e) { collector.reportError(e); } collector.ack(tuple); }
@Override public void execute(Tuple tuple) { JsonObject obj = new JsonObject(); obj.addProperty(Constants.FIELD_TIMESTAMP, tuple.getLongByField(Constants.FIELD_TIMESTAMP)); obj.addProperty(Constants.FIELD_AGGREGATION_WINDOW, tuple.getIntegerByField(Constants.FIELD_AGGREGATION_WINDOW)); obj.addProperty(Constants.FIELD_RULE_ACTION_ID, tuple.getStringByField(Constants.FIELD_RULE_ACTION_ID)); obj.addProperty(Constants.FIELD_AGGREGATION_KEY, tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY)); if (tuple.contains(Constants.FIELD_STATE_TRACK)) { obj.addProperty(Constants.FIELD_STATE_TRACK, tuple.getBooleanByField(Constants.FIELD_STATE_TRACK)); } else if (tuple.contains(Constants.FIELD_AGGREGATION_VALUE)) { obj.addProperty(Constants.FIELD_AGGREGATION_VALUE, tuple.getValueByField(Constants.FIELD_AGGREGATION_VALUE).toString()); } else { // invalid event collector.fail(tuple); return; } collector.emit(tuple, new Values(tuple.getStringByField(Constants.FIELD_RULE_ACTION_ID) + "_" + tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY), gson.toJson(obj))); collector.ack(tuple); }
@Override public void execute(Tuple input) { CallDetailRecord cdr = (CallDetailRecord) input.getValueByField(Field.RECORD); boolean newCallee = input.getBooleanByField(Field.NEW_CALLEE); if (cdr.isCallEstablished() && newCallee) { String caller = input.getStringByField(Field.CALLING_NUM); long timestamp = cdr.getAnswerTime().getMillis()/1000; filter.add(caller, cdr.getCallDuration(), timestamp); double calltime = filter.estimateCount(caller, timestamp); LOG.debug(String.format("CallTime: %f", calltime)); collector.emit(new Values(caller, timestamp, calltime, cdr)); } } }
@Test public void testBasicSerialization() { AggregationSerializerBolt bolt = new AggregationSerializerBolt(); Map<String, String> conf = new HashMap<>(); bolt.prepare(conf, null, collector); when(tuple.getLongByField(Constants.FIELD_TIMESTAMP)).thenReturn(143322L); when(tuple.getStringByField(Constants.FIELD_RULE_ACTION_ID)).thenReturn("34_22"); when(tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY)).thenReturn("host1"); when(tuple.getIntegerByField(Constants.FIELD_AGGREGATION_WINDOW)).thenReturn(100); when(tuple.getBooleanByField(Constants.FIELD_STATE_TRACK)).thenReturn(true); when(tuple.contains(Constants.FIELD_STATE_TRACK)).thenReturn(true); bolt.execute(tuple); verify(collector, times(1)).ack(tuple); }
boolean isSpam = input.getBooleanByField(Field.IS_SPAM);
@Override public void execute(Tuple input) { CallDetailRecord cdr = (CallDetailRecord) input.getValueByField(Field.RECORD); boolean newCallee = input.getBooleanByField(Field.NEW_CALLEE); if (cdr.isCallEstablished() && newCallee) { String caller = input.getStringByField(Field.CALLING_NUM); long timestamp = cdr.getAnswerTime().getMillis()/1000; filter.add(caller, 1, timestamp); double rate = filter.estimateCount(caller, timestamp); collector.emit(new Values(caller, timestamp, rate, cdr)); } } }
@Test public void testJSONSerialization() { AggregationSerializerBolt bolt = new AggregationSerializerBolt(); Map<String, String> conf = new HashMap<>(); final AtomicReference<Values> outputTuple = new AtomicReference<Values>(null); OutputCollector mockCollector = MockTupleHelpers.mockCollector(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object newEvent = invocation.getArguments()[1]; outputTuple.set((Values) newEvent); return new ArrayList<>(); } }); bolt.prepare(conf, null, mockCollector); when(tuple.getLongByField(Constants.FIELD_TIMESTAMP)).thenReturn(143322L); when(tuple.getStringByField(Constants.FIELD_RULE_ACTION_ID)).thenReturn("34_22"); when(tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY)).thenReturn("host1"); when(tuple.getIntegerByField(Constants.FIELD_AGGREGATION_WINDOW)).thenReturn(100); when(tuple.getBooleanByField(Constants.FIELD_STATE_TRACK)).thenReturn(true); when(tuple.contains(Constants.FIELD_STATE_TRACK)).thenReturn(true); bolt.execute(tuple); verify(mockCollector, times(1)).ack(tuple); assertEquals("34_22_host1", outputTuple.get().get(0)); JsonObject obj = new Gson().fromJson(outputTuple.get().get(1).toString(), JsonObject.class); assertEquals(143322L, obj.get(Constants.FIELD_TIMESTAMP).getAsLong()); assertEquals("34_22", obj.get(Constants.FIELD_RULE_ACTION_ID).getAsString()); assertEquals("host1", obj.get(Constants.FIELD_AGGREGATION_KEY).getAsString()); assertEquals(100, obj.get(Constants.FIELD_AGGREGATION_WINDOW).getAsInt()); assertEquals(true, obj.get(Constants.FIELD_STATE_TRACK).getAsBoolean()); }
when(tuple.getIntegerByField(Constants.FIELD_AGGREGATION_WINDOW)).thenReturn(10); when(tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY)).thenReturn("series1"); when(tuple.getBooleanByField(Constants.FIELD_STATE_TRACK)).thenReturn(true); when(tuple.getLongByField(Constants.FIELD_TIMESTAMP)).thenReturn(1464038054645L); bolt.execute(tuple);
stateHit.scope(Utils.separateRuleActionId(tuple.getStringByField(Constants.FIELD_RULE_ACTION_ID)) .getKey().toString()).incr(); if (tuple.getBooleanByField(Constants.FIELD_STATE_TRACK)) { logger.fine("State tracking true:" + tuple); stateTrackingEngine.track(tuple.getLongByField(Constants.FIELD_TIMESTAMP),
when(tuple.getIntegerByField(Constants.FIELD_AGGREGATION_WINDOW)).thenReturn(10); when(tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY)).thenReturn("series1"); when(tuple.getBooleanByField(Constants.FIELD_STATE_TRACK)).thenReturn(true); when(tuple.getLongByField(Constants.FIELD_TIMESTAMP)).thenReturn(1464038054645L); bolt.execute(tuple);
stateHit.scope(Utils.separateRuleActionId(tuple.getStringByField(Constants.FIELD_RULE_ACTION_ID)) .getKey().toString()).incr(); if (tuple.getBooleanByField(Constants.FIELD_STATE_TRACK)) { logger.fine("State tracking true:" + tuple); stateTrackingEngine.track(tuple.getLongByField(Constants.FIELD_TIMESTAMP),
when(tuple.getIntegerByField(Constants.FIELD_AGGREGATION_WINDOW)).thenReturn(10); when(tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY)).thenReturn("series1"); when(tuple.getBooleanByField(Constants.FIELD_STATE_TRACK)).thenReturn(true); when(tuple.getLongByField(Constants.FIELD_TIMESTAMP)).thenReturn(1464038054645L); bolt.execute(tuple);
when(tuple.getIntegerByField(Constants.FIELD_AGGREGATION_WINDOW)).thenReturn(10); when(tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY)).thenReturn("series1"); when(tuple.getBooleanByField(Constants.FIELD_STATE_TRACK)).thenReturn(true); when(tuple.getLongByField(Constants.FIELD_TIMESTAMP)).thenReturn(1464038054645L); bolt.execute(tuple);
when(tuple.getIntegerByField(Constants.FIELD_AGGREGATION_WINDOW)).thenReturn(10); when(tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY)).thenReturn("series1"); when(tuple.getBooleanByField(Constants.FIELD_STATE_TRACK)).thenReturn(true); when(tuple.getLongByField(Constants.FIELD_TIMESTAMP)).thenReturn(1464038054645L); when(tuple.getBooleanByField(Constants.FIELD_STATE_TRACK)).thenReturn(false);
when(tuple.getIntegerByField(Constants.FIELD_AGGREGATION_WINDOW)).thenReturn((Integer) values.get(2)); when(tuple.getStringByField(Constants.FIELD_RULE_ACTION_ID)).thenReturn((String) values.get(3)); when(tuple.getBooleanByField(Constants.FIELD_STATE_TRACK)).thenReturn((Boolean) values.get(0)); when(tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY)).thenReturn((String) values.get(4));
String word = input.getStringByField(Field.WORD); int count = input.getIntegerByField(Field.COUNT); boolean isSpam = input.getBooleanByField(Field.IS_SPAM);