Search in sources :

Example 1 with ELEvaluationException

use of org.apache.oozie.util.ELEvaluationException in project oozie by apache.

the class JavaActionExecutor method parseJobXmlAndConfiguration.

public static void parseJobXmlAndConfiguration(Context context, Element element, Path appPath, Configuration conf, boolean isLauncher) throws IOException, ActionExecutorException, HadoopAccessorException, URISyntaxException {
    Namespace ns = element.getNamespace();
    @SuppressWarnings("unchecked") Iterator<Element> it = element.getChildren("job-xml", ns).iterator();
    HashMap<String, FileSystem> filesystemsMap = new HashMap<String, FileSystem>();
    HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
    while (it.hasNext()) {
        Element e = it.next();
        String jobXml = e.getTextTrim();
        Path pathSpecified = new Path(jobXml);
        Path path = pathSpecified.isAbsolute() ? pathSpecified : new Path(appPath, jobXml);
        FileSystem fs;
        if (filesystemsMap.containsKey(path.toUri().getAuthority())) {
            fs = filesystemsMap.get(path.toUri().getAuthority());
        } else {
            if (path.toUri().getAuthority() != null) {
                fs = has.createFileSystem(context.getWorkflow().getUser(), path.toUri(), has.createConfiguration(path.toUri().getAuthority()));
            } else {
                fs = context.getAppFileSystem();
            }
            filesystemsMap.put(path.toUri().getAuthority(), fs);
        }
        Configuration jobXmlConf = new XConfiguration(fs.open(path));
        try {
            String jobXmlConfString = XmlUtils.prettyPrint(jobXmlConf).toString();
            jobXmlConfString = XmlUtils.removeComments(jobXmlConfString);
            jobXmlConfString = context.getELEvaluator().evaluate(jobXmlConfString, String.class);
            jobXmlConf = new XConfiguration(new StringReader(jobXmlConfString));
        } catch (ELEvaluationException ex) {
            throw new ActionExecutorException(ActionExecutorException.ErrorType.TRANSIENT, "EL_EVAL_ERROR", ex.getMessage(), ex);
        } catch (Exception ex) {
            context.setErrorInfo("EL_ERROR", ex.getMessage());
        }
        checkForDisallowedProps(jobXmlConf, "job-xml");
        if (isLauncher) {
            new LauncherConfigurationInjector(jobXmlConf).inject(conf);
        } else {
            XConfiguration.copy(jobXmlConf, conf);
        }
    }
    Element e = element.getChild("configuration", ns);
    if (e != null) {
        String strConf = XmlUtils.prettyPrint(e).toString();
        XConfiguration inlineConf = new XConfiguration(new StringReader(strConf));
        checkForDisallowedProps(inlineConf, "inline configuration");
        if (isLauncher) {
            new LauncherConfigurationInjector(inlineConf).inject(conf);
        } else {
            XConfiguration.copy(inlineConf, conf);
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Element(org.jdom.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) HadoopAccessorService(org.apache.oozie.service.HadoopAccessorService) Namespace(org.jdom.Namespace) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) FileNotFoundException(java.io.FileNotFoundException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) ConnectException(java.net.ConnectException) ELEvaluationException(org.apache.oozie.util.ELEvaluationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) RemoteException(org.apache.hadoop.ipc.RemoteException) AccessControlException(org.apache.hadoop.security.AccessControlException) XConfiguration(org.apache.oozie.util.XConfiguration) ELEvaluationException(org.apache.oozie.util.ELEvaluationException) FileSystem(org.apache.hadoop.fs.FileSystem) StringReader(java.io.StringReader)

Example 2 with ELEvaluationException

use of org.apache.oozie.util.ELEvaluationException in project oozie by apache.

the class ActionStartXCommand method execute.

@Override
protected ActionExecutorContext execute() throws CommandException {
    LOG.debug("STARTED ActionStartXCommand for wf actionId=" + actionId);
    Configuration conf = wfJob.getWorkflowInstance().getConf();
    int maxRetries = 0;
    long retryInterval = 0;
    boolean execSynchronous = false;
    if (!(executor instanceof ControlNodeActionExecutor)) {
        maxRetries = conf.getInt(OozieClient.ACTION_MAX_RETRIES, executor.getMaxRetries());
        retryInterval = conf.getLong(OozieClient.ACTION_RETRY_INTERVAL, executor.getRetryInterval());
    }
    executor.setMaxRetries(maxRetries);
    executor.setRetryInterval(retryInterval);
    try {
        boolean isRetry = false;
        if (wfAction.getStatus() == WorkflowActionBean.Status.START_RETRY || wfAction.getStatus() == WorkflowActionBean.Status.START_MANUAL) {
            isRetry = true;
            prepareForRetry(wfAction);
        }
        boolean isUserRetry = false;
        if (wfAction.getStatus() == WorkflowActionBean.Status.USER_RETRY) {
            isUserRetry = true;
            prepareForRetry(wfAction);
        }
        context = getContext(isRetry, isUserRetry);
        boolean caught = false;
        try {
            if (!(executor instanceof ControlNodeActionExecutor)) {
                String tmpActionConf = XmlUtils.removeComments(wfAction.getConf());
                String actionConf = context.getELEvaluator().evaluate(tmpActionConf, String.class);
                wfAction.setConf(actionConf);
                LOG.debug("Start, name [{0}] type [{1}] configuration{E}{E}{2}{E}", wfAction.getName(), wfAction.getType(), actionConf);
            }
        } catch (ELEvaluationException ex) {
            caught = true;
            throw new ActionExecutorException(ActionExecutorException.ErrorType.TRANSIENT, EL_EVAL_ERROR, ex.getMessage(), ex);
        } catch (ELException ex) {
            caught = true;
            context.setErrorInfo(EL_ERROR, ex.getMessage());
            LOG.warn("ELException in ActionStartXCommand ", ex.getMessage(), ex);
            handleError(context, wfJob, wfAction);
        } catch (org.jdom.JDOMException je) {
            caught = true;
            context.setErrorInfo("ParsingError", je.getMessage());
            LOG.warn("JDOMException in ActionStartXCommand ", je.getMessage(), je);
            handleError(context, wfJob, wfAction);
        } catch (Exception ex) {
            caught = true;
            context.setErrorInfo(EL_ERROR, ex.getMessage());
            LOG.warn("Exception in ActionStartXCommand ", ex.getMessage(), ex);
            handleError(context, wfJob, wfAction);
        }
        if (!caught) {
            wfAction.setErrorInfo(null, null);
            incrActionCounter(wfAction.getType(), 1);
            LOG.info("Start action [{0}] with user-retry state : userRetryCount [{1}], userRetryMax [{2}], userRetryInterval" + " [{3}]", wfAction.getId(), wfAction.getUserRetryCount(), wfAction.getUserRetryMax(), wfAction.getUserRetryInterval());
            Instrumentation.Cron cron = new Instrumentation.Cron();
            cron.start();
            // do not override starttime for retries
            if (wfAction.getStartTime() == null) {
                context.setStartTime();
            }
            context.setVar(JobUtils.getRetryKey(wfAction, JsonTags.WORKFLOW_ACTION_START_TIME), String.valueOf(new Date().getTime()));
            executor.start(context, wfAction);
            cron.stop();
            FaultInjection.activate("org.apache.oozie.command.SkipCommitFaultInjection");
            addActionCron(wfAction.getType(), cron);
            wfAction.setRetries(0);
            if (wfAction.isExecutionComplete()) {
                if (!context.isExecuted()) {
                    LOG.warn(XLog.OPS, "Action Completed, ActionExecutor [{0}] must call setExecutionData()", executor.getType());
                    wfAction.setErrorInfo(EXEC_DATA_MISSING, "Execution Complete, but Execution Data Missing from Action");
                    failJob(context);
                } else {
                    wfAction.setPending();
                    if (!(executor instanceof ControlNodeActionExecutor)) {
                        queue(new ActionEndXCommand(wfAction.getId(), wfAction.getType()));
                    } else {
                        execSynchronous = true;
                    }
                }
            } else {
                if (!context.isStarted()) {
                    LOG.warn(XLog.OPS, "Action Started, ActionExecutor [{0}] must call setStartData()", executor.getType());
                    wfAction.setErrorInfo(START_DATA_MISSING, "Execution Started, but Start Data Missing from Action");
                    failJob(context);
                } else {
                    queue(new WorkflowNotificationXCommand(wfJob, wfAction));
                }
            }
            LOG.info(XLog.STD, "[***" + wfAction.getId() + "***]" + "Action status=" + wfAction.getStatusStr());
            updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_START, wfAction));
            updateJobLastModified();
            // Add SLA status event (STARTED) for WF_ACTION
            SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(wfAction.getSlaXml(), wfAction.getId(), Status.STARTED, SlaAppType.WORKFLOW_ACTION);
            if (slaEvent != null) {
                insertList.add(slaEvent);
            }
            LOG.info(XLog.STD, "[***" + wfAction.getId() + "***]" + "Action updated in DB!");
        }
    } catch (ActionExecutorException ex) {
        LOG.warn("Error starting action [{0}]. ErrorType [{1}], ErrorCode [{2}], Message [{3}]", wfAction.getName(), ex.getErrorType(), ex.getErrorCode(), ex.getMessage(), ex);
        wfAction.setErrorInfo(ex.getErrorCode(), ex.getMessage());
        switch(ex.getErrorType()) {
            case TRANSIENT:
                if (!handleTransient(context, executor, WorkflowAction.Status.START_RETRY)) {
                    handleNonTransient(context, executor, WorkflowAction.Status.START_MANUAL);
                    wfAction.setPendingAge(new Date());
                    wfAction.setRetries(0);
                    wfAction.setStartTime(null);
                }
                break;
            case NON_TRANSIENT:
                handleNonTransient(context, executor, WorkflowAction.Status.START_MANUAL);
                break;
            case ERROR:
                handleError(context, executor, WorkflowAction.Status.ERROR.toString(), true, WorkflowAction.Status.DONE);
                break;
            case FAILED:
                try {
                    failJob(context);
                    endWF();
                    SLAEventBean slaEvent1 = SLADbXOperations.createStatusEvent(wfAction.getSlaXml(), wfAction.getId(), Status.FAILED, SlaAppType.WORKFLOW_ACTION);
                    if (slaEvent1 != null) {
                        insertList.add(slaEvent1);
                    }
                } catch (XException x) {
                    LOG.warn("ActionStartXCommand - case:FAILED ", x.getMessage());
                }
                break;
        }
        updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_START, wfAction));
        updateJobLastModified();
    } finally {
        try {
            BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
            if (!(executor instanceof ControlNodeActionExecutor) && EventHandlerService.isEnabled()) {
                generateEvent(wfAction, wfJob.getUser());
            }
            if (execSynchronous) {
                // Changing to synchronous call from asynchronous queuing to prevent
                // undue delay from ::start:: to action due to queuing
                callActionEnd();
            }
        } catch (JPAExecutorException e) {
            throw new CommandException(e);
        }
    }
    LOG.debug("ENDED ActionStartXCommand for wf actionId=" + actionId + ", jobId=" + jobId);
    return null;
}
Also used : UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) Configuration(org.apache.hadoop.conf.Configuration) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) Instrumentation(org.apache.oozie.util.Instrumentation) ELEvaluationException(org.apache.oozie.util.ELEvaluationException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) XException(org.apache.oozie.XException) ControlNodeActionExecutor(org.apache.oozie.action.control.ControlNodeActionExecutor) ELException(javax.servlet.jsp.el.ELException) WorkflowActionQuery(org.apache.oozie.executor.jpa.WorkflowActionQueryExecutor.WorkflowActionQuery) CommandException(org.apache.oozie.command.CommandException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) ELEvaluationException(org.apache.oozie.util.ELEvaluationException) ELException(javax.servlet.jsp.el.ELException) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException) Date(java.util.Date) SLAEventBean(org.apache.oozie.SLAEventBean)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)2 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)2 ELEvaluationException (org.apache.oozie.util.ELEvaluationException)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ConnectException (java.net.ConnectException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ELException (javax.servlet.jsp.el.ELException)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 RemoteException (org.apache.hadoop.ipc.RemoteException)1 AccessControlException (org.apache.hadoop.security.AccessControlException)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 SLAEventBean (org.apache.oozie.SLAEventBean)1 XException (org.apache.oozie.XException)1