@Test public void escalation_with_message() throws ScriptException { String expectedMessage = "I am expected"; Snapshot snapshot = new Snapshot.Builder().instanceName("something").build(); when(cut.scripting.activeScripts()).thenReturn(scripts("true", expectedMessage)); this.cut.escalate(snapshot); this.cut.escalate(snapshot); verify(this.cut.escalationSink).fire((Escalation) anyObject()); assertEquals(expectedMessage, lastEscalation.getBasicMessage()); assertEquals(snapshot, lastEscalation.getSnapshot()); }
public void escalate(@Observes @Severity(Severity.Level.HEARTBEAT) Snapshot current) { List<Script> scripts = this.scripting.activeScripts(); try { Bindings binding = this.scriptEngine.createBindings(); binding.put("current", current); Snapshot recent = this.recentSnapshots.get(current.getInstanceName()); binding.put("previous", recent); long start = System.currentTimeMillis(); try { if (recent != null) { for (Script script : scripts) { Object retVal = null; try { final String content = script.getContent(); if(content == null) return; retVal = this.scriptEngine.eval(content, binding); } catch (ScriptException scriptException) { LOG.error("Cannot evaluate script: " + script, scriptException); } if (canBeConvertedToTrue(retVal)) { String basicMessage = messageProcessor.processBasicMessage(script.getBasicMessage(), current); String richMessage = messageProcessor.processRichMessage(script.getRichMessage(), current); Escalation escalation = new Escalation.Builder() .channel(script.getName()) .basicMessage(basicMessage) .richMessage(richMessage) .snapshot(current) .build(); escalationSink.fire(escalation); LOG.info("Escalated: " + script + " for snapshot: " + current + " and recent: " + recentSnapshots); } } } } finally { LOG.info("Performance: " + (System.currentTimeMillis() - start)); } this.recentSnapshots.put(current.getInstanceName(), current); } catch (Exception e) { throw new IllegalStateException("Exception during script evaluation: " + e, e); } }
SnapshotEscalator { public void escalate(@Observes @Severity(Severity.Level.HEARTBEAT) Snapshot current) { List<Script> scripts = this.scripting.activeScripts(); try { Bindings binding = this.scriptEngine.createBindings(); binding.put("current", current); Snapshot recent = this.recentSnapshots.get(current.getInstanceName()); binding.put("previous", recent); long start = System.currentTimeMillis(); try { if (recent != null) { for (Script script : scripts) { Object retVal = null; try { final String content = script.getContent(); if(content == null) return; retVal = this.scriptEngine.eval(content, binding); } catch (ScriptException scriptException) { LOG.error("Cannot evaluate script: " + script, scriptException); } if (canBeConvertedToTrue(retVal)) { String basicMessage = messageProcessor.processBasicMessage(script.getBasicMessage(), current); String richMessage = messageProcessor.processRichMessage(script.getRichMessage(), current); Escalation escalation = new Escalation.Builder() .channel(script.getName()) .basicMessage(basicMessage) .richMessage(richMessage) .snapshot(current) .build(); escalationSink.fire(escalation); LOG.info("Escalated: " + script + " for snapshot: " + current + " and recent: " + recentSnapshots); } } } } finally { LOG.info("Performance: " + (System.currentTimeMillis() - start)); } this.recentSnapshots.put(current.getInstanceName(), current); } catch (Exception e) { throw new IllegalStateException("Exception during script evaluation: " + e, e); } } }
SnapshotEscalator { public void escalate(@Observes @Severity(Severity.Level.HEARTBEAT) Snapshot current) { List<Script> scripts = this.scripting.activeScripts(); try { Bindings binding = this.scriptEngine.createBindings(); binding.put("current", current); Snapshot recent = this.recentSnapshots.get(current.getInstanceName()); binding.put("previous", recent); long start = System.currentTimeMillis(); try { if (recent != null) { for (Script script : scripts) { Object retVal = null; try { final String content = script.getContent(); if(content == null) return; retVal = this.scriptEngine.eval(content, binding); } catch (ScriptException scriptException) { LOG.error("Cannot evaluate script: " + script, scriptException); } if (canBeConvertedToTrue(retVal)) { String basicMessage = messageProcessor.processBasicMessage(script.getBasicMessage(), current); String richMessage = messageProcessor.processRichMessage(script.getRichMessage(), current); Escalation escalation = new Escalation.Builder() .channel(script.getName()) .basicMessage(basicMessage) .richMessage(richMessage) .snapshot(current) .build(); escalationSink.fire(escalation); LOG.info("Escalated: " + script + " for snapshot: " + current + " and recent: " + recentSnapshots); } } } } finally { LOG.info("Performance: " + (System.currentTimeMillis() - start)); } this.recentSnapshots.put(current.getInstanceName(), current); } catch (Exception e) { throw new IllegalStateException("Exception during script evaluation: " + e, e); } }  }
SnapshotEscalator { public void escalate(@Observes @Severity(Severity.Level.HEARTBEAT) Snapshot current) { List<Script> scripts = this.scripting.activeScripts(); try { Bindings binding = this.scriptEngine.createBindings(); binding.put("current", current); Snapshot recent = this.recentSnapshots.get(current.getInstanceName()); binding.put("previous", recent); long start = System.currentTimeMillis(); try { if (recent != null) { for (Script script : scripts) { Object retVal = null; try { final String content = script.getContent(); if(content == null) return; retVal = this.scriptEngine.eval(content, binding); } catch (ScriptException scriptException) { LOG.error("Cannot evaluate script: " + script, scriptException); } if (canBeConvertedToTrue(retVal)) { String basicMessage = messageProcessor.processBasicMessage(script.getBasicMessage(), current); String richMessage = messageProcessor.processRichMessage(script.getRichMessage(), current); Escalation escalation = new Escalation.Builder() .channel(script.getName()) .basicMessage(basicMessage) .richMessage(richMessage) .snapshot(current) .build(); escalationSink.fire(escalation); LOG.info("Escalated: " + script + " for snapshot: " + current + " and recent: " + recentSnapshots); } } } } finally { LOG.info("Performance: " + (System.currentTimeMillis() - start)); } this.recentSnapshots.put(current.getInstanceName(), current); } catch (Exception e) { throw new IllegalStateException("Exception during script evaluation: " + e, e); } }  @PostConstruct void initScripting(); void escalate(@Observes @Severity(Severity.Level.HEARTBEAT) Snapshot current); }
SnapshotEscalator { public void escalate(@Observes @Severity(Severity.Level.HEARTBEAT) Snapshot current) { List<Script> scripts = this.scripting.activeScripts(); try { Bindings binding = this.scriptEngine.createBindings(); binding.put("current", current); Snapshot recent = this.recentSnapshots.get(current.getInstanceName()); binding.put("previous", recent); long start = System.currentTimeMillis(); try { if (recent != null) { for (Script script : scripts) { Object retVal = null; try { final String content = script.getContent(); if(content == null) return; retVal = this.scriptEngine.eval(content, binding); } catch (ScriptException scriptException) { LOG.error("Cannot evaluate script: " + script, scriptException); } if (canBeConvertedToTrue(retVal)) { String basicMessage = messageProcessor.processBasicMessage(script.getBasicMessage(), current); String richMessage = messageProcessor.processRichMessage(script.getRichMessage(), current); Escalation escalation = new Escalation.Builder() .channel(script.getName()) .basicMessage(basicMessage) .richMessage(richMessage) .snapshot(current) .build(); escalationSink.fire(escalation); LOG.info("Escalated: " + script + " for snapshot: " + current + " and recent: " + recentSnapshots); } } } } finally { LOG.info("Performance: " + (System.currentTimeMillis() - start)); } this.recentSnapshots.put(current.getInstanceName(), current); } catch (Exception e) { throw new IllegalStateException("Exception during script evaluation: " + e, e); } }  @PostConstruct void initScripting(); void escalate(@Observes @Severity(Severity.Level.HEARTBEAT) Snapshot current);  }