@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()); } }
@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()); } }
@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()); } }
@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); }
@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"); }
@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"); }
@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"); }
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; }
@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); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { this.logger = Logger.getLogger(RulesEngineBolt.class.getName()); UnifiedFactory factory = new UnifiedFactory(); this.rulesEngine = new StatelessRulesEngine<Tuple, OutputCollector>(this, factory, factory); try { this.rulesEngine.initialize(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"); }
@Override public void internalPrepare(OutputCollector collector, IMetadataChangeNotifyService coordinatorService, Config config, TopologyContext context) { coordinatorService.registerListener(this); coordinatorService.init(config, MetadataType.ALERT_PUBLISH_BOLT); this.alertPublisher.init(config, stormConf); streamContext = new StreamContextImpl(config, context.registerMetric("eagle.publisher", new MultiCountMetric(), 60), context); this.context = context; this.alertTemplateEngine = AlertTemplateProvider.createAlertTemplateEngine(); this.alertTemplateEngine.init(config); this.alertFilter = new PipeStreamFilter(new AlertContextEnrichFilter(this), new AlertTemplateFilter(alertTemplateEngine)); }
PolicyHandlerContext context = new PolicyHandlerContext(); context.setPolicyDefinition(policyDefinition); context.setPolicyCounter(new StormMultiCountMetric(new MultiCountMetric())); context.setPolicyEvaluator(new PolicyGroupEvaluatorImpl("evalutorId")); handler.prepare(collector, context);
when(context.registerMetric(any(String.class), any(MultiCountMetric.class), any(int.class))).thenReturn(new MultiCountMetric()); StreamContext streamContext = new StreamContextImpl(null, context.registerMetric("eagle.router", new MultiCountMetric(), 60), context); StreamRouterBoltOutputCollector collector = new StreamRouterBoltOutputCollector("test", new StormOutputCollector(new OutputCollector(delegate), null), null, streamContext);
@SuppressWarnings("serial") @Test public void testBySendSimpleEvent() throws Exception { SiddhiPolicyHandler handler; MockStreamCollector collector; handler = new SiddhiPolicyHandler(createDefinition("sampleStream_1", "sampleStream_2"), 0); collector = new MockStreamCollector(); PolicyDefinition policyDefinition = MockSampleMetadataFactory.createSingleMetricSamplePolicy(); PolicyHandlerContext context = new PolicyHandlerContext(); context.setPolicyDefinition(policyDefinition); context.setPolicyCounter(new StormMultiCountMetric(new MultiCountMetric())); context.setPolicyEvaluator(new PolicyGroupEvaluatorImpl("evalutorId")); handler.prepare(collector, context); StreamEvent event = StreamEvent.builder() .schema(MockSampleMetadataFactory.createSampleStreamDefinition("sampleStream_1")) .streamId("sampleStream_1") .timestamep(System.currentTimeMillis()) .attributes(new HashMap<String, Object>() {{ put("name", "cpu"); put("value", 60.0); put("bad", "bad column value"); }}).build(); handler.send(event); handler.close(); }
when(topologyContext.registerMetric(any(String.class), any(MultiCountMetric.class), any(int.class))).thenReturn(new MultiCountMetric()); routerBolt.prepare(stormConf, topologyContext, collector);