Search in sources :

Example 81 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean 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)

Example 82 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean in project oozie by apache.

the class TestSLAJobEventListener method createWorkflow.

private WorkflowJobBean createWorkflow(String id, Date actualStart) throws Exception {
    List<JsonBean> insertList = new ArrayList<JsonBean>();
    WorkflowJobBean workflow = new WorkflowJobBean();
    workflow.setId(id);
    workflow.setStatusStr("PREP");
    workflow.setStartTime(actualStart);
    workflow.setSlaXml("<sla></sla>");
    insertList.add(workflow);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
    return workflow;
}
Also used : JsonBean(org.apache.oozie.client.rest.JsonBean) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 83 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean in project oozie by apache.

the class TestGraphGenerator method testSimpleGraphDot.

public void testSimpleGraphDot() {
    final WorkflowJobBean jsonWFJob = createSimpleWorkflow();
    File outputDot = null;
    try {
        outputDot = File.createTempFile("graph-output", "graph-workflow-simple.dot");
        final String content = IOUtils.getResourceAsString("graph-workflow-simple.xml", -1);
        final GraphGenerator g = new GraphGenerator(content, jsonWFJob, true, new GraphvizRenderer());
        g.write(new FileOutputStream(outputDot), OutputFormat.DOT);
        final BufferedReader dotReader = new BufferedReader(new FileReader(outputDot));
        Assert.assertTrue("Rendered and written graph output file is not a DOT file", dotReader.readLine().equals("digraph {"));
    } catch (final Exception e) {
        Assert.fail("Render and write DOT failed: " + e.getMessage());
    } finally {
        if (outputDot != null) {
            outputDot.delete();
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) File(java.io.File) IOException(java.io.IOException)

Example 84 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean in project oozie by apache.

the class XDataTestCase method addRecordToWfJobTable.

protected WorkflowJobBean addRecordToWfJobTable(WorkflowApp app, WorkflowJob.Status jobStatus, WorkflowInstance.Status instanceStatus) throws Exception {
    Configuration conf = new Configuration();
    Path appUri = new Path(getAppPath(), "workflow.xml");
    conf.set(OozieClient.APP_PATH, appUri.toString());
    conf.set(OozieClient.LOG_TOKEN, "testToken");
    conf.set(OozieClient.USER_NAME, getTestUser());
    WorkflowJobBean wfBean = createWorkflow(app, conf, jobStatus, instanceStatus);
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        WorkflowJobInsertJPAExecutor wfInsertCmd = new WorkflowJobInsertJPAExecutor(wfBean);
        jpaService.execute(wfInsertCmd);
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test wf job record to table");
        throw je;
    }
    return wfBean;
}
Also used : Path(org.apache.hadoop.fs.Path) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowJobInsertJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 85 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean in project oozie by apache.

the class XDataTestCase method addRecordToWfJobTable.

/**
 * Insert subwf job for testing.
 *
 * @param jobStatus workflow job status
 * @param instanceStatus workflow instance status
 * @param parentId the id of the parent workflow
 * @return workflow job bean
 * @throws Exception thrown if unable to create workflow job bean
 */
protected WorkflowJobBean addRecordToWfJobTable(WorkflowJob.Status jobStatus, WorkflowInstance.Status instanceStatus, String parentId) throws Exception {
    WorkflowJobBean subwfBean = addRecordToWfJobTable(jobStatus, instanceStatus);
    subwfBean.setParentId(parentId);
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_PARENT_MODIFIED, subwfBean);
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test wf job record to table");
        throw je;
    }
    return subwfBean;
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Aggregations

WorkflowJobBean (org.apache.oozie.WorkflowJobBean)304 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)164 JPAService (org.apache.oozie.service.JPAService)95 XConfiguration (org.apache.oozie.util.XConfiguration)94 Configuration (org.apache.hadoop.conf.Configuration)66 Date (java.util.Date)60 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)58 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)57 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)53 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)53 Path (org.apache.hadoop.fs.Path)50 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)47 ArrayList (java.util.ArrayList)46 Test (org.junit.Test)32 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)30 Element (org.jdom.Element)28 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)26 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)25 HashMap (java.util.HashMap)23 BundleJobBean (org.apache.oozie.BundleJobBean)21