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()));
}
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;
}
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();
}
}
}
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;
}
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;
}
Aggregations