@Override public boolean respondsTo(Event event) { if (event instanceof RunEvent) { RunEvent re = (RunEvent) event; Run r = re.getEventObject(); if (re.getEventType().equals(MisoEventType.RUN_FAILED) && r.getStatus() != null && r.getStatus().getHealth().equals(HealthType.Failed)) { log.info("Run " + r.getAlias() + ": " + re.getEventMessage()); return true; } } return false; }
@Override public void generateResponse(Event event) { if (event instanceof RunEvent) { RunEvent re = (RunEvent) event; Run r = re.getEventObject(); for (User user : r.getWatchers()) { Alert a = new DefaultAlert(user); a.setAlertLevel(AlertLevel.CRITICAL); a.setAlertTitle("Run Failed: " + r.getAlias()); StringBuilder at = new StringBuilder(); at.append( "The following Run has been set to FAILED: " + r.getAlias() + " (" + event.getEventMessage() + "). Please view Run " + r.getId() + " in MISO for more information"); if (event.getEventContext().has("baseURL")) { at.append(":\n\n" + event.getEventContext().getString("baseURL") + "/run/" + r.getId()); } a.setAlertText(at.toString()); for (AlerterService as : alerterServices) { try { as.raiseAlert(a); } catch (AlertingException e) { log.error("Cannot raise user-level alert:" + e.getMessage()); e.printStackTrace(); } } } if (getSaveSystemAlert()) { raiseSystemAlert(event); } } }