Search in sources :

Example 11 with ActionExecutor

use of org.apache.oozie.action.ActionExecutor in project oozie by apache.

the class LiteWorkflowAppParser method handleDefaultsAndGlobal.

private void handleDefaultsAndGlobal(GlobalSectionData gData, Configuration configDefault, Element actionElement, Namespace ns) throws WorkflowException {
    ActionExecutor ae = Services.get().get(ActionService.class).getExecutor(actionElement.getName());
    if (ae == null && !GLOBAL.equals(actionElement.getName())) {
        throw new WorkflowException(ErrorCode.E0723, actionElement.getName(), ActionService.class.getName());
    }
    Namespace actionNs = actionElement.getNamespace();
    // Also, we only parse the NN (not the JT) for the FS Action.
    if (SubWorkflowActionExecutor.ACTION_TYPE.equals(actionElement.getName()) || FsActionExecutor.ACTION_TYPE.equals(actionElement.getName()) || GLOBAL.equals(actionElement.getName()) || ae.requiresNameNodeJobTracker()) {
        if (actionElement.getChild(NAME_NODE, actionNs) == null) {
            if (gData != null && gData.nameNode != null) {
                addChildElement(actionElement, actionNs, NAME_NODE, gData.nameNode);
            } else if (defaultNameNode != null) {
                addChildElement(actionElement, actionNs, NAME_NODE, defaultNameNode);
            } else if (!(SubWorkflowActionExecutor.ACTION_TYPE.equals(actionElement.getName()) || FsActionExecutor.ACTION_TYPE.equals(actionElement.getName()) || GLOBAL.equals(actionElement.getName()))) {
                throw new WorkflowException(ErrorCode.E0701, "No " + NAME_NODE + " defined");
            }
        }
        if (getResourceManager(actionNs, actionElement) == null && !FsActionExecutor.ACTION_TYPE.equals(actionElement.getName())) {
            if (gData != null && gData.jobTracker != null) {
                addResourceManagerOrJobTracker(actionElement, actionNs, gData.jobTracker, isResourceManagerTagUsed);
            } else if (defaultResourceManager != null) {
                addResourceManagerOrJobTracker(actionElement, actionNs, defaultResourceManager, true);
            } else if (defaultJobTracker != null) {
                addResourceManagerOrJobTracker(actionElement, actionNs, defaultJobTracker, false);
            } else if (!(SubWorkflowActionExecutor.ACTION_TYPE.equals(actionElement.getName()) || GLOBAL.equals(actionElement.getName()))) {
                throw new WorkflowException(ErrorCode.E0701, "No " + JOB_TRACKER + " or " + RESOURCE_MANAGER + " defined");
            }
        }
    }
    // defined, empty values are placed.  Exceptions are thrown if there's an error parsing, but not if they're not given.
    if (GLOBAL.equals(actionElement.getName()) || ae.supportsConfigurationJobXML()) {
        @SuppressWarnings("unchecked") List<Element> actionJobXmls = actionElement.getChildren(JOB_XML, actionNs);
        if (gData != null && gData.jobXmls != null) {
            for (String gJobXml : gData.jobXmls) {
                boolean alreadyExists = false;
                for (Element actionXml : actionJobXmls) {
                    if (gJobXml.equals(actionXml.getText())) {
                        alreadyExists = true;
                        break;
                    }
                }
                if (!alreadyExists) {
                    Element ejobXml = new Element(JOB_XML, actionNs);
                    ejobXml.setText(gJobXml);
                    actionElement.addContent(ejobXml);
                }
            }
        }
        try {
            XConfiguration actionConf = new XConfiguration();
            if (configDefault != null)
                XConfiguration.copy(configDefault, actionConf);
            if (gData != null && gData.conf != null) {
                XConfiguration.copy(gData.conf, actionConf);
            }
            Element launcherConfiguration = actionElement.getChild(LAUNCHER_E, actionNs);
            if (launcherConfiguration != null) {
                LauncherConfigHandler launcherConfigHandler = new LauncherConfigHandler(actionConf, launcherConfiguration, actionNs);
                launcherConfigHandler.processSettings();
            }
            Element actionConfiguration = actionElement.getChild(CONFIGURATION, actionNs);
            if (actionConfiguration != null) {
                // copy and override
                XConfiguration.copy(new XConfiguration(new StringReader(XmlUtils.prettyPrint(actionConfiguration).toString())), actionConf);
            }
            int position = actionElement.indexOf(actionConfiguration);
            // replace with enhanced one
            actionElement.removeContent(actionConfiguration);
            Element eConfXml = XmlUtils.parseXml(actionConf.toXmlString(false));
            eConfXml.detach();
            eConfXml.setNamespace(actionNs);
            if (position > 0) {
                actionElement.addContent(position, eConfXml);
            } else {
                actionElement.addContent(eConfXml);
            }
        } catch (IOException e) {
            throw new WorkflowException(ErrorCode.E0700, "Error while processing action conf");
        } catch (JDOMException e) {
            throw new WorkflowException(ErrorCode.E0700, "Error while processing action conf");
        }
    }
}
Also used : SubWorkflowActionExecutor(org.apache.oozie.action.oozie.SubWorkflowActionExecutor) FsActionExecutor(org.apache.oozie.action.hadoop.FsActionExecutor) ActionExecutor(org.apache.oozie.action.ActionExecutor) WorkflowException(org.apache.oozie.workflow.WorkflowException) Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) Namespace(org.jdom.Namespace) XConfiguration(org.apache.oozie.util.XConfiguration) StringReader(java.io.StringReader) ActionService(org.apache.oozie.service.ActionService)

Example 12 with ActionExecutor

use of org.apache.oozie.action.ActionExecutor in project oozie by apache.

the class TestJavaActionExecutor method testSimplestSubmitWithResourceManagerOK.

public void testSimplestSubmitWithResourceManagerOK() throws Exception {
    final String actionXml = "<java>" + "<resource-manager>" + getJobTrackerUri() + "</resource-manager>" + "<name-node>" + getNameNodeUri() + "</name-node>" + "<main-class>" + LauncherMainTester.class.getName() + "</main-class>" + "</java>";
    final Context context = createContext(actionXml, null);
    submitAction(context);
    waitUntilYarnAppDoneAndAssertSuccess(context.getAction().getExternalId());
    final ActionExecutor ae = new JavaActionExecutor();
    ae.check(context, context.getAction());
    assertEquals("SUCCEEDED", context.getAction().getExternalStatus());
    assertNull(context.getAction().getData());
    ae.end(context, context.getAction());
    assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
}
Also used : ActionExecutor(org.apache.oozie.action.ActionExecutor)

Example 13 with ActionExecutor

use of org.apache.oozie.action.ActionExecutor in project oozie by apache.

the class TestJavaActionExecutor method testOutputSubmitOK.

public void testOutputSubmitOK() throws Exception {
    String actionXml = "<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>" + getNameNodeUri() + "</name-node>" + "<main-class>" + LauncherMainTester.class.getName() + "</main-class>" + "<arg>out</arg>" + "<capture-output/>" + "</java>";
    Context context = createContext(actionXml, null);
    final String runningJob = submitAction(context);
    waitUntilYarnAppDoneAndAssertSuccess(runningJob);
    ActionExecutor ae = new JavaActionExecutor();
    ae.check(context, context.getAction());
    assertEquals("SUCCEEDED", context.getAction().getExternalStatus());
    assertNotNull(context.getAction().getData());
    StringReader sr = new StringReader(context.getAction().getData());
    Properties props = new Properties();
    props.load(sr);
    assertEquals("A", props.get("a"));
    ae.end(context, context.getAction());
    assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
}
Also used : ActionExecutor(org.apache.oozie.action.ActionExecutor) StringReader(java.io.StringReader) Properties(java.util.Properties)

Example 14 with ActionExecutor

use of org.apache.oozie.action.ActionExecutor in project oozie by apache.

the class TestDecisionActionExecutor method testDecision.

public void testDecision() throws Exception {
    new Services().init();
    try {
        ActionExecutor decision = new DecisionActionExecutor();
        assertEquals(DecisionActionExecutor.ACTION_TYPE, decision.getType());
        WorkflowActionBean action = new WorkflowActionBean();
        action.setConf("<switch xmlns='uri:oozie:workflow:0.1'>" + "<case to='a'>true</case>" + "<case to='b'>true</case>" + "<case to='c'>false</case>" + "<default to='d'/></switch>");
        decision.start(new Context(action), action);
        assertEquals(WorkflowAction.Status.DONE, action.getStatus());
        decision.end(new Context(action), action);
        assertEquals(WorkflowAction.Status.OK, action.getStatus());
        assertEquals("a", action.getExternalStatus());
        action.setConf("<switch xmlns='uri:oozie:workflow:0.1'>" + "<case to='a'>false</case>" + "<case to='b'>true</case>" + "<case to='c'>false</case>" + "<default to='d'/></switch>");
        decision.start(new Context(action), action);
        assertEquals(WorkflowAction.Status.DONE, action.getStatus());
        decision.end(new Context(action), action);
        assertEquals(WorkflowAction.Status.OK, action.getStatus());
        assertEquals("b", action.getExternalStatus());
        action.setConf("<switch xmlns='uri:oozie:workflow:0.1'>" + "<case to='a'>false</case>" + "<case to='b'>false</case>" + "<case to='c'>false</case>" + "<default to='d'/></switch>");
        decision.start(new Context(action), action);
        assertEquals(WorkflowAction.Status.DONE, action.getStatus());
        decision.end(new Context(action), action);
        assertEquals(WorkflowAction.Status.OK, action.getStatus());
        assertEquals("d", action.getExternalStatus());
        try {
            action.setConf("<wrong>" + "<case to='a'>false</case>" + "<case to='b'>false</case>" + "<case to='c'>false</case>" + "<default to='d'/></switch>");
            decision.start(new Context(action), action);
            fail();
        } catch (ActionExecutorException ex) {
            assertEquals(ActionExecutorException.ErrorType.FAILED, ex.getErrorType());
            assertEquals(DecisionActionExecutor.XML_ERROR, ex.getErrorCode());
        } catch (Exception ex) {
            fail();
        }
    } finally {
        Services.get().destroy();
    }
}
Also used : Services(org.apache.oozie.service.Services) ActionExecutor(org.apache.oozie.action.ActionExecutor) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) URISyntaxException(java.net.URISyntaxException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) IOException(java.io.IOException)

Example 15 with ActionExecutor

use of org.apache.oozie.action.ActionExecutor in project oozie by apache.

the class ActionKillXCommand method execute.

@Override
protected Void execute() throws CommandException {
    LOG.debug("STARTED WorkflowActionKillXCommand for action " + actionId);
    if (wfAction.isPending()) {
        ActionExecutor executor = Services.get().get(ActionService.class).getExecutor(wfAction.getType());
        if (executor != null) {
            ActionExecutorContext context = null;
            try {
                boolean isRetry = false;
                boolean isUserRetry = false;
                context = new ActionXCommand.ActionExecutorContext(wfJob, wfAction, isRetry, isUserRetry);
                incrActionCounter(wfAction.getType(), 1);
                Instrumentation.Cron cron = new Instrumentation.Cron();
                cron.start();
                executor.kill(context, wfAction);
                cron.stop();
                addActionCron(wfAction.getType(), cron);
                wfAction.resetPending();
                wfAction.setStatus(WorkflowActionBean.Status.KILLED);
                wfAction.setEndTime(new Date());
                updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_END, wfAction));
                wfJob.setLastModifiedTime(new Date());
                updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW_MODTIME, wfJob));
                // Add SLA status event (KILLED) for WF_ACTION
                SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(wfAction.getSlaXml(), wfAction.getId(), Status.KILLED, SlaAppType.WORKFLOW_ACTION);
                if (slaEvent != null) {
                    insertList.add(slaEvent);
                }
                queue(new WorkflowNotificationXCommand(wfJob, wfAction));
            } catch (ActionExecutorException ex) {
                wfAction.resetPending();
                wfAction.setStatus(WorkflowActionBean.Status.FAILED);
                wfAction.setErrorInfo(ex.getErrorCode().toString(), "KILL COMMAND FAILED - exception while executing job kill");
                wfAction.setEndTime(new Date());
                wfJob.setStatus(WorkflowJobBean.Status.KILLED);
                updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_END, wfAction));
                wfJob.setLastModifiedTime(new Date());
                updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wfJob));
                // What will happen to WF and COORD_ACTION, NOTIFICATION?
                SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(wfAction.getSlaXml(), wfAction.getId(), Status.FAILED, SlaAppType.WORKFLOW_ACTION);
                if (slaEvent != null) {
                    insertList.add(slaEvent);
                }
                LOG.warn("Exception while executing kill(). Error Code [{0}], Message[{1}]", ex.getErrorCode(), ex.getMessage(), ex);
            } finally {
                try {
                    cleanupActionDir(context);
                    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
                    if (!(executor instanceof ControlNodeActionExecutor) && EventHandlerService.isEnabled()) {
                        generateEvent(wfAction, wfJob.getUser());
                    }
                } catch (JPAExecutorException e) {
                    throw new CommandException(e);
                }
            }
        }
    }
    LOG.debug("ENDED WorkflowActionKillXCommand for action " + actionId);
    return null;
}
Also used : ControlNodeActionExecutor(org.apache.oozie.action.control.ControlNodeActionExecutor) ActionExecutor(org.apache.oozie.action.ActionExecutor) WorkflowActionQuery(org.apache.oozie.executor.jpa.WorkflowActionQueryExecutor.WorkflowActionQuery) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) Instrumentation(org.apache.oozie.util.Instrumentation) CommandException(org.apache.oozie.command.CommandException) Date(java.util.Date) SLAEventBean(org.apache.oozie.SLAEventBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) ControlNodeActionExecutor(org.apache.oozie.action.control.ControlNodeActionExecutor) ActionService(org.apache.oozie.service.ActionService)

Aggregations

ActionExecutor (org.apache.oozie.action.ActionExecutor)28 ActionService (org.apache.oozie.service.ActionService)5 IOException (java.io.IOException)4 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)4 Path (org.apache.hadoop.fs.Path)3 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)3 ForkActionExecutor (org.apache.oozie.action.control.ForkActionExecutor)3 StartActionExecutor (org.apache.oozie.action.control.StartActionExecutor)3 CommandException (org.apache.oozie.command.CommandException)3 StringReader (java.io.StringReader)2 Date (java.util.Date)2 SLAEventBean (org.apache.oozie.SLAEventBean)2 ControlNodeActionExecutor (org.apache.oozie.action.control.ControlNodeActionExecutor)2 EndActionExecutor (org.apache.oozie.action.control.EndActionExecutor)2 JoinActionExecutor (org.apache.oozie.action.control.JoinActionExecutor)2 KillActionExecutor (org.apache.oozie.action.control.KillActionExecutor)2 JavaActionExecutor (org.apache.oozie.action.hadoop.JavaActionExecutor)2 SubWorkflowActionExecutor (org.apache.oozie.action.oozie.SubWorkflowActionExecutor)2 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)2 WorkflowActionQuery (org.apache.oozie.executor.jpa.WorkflowActionQueryExecutor.WorkflowActionQuery)2