Search in sources :

Example 26 with WorkflowException

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

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

the class LiteWorkflowStoreService method getUserRetryMax.

private static int getUserRetryMax(NodeHandler.Context context) throws WorkflowException {
    XLog log = XLog.getLog(LiteWorkflowStoreService.class);
    int ret = ConfigurationService.getInt(CONF_USER_RETRY_MAX);
    int max = ret;
    String userRetryMax = context.getNodeDef().getUserRetryMax();
    if (!userRetryMax.equals("null")) {
        try {
            ret = Integer.parseInt(userRetryMax);
            if (ret > max) {
                ret = max;
                log.warn(ErrorCode.E0820.getTemplate(), ret, max);
            }
        } catch (NumberFormatException nfe) {
            throw new WorkflowException(ErrorCode.E0700, nfe.getMessage(), nfe);
        }
    } else {
        ret = 0;
    }
    return ret;
}
Also used : XLog(org.apache.oozie.util.XLog) WorkflowException(org.apache.oozie.workflow.WorkflowException)

Example 28 with WorkflowException

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

the class LiteWorkflowStoreService method liteExecute.

/**
 * Delegation method used by the Action and Decision {@link NodeHandler} on start. <p> This method provides the
 * necessary information to create ActionExecutors.
 *
 * @param context NodeHandler context.
 * @param actionType the action type.
 * @throws WorkflowException thrown if there was an error parsing the action configuration.
 */
@SuppressWarnings("unchecked")
protected static void liteExecute(NodeHandler.Context context, String actionType) throws WorkflowException {
    XLog log = XLog.getLog(LiteWorkflowStoreService.class);
    String jobId = context.getProcessInstance().getId();
    String nodeName = context.getNodeDef().getName();
    String skipVar = context.getProcessInstance().getVar(context.getNodeDef().getName() + WorkflowInstance.NODE_VAR_SEPARATOR + ReRunXCommand.TO_SKIP);
    boolean skipAction = false;
    if (skipVar != null) {
        skipAction = skipVar.equals("true");
    }
    WorkflowActionBean action = new WorkflowActionBean();
    String actionId = Services.get().get(UUIDService.class).generateChildId(jobId, nodeName);
    if (!skipAction) {
        String nodeConf = context.getNodeDef().getConf();
        if (actionType == null) {
            try {
                Element element = XmlUtils.parseXml(nodeConf);
                actionType = element.getName();
                nodeConf = XmlUtils.prettyPrint(element).toString();
            } catch (JDOMException ex) {
                throw new WorkflowException(ErrorCode.E0700, ex.getMessage(), ex);
            }
        }
        log.debug(" Creating action for node [{0}]", nodeName);
        action.setType(actionType);
        action.setConf(nodeConf);
        action.setLogToken(((WorkflowJobBean) context.getTransientVar(WORKFLOW_BEAN)).getLogToken());
        action.setStatus(WorkflowAction.Status.PREP);
        action.setJobId(jobId);
    }
    String executionPath = context.getExecutionPath();
    action.setExecutionPath(executionPath);
    action.setCred(context.getNodeDef().getCred());
    log.debug("Setting action for cred: '" + context.getNodeDef().getCred() + "', name: '" + context.getNodeDef().getName() + "'");
    action.setUserRetryCount(0);
    int userRetryMax = getUserRetryMax(context);
    int userRetryInterval = getUserRetryInterval(context);
    action.setUserRetryMax(userRetryMax);
    action.setUserRetryInterval(userRetryInterval);
    log.debug("Setting action for userRetryMax: '" + userRetryMax + "', userRetryInterval: '" + userRetryInterval + "', name: '" + context.getNodeDef().getName() + "'");
    action.setName(nodeName);
    action.setId(actionId);
    context.setVar(nodeName + WorkflowInstance.NODE_VAR_SEPARATOR + ACTION_ID, actionId);
    List list = (List) context.getTransientVar(ACTIONS_TO_START);
    if (list == null) {
        list = new ArrayList();
        context.setTransientVar(ACTIONS_TO_START, list);
    }
    list.add(action);
}
Also used : XLog(org.apache.oozie.util.XLog) Element(org.jdom.Element) WorkflowException(org.apache.oozie.workflow.WorkflowException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JDOMException(org.jdom.JDOMException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 29 with WorkflowException

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

the class WorkflowAppService method createProtoActionConf.

/**
 * Create proto configuration. <p> The proto configuration includes the user,group and the paths which need to be
 * added to distributed cache. These paths include .jar,.so and the resource file paths.
 *
 * @param jobConf job configuration.
 * @param isWorkflowJob indicates if the job is a workflow job or not.
 * @return proto configuration.
 * @throws WorkflowException thrown if the proto action configuration could not be created.
 */
public XConfiguration createProtoActionConf(Configuration jobConf, boolean isWorkflowJob) throws WorkflowException {
    try {
        HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
        URI uri = new URI(jobConf.get(OozieClient.APP_PATH));
        Configuration conf = has.createConfiguration(uri.getAuthority());
        XConfiguration protoConf = new XConfiguration();
        String user = jobConf.get(OozieClient.USER_NAME);
        conf.set(OozieClient.USER_NAME, user);
        protoConf.set(OozieClient.USER_NAME, user);
        FileSystem fs = has.createFileSystem(user, uri, conf);
        Path appPath = new Path(uri);
        XLog.getLog(getClass()).debug("jobConf.libPath = " + jobConf.get(OozieClient.LIBPATH));
        XLog.getLog(getClass()).debug("jobConf.appPath = " + appPath);
        Collection<String> filePaths;
        if (isWorkflowJob) {
            // app path could be a directory
            Path path = new Path(uri.getPath());
            if (!fs.isFile(path)) {
                filePaths = getLibFiles(fs, new Path(appPath + "/lib"));
            } else {
                filePaths = getLibFiles(fs, new Path(appPath.getParent(), "lib"));
            }
        } else {
            filePaths = new LinkedHashSet<String>();
        }
        String[] libPaths = jobConf.getStrings(OozieClient.LIBPATH);
        if (libPaths != null && libPaths.length > 0) {
            for (int i = 0; i < libPaths.length; i++) {
                if (libPaths[i].trim().length() > 0) {
                    Path libPath = new Path(libPaths[i].trim());
                    Collection<String> libFilePaths = getLibFiles(fs, libPath);
                    filePaths.addAll(libFilePaths);
                }
            }
        }
        // If OOZIE_WF_SUBWORKFLOW_CLASSPATH_INHERITANCE isn't specified, we use OOZIE_SUBWORKFLOW_CLASSPATH_INHERITANCE
        if (jobConf.getBoolean(OOZIE_WF_SUBWORKFLOW_CLASSPATH_INHERITANCE, oozieSubWfCPInheritance)) {
            // Keep any libs from a parent workflow that might already be in APP_LIB_PATH_LIST and also remove duplicates
            String[] parentFilePaths = jobConf.getStrings(APP_LIB_PATH_LIST);
            if (parentFilePaths != null && parentFilePaths.length > 0) {
                String[] filePathsNames = filePaths.toArray(new String[filePaths.size()]);
                for (int i = 0; i < filePathsNames.length; i++) {
                    Path p = new Path(filePathsNames[i]);
                    filePathsNames[i] = p.getName();
                }
                Arrays.sort(filePathsNames);
                List<String> nonDuplicateParentFilePaths = new ArrayList<String>();
                for (String parentFilePath : parentFilePaths) {
                    Path p = new Path(parentFilePath);
                    if (Arrays.binarySearch(filePathsNames, p.getName()) < 0) {
                        nonDuplicateParentFilePaths.add(parentFilePath);
                    }
                }
                filePaths.addAll(nonDuplicateParentFilePaths);
            }
        }
        protoConf.setStrings(APP_LIB_PATH_LIST, filePaths.toArray(new String[filePaths.size()]));
        // Add all properties start with 'oozie.'
        for (Map.Entry<String, String> entry : jobConf) {
            if (entry.getKey().startsWith("oozie.")) {
                String name = entry.getKey();
                String value = entry.getValue();
                // if property already exists, should not overwrite
                if (protoConf.get(name) == null) {
                    protoConf.set(name, value);
                }
            }
        }
        return protoConf;
    } catch (IOException ex) {
        throw new WorkflowException(ErrorCode.E0712, jobConf.get(OozieClient.APP_PATH), ex.getMessage(), ex);
    } catch (URISyntaxException ex) {
        throw new WorkflowException(ErrorCode.E0711, jobConf.get(OozieClient.APP_PATH), ex.getMessage(), ex);
    } catch (HadoopAccessorException ex) {
        throw new WorkflowException(ex);
    } catch (Exception ex) {
        throw new WorkflowException(ErrorCode.E0712, jobConf.get(OozieClient.APP_PATH), ex.getMessage(), ex);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowException(org.apache.oozie.workflow.WorkflowException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) WorkflowException(org.apache.oozie.workflow.WorkflowException) XConfiguration(org.apache.oozie.util.XConfiguration) FileSystem(org.apache.hadoop.fs.FileSystem) Map(java.util.Map)

Example 30 with WorkflowException

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

the class WorkflowAppService method readDefinition.

/**
 * Read workflow definition.
 *
 * @param appPath application path.
 * @param user user name.
 * @return workflow definition.
 * @throws WorkflowException thrown if the definition could not be read.
 */
protected String readDefinition(String appPath, String user, Configuration conf) throws WorkflowException {
    try {
        URI uri = new URI(appPath);
        HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
        Configuration appConf = has.createConfiguration(uri.getAuthority());
        FileSystem fs = has.createFileSystem(user, uri, appConf);
        // app path could be a directory
        Path path = new Path(uri.getPath());
        if (!fs.isFile(path)) {
            path = new Path(path, "workflow.xml");
        }
        FileStatus fsStatus = fs.getFileStatus(path);
        if (fsStatus.getLen() > this.maxWFLength) {
            throw new WorkflowException(ErrorCode.E0736, fsStatus.getLen(), this.maxWFLength);
        }
        Reader reader = new InputStreamReader(fs.open(path));
        StringWriter writer = new StringWriter();
        IOUtils.copyCharStream(reader, writer);
        return writer.toString();
    } catch (WorkflowException wfe) {
        throw wfe;
    } catch (IOException ex) {
        throw new WorkflowException(ErrorCode.E0710, ex.getMessage(), ex);
    } catch (URISyntaxException ex) {
        throw new WorkflowException(ErrorCode.E0711, appPath, ex.getMessage(), ex);
    } catch (HadoopAccessorException ex) {
        throw new WorkflowException(ex);
    } catch (Exception ex) {
        throw new WorkflowException(ErrorCode.E0710, ex.getMessage(), ex);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) InputStreamReader(java.io.InputStreamReader) WorkflowException(org.apache.oozie.workflow.WorkflowException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) WorkflowException(org.apache.oozie.workflow.WorkflowException) StringWriter(java.io.StringWriter) FileSystem(org.apache.hadoop.fs.FileSystem)

Aggregations

WorkflowException (org.apache.oozie.workflow.WorkflowException)41 XConfiguration (org.apache.oozie.util.XConfiguration)23 IOException (java.io.IOException)15 Configuration (org.apache.hadoop.conf.Configuration)15 CommandException (org.apache.oozie.command.CommandException)8 Date (java.util.Date)7 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)7 Element (org.jdom.Element)7 ArrayList (java.util.ArrayList)6 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)6 JDOMException (org.jdom.JDOMException)6 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)5 WorkflowJobQuery (org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)5 File (java.io.File)4 Reader (java.io.Reader)4 URI (java.net.URI)4 FileSystem (org.apache.hadoop.fs.FileSystem)4 Path (org.apache.hadoop.fs.Path)4 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)4 WorkflowApp (org.apache.oozie.workflow.WorkflowApp)4