Search in sources :

Example 11 with WorkflowApp

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);
    }
}
Also used : WorkflowApp(org.apache.oozie.workflow.WorkflowApp) WorkflowLib(org.apache.oozie.workflow.WorkflowLib) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowAppService(org.apache.oozie.service.WorkflowAppService) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) WorkflowException(org.apache.oozie.workflow.WorkflowException) WorkflowJobInsertJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor) CommandException(org.apache.oozie.command.CommandException) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) StoreException(org.apache.oozie.store.StoreException) WorkflowException(org.apache.oozie.workflow.WorkflowException) CommandException(org.apache.oozie.command.CommandException) StoreException(org.apache.oozie.store.StoreException) XConfiguration(org.apache.oozie.util.XConfiguration) JPAService(org.apache.oozie.service.JPAService) Map(java.util.Map)

Example 12 with WorkflowApp

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;
}
Also used : Path(org.apache.hadoop.fs.Path) WorkflowApp(org.apache.oozie.workflow.WorkflowApp) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) XConfiguration(org.apache.oozie.util.XConfiguration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) Reader(java.io.Reader) StringReader(java.io.StringReader) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 13 with WorkflowApp

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;
}
Also used : Path(org.apache.hadoop.fs.Path) WorkflowApp(org.apache.oozie.workflow.WorkflowApp) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) XConfiguration(org.apache.oozie.util.XConfiguration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 14 with WorkflowApp

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;
}
Also used : WorkflowApp(org.apache.oozie.workflow.WorkflowApp) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) WorkflowJobInsertJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) JPAService(org.apache.oozie.service.JPAService)

Example 15 with WorkflowApp

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;
}
Also used : LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) WorkflowApp(org.apache.oozie.workflow.WorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) Configuration(org.apache.hadoop.conf.Configuration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) WorkflowJobInsertJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef)

Aggregations

WorkflowApp (org.apache.oozie.workflow.WorkflowApp)17 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)14 LiteWorkflowApp (org.apache.oozie.workflow.lite.LiteWorkflowApp)14 Configuration (org.apache.hadoop.conf.Configuration)13 EndNodeDef (org.apache.oozie.workflow.lite.EndNodeDef)13 StartNodeDef (org.apache.oozie.workflow.lite.StartNodeDef)13 LiteWorkflowStoreService (org.apache.oozie.service.LiteWorkflowStoreService)11 XConfiguration (org.apache.oozie.util.XConfiguration)10 Path (org.apache.hadoop.fs.Path)9 JPAService (org.apache.oozie.service.JPAService)8 WorkflowJobInsertJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor)7 Date (java.util.Date)6 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)6 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)5 WorkflowStoreService (org.apache.oozie.service.WorkflowStoreService)4 WorkflowException (org.apache.oozie.workflow.WorkflowException)4 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)4 WorkflowLib (org.apache.oozie.workflow.WorkflowLib)4 URI (java.net.URI)3 Map (java.util.Map)3