use of org.apache.oozie.workflow.lite.LiteWorkflowInstance in project oozie by apache.
the class TestHadoopELFunctions method testHadoopConfFunctions.
public void testHadoopConfFunctions() throws Exception {
XConfiguration jobConf = new XConfiguration();
XConfiguration.copy(createJobConf(), jobConf);
String testHadoopOptionValue = jobConf.get("mapred.tasktracker.map.tasks.maximum");
jobConf.set("test.name.node.uri", getNameNodeUri());
jobConf.set("test.hadoop.option", "mapred.tasktracker.map.tasks.maximum");
WorkflowJobBean workflow = new WorkflowJobBean();
workflow.setProtoActionConf("<configuration/>");
LiteWorkflowApp wfApp = new LiteWorkflowApp("x", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "a"));
wfApp.addNode(new EndNodeDef("a", LiteWorkflowStoreService.LiteControlNodeHandler.class));
WorkflowInstance wi = new LiteWorkflowInstance(wfApp, jobConf, "1");
workflow.setWorkflowInstance(wi);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
jobConf.writeXml(baos);
workflow.setProtoActionConf(baos.toString());
final WorkflowActionBean action = new WorkflowActionBean();
ELEvaluator eval = Services.get().get(ELService.class).createEvaluator("workflow");
DagELFunctions.configureEvaluator(eval, workflow, action);
assertEquals(testHadoopOptionValue, eval.evaluate("${hadoop:conf(wf:conf('test.name.node.uri'), wf:conf('test.hadoop.option'))}", String.class));
}
use of org.apache.oozie.workflow.lite.LiteWorkflowInstance in project oozie by apache.
the class ActionXCommand method failJob.
/**
* Fail the job due to failed action
*
* @param context the execution context.
* @param action the action that caused the workflow to fail
* @throws CommandException thrown if unable to fail job
*/
public void failJob(ActionExecutor.Context context, WorkflowActionBean action) throws CommandException {
WorkflowJobBean workflow = (WorkflowJobBean) context.getWorkflow();
if (!handleUserRetry(context, action)) {
incrActionErrorCounter(action.getType(), "failed", 1);
LOG.warn("Failing Job due to failed action [{0}]", action.getName());
try {
workflow.getWorkflowInstance().fail(action.getName());
WorkflowInstance wfInstance = workflow.getWorkflowInstance();
((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.FAILED);
workflow.setWorkflowInstance(wfInstance);
workflow.setStatus(WorkflowJob.Status.FAILED);
action.setStatus(WorkflowAction.Status.FAILED);
action.resetPending();
queue(new WorkflowNotificationXCommand(workflow, action));
queue(new KillXCommand(workflow.getId()));
InstrumentUtils.incrJobCounter(INSTR_FAILED_JOBS_COUNTER_NAME, 1, getInstrumentation());
} catch (WorkflowException ex) {
throw new CommandException(ex);
}
}
}
use of org.apache.oozie.workflow.lite.LiteWorkflowInstance in project oozie by apache.
the class ResumeXCommand method execute.
@Override
protected Void execute() throws CommandException {
try {
if (workflow.getStatus() == WorkflowJob.Status.SUSPENDED) {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
workflow.getWorkflowInstance().resume();
WorkflowInstance wfInstance = workflow.getWorkflowInstance();
((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.RUNNING);
workflow.setWorkflowInstance(wfInstance);
workflow.setStatus(WorkflowJob.Status.RUNNING);
// for (WorkflowActionBean action : store.getActionsForWorkflow(id, false)) {
for (WorkflowActionBean action : jpaService.execute(new WorkflowJobGetActionsJPAExecutor(id))) {
// START_MANUAL or END_RETRY or END_MANUAL
if (action.isRetryOrManual()) {
action.setPendingOnly();
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_STATUS_PENDING, action));
}
if (action.isPending()) {
if (action.getStatus() == WorkflowActionBean.Status.PREP || action.getStatus() == WorkflowActionBean.Status.START_MANUAL) {
// a repeated transient error, we have to clean up the action dir
if (// The control actions have invalid
!action.getType().equals(StartActionExecutor.TYPE) && // action dir paths because they
!action.getType().equals(ForkActionExecutor.TYPE) && // contain ":" (colons)
!action.getType().equals(JoinActionExecutor.TYPE) && !action.getType().equals(KillActionExecutor.TYPE) && !action.getType().equals(EndActionExecutor.TYPE)) {
ActionExecutorContext context = new ActionXCommand.ActionExecutorContext(workflow, action, false, false);
if (context.getAppFileSystem().exists(context.getActionDir())) {
context.getAppFileSystem().delete(context.getActionDir(), true);
}
}
queue(new ActionStartXCommand(action.getId(), action.getType()));
} else {
if (action.getStatus() == WorkflowActionBean.Status.START_RETRY) {
Date nextRunTime = action.getPendingAge();
queue(new ActionStartXCommand(action.getId(), action.getType()), nextRunTime.getTime() - System.currentTimeMillis());
} else {
if (action.getStatus() == WorkflowActionBean.Status.DONE || action.getStatus() == WorkflowActionBean.Status.END_MANUAL) {
queue(new ActionEndXCommand(action.getId(), action.getType()));
} else {
if (action.getStatus() == WorkflowActionBean.Status.END_RETRY) {
Date nextRunTime = action.getPendingAge();
queue(new ActionEndXCommand(action.getId(), action.getType()), nextRunTime.getTime() - System.currentTimeMillis());
}
}
}
}
}
}
workflow.setLastModifiedTime(new Date());
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MODIFIED, workflow));
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(null, updateList, null);
if (EventHandlerService.isEnabled()) {
generateEvent(workflow);
}
queue(new WorkflowNotificationXCommand(workflow));
}
return null;
} catch (WorkflowException ex) {
throw new CommandException(ex);
} catch (JPAExecutorException e) {
throw new CommandException(e);
} catch (HadoopAccessorException e) {
throw new CommandException(e);
} catch (IOException e) {
throw new CommandException(ErrorCode.E0902, e.getMessage(), e);
} catch (URISyntaxException e) {
throw new CommandException(ErrorCode.E0902, e.getMessage(), e);
} finally {
updateParentIfNecessary(workflow);
}
}
use of org.apache.oozie.workflow.lite.LiteWorkflowInstance in project oozie by apache.
the class TestFsELFunctions method testFunctions.
public void testFunctions() throws Exception {
String file1 = new Path(getFsTestCaseDir(), "file1").toString();
String file2 = new Path(getFsTestCaseDir(), "file2").toString();
String dir = new Path(getFsTestCaseDir(), "dir").toString();
Configuration protoConf = new Configuration();
protoConf.set(OozieClient.USER_NAME, getTestUser());
protoConf.set("hadoop.job.ugi", getTestUser() + "," + "group");
FileSystem fs = getFileSystem();
fs.mkdirs(new Path(dir));
fs.create(new Path(file1)).close();
OutputStream os = fs.create(new Path(dir, "a"));
byte[] arr = new byte[1];
os.write(arr);
os.close();
os = fs.create(new Path(dir, "b"));
arr = new byte[2];
os.write(arr);
os.close();
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, "appPath");
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("test.dir", getTestCaseDir());
conf.set("file1", file1);
conf.set("file2", file2);
conf.set("file3", "${file2}");
conf.set("file4", getFsTestCaseDir() + "/file{1,2}");
conf.set("file5", getFsTestCaseDir() + "/file*");
conf.set("file6", getFsTestCaseDir() + "/file_*");
conf.set("dir", dir);
LiteWorkflowApp def = new LiteWorkflowApp("name", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
LiteWorkflowInstance job = new LiteWorkflowInstance(def, conf, "wfId");
WorkflowJobBean wf = new WorkflowJobBean();
wf.setId(job.getId());
wf.setAppName("name");
wf.setAppPath("appPath");
wf.setUser(getTestUser());
wf.setGroup("group");
wf.setWorkflowInstance(job);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
protoConf.writeXml(baos);
wf.setProtoActionConf(baos.toString());
WorkflowActionBean action = new WorkflowActionBean();
action.setId("actionId");
action.setName("actionName");
ELEvaluator eval = Services.get().get(ELService.class).createEvaluator("workflow");
DagELFunctions.configureEvaluator(eval, wf, action);
assertEquals(true, (boolean) eval.evaluate("${fs:exists(wf:conf('file1'))}", Boolean.class));
assertEquals(false, (boolean) eval.evaluate("${fs:exists(wf:conf('file2'))}", Boolean.class));
assertEquals(true, (boolean) eval.evaluate("${fs:exists(wf:conf('file4'))}", Boolean.class));
assertEquals(true, (boolean) eval.evaluate("${fs:exists(wf:conf('file5'))}", Boolean.class));
assertEquals(false, (boolean) eval.evaluate("${fs:exists(wf:conf('file6'))}", Boolean.class));
assertEquals(true, (boolean) eval.evaluate("${fs:exists(wf:conf('dir'))}", Boolean.class));
assertEquals(false, (boolean) eval.evaluate("${fs:isDir(wf:conf('file1'))}", Boolean.class));
assertEquals(0, (int) eval.evaluate("${fs:fileSize(wf:conf('file1'))}", Integer.class));
assertEquals(-1, (int) eval.evaluate("${fs:fileSize(wf:conf('file2'))}", Integer.class));
assertEquals(3, (int) eval.evaluate("${fs:dirSize(wf:conf('dir'))}", Integer.class));
assertEquals(-1, (int) eval.evaluate("${fs:blockSize(wf:conf('file2'))}", Integer.class));
assertTrue(eval.evaluate("${fs:blockSize(wf:conf('file1'))}", Integer.class) > 0);
}
use of org.apache.oozie.workflow.lite.LiteWorkflowInstance in project oozie by apache.
the class TestDagELFunctions method testFunctions.
public void testFunctions() throws Exception {
XConfiguration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, "appPath");
conf.set(OozieClient.USER_NAME, "user");
conf.set("a", "A");
LiteWorkflowApp def = new LiteWorkflowApp("name", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
LiteWorkflowInstance job = new LiteWorkflowInstance(def, conf, "wfId");
WorkflowJobBean wf = new WorkflowJobBean();
wf.setId(job.getId());
wf.setAppName("name");
wf.setAppPath("appPath");
wf.setUser("user");
wf.setGroup("group");
wf.setWorkflowInstance(job);
wf.setRun(2);
wf.setProtoActionConf(conf.toXmlString());
WorkflowActionBean action = new WorkflowActionBean();
action.setId("actionId");
action.setName("actionName");
action.setErrorInfo("ec", "em");
action.setData("b=B");
action.setExternalId("ext");
action.setTrackerUri("tracker");
action.setExternalStatus("externalStatus");
ELEvaluator eval = Services.get().get(ELService.class).createEvaluator("workflow");
DagELFunctions.configureEvaluator(eval, wf, action);
assertEquals("wfId", eval.evaluate("${wf:id()}", String.class));
assertEquals("name", eval.evaluate("${wf:name()}", String.class));
assertEquals("appPath", eval.evaluate("${wf:appPath()}", String.class));
assertEquals("A", eval.evaluate("${wf:conf('a')}", String.class));
assertEquals("A", eval.evaluate("${a}", String.class));
assertEquals("user", eval.evaluate("${wf:user()}", String.class));
assertEquals("group", eval.evaluate("${wf:group()}", String.class));
assertTrue(eval.evaluate("${wf:callback('XX')}", String.class).contains("id=actionId"));
assertTrue(eval.evaluate("${wf:callback('XX')}", String.class).contains("status=XX"));
assertTrue(eval.evaluate("${wf:callback('XX')}", String.class).contains("status=XX"));
assertEquals(2, (int) eval.evaluate("${wf:run()}", Integer.class));
action.setStatus(WorkflowAction.Status.ERROR);
System.out.println("WorkflowInstance " + wf.getWorkflowInstance().getStatus().toString());
WorkflowInstance wfInstance = wf.getWorkflowInstance();
DagELFunctions.setActionInfo(wfInstance, action);
wf.setWorkflowInstance(wfInstance);
assertEquals("actionName", eval.evaluate("${wf:lastErrorNode()}", String.class));
assertEquals("ec", eval.evaluate("${wf:errorCode('actionName')}", String.class));
assertEquals("em", eval.evaluate("${wf:errorMessage('actionName')}", String.class));
assertEquals("B", eval.evaluate("${wf:actionData('actionName')['b']}", String.class));
String expected = XmlUtils.escapeCharsForXML("{\"b\":\"B\"}");
assertEquals(expected, eval.evaluate("${toJsonStr(wf:actionData('actionName'))}", String.class));
expected = XmlUtils.escapeCharsForXML("b=B");
assertTrue(eval.evaluate("${toPropertiesStr(wf:actionData('actionName'))}", String.class).contains(expected));
conf = new XConfiguration();
conf.set("b", "B");
expected = XmlUtils.escapeCharsForXML(XmlUtils.prettyPrint(conf).toString());
assertTrue(eval.evaluate("${toConfigurationStr(wf:actionData('actionName'))}", String.class).contains(expected));
assertEquals("ext", eval.evaluate("${wf:actionExternalId('actionName')}", String.class));
assertEquals("tracker", eval.evaluate("${wf:actionTrackerUri('actionName')}", String.class));
assertEquals("externalStatus", eval.evaluate("${wf:actionExternalStatus('actionName')}", String.class));
}
Aggregations