@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { this.logger = Logger.getLogger(MarkovianAggregationBolt.class.getName()); this.collector = collector; if (stormConf.containsKey(STATE_FLUSH_BUFFER_SIZE)) { bufferSize = Integer.parseInt(stormConf.get(STATE_FLUSH_BUFFER_SIZE).toString()); } else { bufferSize = DEFAULT_STATE_FLUSH_BUFFER_SIZE; } this.buffer = new ArrayList<>(bufferSize); this.unifiedFactory = new UnifiedFactory(); this.engine = new MarkovianAggregationEngineImpl(unifiedFactory, unifiedFactory, aggregatorType); int taskId = context.getThisTaskIndex(); try { engine.initialize(stormConf, taskId); } catch (Exception e) { throw new RuntimeException(e); } aggregationHit = new MultiCountMetric(); if (context != null) { context.registerMetric(_METRIC_AGGREGATION_HIT, aggregationHit, Constants.METRICS_FREQUENCY); } this.flushTimeout = 30; if (stormConf.containsKey(AGGREGATION_FLUSH_TIMEOUT)) { this.flushTimeout = Integer.parseInt(stormConf.get(AGGREGATION_FLUSH_TIMEOUT).toString()); } }
@Override public void scope(String scopeName) { countMetric.scope(scopeName); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { this.logger = Logger.getLogger(StateTrackingBolt.class.getName()); this.collector = collector; if (stormConf.containsKey(STATE_FLUSH_BUFFER_SIZE)) { bufferSize = Integer.parseInt(stormConf.get(STATE_FLUSH_BUFFER_SIZE).toString()); } else { bufferSize = DEFAULT_STATE_FLUSH_BUFFER_SIZE; } this.buffer = new ArrayList<>(bufferSize); this.unifiedFactory = new UnifiedFactory(); this.stateTrackingEngine = new StateTrackingEngine(unifiedFactory, unifiedFactory); int taskId = context.getThisTaskIndex(); try { stateTrackingEngine.initialize(stormConf, taskId); } catch (Exception e) { throw new RuntimeException(e); } stateHit = new MultiCountMetric(); if (context != null) { context.registerMetric(_METRIC_STATE_HIT, stateHit, Constants.METRICS_FREQUENCY); } this.flushTimeout = 30; if (stormConf.containsKey(STATE_FLUSH_TIMEOUT)) { this.flushTimeout = Integer.parseInt(stormConf.get(STATE_FLUSH_TIMEOUT).toString()); } }
@Override public void incrBy(String scopeName, int length) { countMetric.scope(scopeName).incrBy(length); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { this.logger = Logger.getLogger(MarkovianAggregationBolt.class.getName()); this.collector = collector; if (stormConf.containsKey(STATE_FLUSH_BUFFER_SIZE)) { bufferSize = Integer.parseInt(stormConf.get(STATE_FLUSH_BUFFER_SIZE).toString()); } else { bufferSize = DEFAULT_STATE_FLUSH_BUFFER_SIZE; } this.buffer = new ArrayList<>(bufferSize); this.unifiedFactory = new UnifiedFactory(); this.engine = new MarkovianAggregationEngineImpl(unifiedFactory, unifiedFactory, aggregatorType); int taskId = context.getThisTaskIndex(); try { engine.initialize(stormConf, taskId); } catch (Exception e) { throw new RuntimeException(e); } aggregationHit = new MultiCountMetric(); if (context != null) { context.registerMetric(_METRIC_AGGREGATION_HIT, aggregationHit, Constants.METRICS_FREQUENCY); } this.flushTimeout = 30; if (stormConf.containsKey(AGGREGATION_FLUSH_TIMEOUT)) { this.flushTimeout = Integer.parseInt(stormConf.get(AGGREGATION_FLUSH_TIMEOUT).toString()); } }
@Override public void incr(String scopeName) { countMetric.scope(scopeName).incr(); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { this.logger = Logger.getLogger(StateTrackingBolt.class.getName()); this.collector = collector; if (stormConf.containsKey(STATE_FLUSH_BUFFER_SIZE)) { bufferSize = Integer.parseInt(stormConf.get(STATE_FLUSH_BUFFER_SIZE).toString()); } else { bufferSize = DEFAULT_STATE_FLUSH_BUFFER_SIZE; } this.buffer = new ArrayList<>(bufferSize); this.unifiedFactory = new UnifiedFactory(); this.stateTrackingEngine = new StateTrackingEngine(unifiedFactory, unifiedFactory); int taskId = context.getThisTaskIndex(); try { stateTrackingEngine.initialize(stormConf, taskId); } catch (Exception e) { throw new RuntimeException(e); } stateHit = new MultiCountMetric(); if (context != null) { context.registerMetric(_METRIC_STATE_HIT, stateHit, Constants.METRICS_FREQUENCY); } this.flushTimeout = 30; if (stormConf.containsKey(STATE_FLUSH_TIMEOUT)) { this.flushTimeout = Integer.parseInt(stormConf.get(STATE_FLUSH_TIMEOUT).toString()); } }
@Override public void internalPrepare(OutputCollector collector, IMetadataChangeNotifyService metadataChangeNotifyService, Config config, TopologyContext context) { // instantiate output lock object outputLock = new Object(); streamContext = new StreamContextImpl(config, context.registerMetric("eagle.evaluator", new MultiCountMetric(), 60), context); alertOutputCollector = new AlertBoltOutputCollectorWrapper(new StormOutputCollector(collector), outputLock, streamContext); policyGroupEvaluator.init(streamContext, alertOutputCollector); metadataChangeNotifyService.registerListener(this); metadataChangeNotifyService.init(config, MetadataType.ALERT_BOLT); }
@Override public void handleRuleNoMatch(OutputCollector eventCollector, Tuple eventContainer, Event inputEvent, Rule rule) { ruleNoHitCount.scope(String.valueOf(rule.getRuleId())).incr(); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { this.multiTenancyActive = Boolean .parseBoolean(stormConf.getOrDefault(Constants.RULE_GROUP_ACTIVE, Constants.FALSE).toString()); this.collector = collector; this.gson = new Gson(); this.templateMap = new HashMap<>(); this.storeFactory = new UnifiedFactory(); this.runtimeServices = RuntimeSingleton.getRuntimeServices(); try { initializeTemplates(runtimeServices, templateMap, storeFactory, stormConf); } catch (Exception e) { logger.log(Level.SEVERE, "Failed to initialize templates for alerts", e); throw new RuntimeException(e); } templateEfficiency = new MultiReducedMetric(new MeanReducer()); templateHit = new MultiCountMetric(); if (context != null) { context.registerMetric(_METRIC_TEMPLATE_EFFICIENCY, templateEfficiency, Constants.METRICS_FREQUENCY); context.registerMetric(_METRIC_TEMPLATE_HIT, templateHit, Constants.METRICS_FREQUENCY); } logger.info("Templated alerting Engine Bolt initialized"); }
@Override public void reportRuleHit(String ruleGroup, short ruleId) { ruleHitCount.scope(Utils.concat(ruleGroup, TENANTID_SEPARATOR, String.valueOf(ruleId))).incr(); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { this.collector = collector; this.gson = new Gson(); this.templateMap = new HashMap<>(); this.storeFactory = new UnifiedFactory(); this.runtimeServices = RuntimeSingleton.getRuntimeServices(); try { initializeTemplates(runtimeServices, templateMap, storeFactory, stormConf); } catch (Exception e) { logger.log(Level.SEVERE, "Failed to initialize templates for alerts", e); throw new RuntimeException(e); } templateEfficiency = new MultiReducedMetric(new MeanReducer()); templateHit = new MultiCountMetric(); if (context != null) { context.registerMetric(_METRIC_TEMPLATE_EFFICIENCY, templateEfficiency, Constants.METRICS_FREQUENCY); context.registerMetric(_METRIC_TEMPLATE_HIT, templateHit, Constants.METRICS_FREQUENCY); } logger.info("Templated alerting Engine Bolt initialized"); }
@Override public void handleRuleNoMatch(OutputCollector eventCollector, Tuple eventContainer, Event inputEvent, Rule rule) { ruleNoHitCount.scope(String.valueOf(rule.getRuleId())).incr(); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { this.multiTenancyActive = Boolean .parseBoolean(stormConf.getOrDefault(Constants.RULE_GROUP_ACTIVE, Constants.FALSE).toString()); this.logger = Logger.getLogger(RulesEngineBolt.class.getName()); UnifiedFactory factory = new UnifiedFactory(); this.rulesEngine = new StatelessRulesEngine<Tuple, OutputCollector>(this, factory, factory); try { this.rulesEngine.initializeRules(stormConf); } catch (Exception e) { throw new RuntimeException(e); } this.gson = new Gson(); this.collector = collector; this.ruleEfficiency = new MultiReducedMetric(new MeanReducer()); this.conditionEfficiency = new MultiReducedMetric(new MeanReducer()); this.ruleHitCount = new MultiCountMetric(); this.ruleNoHitCount = new MultiCountMetric(); if (context != null) { context.registerMetric(_METRIC_RULE_EFFICIENCY, ruleEfficiency, Constants.METRICS_FREQUENCY); context.registerMetric(_METRIC_CONDITION_EFFICIENCY, conditionEfficiency, Constants.METRICS_FREQUENCY); context.registerMetric(_METRIC_RULE_HIT_COUNT, ruleHitCount, Constants.METRICS_FREQUENCY); context.registerMetric(_METRIC_RULE_NO_HIT_COUNT, ruleHitCount, Constants.METRICS_FREQUENCY); } logger.info("Rules Engine Bolt initialized"); }
long timestamp) { Alert alert = new Alert(); templateHit.scope(String.valueOf(templateId)).incr(); VelocityAlertTemplate template = templateMap.get(templateId); if (template != null) {
public static AlertBolt createAlertBolt(OutputCollector collector) { Config config = ConfigFactory.load(); PolicyGroupEvaluator policyGroupEvaluator = new PolicyGroupEvaluatorImpl("testPolicyGroupEvaluatorImpl"); TestStreamRouterBolt.MockChangeService mockChangeService = new TestStreamRouterBolt.MockChangeService(); AlertBolt bolt = new AlertBolt("alertBolt1", config, mockChangeService); Map stormConf = new HashMap<>(); TopologyContext topologyContext = mock(TopologyContext.class); when(topologyContext.registerMetric(any(String.class), any(MultiCountMetric.class), any(int.class))).thenReturn(new MultiCountMetric()); bolt.prepare(stormConf, topologyContext, collector); return bolt; }
short templateId, long timestamp) { Alert alert = new Alert(); templateHit.scope(String.valueOf(templateId)).incr(); VelocityAlertTemplate template = templateMap.get(templateId); if (template != null) {
@Override public void internalPrepare(OutputCollector collector, IMetadataChangeNotifyService changeNotifyService, Config config, TopologyContext context) { streamContext = new StreamContextImpl(config, context.registerMetric("eagle.router", new MultiCountMetric(), 60), context); routeCollector = new StreamRouterBoltOutputCollector(getBoltId(), new StormOutputCollector(collector, serializer), this.getOutputStreamIds(), streamContext); router.prepare(streamContext, routeCollector); changeNotifyService.registerListener(this); changeNotifyService.init(config, MetadataType.STREAM_ROUTER_BOLT); }
protected void aggregate(Tuple tuple) { try { aggregationHit.scope(Utils.separateRuleActionId(tuple.getStringByField(Constants.FIELD_RULE_ACTION_ID)) .getKey().toString()).incr(); engine.aggregate(tuple.getLongByField(Constants.FIELD_TIMESTAMP), tuple.getIntegerByField(Constants.FIELD_AGGREGATION_WINDOW), tuple.getStringByField(Constants.FIELD_RULE_ACTION_ID), tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY), tuple.getStringByField(Constants.FIELD_AGGREGATION_VALUE)); buffer.add(tuple); if (buffer.size() >= bufferSize) { flushAckAndClearBuffer(); } } catch (AggregationRejectException e) { StormContextUtil.emitErrorTuple(collector, tuple, MarkovianAggregationBolt.class, "", "Aggregation rejected", e); collector.ack(tuple); } catch (IOException e) { failAndClearBuffer(); StormContextUtil.emitErrorTuple(collector, tuple, MarkovianAggregationBolt.class, "", "Aggregation flush failed", e); } }