use of org.apache.oozie.workflow.WorkflowApp in project oozie by apache.
the class SubmitHttpXCommand method execute.
/* (non-Javadoc)
* @see org.apache.oozie.command.XCommand#execute()
*/
@Override
protected String execute() throws CommandException {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
WorkflowAppService wps = Services.get().get(WorkflowAppService.class);
try {
XLog.Info.get().setParameter(DagXLogInfoService.TOKEN, conf.get(OozieClient.LOG_TOKEN));
String wfXml = getWorkflowXml(conf);
LOG.debug("workflow xml created on the server side is :\n");
LOG.debug(wfXml);
WorkflowApp app = wps.parseDef(wfXml, conf);
XConfiguration protoActionConf = wps.createProtoActionConf(conf, false);
WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
PropertiesUtils.checkDisallowedProperties(conf, DISALLOWED_USER_PROPERTIES);
// Resolving all variables in the job properties.
// This ensures the Hadoop Configuration semantics is preserved.
XConfiguration resolvedVarsConf = new XConfiguration();
for (Map.Entry<String, String> entry : conf) {
resolvedVarsConf.set(entry.getKey(), conf.get(entry.getKey()));
}
conf = resolvedVarsConf;
WorkflowInstance wfInstance;
try {
wfInstance = workflowLib.createInstance(app, conf);
} catch (WorkflowException e) {
throw new StoreException(e);
}
Configuration conf = wfInstance.getConf();
WorkflowJobBean workflow = new WorkflowJobBean();
workflow.setId(wfInstance.getId());
workflow.setAppName(app.getName());
workflow.setAppPath(conf.get(OozieClient.APP_PATH));
workflow.setConf(XmlUtils.prettyPrint(conf).toString());
workflow.setProtoActionConf(protoActionConf.toXmlString());
workflow.setCreatedTime(new Date());
workflow.setLastModifiedTime(new Date());
workflow.setLogToken(conf.get(OozieClient.LOG_TOKEN, ""));
workflow.setStatus(WorkflowJob.Status.PREP);
workflow.setRun(0);
workflow.setUser(conf.get(OozieClient.USER_NAME));
workflow.setGroup(conf.get(OozieClient.GROUP_NAME));
workflow.setWorkflowInstance(wfInstance);
workflow.setExternalId(conf.get(OozieClient.EXTERNAL_ID));
LogUtils.setLogInfo(workflow);
JPAService jpaService = Services.get().get(JPAService.class);
if (jpaService != null) {
jpaService.execute(new WorkflowJobInsertJPAExecutor(workflow));
} else {
LOG.error(ErrorCode.E0610);
return null;
}
return workflow.getId();
} catch (WorkflowException ex) {
throw new CommandException(ex);
} catch (Exception ex) {
throw new CommandException(ErrorCode.E0803, ex.getMessage(), ex);
}
}
use of org.apache.oozie.workflow.WorkflowApp in project oozie by apache.
the class ActionExecutorTestCase method createBaseWorkflowWithCredentials.
/**
* Return a workflow job which contains one action with no configuration and workflow contains credentials information.
*
* @param protoConf
* @param actionName
* @return workflow job bean
* @throws Exception
*/
protected WorkflowJobBean createBaseWorkflowWithCredentials(XConfiguration protoConf, String actionName) throws Exception {
Path appUri = new Path(getAppPath(), "workflow.xml");
Reader reader = IOUtils.getResourceAsReader("wf-credentials.xml", -1);
String wfxml = IOUtils.getReaderAsString(reader, -1);
writeToFile(wfxml, getAppPath(), "workflow.xml");
WorkflowApp app = new LiteWorkflowApp("test-wf-cred", wfxml, new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "start")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
XConfiguration wfConf = new XConfiguration();
wfConf.set(OozieClient.USER_NAME, getTestUser());
wfConf.set(OozieClient.APP_PATH, appUri.toString());
WorkflowJobBean workflow = createWorkflow(app, wfConf, protoConf);
WorkflowActionBean action = new WorkflowActionBean();
action.setName(actionName);
action.setId(Services.get().get(UUIDService.class).generateChildId(workflow.getId(), actionName));
workflow.getActions().add(action);
return workflow;
}
use of org.apache.oozie.workflow.WorkflowApp in project oozie by apache.
the class ActionExecutorTestCase method createBaseWorkflow.
/**
* Return a workflow job which contains one action with no configuration.
*
* @param protoConf
* @param actionName
* @return workflow job bean
* @throws Exception
*/
protected WorkflowJobBean createBaseWorkflow(XConfiguration protoConf, String actionName) throws Exception {
Path appUri = new Path(getAppPath(), "workflow.xml");
String content = "<workflow-app xmlns='uri:oozie:workflow:1.0' xmlns:sla='uri:oozie:sla:0.1' name='no-op-wf'>";
content += "<start to='end' />";
content += "<end name='end' /></workflow-app>";
writeToFile(content, getAppPath(), "workflow.xml");
WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
XConfiguration wfConf = new XConfiguration();
wfConf.set(OozieClient.USER_NAME, getTestUser());
wfConf.set(OozieClient.APP_PATH, appUri.toString());
WorkflowJobBean workflow = createWorkflow(app, wfConf, protoConf);
WorkflowActionBean action = new WorkflowActionBean();
action.setName(actionName);
action.setId(Services.get().get(UUIDService.class).generateChildId(workflow.getId(), actionName));
workflow.getActions().add(action);
return workflow;
}
use of org.apache.oozie.workflow.WorkflowApp in project oozie by apache.
the class TestPurgeXCommand method addRecordToWfJobTableForNegCase.
protected WorkflowJobBean addRecordToWfJobTableForNegCase(WorkflowJob.Status jobStatus, WorkflowInstance.Status instanceStatus) throws Exception {
WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
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);
// Set start time to 100 days from now
wfBean.setStartTime(new Date(System.currentTimeMillis() + (long) 100 * 24 * 60 * 60 * 1000));
// Set end time to 100 days + 2 hours from now
wfBean.setEndTime(new Date(System.currentTimeMillis() + (long) 100 * 24 * 60 * 60 * 1000 + (long) 2 * 60 * 60 * 1000));
try {
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
WorkflowJobInsertJPAExecutor wfInsertCmd = new WorkflowJobInsertJPAExecutor(wfBean);
jpaService.execute(wfInsertCmd);
} catch (JPAExecutorException ce) {
ce.printStackTrace();
fail("Unable to insert the test wf job record to table");
throw ce;
}
return wfBean;
}
use of org.apache.oozie.workflow.WorkflowApp in project oozie by apache.
the class TestWorkflowIdGetForExternalIdJPAExecutor method addRecordToWfJobTable.
@Override
protected WorkflowJobBean addRecordToWfJobTable(WorkflowJob.Status jobStatus, WorkflowInstance.Status instanceStatus) throws Exception {
WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
Configuration conf = new Configuration();
conf.set(OozieClient.APP_PATH, "testPath");
conf.set(OozieClient.LOG_TOKEN, "testToken");
conf.set(OozieClient.USER_NAME, getTestUser());
WorkflowJobBean wfBean = createWorkflow(app, conf, jobStatus, instanceStatus);
wfBean.setExternalId("external-id");
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;
}
Aggregations