Search in sources :

Example 1 with ReRunXCommand

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

the class DagEngine method reRun.

/**
 * Rerun a job.
 *
 * @param jobId job Id to rerun.
 * @param conf configuration information for the rerun.
 * @throws DagEngineException thrown if the job could not be rerun.
 */
@Override
public void reRun(String jobId, Configuration conf) throws DagEngineException {
    try {
        WorkflowJobBean wfBean = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, jobId);
        Configuration wfConf = new XConfiguration(new StringReader(wfBean.getConf()));
        XConfiguration.copy(conf, wfConf);
        validateReRunConfiguration(wfConf);
        new ReRunXCommand(jobId, wfConf).call();
    } catch (CommandException ex) {
        throw new DagEngineException(ex);
    } catch (JPAExecutorException ex) {
        throw new DagEngineException(ex);
    } catch (IOException ex) {
        throw new DagEngineException(ErrorCode.E0803, ex.getMessage());
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) ReRunXCommand(org.apache.oozie.command.wf.ReRunXCommand) StringReader(java.io.StringReader) CommandException(org.apache.oozie.command.CommandException) IOException(java.io.IOException)

Example 2 with ReRunXCommand

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

the class TestSLAEventGeneration method testWorkflowJobSLARerun.

/**
 * Test for SLA Events generated through wf rerun
 *
 * @throws Exception
 */
@Test
public void testWorkflowJobSLARerun() throws Exception {
    SLAService slas = services.get(SLAService.class);
    String wfXml = IOUtils.getResourceAsString("wf-job-sla.xml", -1);
    Path appPath = getFsTestCaseDir();
    writeToFile(wfXml, appPath, "workflow.xml");
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, appPath.toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    cal.setTime(new Date());
    // for start_miss
    cal.add(Calendar.MINUTE, -40);
    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());
    // Call SubmitX
    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()));
    slas.runSLAWorker();
    slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
    assertEquals(SLAStatus.NOT_STARTED, slaEvent.getSLAStatus());
    assertEquals(EventStatus.START_MISS, slaEvent.getEventStatus());
    slas.getSLACalculator().clear();
    JPAService jpaService = Services.get().get(JPAService.class);
    WorkflowJobBean wfBean = jpaService.execute(new WorkflowJobGetJPAExecutor(jobId));
    // set job status to succeeded, so rerun doesn't fail
    wfBean.setStatus(WorkflowJob.Status.SUCCEEDED);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wfBean);
    // change conf for rerun
    cal.setTime(new Date());
    // for start_miss
    cal.add(Calendar.MINUTE, -20);
    nominalTime = DateUtils.formatDateOozieTZ(cal.getTime());
    conf.set("nominal_time", nominalTime);
    nominal = cal.getTime();
    // as per the sla xml
    cal.add(Calendar.MINUTE, 10);
    expectedStart = DateUtils.formatDateOozieTZ(cal.getTime());
    cal.setTime(nominal);
    // as per the sla xml
    cal.add(Calendar.MINUTE, 30);
    expectedEnd = DateUtils.formatDateOozieTZ(cal.getTime());
    ReRunXCommand rerun = new ReRunXCommand(jobId, conf);
    rerun.call();
    slaEvent = slas.getSLACalculator().get(jobId);
    // assert for new conf
    assertNotNull(slaEvent);
    assertEquals(jobId, slaEvent.getId());
    assertEquals("test-wf-job-sla", slaEvent.getAppName());
    assertEquals(AppType.WORKFLOW_JOB, slaEvent.getAppType());
    // assert for new conf
    assertEquals(nominalTime, DateUtils.formatDateOozieTZ(slaEvent.getNominalTime()));
    assertEquals(expectedStart, DateUtils.formatDateOozieTZ(slaEvent.getExpectedStart()));
    assertEquals(expectedEnd, DateUtils.formatDateOozieTZ(slaEvent.getExpectedEnd()));
    // assert for values in summary bean to be reset
    SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
    assertEquals(0, slaSummary.getEventProcessed());
    assertEquals(-1, slaSummary.getActualDuration());
    assertNull(slaSummary.getActualStart());
    assertNull(slaSummary.getActualEnd());
    assertEquals("PREP", slaSummary.getJobStatus());
    assertEquals(SLAStatus.NOT_STARTED, slaSummary.getSLAStatus());
    assertNull(slaEvent.getEventStatus());
    ehs.getEventQueue().clear();
    slas.runSLAWorker();
    slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
    assertEquals(SLAStatus.IN_PROCESS, slaEvent.getSLAStatus());
    assertEquals(EventStatus.START_MISS, slaEvent.getEventStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) SLAService(org.apache.oozie.sla.service.SLAService) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) ReRunXCommand(org.apache.oozie.command.wf.ReRunXCommand) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) XConfiguration(org.apache.oozie.util.XConfiguration) CoordSubmitXCommand(org.apache.oozie.command.coord.CoordSubmitXCommand) SubmitXCommand(org.apache.oozie.command.wf.SubmitXCommand) JPAService(org.apache.oozie.service.JPAService) Test(org.junit.Test)

Example 3 with ReRunXCommand

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

the class TestSLAEventGeneration method testWorkflowActionSLARerun.

/**
 * Test for SLA Events generated through wf action rerun
 *
 * @throws Exception
 */
@Test
public void testWorkflowActionSLARerun() throws Exception {
    SLAService slas = services.get(SLAService.class);
    String wfXml = IOUtils.getResourceAsString("wf-action-sla.xml", -1);
    Path appPath = getFsTestCaseDir();
    writeToFile(wfXml, appPath, "workflow.xml");
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, appPath.toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    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);
    // Call SubmitX
    SubmitXCommand sc = new SubmitXCommand(conf);
    String jobId = sc.call();
    String actionId = jobId + "@grouper";
    slas.getSLACalculator().clear();
    JPAService jpaService = Services.get().get(JPAService.class);
    WorkflowJobBean wfBean = jpaService.execute(new WorkflowJobGetJPAExecutor(jobId));
    // set job status to succeeded, so rerun doesn't fail
    wfBean.setStatus(WorkflowJob.Status.SUCCEEDED);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wfBean);
    // change conf for rerun
    cal.setTime(new Date());
    nominalTime = DateUtils.formatDateOozieTZ(cal.getTime());
    conf.set("nominal_time", nominalTime);
    nominal = cal.getTime();
    // 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());
    ReRunXCommand rerun = new ReRunXCommand(jobId, conf);
    rerun.call();
    SLACalcStatus slaEvent = slas.getSLACalculator().get(actionId);
    assertNotNull(slaEvent);
    // assert for action configs
    assertEquals(actionId, slaEvent.getId());
    assertEquals("test-wf-action-sla", slaEvent.getAppName());
    assertEquals(AppType.WORKFLOW_ACTION, slaEvent.getAppType());
    // assert for new conf
    assertEquals(nominalTime, DateUtils.formatDateOozieTZ(slaEvent.getNominalTime()));
    assertEquals(expectedStart, DateUtils.formatDateOozieTZ(slaEvent.getExpectedStart()));
    assertEquals(expectedEnd, DateUtils.formatDateOozieTZ(slaEvent.getExpectedEnd()));
}
Also used : Path(org.apache.hadoop.fs.Path) WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) SLAService(org.apache.oozie.sla.service.SLAService) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) ReRunXCommand(org.apache.oozie.command.wf.ReRunXCommand) CoordSubmitXCommand(org.apache.oozie.command.coord.CoordSubmitXCommand) SubmitXCommand(org.apache.oozie.command.wf.SubmitXCommand) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)3 ReRunXCommand (org.apache.oozie.command.wf.ReRunXCommand)3 XConfiguration (org.apache.oozie.util.XConfiguration)3 Date (java.util.Date)2 Path (org.apache.hadoop.fs.Path)2 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)2 CoordSubmitXCommand (org.apache.oozie.command.coord.CoordSubmitXCommand)2 SubmitXCommand (org.apache.oozie.command.wf.SubmitXCommand)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 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 CommandException (org.apache.oozie.command.CommandException)1 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)1