use of org.apache.oozie.DagEngine in project oozie by apache.
the class TestActionErrors method _testNonTransientWithCoordActionUpdate.
/**
* Provides functionality to test non transient failures and coordinator action update
*
* @param errorType the error type. (start.non-transient, end.non-transient)
* @param expStatus1 expected status. (START_MANUAL, END_MANUAL)
* @param expErrorMsg expected error message.
* @throws Exception
*/
private void _testNonTransientWithCoordActionUpdate(String errorType, WorkflowActionBean.Status expStatus1, String expErrorMsg) throws Exception {
String workflowPath = getTestCaseFileUri("workflow.xml");
Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
IOUtils.copyCharStream(reader, writer);
final DagEngine engine = new DagEngine("u");
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, workflowPath);
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set(OozieClient.LOG_TOKEN, "t");
conf.set("signal-value", "OK");
conf.set("external-status", "ok");
conf.set("error", errorType);
final String jobId = engine.submitJob(conf, false);
final JPAService jpaService = Services.get().get(JPAService.class);
final CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
CoordinatorActionBean coordAction = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", jobId, "RUNNING", 0);
engine.start(jobId);
waitFor(5000, new Predicate() {
public boolean evaluate() throws Exception {
return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUSPENDED);
}
});
assertNotNull(jpaService);
WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(jobId);
WorkflowJobBean job = jpaService.execute(wfGetCmd);
WorkflowActionsGetForJobJPAExecutor actionsGetExe = new WorkflowActionsGetForJobJPAExecutor(jobId);
List<WorkflowActionBean> actionsList = jpaService.execute(actionsGetExe);
int n = actionsList.size();
WorkflowActionBean action = actionsList.get(n - 1);
assertEquals("TEST_ERROR", action.getErrorCode());
assertEquals(expErrorMsg, action.getErrorMessage());
assertEquals(expStatus1, action.getStatus());
assertFalse(action.isPending());
assertEquals(WorkflowJob.Status.SUSPENDED, job.getStatus());
waitFor(5000, new Predicate() {
public boolean evaluate() throws Exception {
CoordinatorActionBean coordAction2 = jpaService.execute(new CoordActionGetForExternalIdJPAExecutor(jobId));
return coordAction2.getStatus().equals(CoordinatorAction.Status.SUSPENDED);
}
});
coordAction = jpaService.execute(new CoordActionGetForExternalIdJPAExecutor(jobId));
assertEquals(CoordinatorAction.Status.SUSPENDED, coordAction.getStatus());
}
use of org.apache.oozie.DagEngine in project oozie by apache.
the class TestEventGeneration method testForNoDuplicatesWorkflowEvents.
@Test
public void testForNoDuplicatesWorkflowEvents() throws Exception {
// test workflow job events
Reader reader = IOUtils.getResourceAsReader("wf-no-op.xml", -1);
Writer writer = new FileWriter(getTestCaseDir() + "/workflow.xml");
IOUtils.copyCharStream(reader, writer);
final DagEngine engine = new DagEngine(getTestUser());
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
conf.set(OozieClient.USER_NAME, getTestUser());
final String jobId1 = engine.submitJob(conf, true);
final WorkflowJobGetJPAExecutor readCmd = new WorkflowJobGetJPAExecutor(jobId1);
waitFor(1 * 100, new Predicate() {
@Override
public boolean evaluate() throws Exception {
return jpaService.execute(readCmd).getStatus() == WorkflowJob.Status.SUCCEEDED;
}
});
assertEquals(2, queue.size());
assertEquals(EventStatus.STARTED, ((JobEvent) queue.poll()).getEventStatus());
assertEquals(EventStatus.SUCCESS, ((JobEvent) queue.poll()).getEventStatus());
queue.clear();
}
use of org.apache.oozie.DagEngine in project oozie by apache.
the class TestSignalXCommand method _testJoinFail.
public void _testJoinFail() throws Exception {
Logger logger = Logger.getLogger(SignalXCommand.class);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, out);
logger.addAppender(appender);
FileSystem fs = getFileSystem();
Path appPath = new Path(getFsTestCaseDir(), "app");
fs.mkdirs(appPath);
Reader reader = IOUtils.getResourceAsReader("wf-fork.xml", -1);
Writer writer = new OutputStreamWriter(fs.create(new Path(appPath, "workflow.xml")));
IOUtils.copyCharStream(reader, writer);
writer.close();
reader.close();
final DagEngine engine = new DagEngine("u");
XConfiguration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, new Path(appPath, "workflow.xml").toString());
conf.set(OozieClient.USER_NAME, getTestUser());
final String jobId = engine.submitJob(conf, false);
assertNotNull(jobId);
engine.start(jobId);
Thread.sleep(2000);
assertFalse(out.toString().contains("EntityExistsException"));
}
use of org.apache.oozie.DagEngine in project oozie by apache.
the class TestPurgeService method testPurgeServiceForWorkflow.
/**
* Tests the {@link org.apache.oozie.service.PurgeService}.
* </p>
* Creates and runs a new workflow job to completion.
* Attempts to purge jobs older than a day. Verifies the presence of the job in the system.
* </p>
* Sets the end date for the same job to make it qualify for the purge criteria.
* Calls the purge service, and ensure the job does not exist in the system.
*/
public void testPurgeServiceForWorkflow() throws Exception {
Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
IOUtils.copyCharStream(reader, writer);
final DagEngine engine = new DagEngine("u");
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
conf.setStrings(OozieClient.USER_NAME, getTestUser());
conf.setStrings(OozieClient.GROUP_NAME, getTestGroup());
conf.set(OozieClient.LOG_TOKEN, "t");
conf.set("external-status", "ok");
conf.set("signal-value", "based_on_action_status");
final String jobId = engine.submitJob(conf, true);
waitFor(5000, new Predicate() {
public boolean evaluate() throws Exception {
return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED);
}
});
assertEquals(WorkflowJob.Status.SUCCEEDED, engine.getJob(jobId).getStatus());
new PurgeXCommand(1, 1, 1, 10000).call();
sleep(1000);
JPAService jpaService = Services.get().get(JPAService.class);
WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(jobId);
WorkflowJobBean wfBean = jpaService.execute(wfJobGetCmd);
Date endDate = new Date(System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000);
wfBean.setEndTime(endDate);
wfBean.setLastModifiedTime(new Date());
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_END, wfBean);
Runnable purgeRunnable = new PurgeRunnable(1, 1, 1, 100);
purgeRunnable.run();
waitFor(10000, new Predicate() {
public boolean evaluate() throws Exception {
try {
engine.getJob(jobId).getStatus();
} catch (Exception ex) {
return true;
}
return false;
}
});
try {
engine.getJob(jobId).getStatus();
fail("Job should be purged. Should fail.");
} catch (Exception ex) {
assertEquals(ex.getClass(), DagEngineException.class);
DagEngineException dex = (DagEngineException) ex;
assertEquals(ErrorCode.E0604, dex.getErrorCode());
}
}
use of org.apache.oozie.DagEngine in project oozie by apache.
the class TestActionCheckerService method testActionCheckerServiceDelay.
/**
* Tests the delayed check functionality of the Action Check Service
* Runnable. </p> Starts an action which behaves like an Async Action
* (Action and Job state set to Running). Verifies the action status to be
* RUNNING. </p> Updates the last check time to now, and attempts to run the
* ActionCheckRunnable with the delay configured to 20 seconds.
*
* @throws Exception
*/
public void testActionCheckerServiceDelay() throws Exception {
Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
IOUtils.copyCharStream(reader, writer);
final DagEngine engine = new DagEngine("u");
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
conf.setStrings(WorkflowAppService.HADOOP_USER, getTestUser());
conf.setStrings(OozieClient.GROUP_NAME, getTestGroup());
conf.set(OozieClient.LOG_TOKEN, "t");
conf.set("external-status", "ok");
conf.set("signal-value", "based_on_action_status");
conf.set("running-mode", "async");
final String jobId = engine.submitJob(conf, true);
sleep(200);
waitFor(5000, new Predicate() {
public boolean evaluate() throws Exception {
return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.RUNNING);
}
});
sleep(100);
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobId);
List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
WorkflowActionBean action = null;
for (WorkflowActionBean bean : actions) {
if (bean.getType().equals("test")) {
action = bean;
break;
}
}
assertNotNull(action);
assertEquals(WorkflowActionBean.Status.RUNNING, action.getStatus());
action.setLastCheckTime(new Date());
WorkflowActionQueryExecutor.getInstance().executeUpdate(WorkflowActionQuery.UPDATE_ACTION_FOR_LAST_CHECKED_TIME, action);
int actionCheckDelay = 20;
Runnable actionCheckRunnable = new ActionCheckRunnable(actionCheckDelay);
actionCheckRunnable.run();
sleep(3000);
List<WorkflowActionBean> actions2 = jpaService.execute(actionsGetExecutor);
WorkflowActionBean action2 = null;
for (WorkflowActionBean bean : actions2) {
if (bean.getType().equals("test")) {
action2 = bean;
break;
}
}
assertNotNull(action);
assertEquals(WorkflowActionBean.Status.RUNNING, action2.getStatus());
assertEquals(WorkflowJob.Status.RUNNING, engine.getJob(jobId).getStatus());
}
Aggregations