Search in sources :

Example 1 with SLACalculator

use of org.apache.oozie.sla.SLACalculator in project oozie by apache.

the class TestCoordSubmitXCommand method testSubmitWithSLAAlertsDisable.

public void testSubmitWithSLAAlertsDisable() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    // CASE 1: Failure case i.e. multiple data-in instances
    Reader reader = IOUtils.getResourceAsReader("coord-action-sla.xml", -1);
    Writer writer = new FileWriter(appPathFile);
    IOUtils.copyCharStream(reader, writer);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set("start", DateUtils.formatDateOozieTZ(new Date()));
    conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
    conf.set("frequency", "coord:days(1)");
    conf.set(OozieClient.USER_NAME, getTestUser());
    reader = IOUtils.getResourceAsReader("wf-credentials.xml", -1);
    appPathFile = new File(getTestCaseDir(), "workflow.xml");
    writer = new FileWriter(appPathFile);
    IOUtils.copyCharStream(reader, writer);
    conf.set("wfAppPath", appPathFile.getPath());
    Date nominalTime = new Date();
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(nominalTime));
    String coordId = new CoordSubmitXCommand(conf).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    SLAService slaService = services.get(SLAService.class);
    SLACalculator calc = slaService.getSLACalculator();
    SLACalcStatus slaCalc = calc.get(coordId + "@" + 1);
    assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    Configuration conf1 = new Configuration(conf);
    // CASE I: "ALL"
    conf1.set(OozieClient.SLA_DISABLE_ALERT, "ALL");
    coordId = new CoordSubmitXCommand(conf1).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaService = services.get(SLAService.class);
    calc = slaService.getSLACalculator();
    slaCalc = calc.get(coordId + "@" + 1);
    assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // CASE II: Date Range
    Configuration conf2 = new Configuration(conf);
    Date startRangeDate = new Date(nominalTime.getTime() - 3600 * 1000);
    conf2.set(OozieClient.SLA_DISABLE_ALERT, DateUtils.formatDateOozieTZ(startRangeDate) + "::" + DateUtils.formatDateOozieTZ(nominalTime));
    coordId = new CoordSubmitXCommand(conf2).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // CASE III: Coord name (negative test)
    Configuration conf3 = new Configuration(conf);
    conf3.set(OozieClient.SLA_DISABLE_ALERT_COORD, "test-coord-sla-x");
    coordId = new CoordSubmitXCommand(conf3).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // CASE IV: Older than n(hours)
    Date otherNominalTime = new Date(nominalTime.getTime() - 73 * 3600 * 1000);
    conf = new XConfiguration();
    appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set("wfAppPath", appPathFile.getPath());
    conf.set("start", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
    conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(otherNominalTime));
    conf.setInt(OozieClient.SLA_DISABLE_ALERT_OLDER_THAN, 72);
    coordId = new CoordSubmitXCommand(conf).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // catchup mode
    conf = new XConfiguration();
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set("wfAppPath", appPathFile.getPath());
    conf.set("start", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
    conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
    coordId = new CoordSubmitXCommand(conf).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // normal mode
    conf = new XConfiguration();
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set("wfAppPath", appPathFile.getPath());
    conf.set("start", DateUtils.formatDateOozieTZ(new Date()));
    conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(new Date()));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(new Date()));
    coordId = new CoordSubmitXCommand(conf).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) SLAService(org.apache.oozie.sla.service.SLAService) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) FileWriter(java.io.FileWriter) Reader(java.io.Reader) Date(java.util.Date) XConfiguration(org.apache.oozie.util.XConfiguration) SLACalculator(org.apache.oozie.sla.SLACalculator) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 2 with SLACalculator

use of org.apache.oozie.sla.SLACalculator in project oozie by apache.

the class SLAService method init.

@Override
public void init(Services services) throws ServiceException {
    try {
        Configuration conf = services.getConf();
        Class<? extends SLACalculator> calcClazz = (Class<? extends SLACalculator>) ConfigurationService.getClass(conf, CONF_CALCULATOR_IMPL);
        calcImpl = calcClazz == null ? new SLACalculatorMemory() : (SLACalculator) calcClazz.newInstance();
        calcImpl.init(conf);
        eventHandler = Services.get().get(EventHandlerService.class);
        if (eventHandler == null) {
            throw new ServiceException(ErrorCode.E0103, "EventHandlerService", "Add it under config " + Services.CONF_SERVICE_EXT_CLASSES + " or declare it BEFORE SLAService");
        }
        LOG = XLog.getLog(getClass());
        java.util.Set<String> appTypes = eventHandler.getAppTypes();
        appTypes.add("workflow_action");
        eventHandler.setAppTypes(appTypes);
        Runnable slaThread = new SLAWorker(calcImpl);
        // schedule runnable by default every 30 sec
        int slaCheckInterval = ConfigurationService.getInt(conf, CONF_SLA_CHECK_INTERVAL);
        int slaCheckInitialDelay = ConfigurationService.getInt(conf, CONF_SLA_CHECK_INITIAL_DELAY);
        services.get(SchedulerService.class).schedule(slaThread, slaCheckInitialDelay, slaCheckInterval, SchedulerService.Unit.SEC);
        slaEnabled = true;
        LOG.info("SLAService initialized with impl [{0}] capacity [{1}]", calcImpl.getClass().getName(), conf.get(SLAService.CONF_CAPACITY));
    } catch (Exception ex) {
        throw new ServiceException(ErrorCode.E0102, ex.getMessage(), ex);
    }
}
Also used : SchedulerService(org.apache.oozie.service.SchedulerService) Configuration(org.apache.hadoop.conf.Configuration) SLACalculatorMemory(org.apache.oozie.sla.SLACalculatorMemory) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) ServiceException(org.apache.oozie.service.ServiceException) EventHandlerService(org.apache.oozie.service.EventHandlerService) SLACalculator(org.apache.oozie.sla.SLACalculator) ServiceException(org.apache.oozie.service.ServiceException)

Example 3 with SLACalculator

use of org.apache.oozie.sla.SLACalculator in project oozie by apache.

the class TestCoordSubmitXCommand method testSLAAlertWithNewlyCreatedActions.

public void testSLAAlertWithNewlyCreatedActions() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    // CASE 1: Failure case i.e. multiple data-in instances
    Reader reader = IOUtils.getResourceAsReader("coord-action-sla.xml", -1);
    Writer writer = new FileWriter(appPathFile);
    IOUtils.copyCharStream(reader, writer);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set("start", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addDays(new Date(), -1)));
    conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
    conf.set(OozieClient.USER_NAME, getTestUser());
    reader = IOUtils.getResourceAsReader("wf-credentials.xml", -1);
    appPathFile = new File(getTestCaseDir(), "workflow.xml");
    writer = new FileWriter(appPathFile);
    IOUtils.copyCharStream(reader, writer);
    conf.set("wfAppPath", appPathFile.getPath());
    Date nominalTime = new Date();
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(nominalTime));
    String coordId = new CoordSubmitXCommand(conf).call();
    CoordinatorJobBean job = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, coordId);
    job.setMatThrottling(1);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQueryExecutor.CoordJobQuery.UPDATE_COORD_JOB, job);
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    SLAService slaService = services.get(SLAService.class);
    SLACalculator calc = slaService.getSLACalculator();
    SLACalcStatus slaCalc = calc.get(coordId + "@" + 1);
    assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    assertEquals(slaCalc.getExpectedDuration(), 1800000);
    job = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, coordId);
    assertEquals(job.getLastActionNumber(), 1);
    String newParams = RestConstants.SLA_MAX_DURATION + "=${5 * MINUTES}";
    new CoordSLAChangeXCommand(coordId, null, null, JobUtils.parseChangeValue(newParams)).call();
    new CoordSLAAlertsDisableXCommand(coordId, null, null).call();
    job = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, coordId);
    job.setMatThrottling(2);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQueryExecutor.CoordJobQuery.UPDATE_COORD_JOB, job);
    job = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, coordId);
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    job = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, coordId);
    slaCalc = calc.get(coordId + "@" + job.getLastActionNumber());
    assertEquals(slaCalc.getExpectedDuration(), 300000);
    // newly action should have sla disable after coord disable command on coord job
    assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    Element eAction = XmlUtils.parseXml(job.getJobXml());
    Element eSla = eAction.getChild("action", eAction.getNamespace()).getChild("info", eAction.getNamespace("sla"));
    assertEquals(SLAOperations.getTagElement(eSla, "max-duration"), "${5 * MINUTES}");
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) SLAService(org.apache.oozie.sla.service.SLAService) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) FileWriter(java.io.FileWriter) Element(org.jdom.Element) Reader(java.io.Reader) Date(java.util.Date) XConfiguration(org.apache.oozie.util.XConfiguration) SLACalculator(org.apache.oozie.sla.SLACalculator) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)3 SLACalculator (org.apache.oozie.sla.SLACalculator)3 File (java.io.File)2 FileWriter (java.io.FileWriter)2 Reader (java.io.Reader)2 Writer (java.io.Writer)2 Date (java.util.Date)2 SLACalcStatus (org.apache.oozie.sla.SLACalcStatus)2 SLAService (org.apache.oozie.sla.service.SLAService)2 XConfiguration (org.apache.oozie.util.XConfiguration)2 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)1 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)1 EventHandlerService (org.apache.oozie.service.EventHandlerService)1 SchedulerService (org.apache.oozie.service.SchedulerService)1 ServiceException (org.apache.oozie.service.ServiceException)1 SLACalculatorMemory (org.apache.oozie.sla.SLACalculatorMemory)1 Element (org.jdom.Element)1