Search in sources :

Example 66 with CommandException

use of org.apache.oozie.command.CommandException in project oozie by apache.

the class CoordActionTimeOutXCommand method loadState.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#loadState()
     */
@Override
protected void loadState() throws CommandException {
    jpaService = Services.get().get(JPAService.class);
    if (jpaService == null) {
        throw new CommandException(ErrorCode.E0610);
    }
    try {
        actionBean = jpaService.execute(new CoordActionGetForTimeoutJPAExecutor(actionBean.getId()));
    } catch (JPAExecutorException e) {
        throw new CommandException(e);
    }
    LogUtils.setLogInfo(actionBean);
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordActionGetForTimeoutJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetForTimeoutJPAExecutor) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService)

Example 67 with CommandException

use of org.apache.oozie.command.CommandException in project oozie by apache.

the class CoordActionsKillXCommand method loadState.

@Override
protected void loadState() throws CommandException {
    try {
        jpaService = Services.get().get(JPAService.class);
        if (jpaService != null) {
            coordJob = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB_ACTION_KILL, jobId);
            LogUtils.setLogInfo(coordJob);
            coordActions = CoordUtils.getCoordActions(rangeType, coordJob.getId(), scope, true);
        } else {
            throw new CommandException(ErrorCode.E0610);
        }
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService)

Example 68 with CommandException

use of org.apache.oozie.command.CommandException in project oozie by apache.

the class CoordCommandUtils method resolveInstanceRange.

/**
 * Resolve <start-instance> <end-insatnce> tag. Don't resolve any
 * latest()/future()
 *
 * @param event
 * @param instances
 * @param appInst
 * @param conf
 * @param eval ELEvalautor
 * @throws Exception
 */
public static void resolveInstanceRange(Element event, StringBuilder instances, SyncCoordAction appInst, Configuration conf, ELEvaluator eval) throws Exception {
    Element eStartInst = event.getChild("start-instance", event.getNamespace());
    Element eEndInst = event.getChild("end-instance", event.getNamespace());
    if (eStartInst != null && eEndInst != null) {
        String strStart = evaluateInstanceFunction(event, appInst, conf, eStartInst.getTextTrim());
        String strEnd = evaluateInstanceFunction(event, appInst, conf, eEndInst.getTextTrim());
        checkIfBothSameType(strStart, strEnd);
        // To store rest
        StringBuilder restArg = new StringBuilder();
        // arguments for
        // future
        // function
        int startIndex = getInstanceNumber(strStart, restArg);
        String startRestArg = restArg.toString();
        restArg.delete(0, restArg.length());
        int endIndex = getInstanceNumber(strEnd, restArg);
        String endRestArg = restArg.toString();
        int funcType = getFuncType(strStart);
        if (funcType == ABSOLUTE) {
            resolveAbsoluteRange(event, instances, appInst, conf, eval, strStart, endIndex, parseOneStringArg(strStart));
        } else if (funcType == ENDOFMONTHS) {
            resolveInstanceRangeEndOfDuration(TimeUnit.MONTH, event, instances, appInst, conf, eval, strStart, startIndex, endIndex);
        } else if (funcType == ENDOFWEEKS) {
            resolveInstanceRangeEndOfDuration(TimeUnit.WEEK, event, instances, appInst, conf, eval, strStart, startIndex, endIndex);
        } else if (funcType == ENDOFDAYS) {
            resolveInstanceRangeEndOfDuration(TimeUnit.DAY, event, instances, appInst, conf, eval, strStart, startIndex, endIndex);
        } else {
            if (funcType == OFFSET) {
                TimeUnit startU = TimeUnit.valueOf(startRestArg);
                TimeUnit endU = TimeUnit.valueOf(endRestArg);
                if (startU.getCalendarUnit() * startIndex > endU.getCalendarUnit() * endIndex) {
                    throw new CommandException(ErrorCode.E1010, " start-instance should be equal or earlier than the end-instance \n" + XmlUtils.prettyPrint(event));
                }
                Calendar startCal = CoordELFunctions.resolveOffsetRawTime(startIndex, startU, eval);
                Calendar endCal = CoordELFunctions.resolveOffsetRawTime(endIndex, endU, eval);
                if (startCal != null && endCal != null) {
                    List<Integer> expandedFreqs = CoordELFunctions.expandOffsetTimes(startCal, endCal, eval);
                    for (int i = expandedFreqs.size() - 1; i >= 0; i--) {
                        // we need to use DS timeout, bcz expandOffsetTimes will expand offset in Freqs in DS timeunit
                        String matInstance = materializeInstance(event, "${coord:offset(" + expandedFreqs.get(i) + ", \"" + CoordELFunctions.getDSTimeUnit(eval) + "\")}", appInst, conf, eval);
                        if (matInstance == null || matInstance.length() == 0) {
                            // Earlier than dataset's initial instance
                            break;
                        }
                        if (instances.length() > 0) {
                            instances.append(CoordELFunctions.INSTANCE_SEPARATOR);
                        }
                        instances.append(matInstance);
                    }
                }
            } else {
                if (startIndex > endIndex) {
                    throw new CommandException(ErrorCode.E1010, " start-instance should be equal or earlier than the end-instance \n" + XmlUtils.prettyPrint(event));
                }
                if (funcType == CURRENT) {
                    // Everything could be resolved NOW. no latest() ELs
                    String matInstance = materializeInstance(event, "${coord:currentRange(" + startIndex + "," + endIndex + ")}", appInst, conf, eval);
                    if (matInstance != null && !matInstance.isEmpty()) {
                        if (instances.length() > 0) {
                            instances.append(CoordELFunctions.INSTANCE_SEPARATOR);
                        }
                        instances.append(matInstance);
                    }
                } else {
                    // latest(n)/future() EL is present
                    if (funcType == LATEST) {
                        instances.append("${coord:latestRange(").append(startIndex).append(",").append(endIndex).append(")}");
                    } else if (funcType == FUTURE) {
                        instances.append("${coord:futureRange(").append(startIndex).append(",").append(endIndex).append(",'").append(endRestArg).append("')}");
                    }
                }
            }
        }
        // Remove start-instance and end-instances
        event.removeChild("start-instance", event.getNamespace());
        event.removeChild("end-instance", event.getNamespace());
    }
}
Also used : Element(org.jdom.Element) Calendar(java.util.Calendar) TimeUnit(org.apache.oozie.coord.TimeUnit) ArrayList(java.util.ArrayList) List(java.util.List) CommandException(org.apache.oozie.command.CommandException)

Example 69 with CommandException

use of org.apache.oozie.command.CommandException in project oozie by apache.

the class CoordJobsXCommand method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
@Override
protected CoordinatorJobInfo execute() throws CommandException {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        CoordinatorJobInfo coordInfo = null;
        if (jpaService != null) {
            coordInfo = jpaService.execute(new CoordJobInfoGetJPAExecutor(filter, start, len));
        } else {
            LOG.error(ErrorCode.E0610);
        }
        return coordInfo;
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : CoordinatorJobInfo(org.apache.oozie.CoordinatorJobInfo) CoordJobInfoGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobInfoGetJPAExecutor) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService)

Example 70 with CommandException

use of org.apache.oozie.command.CommandException in project oozie by apache.

the class ReRunXCommand method setupReRun.

private void setupReRun() throws CommandException {
    InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
    LogUtils.setLogInfo(wfBean);
    WorkflowInstance oldWfInstance = this.wfBean.getWorkflowInstance();
    WorkflowInstance newWfInstance;
    String appPath = null;
    WorkflowAppService wps = Services.get().get(WorkflowAppService.class);
    try {
        XLog.Info.get().setParameter(DagXLogInfoService.TOKEN, conf.get(OozieClient.LOG_TOKEN));
        WorkflowApp app = wps.parseDef(conf, null);
        XConfiguration protoActionConf = wps.createProtoActionConf(conf, true);
        WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
        appPath = conf.get(OozieClient.APP_PATH);
        URI uri = new URI(appPath);
        HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
        Configuration fsConf = has.createConfiguration(uri.getAuthority());
        FileSystem fs = has.createFileSystem(wfBean.getUser(), uri, fsConf);
        Path configDefault = null;
        // app path could be a directory
        Path path = new Path(uri.getPath());
        if (!fs.isFile(path)) {
            configDefault = new Path(path, SubmitXCommand.CONFIG_DEFAULT);
        } else {
            configDefault = new Path(path.getParent(), SubmitXCommand.CONFIG_DEFAULT);
        }
        if (fs.exists(configDefault)) {
            Configuration defaultConf = new XConfiguration(fs.open(configDefault));
            PropertiesUtils.checkDisallowedProperties(defaultConf, DISALLOWED_DEFAULT_PROPERTIES);
            XConfiguration.injectDefaults(defaultConf, conf);
        }
        PropertiesUtils.checkDisallowedProperties(conf, DISALLOWED_USER_PROPERTIES);
        // Resolving all variables in the job properties. This ensures the Hadoop Configuration semantics are
        // preserved. The Configuration.get function within XConfiguration.resolve() works recursively to get the
        // final value corresponding to a key in the map Resetting the conf to contain all the resolved values is
        // necessary to ensure propagation of Oozie properties to Hadoop calls downstream
        conf = ((XConfiguration) conf).resolve();
        try {
            newWfInstance = workflowLib.createInstance(app, conf, jobId);
        } catch (WorkflowException e) {
            throw new CommandException(e);
        }
        String appName = ELUtils.resolveAppName(app.getName(), conf);
        if (SLAService.isEnabled()) {
            Element wfElem = XmlUtils.parseXml(app.getDefinition());
            ELEvaluator evalSla = SubmitXCommand.createELEvaluatorForGroup(conf, "wf-sla-submit");
            Element eSla = XmlUtils.getSLAElement(wfElem);
            String jobSlaXml = null;
            if (eSla != null) {
                jobSlaXml = SubmitXCommand.resolveSla(eSla, evalSla);
            }
            writeSLARegistration(wfElem, jobSlaXml, newWfInstance.getId(), conf.get(SubWorkflowActionExecutor.PARENT_ID), conf.get(OozieClient.USER_NAME), appName, evalSla);
        }
        wfBean.setAppName(appName);
        wfBean.setProtoActionConf(protoActionConf.toXmlString());
    } catch (WorkflowException ex) {
        throw new CommandException(ex);
    } catch (IOException ex) {
        throw new CommandException(ErrorCode.E0803, ex.getMessage(), ex);
    } catch (HadoopAccessorException ex) {
        throw new CommandException(ex);
    } catch (URISyntaxException ex) {
        throw new CommandException(ErrorCode.E0711, appPath, ex.getMessage(), ex);
    } catch (Exception ex) {
        throw new CommandException(ErrorCode.E1007, ex.getMessage(), ex);
    }
    for (int i = 0; i < actions.size(); i++) {
        // action will be used to rerun the job.
        if (!nodesToSkip.contains(actions.get(i).getName()) && !(conf.getBoolean(OozieClient.RERUN_FAIL_NODES, false) && SubWorkflowActionExecutor.ACTION_TYPE.equals(actions.get(i).getType()))) {
            deleteList.add(actions.get(i));
            LOG.info("Deleting Action[{0}] for re-run", actions.get(i).getId());
        } else {
            copyActionData(newWfInstance, oldWfInstance);
        }
    }
    wfBean.setAppPath(conf.get(OozieClient.APP_PATH));
    wfBean.setConf(XmlUtils.prettyPrint(conf).toString());
    wfBean.setLogToken(conf.get(OozieClient.LOG_TOKEN, ""));
    wfBean.setUser(conf.get(OozieClient.USER_NAME));
    String group = ConfigUtils.getWithDeprecatedCheck(conf, OozieClient.JOB_ACL, OozieClient.GROUP_NAME, null);
    wfBean.setGroup(group);
    wfBean.setExternalId(conf.get(OozieClient.EXTERNAL_ID));
    wfBean.setEndTime(null);
    wfBean.setRun(wfBean.getRun() + 1);
    wfBean.setStatus(WorkflowJob.Status.PREP);
    wfBean.setWorkflowInstance(newWfInstance);
    try {
        wfBean.setLastModifiedTime(new Date());
        updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW_RERUN, wfBean));
        // call JPAExecutor to do the bulk writes
        BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(null, updateList, deleteList);
    } catch (JPAExecutorException je) {
        throw new CommandException(je);
    } finally {
        updateParentIfNecessary(wfBean);
    }
}
Also used : WorkflowApp(org.apache.oozie.workflow.WorkflowApp) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) Element(org.jdom.Element) URISyntaxException(java.net.URISyntaxException) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) URI(java.net.URI) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) FileSystem(org.apache.hadoop.fs.FileSystem) ELEvaluator(org.apache.oozie.util.ELEvaluator) Path(org.apache.hadoop.fs.Path) WorkflowLib(org.apache.oozie.workflow.WorkflowLib) WorkflowAppService(org.apache.oozie.service.WorkflowAppService) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) WorkflowException(org.apache.oozie.workflow.WorkflowException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) CommandException(org.apache.oozie.command.CommandException) IOException(java.io.IOException) HadoopAccessorService(org.apache.oozie.service.HadoopAccessorService) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException) IOException(java.io.IOException) WorkflowException(org.apache.oozie.workflow.WorkflowException) Date(java.util.Date) XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)

Aggregations

CommandException (org.apache.oozie.command.CommandException)225 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)85 XConfiguration (org.apache.oozie.util.XConfiguration)62 Date (java.util.Date)59 IOException (java.io.IOException)57 Configuration (org.apache.hadoop.conf.Configuration)56 JPAService (org.apache.oozie.service.JPAService)56 XException (org.apache.oozie.XException)42 PreconditionException (org.apache.oozie.command.PreconditionException)35 ArrayList (java.util.ArrayList)26 StringReader (java.io.StringReader)25 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)24 List (java.util.List)23 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)23 Element (org.jdom.Element)23 JDOMException (org.jdom.JDOMException)20 File (java.io.File)16 HadoopAccessorException (org.apache.oozie.service.HadoopAccessorException)16 WorkflowException (org.apache.oozie.workflow.WorkflowException)16 URISyntaxException (java.net.URISyntaxException)14