use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class TestDBWorkflowStore method _testSaveAction.
private void _testSaveAction() throws StoreException, SQLException {
WorkflowActionBean a11 = new WorkflowActionBean();
store.beginTrx();
StringBuilder str = new StringBuilder();
str.append(System.currentTimeMillis());
str.append("11");
this.actionId = str.toString();
a11.setId(actionId);
a11.setJobId(wfBean1.getId());
a11.setName("a11");
a11.setStatus(WorkflowAction.Status.PREP);
store.insertAction(a11);
store.commitTrx();
/*
* WorkflowActionBean a12 = new WorkflowActionBean(); store.beginTrx();
* a12.setId("12"); a12.setName("a12"); a12.setJobId(wfBean1.getId());
* a12.setStatus(WorkflowAction.Status.PREP); store.insertAction(a12);
* store.commitTrx();
*
* WorkflowActionBean a21 = new WorkflowActionBean(); store.beginTrx();
* a21.setId("21"); a21.setName("a21"); a21.setJobId(wfBean2.getId());
* a21.setStatus(WorkflowAction.Status.PREP); store.insertAction(a21);
* store.commitTrx();
*
* WorkflowActionBean a22 = new WorkflowActionBean(); store.beginTrx();
* a22.setId("22"); a22.setName("a22"); a22.setJobId(wfBean2.getId());
* a22.setStatus(WorkflowAction.Status.PREP); store.insertAction(a22);
* store.commitTrx();
*/
/*
* SqlStatement s = getCount(OozieTable.ACTIONS); ResultSet rs =
* s.prepareAndSetValues(conn).executeQuery(); rs.next(); assertEquals(4,
* rs.getInt(1)); rs.close();
*
* s = getCount(OozieTable.ACTIONS).where(isEqual(ACTIONS_wfId,
* wfBean1.getId())); rs = s.prepareAndSetValues(conn).executeQuery();
* rs.next(); assertEquals(2, rs.getInt(1)); rs.close();
*
* s = getCount(OozieTable.ACTIONS).where(isEqual(ACTIONS_wfId,
* wfBean2.getId())); rs = s.prepareAndSetValues(conn).executeQuery();
* rs.next(); assertEquals(2, rs.getInt(1)); rs.close();
*
* s = getCount(OozieTable.ACTIONS).where(isEqual(ACTIONS_id, "11")); rs =
* s.prepareAndSetValues(conn).executeQuery(); rs.next(); assertEquals(1,
* rs.getInt(1)); rs.close();
*
* s = getCount(OozieTable.ACTIONS).where(isEqual(ACTIONS_id, "12")); rs =
* s.prepareAndSetValues(conn).executeQuery(); rs.next(); assertEquals(1,
* rs.getInt(1)); rs.close();
*/
}
use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class TestDBWorkflowStore method _testPurge.
private void _testPurge() throws Exception {
store.beginTrx();
wfBean1.setEndTime(new Date(System.currentTimeMillis() - (31 * 24 * 60 * 60 * 1000l)));
wfBean2.setEndTime(new Date(System.currentTimeMillis() - (31 * 24 * 60 * 60 * 1000l)));
WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
Configuration conf2 = new Configuration();
conf2.set(OozieClient.APP_PATH, "testPath");
conf2.set(OozieClient.LOG_TOKEN, "testToken");
conf2.set(OozieClient.USER_NAME, getTestUser2());
WorkflowJobBean wfBean3 = createWorkflow(app, conf2, "auth");
store.insertWorkflow(wfBean3);
store.updateWorkflow(wfBean2);
store.updateWorkflow(wfBean1);
store.commitTrx();
WorkflowActionBean a31 = new WorkflowActionBean();
StringBuilder str = new StringBuilder();
str.append(System.currentTimeMillis());
str.append("31");
a31.setId(str.toString());
a31.setJobId(wfBean3.getId());
a31.setStatus(WorkflowAction.Status.PREP);
store.beginTrx();
store.insertAction(a31);
store.commitTrx();
store.beginTrx();
store.purge(30, 10000);
store.commitTrx();
/*
* SqlStatement s = getCount(OozieTable.WF_JOBS); ResultSet rs =
* s.prepareAndSetValues(conn).executeQuery(); rs.next(); assertEquals(3,
* rs.getInt(1)); rs.close();
*
* s = getCount(OozieTable.WF_ACTIONS); rs =
* s.prepareAndSetValues(conn).executeQuery(); rs.next(); assertEquals(4,
* rs.getInt(1)); rs.close();
*
* store.purge(30); store.commit();
*
* s = getCount(OozieTable.WF_JOBS); rs =
* s.prepareAndSetValues(conn).executeQuery(); rs.next(); assertEquals(1,
* rs.getInt(1)); rs.close();
*
* WorkflowJobBean tmp = store.getWorkflow(wfBean3.getId(), false);
* assertEquals(tmp.getId(), wfBean3.getId());
*
* s = getCount(OozieTable.WF_ACTIONS); rs =
* s.prepareAndSetValues(conn).executeQuery(); rs.next(); assertEquals(1,
* rs.getInt(1)); rs.close();
*
* WorkflowActionBean tmpa = store.getAction("31", false); assertEquals("31",
* tmpa.getId());
*/
}
use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class TestDBWorkflowStore method _testLoadAction.
private void _testLoadAction() throws StoreException {
store.beginTrx();
WorkflowActionBean a11 = store.getAction(actionId, false);
assertEquals(a11.getId(), actionId);
assertEquals(a11.getJobId(), wfBean1.getId());
assertEquals(a11.getStatus(), WorkflowAction.Status.PREP);
store.commitTrx();
}
use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class ReRunXCommand method eagerVerifyPrecondition.
/**
* Checks the pre-conditions that are required for workflow to recover - Last run of Workflow should be completed -
* The nodes that are to be skipped are to be completed successfully in the base run.
*
* @throws CommandException
* @throws PreconditionException On failure of pre-conditions
*/
@Override
protected void eagerVerifyPrecondition() throws CommandException, PreconditionException {
// through conf.
if (wfBean.getParentId() != null && !conf.getBoolean(SubWorkflowActionExecutor.SUBWORKFLOW_RERUN, false) && ConfigurationService.getBoolean(DISABLE_CHILD_RERUN)) {
throw new CommandException(ErrorCode.E0755, " Rerun is not allowed through child workflow, please" + " re-run through the parent " + wfBean.getParentId());
}
if (!(wfBean.getStatus().equals(WorkflowJob.Status.FAILED) || wfBean.getStatus().equals(WorkflowJob.Status.KILLED) || wfBean.getStatus().equals(WorkflowJob.Status.SUCCEEDED))) {
throw new CommandException(ErrorCode.E0805, wfBean.getStatus());
}
Set<String> unmachedNodes = new HashSet<String>(nodesToSkip);
for (WorkflowActionBean action : actions) {
if (nodesToSkip.contains(action.getName())) {
if (!action.getStatus().equals(WorkflowAction.Status.OK) && !action.getStatus().equals(WorkflowAction.Status.ERROR)) {
throw new CommandException(ErrorCode.E0806, action.getName());
}
unmachedNodes.remove(action.getName());
}
}
if (unmachedNodes.size() > 0) {
StringBuilder sb = new StringBuilder();
String separator = "";
for (String s : unmachedNodes) {
sb.append(separator).append(s);
separator = ",";
}
throw new CommandException(ErrorCode.E0807, sb);
}
}
use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class KillXCommand method execute.
@Override
protected Void execute() throws CommandException {
LOG.info("STARTED WorkflowKillXCommand for jobId=" + wfId);
wfJob.setEndTime(new Date());
if (wfJob.getStatus() != WorkflowJob.Status.FAILED) {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
wfJob.setStatus(WorkflowJob.Status.KILLED);
SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(wfJob.getSlaXml(), wfJob.getId(), Status.KILLED, SlaAppType.WORKFLOW_JOB);
if (slaEvent != null) {
insertList.add(slaEvent);
}
try {
wfJob.getWorkflowInstance().kill();
} catch (WorkflowException e) {
throw new CommandException(ErrorCode.E0725, e.getMessage(), e);
}
WorkflowInstance wfInstance = wfJob.getWorkflowInstance();
((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.KILLED);
wfJob.setWorkflowInstance(wfInstance);
}
try {
for (WorkflowActionBean action : actionList) {
if (action.getStatus() == WorkflowActionBean.Status.RUNNING || action.getStatus() == WorkflowActionBean.Status.DONE) {
if (!(actionService.getExecutor(action.getType()) instanceof ControlNodeActionExecutor)) {
action.setPending();
}
action.setStatus(WorkflowActionBean.Status.KILLED);
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_STATUS_PENDING, action));
queue(new ActionKillXCommand(action.getId(), action.getType()));
} else if (action.getStatus() == WorkflowActionBean.Status.PREP || action.getStatus() == WorkflowActionBean.Status.START_RETRY || action.getStatus() == WorkflowActionBean.Status.START_MANUAL || action.getStatus() == WorkflowActionBean.Status.END_RETRY || action.getStatus() == WorkflowActionBean.Status.END_MANUAL || action.getStatus() == WorkflowActionBean.Status.USER_RETRY) {
action.setStatus(WorkflowActionBean.Status.KILLED);
action.resetPending();
SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(action.getSlaXml(), action.getId(), Status.KILLED, SlaAppType.WORKFLOW_ACTION);
if (slaEvent != null) {
insertList.add(slaEvent);
}
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_STATUS_PENDING, action));
if (EventHandlerService.isEnabled() && !(actionService.getExecutor(action.getType()) instanceof ControlNodeActionExecutor)) {
generateEvent(action, wfJob.getUser());
}
}
}
wfJob.setLastModifiedTime(new Date());
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_END, wfJob));
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
if (EventHandlerService.isEnabled()) {
generateEvent(wfJob);
}
queue(new WorkflowNotificationXCommand(wfJob));
} catch (JPAExecutorException e) {
throw new CommandException(e);
} finally {
if (wfJob.getStatus() == WorkflowJob.Status.KILLED) {
// To delete the WF temp dir
new WfEndXCommand(wfJob).call();
}
updateParentIfNecessary(wfJob);
}
LOG.info("ENDED WorkflowKillXCommand for jobId=" + wfId);
return null;
}
Aggregations