Esempio n. 1
0
 /**
  * Retrieve registration event
  *
  * @param jobId the jobId
  * @throws CommandException
  * @throws JPAExecutorException
  */
 public static void updateRegistrationEvent(String jobId)
     throws CommandException, JPAExecutorException {
   JPAService jpaService = Services.get().get(JPAService.class);
   SLAService slaService = Services.get().get(SLAService.class);
   try {
     SLARegistrationBean reg =
         SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, jobId);
     if (reg != null) { // handle coord rerun with different config without sla
       slaService.updateRegistrationEvent(reg);
     }
   } catch (ServiceException e) {
     throw new CommandException(ErrorCode.E1007, " id " + jobId, e.getMessage(), e);
   }
 }
 @Test
 public void testListenerConfigured() throws Exception {
   EventHandlerService ehs = services.get(EventHandlerService.class);
   assertNotNull(ehs);
   assertTrue(SLAService.isEnabled());
   assertTrue(ehs.listEventListeners().contains(SLAJobEventListener.class.getCanonicalName()));
 }
Esempio n. 3
0
  @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();
      }
    }
  }
Esempio n. 4
0
  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;
  }
  @Test
  public void testOnJobEvent() throws Exception {
    SLAService slas = services.get(SLAService.class);
    SLAJobEventListener listener = new SLAJobEventListener();
    listener.init(services.getConf());
    // add dummy registration events to the SLAService map
    SLARegistrationBean job = _createSLARegBean("wf1", AppType.WORKFLOW_JOB);
    job.setExpectedStart(DateUtils.parseDateUTC("2012-07-22T00:00Z"));
    slas.addRegistrationEvent(job);
    assertEquals(1, slas.getSLACalculator().size());
    Date actualStart = DateUtils.parseDateUTC("2012-07-22T01:00Z");
    WorkflowJobEvent wfe =
        new WorkflowJobEvent(
            "wf1", "caId1", WorkflowJob.Status.RUNNING, "user1", "wf-app-name1", actualStart, null);
    listener.onWorkflowJobEvent(wfe);
    SLACalcStatus serviceObj = slas.getSLACalculator().get("wf1");
    // check that start sla has been calculated
    assertEquals(EventStatus.START_MISS, serviceObj.getEventStatus());
    assertEquals(1, serviceObj.getEventProcessed()); // Job switching to running is only partially
    // sla processed. so state = 1

    job = _createSLARegBean("wfId1@wa1", AppType.WORKFLOW_ACTION);
    slas.addRegistrationEvent(job);
    assertEquals(2, slas.getSLACalculator().size());
    job.setExpectedStart(DateUtils.parseDateUTC("2012-07-22T00:00Z"));
    WorkflowActionEvent wae =
        new WorkflowActionEvent(
            "wfId1@wa1",
            "wfId1",
            WorkflowAction.Status.RUNNING,
            "user1",
            "wf-app-name1",
            actualStart,
            null);
    listener.onWorkflowActionEvent(wae);
    serviceObj = slas.getSLACalculator().get("wfId1@wa1");
    // check that start sla has been calculated
    assertEquals(EventStatus.START_MISS, serviceObj.getEventStatus());

    job = _createSLARegBean("cj1", AppType.COORDINATOR_JOB);
    job.setExpectedEnd(DateUtils.parseDateUTC("2012-07-22T01:00Z"));
    slas.addRegistrationEvent(job);
    assertEquals(3, slas.getSLACalculator().size());
    Date actualEnd = DateUtils.parseDateUTC("2012-07-22T00:00Z");
    CoordinatorJobEvent cje =
        new CoordinatorJobEvent(
            "cj1",
            "bj1",
            CoordinatorJob.Status.SUCCEEDED,
            "user1",
            "coord-app-name1",
            actualStart,
            actualEnd);
    listener.onCoordinatorJobEvent(cje);

    SLASummaryBean summary =
        SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, "cj1");
    // check that end and duration sla has been calculated
    assertEquals(6, summary.getEventProcessed());

    assertEquals(EventStatus.END_MET, summary.getEventStatus());

    job = _createSLARegBean("cj1@ca1", AppType.COORDINATOR_ACTION);
    actualEnd = DateUtils.parseDateUTC("2012-07-22T02:00Z");
    slas.addRegistrationEvent(job);
    assertEquals(4, slas.getSLACalculator().size());
    CoordinatorActionEvent cae =
        new CoordinatorActionEvent(
            "cj1@ca1",
            "cj1",
            CoordinatorAction.Status.RUNNING,
            "user1",
            "coord-app-name1",
            null,
            actualEnd,
            null);
    listener.onCoordinatorActionEvent(cae);
    cae =
        new CoordinatorActionEvent(
            "cj1@ca1",
            "cj1",
            CoordinatorAction.Status.KILLED,
            "user1",
            "coord-app-name1",
            null,
            actualEnd,
            null);
    listener.onCoordinatorActionEvent(cae);
    summary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, "cj1@ca1");
    // check that all events are processed
    assertEquals(8, summary.getEventProcessed());
    assertEquals(EventStatus.END_MISS, summary.getEventStatus());
    assertEquals(3, slas.getSLACalculator().size());
  }