Search in sources :

Example 21 with WorkflowInstance

use of org.apache.oozie.workflow.WorkflowInstance 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);
        }
    }
}
Also used : LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowException(org.apache.oozie.workflow.WorkflowException) CommandException(org.apache.oozie.command.CommandException) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 22 with WorkflowInstance

use of org.apache.oozie.workflow.WorkflowInstance 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);
    }
}
Also used : WorkflowActionQuery(org.apache.oozie.executor.jpa.WorkflowActionQueryExecutor.WorkflowActionQuery) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowJobGetActionsJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetActionsJPAExecutor) WorkflowException(org.apache.oozie.workflow.WorkflowException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) CommandException(org.apache.oozie.command.CommandException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) ActionExecutorContext(org.apache.oozie.command.wf.ActionXCommand.ActionExecutorContext)

Example 23 with WorkflowInstance

use of org.apache.oozie.workflow.WorkflowInstance 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 24 with WorkflowInstance

use of org.apache.oozie.workflow.WorkflowInstance in project oozie by apache.

the class TestJavaActionExecutor method createWorkflow.

private WorkflowJobBean createWorkflow(WorkflowApp app, Configuration conf, String authToken) throws Exception {
    WorkflowAppService wps = Services.get().get(WorkflowAppService.class);
    Configuration protoActionConf = wps.createProtoActionConf(conf, true);
    WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
    WorkflowInstance wfInstance;
    wfInstance = workflowLib.createInstance(app, conf);
    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(XmlUtils.prettyPrint(protoActionConf).toString());
    workflow.setCreatedTime(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);
    return workflow;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowLib(org.apache.oozie.workflow.WorkflowLib) WorkflowAppService(org.apache.oozie.service.WorkflowAppService) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date)

Example 25 with WorkflowInstance

use of org.apache.oozie.workflow.WorkflowInstance 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));
}
Also used : EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) ELService(org.apache.oozie.service.ELService) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Aggregations

WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)34 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)26 LiteWorkflowInstance (org.apache.oozie.workflow.lite.LiteWorkflowInstance)17 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)16 Date (java.util.Date)15 JPAService (org.apache.oozie.service.JPAService)12 XConfiguration (org.apache.oozie.util.XConfiguration)12 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)11 CommandException (org.apache.oozie.command.CommandException)10 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)10 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)9 WorkflowStoreService (org.apache.oozie.service.WorkflowStoreService)9 WorkflowLib (org.apache.oozie.workflow.WorkflowLib)9 Configuration (org.apache.hadoop.conf.Configuration)8 LiteWorkflowStoreService (org.apache.oozie.service.LiteWorkflowStoreService)7 WorkflowAppService (org.apache.oozie.service.WorkflowAppService)7 WorkflowException (org.apache.oozie.workflow.WorkflowException)7 ELEvaluator (org.apache.oozie.util.ELEvaluator)6 LiteWorkflowApp (org.apache.oozie.workflow.lite.LiteWorkflowApp)6 WorkflowJobQuery (org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)5