Search in sources :

Example 21 with CommandException

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

the class DagEngine method resumeJobs.

/**
 * return the jobs that've been resumed
 * @param filter Filter for jobs that will be resumed, can be name, user, group, status, id or combination of any
 * @param start Offset for the jobs that will be resumed
 * @param len maximum number of jobs that will be resumed
 * @return workflowsInfo returns the jobs that've been resumed
 * @throws DagEngineException if the jobs cloud not be resumed
 */
public WorkflowsInfo resumeJobs(String filter, int start, int len) throws DagEngineException {
    try {
        Map<String, List<String>> filterList = parseFilter(filter);
        WorkflowsInfo workflowsInfo = new BulkWorkflowXCommand(filterList, start, len, OperationType.Resume).call();
        if (workflowsInfo == null) {
            return new WorkflowsInfo(new ArrayList<WorkflowJobBean>(), 0, 0, 0);
        }
        return workflowsInfo;
    } catch (CommandException ex) {
        throw new DagEngineException(ex);
    }
}
Also used : BulkWorkflowXCommand(org.apache.oozie.command.wf.BulkWorkflowXCommand) List(java.util.List) ArrayList(java.util.ArrayList) CommandException(org.apache.oozie.command.CommandException)

Example 22 with CommandException

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

the class DagEngine method submitJob.

/**
 * Submit a workflow job. <p> It validates configuration properties.
 *
 * @param conf job configuration.
 * @param startJob indicates if the job should be started or not.
 * @return the job Id.
 * @throws DagEngineException thrown if the job could not be created.
 */
@Override
public String submitJob(Configuration conf, boolean startJob) throws DagEngineException {
    validateSubmitConfiguration(conf);
    try {
        String jobId;
        SubmitXCommand submit = new SubmitXCommand(conf);
        jobId = submit.call();
        if (startJob) {
            start(jobId);
        }
        return jobId;
    } catch (CommandException ex) {
        throw new DagEngineException(ex);
    }
}
Also used : SubmitXCommand(org.apache.oozie.command.wf.SubmitXCommand) CommandException(org.apache.oozie.command.CommandException)

Example 23 with CommandException

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

the class DagEngine method reRun.

/**
 * Rerun a job.
 *
 * @param jobId job Id to rerun.
 * @param conf configuration information for the rerun.
 * @throws DagEngineException thrown if the job could not be rerun.
 */
@Override
public void reRun(String jobId, Configuration conf) throws DagEngineException {
    try {
        WorkflowJobBean wfBean = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, jobId);
        Configuration wfConf = new XConfiguration(new StringReader(wfBean.getConf()));
        XConfiguration.copy(conf, wfConf);
        validateReRunConfiguration(wfConf);
        new ReRunXCommand(jobId, wfConf).call();
    } catch (CommandException ex) {
        throw new DagEngineException(ex);
    } catch (JPAExecutorException ex) {
        throw new DagEngineException(ex);
    } catch (IOException ex) {
        throw new DagEngineException(ErrorCode.E0803, ex.getMessage());
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) ReRunXCommand(org.apache.oozie.command.wf.ReRunXCommand) StringReader(java.io.StringReader) CommandException(org.apache.oozie.command.CommandException) IOException(java.io.IOException)

Example 24 with CommandException

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

the class LocalOozieClientCoord method getCoordinatorActions.

private List<CoordinatorAction> getCoordinatorActions(String jobId, String rerunType, String scope, boolean refresh, boolean noCleanup, boolean failed, Properties prop) throws OozieClientException {
    try {
        XConfiguration conf = null;
        if (prop != null) {
            conf = new XConfiguration(prop);
        }
        if (!(rerunType.equals(RestConstants.JOB_COORD_SCOPE_DATE) || rerunType.equals(RestConstants.JOB_COORD_SCOPE_ACTION))) {
            throw new CommandException(ErrorCode.E1018, "date or action expected.");
        }
        CoordinatorActionInfo coordInfo = coordEngine.reRun(jobId, rerunType, scope, Boolean.valueOf(refresh), Boolean.valueOf(noCleanup), Boolean.valueOf(failed), conf);
        List<CoordinatorActionBean> actionBeans;
        if (coordInfo != null) {
            actionBeans = coordInfo.getCoordActions();
        } else {
            actionBeans = CoordUtils.getCoordActions(rerunType, jobId, scope, false);
        }
        List<CoordinatorAction> actions = new ArrayList<CoordinatorAction>();
        for (CoordinatorActionBean actionBean : actionBeans) {
            actions.add(actionBean);
        }
        return actions;
    } catch (CommandException ce) {
        throw new OozieClientException(ce.getErrorCode().toString(), ce);
    } catch (BaseEngineException ex) {
        throw new OozieClientException(ex.getErrorCode().toString(), ex);
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) OozieClientException(org.apache.oozie.client.OozieClientException) CoordinatorAction(org.apache.oozie.client.CoordinatorAction) ArrayList(java.util.ArrayList) CommandException(org.apache.oozie.command.CommandException)

Example 25 with CommandException

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

the class TestActionUserRetry method testUserRetryPolicy.

public void testUserRetryPolicy() throws JPAExecutorException, IOException, CommandException {
    Configuration conf = new XConfiguration();
    String workflowUri = getTestCaseFileUri("workflow.xml");
    // @formatter:off
    String appXml = "<workflow-app xmlns=\"uri:oozie:workflow:0.5\" name=\"wf-fork\">" + "<start to=\"fork1\"/>" + "<fork name=\"fork1\">" + "<path start=\"action1\"/>" + "<path start=\"action2\"/>" + "</fork>" + "<action name=\"action1\" retry-max=\"2\" retry-interval=\"1\" retry-policy=\"exponential\">" + "<test xmlns=\"uri:test\">" + "<signal-value>${wf:conf('signal-value')}</signal-value>" + "<external-status>${wf:conf('external-status')}</external-status> " + "<error>${wf:conf('error')}</error>" + "<avoid-set-execution-data>${wf:conf('avoid-set-execution-data')}</avoid-set-execution-data>" + "<avoid-set-end-data>${wf:conf('avoid-set-end-data')}</avoid-set-end-data>" + "<running-mode>${wf:conf('running-mode')}</running-mode>" + "</test>" + "<ok to=\"join1\"/>" + "<error to=\"kill\"/>" + "</action>" + "<action name=\"action2\">" + "<fs></fs><ok to=\"join1\"/>" + "<error to=\"kill\"/>" + "</action>" + "<join name=\"join1\" to=\"end\"/>" + "<kill name=\"kill\"><message>killed</message></kill>" + "<end name=\"end\"/>" + "</workflow-app>";
    // @Formatter:on
    writeToFile(appXml, workflowUri);
    conf.set(OozieClient.APP_PATH, workflowUri);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("error", "start.error");
    conf.set("external-status", "error");
    conf.set("signal-value", "based_on_action_status");
    SubmitXCommand sc = new SubmitXCommand(conf);
    final String jobId = sc.call();
    new StartXCommand(jobId).call();
    final WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobId);
    final JPAService jpaService = Services.get().get(JPAService.class);
    // set a timeout for exponential retry of action with respect to given
    // retry-interval and retry-max.
    // If retry-interval is 1 then, for first retry, delay will be 1 min,
    // for second retry it will be 2 min, 4, 8, 16 & so on.
    int timeout = (1 + 2) * 60 * 1000;
    waitFor(timeout, new Predicate() {

        public boolean evaluate() throws Exception {
            List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
            WorkflowActionBean action = null;
            for (WorkflowActionBean bean : actions) {
                if (bean.getType().equals("test")) {
                    action = bean;
                    break;
                }
            }
            return (action != null && action.getUserRetryCount() == 2);
        }
    });
    List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
    WorkflowActionBean action = null;
    for (WorkflowActionBean bean : actions) {
        if (bean.getType().equals("test")) {
            action = bean;
            break;
        }
    }
    assertNotNull(action);
    assertEquals(2, action.getUserRetryCount());
}
Also used : WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) List(java.util.List) JPAService(org.apache.oozie.service.JPAService)

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