@Test public void testListenerConfigured() throws Exception { EventHandlerService ehs = services.get(EventHandlerService.class); assertNotNull(ehs); assertTrue(SLAService.isEnabled()); assertTrue(ehs.listEventListeners().contains(SLAJobEventListener.class.getCanonicalName())); }
@Override public void rerunChildren() throws CommandException { boolean isError = false; try { CoordinatorActionInfo coordInfo = null; InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation()); List<CoordinatorActionBean> coordActions = CoordUtils.getCoordActions(rerunType, jobId, scope, false); if (checkAllActionsRunnable(coordActions)) { for (CoordinatorActionBean coordAction : coordActions) { String actionXml = coordAction.getActionXml(); if (!noCleanup && !failed) { Element eAction = XmlUtils.parseXml(actionXml); cleanupOutputEvents(eAction); } if (refresh) { refreshAction(coordJob, coordAction); } updateAction(coordJob, coordAction); if (SLAService.isEnabled()) { SLAOperations.updateRegistrationEvent(coordAction.getId()); } queue(new CoordActionNotificationXCommand(coordAction), 100); queue( new CoordActionInputCheckXCommand(coordAction.getId(), coordAction.getJobId()), 100); } } else { isError = true; throw new CommandException( ErrorCode.E1018, "part or all actions are not eligible to rerun!"); } coordInfo = new CoordinatorActionInfo(coordActions); ret = coordInfo; } catch (XException xex) { isError = true; throw new CommandException(xex); } catch (JDOMException jex) { isError = true; throw new CommandException(ErrorCode.E0700, jex.getMessage(), jex); } catch (Exception ex) { isError = true; throw new CommandException(ErrorCode.E1018, ex.getMessage(), ex); } finally { if (isError) { transitToPrevious(); } } }
public static SLARegistrationBean createSlaRegistrationEvent( Element eSla, String jobId, String parentId, AppType appType, String user, String appName, XLog log, boolean rerun) throws CommandException { if (eSla == null || !SLAService.isEnabled()) { log.debug("Not registering SLA for job [{0}]. Sla-Xml null OR SLAService not enabled", jobId); return null; } SLARegistrationBean sla = new SLARegistrationBean(); // Setting nominal time String strNominalTime = getTagElement(eSla, NOMINAL_TIME); if (strNominalTime == null || strNominalTime.length() == 0) { throw new CommandException(ErrorCode.E1101, NOMINAL_TIME); } Date nominalTime; try { nominalTime = DateUtils.parseDateOozieTZ(strNominalTime); sla.setNominalTime(nominalTime); } catch (ParseException pex) { throw new CommandException(ErrorCode.E0302, strNominalTime, pex); } // Setting expected start time String strExpectedStart = getTagElement(eSla, SHOULD_START); if (strExpectedStart != null) { float expectedStart = Float.parseFloat(strExpectedStart); if (expectedStart < 0) { throw new CommandException( ErrorCode.E0302, strExpectedStart, "for SLA Expected start time"); } else { Date expectedStartTime = new Date(nominalTime.getTime() + (long) (expectedStart * 60 * 1000)); sla.setExpectedStart(expectedStartTime); } } // Setting expected end time String strExpectedEnd = getTagElement(eSla, SHOULD_END); if (strExpectedEnd == null || strExpectedEnd.length() == 0) { throw new CommandException(ErrorCode.E1101, SHOULD_END); } float expectedEnd = Float.parseFloat(strExpectedEnd); if (expectedEnd < 0) { throw new CommandException(ErrorCode.E0302, strExpectedEnd, "for SLA Expected end time"); } else { Date expectedEndTime = new Date(nominalTime.getTime() + (long) (expectedEnd * 60 * 1000)); sla.setExpectedEnd(expectedEndTime); } // Setting expected duration in milliseconds String expectedDurationStr = getTagElement(eSla, MAX_DURATION); if (expectedDurationStr != null && expectedDurationStr.length() > 0) { float expectedDuration = Float.parseFloat(expectedDurationStr); if (expectedDuration > 0) { sla.setExpectedDuration((long) (expectedDuration * 60 * 1000)); } } else if (sla.getExpectedStart() != null) { sla.setExpectedDuration(sla.getExpectedEnd().getTime() - sla.getExpectedStart().getTime()); } // Parse desired alert-types i.e. start-miss, end-miss, start-met etc.. String alertEvents = getTagElement(eSla, ALERT_EVENTS); if (alertEvents != null) { String events[] = alertEvents.split(","); StringBuilder alertsStr = new StringBuilder(); for (int i = 0; i < events.length; i++) { String event = events[i].trim().toUpperCase(); try { EventStatus.valueOf(event); } catch (IllegalArgumentException iae) { XLog.getLog(SLAService.class) .warn( "Invalid value: [" + event + "]" + " for SLA Alert-event. Should be one of " + EventStatus.values() + ". Setting it to default [" + EventStatus.END_MISS.name() + "]"); event = EventStatus.END_MISS.name(); } alertsStr.append(event).append(","); } sla.setAlertEvents(alertsStr.toString().substring(0, alertsStr.lastIndexOf(","))); } // Other sla config sla.setNotificationMsg(getTagElement(eSla, "notification-msg")); sla.setAlertContact(getTagElement(eSla, "alert-contact")); sla.setUpstreamApps(getTagElement(eSla, "upstream-apps")); // Oozie defined sla.setId(jobId); sla.setAppType(appType); sla.setAppName(appName); sla.setUser(user); sla.setParentId(parentId); SLAService slaService = Services.get().get(SLAService.class); try { if (!rerun) { slaService.addRegistrationEvent(sla); } else { slaService.updateRegistrationEvent(sla); } } catch (ServiceException e) { throw new CommandException(ErrorCode.E1007, " id " + jobId, e.getMessage(), e); } log.debug( "Job [{0}] reg for SLA. Size of Sla Xml = [{1}]", jobId, XmlUtils.prettyPrint(eSla).toString().length()); return sla; }