Search in sources :

Example 1 with WorkflowException

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

the class LiteWorkflowStoreService method getUserRetryInterval.

private static int getUserRetryInterval(NodeHandler.Context context) throws WorkflowException {
    int ret = ConfigurationService.getInt(CONF_USER_RETRY_INTEVAL);
    String userRetryInterval = context.getNodeDef().getUserRetryInterval();
    if (!userRetryInterval.equals("null")) {
        try {
            ret = Integer.parseInt(userRetryInterval);
        } catch (NumberFormatException nfe) {
            throw new WorkflowException(ErrorCode.E0700, nfe.getMessage(), nfe);
        }
    }
    return ret;
}
Also used : WorkflowException(org.apache.oozie.workflow.WorkflowException)

Example 2 with WorkflowException

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

the class TestLiteWorkflowAppService method testExtSchema.

public void testExtSchema() throws Exception {
    setSystemProperty(SchemaService.WF_CONF_EXT_SCHEMAS, "wf-ext-schema.xsd");
    setSystemProperty("oozie.service.ActionService.executor.ext.classes", TestActionExecutor.class.getName());
    Services services = new Services();
    try {
        services.init();
        Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
        Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
        IOUtils.copyCharStream(reader, writer);
        WorkflowAppService wps = services.get(WorkflowAppService.class);
        Configuration jobConf = new XConfiguration();
        jobConf.set(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
        jobConf.set(OozieClient.USER_NAME, getTestUser());
        LiteWorkflowApp app = (LiteWorkflowApp) wps.parseDef(jobConf);
        assertNotNull(app);
        assertEquals("test-wf", app.getName());
        reader = IOUtils.getResourceAsReader("wf-ext-schema-invalid.xml", -1);
        writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
        IOUtils.copyCharStream(reader, writer);
        try {
            wps.parseDef(jobConf);
            fail();
        } catch (WorkflowException ex) {
        // nop
        }
    } finally {
        services.destroy();
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) FileWriter(java.io.FileWriter) WorkflowException(org.apache.oozie.workflow.WorkflowException) Reader(java.io.Reader) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 3 with WorkflowException

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

the class WorkflowStore method getAction.

/**
 * Load the action data and returns a bean.
 *
 * @param id Action Id
 * @param locking true if the action is to be locked
 * @return Action Bean
 * @throws StoreException If action doesn't exist
 */
public WorkflowActionBean getAction(final String id, final boolean locking) throws StoreException {
    ParamChecker.notEmpty(id, "ActionID");
    WorkflowActionBean action = doOperation("getAction", new Callable<WorkflowActionBean>() {

        public WorkflowActionBean call() throws SQLException, StoreException, WorkflowException, InterruptedException {
            Query q = entityManager.createNamedQuery("GET_ACTION");
            /*
                 * if (locking) { OpenJPAQuery oq = OpenJPAPersistence.cast(q);
                 * FetchPlan fetch = oq.getFetchPlan();
                 * fetch.setReadLockMode(LockModeType.WRITE);
                 * fetch.setLockTimeout(1000); // 1 seconds }
                 */
            WorkflowActionBean action = null;
            q.setParameter("id", id);
            List<WorkflowActionBean> actions = q.getResultList();
            // action = (WorkflowActionBean) q.getSingleResult();
            if (actions.size() > 0) {
                action = actions.get(0);
            } else {
                throw new StoreException(ErrorCode.E0605, id);
            }
            // return action;
            return getBeanForRunningAction(action);
        }
    });
    return action;
}
Also used : OpenJPAQuery(org.apache.openjpa.persistence.OpenJPAQuery) Query(javax.persistence.Query) SQLException(java.sql.SQLException) WorkflowException(org.apache.oozie.workflow.WorkflowException) ArrayList(java.util.ArrayList) List(java.util.List) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 4 with WorkflowException

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

the class WorkflowStore method getWorkflow.

/**
 * Load the Workflow into a Bean and return it. Also load the Workflow Instance into the bean. And lock the Workflow
 * depending on the locking parameter.
 *
 * @param id Workflow ID
 * @param locking true if Workflow is to be locked
 * @return WorkflowJobBean
 * @throws StoreException
 */
public WorkflowJobBean getWorkflow(final String id, final boolean locking) throws StoreException {
    ParamChecker.notEmpty(id, "WorkflowID");
    WorkflowJobBean wfBean = doOperation("getWorkflow", new Callable<WorkflowJobBean>() {

        public WorkflowJobBean call() throws SQLException, StoreException, WorkflowException, InterruptedException {
            WorkflowJobBean wfBean = null;
            wfBean = getWorkflowOnly(id, locking);
            if (wfBean == null) {
                throw new StoreException(ErrorCode.E0604, id);
            }
            /*
                 * WorkflowInstance wfInstance; //krishna and next line
                 * wfInstance = workflowLib.get(id); wfInstance =
                 * wfBean.get(wfBean.getWfInstance());
                 * wfBean.setWorkflowInstance(wfInstance);
                 * wfBean.setWfInstance(wfInstance);
                 */
            return wfBean;
        }
    });
    return wfBean;
}
Also used : SQLException(java.sql.SQLException) WorkflowException(org.apache.oozie.workflow.WorkflowException) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 5 with WorkflowException

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

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