Search in sources :

Example 6 with SubmitXCommand

use of org.apache.oozie.command.wf.SubmitXCommand in project oozie by apache.

the class TestSLAEventGeneration method _testWorkflowJobSubmitStart.

private void _testWorkflowJobSubmitStart(Configuration conf, SLAService slas, boolean isNew) throws Exception {
    cal.setTime(new Date());
    // for start_miss
    cal.add(Calendar.MINUTE, -20);
    Date nominal = cal.getTime();
    String nominalTime = DateUtils.formatDateOozieTZ(nominal);
    conf.set("nominal_time", nominalTime);
    cal.setTime(nominal);
    // as per the sla xml
    cal.add(Calendar.MINUTE, 10);
    String expectedStart = DateUtils.formatDateOozieTZ(cal.getTime());
    cal.setTime(nominal);
    // as per the sla xml
    cal.add(Calendar.MINUTE, 30);
    String expectedEnd = DateUtils.formatDateOozieTZ(cal.getTime());
    // testing creation of new sla registration via Submit command
    SubmitXCommand sc = new SubmitXCommand(conf);
    String jobId = sc.call();
    SLACalcStatus slaEvent = slas.getSLACalculator().get(jobId);
    assertEquals(jobId, slaEvent.getId());
    assertEquals("test-wf-job-sla", slaEvent.getAppName());
    assertEquals(AppType.WORKFLOW_JOB, slaEvent.getAppType());
    assertEquals(nominalTime, DateUtils.formatDateOozieTZ(slaEvent.getNominalTime()));
    assertEquals(expectedStart, DateUtils.formatDateOozieTZ(slaEvent.getExpectedStart()));
    assertEquals(expectedEnd, DateUtils.formatDateOozieTZ(slaEvent.getExpectedEnd()));
    if (isNew) {
        assertEquals(30 * 60 * 1000, slaEvent.getExpectedDuration());
        assertEquals(alert_events, slaEvent.getAlertEvents());
    }
    slas.runSLAWorker();
    slaEvent = skipToSLAEvent();
    assertEquals(SLAStatus.NOT_STARTED, slaEvent.getSLAStatus());
    assertEquals(EventStatus.START_MISS, slaEvent.getEventStatus());
    // test that sla processes the Job Event from Start command
    new StartXCommand(jobId).call();
    slaEvent = slas.getSLACalculator().get(jobId);
    // resetting to receive sla events
    slaEvent.setEventProcessed(0);
    SLASummaryBean suBean = new SLASummaryBean();
    suBean.setId(jobId);
    suBean.setEventProcessed(0);
    SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_EVENTPROCESSED, suBean);
    waitForEventGeneration(200);
    ehs.new EventWorker().run();
    waitForEventGeneration(300);
    slaEvent = skipToSLAEvent();
    assertEquals(jobId, slaEvent.getId());
    assertNotNull(slaEvent.getActualStart());
    assertEquals(SLAStatus.IN_PROCESS, slaEvent.getSLAStatus());
    assertEquals(WorkflowJob.Status.RUNNING.name(), slaEvent.getJobStatus());
    ehs.getEventQueue().clear();
}
Also used : CoordSubmitXCommand(org.apache.oozie.command.coord.CoordSubmitXCommand) SubmitXCommand(org.apache.oozie.command.wf.SubmitXCommand) StartXCommand(org.apache.oozie.command.wf.StartXCommand) CoordActionStartXCommand(org.apache.oozie.command.coord.CoordActionStartXCommand) Date(java.util.Date)

Example 7 with SubmitXCommand

use of org.apache.oozie.command.wf.SubmitXCommand in project oozie by apache.

the class TestSLAEventGeneration method _testWorkflowJobKillCommand.

private void _testWorkflowJobKillCommand(Configuration conf, SLAService slas) throws Exception {
    cal.setTime(new Date());
    // for start_miss
    cal.add(Calendar.MINUTE, -20);
    Date nominal = cal.getTime();
    String nominalTime = DateUtils.formatDateOozieTZ(nominal);
    conf.set("nominal_time", nominalTime);
    // test that sla processes the Job Event from Kill command
    // submit new job
    String jobId = new SubmitXCommand(conf).call();
    new KillXCommand(jobId).call();
    // wait for wf-action kill event to generate
    waitForEventGeneration(200);
    ehs.new EventWorker().run();
    // time for listeners to run
    waitForEventGeneration(300);
    SLACalcStatus slaEvent = skipToSLAEvent();
    assertEquals(jobId, slaEvent.getId());
    assertNotNull(slaEvent.getActualEnd());
    assertEquals(EventStatus.END_MISS, slaEvent.getEventStatus());
    assertEquals(SLAStatus.MISS, slaEvent.getSLAStatus());
    assertEquals(WorkflowJob.Status.KILLED.name(), slaEvent.getJobStatus());
}
Also used : CoordSubmitXCommand(org.apache.oozie.command.coord.CoordSubmitXCommand) SubmitXCommand(org.apache.oozie.command.wf.SubmitXCommand) KillXCommand(org.apache.oozie.command.wf.KillXCommand) CoordKillXCommand(org.apache.oozie.command.coord.CoordKillXCommand) Date(java.util.Date)

Aggregations

SubmitXCommand (org.apache.oozie.command.wf.SubmitXCommand)7 Date (java.util.Date)4 CoordSubmitXCommand (org.apache.oozie.command.coord.CoordSubmitXCommand)4 Configuration (org.apache.hadoop.conf.Configuration)3 XConfiguration (org.apache.oozie.util.XConfiguration)3 Path (org.apache.hadoop.fs.Path)2 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)2 CommandException (org.apache.oozie.command.CommandException)2 ReRunXCommand (org.apache.oozie.command.wf.ReRunXCommand)2 StartXCommand (org.apache.oozie.command.wf.StartXCommand)2 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)2 JPAService (org.apache.oozie.service.JPAService)2 SLAService (org.apache.oozie.sla.service.SLAService)2 Test (org.junit.Test)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringReader (java.io.StringReader)1