Search in sources :

Example 41 with CommandException

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

the class TestBundleSubmitXCommand method testJobXmlCommentRemoved.

/**
 * https://issues.apache.org/jira/browse/OOZIE-945
 *
 * @throws Exception
 */
public void testJobXmlCommentRemoved() throws Exception {
    // this retrieves bundle-submit-job.xml
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    Configuration jobConf = null;
    try {
        jobConf = new XConfiguration(new StringReader(job.getConf()));
    } catch (IOException ioe) {
        log.warn("Configuration parse error. read from DB :" + job.getConf(), ioe);
        throw new CommandException(ErrorCode.E1005, ioe);
    }
    Path appPath = new Path(jobConf.get(OozieClient.BUNDLE_APP_PATH), "bundle.xml");
    jobConf.set(OozieClient.BUNDLE_APP_PATH, appPath.toString());
    BundleSubmitXCommand command = new BundleSubmitXCommand(true, jobConf);
    BundleJobBean bundleBean = (BundleJobBean) command.getJob();
    bundleBean.setStartTime(new Date());
    bundleBean.setEndTime(new Date());
    command.call();
    // result includes bundle-submit-job.xml file instead of jobId since this is a dryRun mode
    String result = command.submit();
    // bundle-submit-job.xml contains the Apache license but this result should not contain the comment block
    assertTrue("submit result should not contain <!-- ", !result.contains("<!--"));
    assertTrue("submit result should not contain --> ", !result.contains("-->"));
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) BundleJobBean(org.apache.oozie.BundleJobBean) StringReader(java.io.StringReader) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 42 with CommandException

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

the class V1JobServlet method reRunCoordinatorActions.

/**
 * Rerun coordinator actions
 *
 * @param request servlet request
 * @param response servlet response
 * @param conf configuration object
 * @throws XServletException
 */
@SuppressWarnings("unchecked")
private JSONObject reRunCoordinatorActions(HttpServletRequest request, HttpServletResponse response, Configuration conf) throws XServletException {
    JSONObject json = new JSONObject();
    CoordinatorEngine coordEngine = Services.get().get(CoordinatorEngineService.class).getCoordinatorEngine(getUser(request));
    String jobId = getResourceName(request);
    String rerunType = request.getParameter(RestConstants.JOB_COORD_RANGE_TYPE_PARAM);
    String scope = request.getParameter(RestConstants.JOB_COORD_SCOPE_PARAM);
    String refresh = request.getParameter(RestConstants.JOB_COORD_RERUN_REFRESH_PARAM);
    String noCleanup = request.getParameter(RestConstants.JOB_COORD_RERUN_NOCLEANUP_PARAM);
    String failed = request.getParameter(RestConstants.JOB_COORD_RERUN_FAILED_PARAM);
    XLog.getLog(getClass()).info("Rerun coordinator for jobId=" + jobId + ", rerunType=" + rerunType + ",scope=" + scope + ",refresh=" + refresh + ", noCleanup=" + noCleanup);
    try {
        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> coordActions;
        if (coordInfo != null) {
            coordActions = coordInfo.getCoordActions();
        } else {
            coordActions = CoordUtils.getCoordActions(rerunType, jobId, scope, false);
        }
        json.put(JsonTags.COORDINATOR_ACTIONS, CoordinatorActionBean.toJSONArray(coordActions, "GMT"));
    } catch (BaseEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    } catch (CommandException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return json;
}
Also used : JSONObject(org.json.simple.JSONObject) CommandException(org.apache.oozie.command.CommandException) CoordinatorEngineService(org.apache.oozie.service.CoordinatorEngineService)

Example 43 with CommandException

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

the class V1JobServlet method killCoordinator.

/**
 * Kill a coord job
 *
 * @param request servlet request
 * @param response servlet response
 * @throws XServletException
 */
@SuppressWarnings("unchecked")
private JSONObject killCoordinator(HttpServletRequest request, HttpServletResponse response) throws XServletException {
    String jobId = getResourceName(request);
    CoordinatorEngine coordEngine = Services.get().get(CoordinatorEngineService.class).getCoordinatorEngine(getUser(request));
    JSONObject json = null;
    String rangeType = request.getParameter(RestConstants.JOB_COORD_RANGE_TYPE_PARAM);
    String scope = request.getParameter(RestConstants.JOB_COORD_SCOPE_PARAM);
    try {
        if (rangeType != null && scope != null) {
            XLog.getLog(getClass()).info("Kill coordinator actions for jobId=" + jobId + ", rangeType=" + rangeType + ",scope=" + scope);
            json = new JSONObject();
            CoordinatorActionInfo coordInfo = coordEngine.killActions(jobId, rangeType, scope);
            List<CoordinatorActionBean> coordActions;
            if (coordInfo != null) {
                coordActions = coordInfo.getCoordActions();
            } else {
                coordActions = CoordUtils.getCoordActions(rangeType, jobId, scope, true);
            }
            json.put(JsonTags.COORDINATOR_ACTIONS, CoordinatorActionBean.toJSONArray(coordActions, "GMT"));
        } else {
            coordEngine.kill(jobId);
        }
    } catch (CoordinatorEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    } catch (CommandException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return json;
}
Also used : JSONObject(org.json.simple.JSONObject) CommandException(org.apache.oozie.command.CommandException) CoordinatorEngineService(org.apache.oozie.service.CoordinatorEngineService)

Example 44 with CommandException

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

the class V2JobServlet method ignoreCoordinatorJob.

/**
 * Ignore a coordinator job/action
 *
 * @param request servlet request
 * @param response servlet response
 * @throws XServletException
 */
@SuppressWarnings("unchecked")
private JSONObject ignoreCoordinatorJob(HttpServletRequest request, HttpServletResponse response) throws XServletException {
    JSONObject json = null;
    CoordinatorEngine coordEngine = Services.get().get(CoordinatorEngineService.class).getCoordinatorEngine(getUser(request));
    String jobId = getResourceName(request);
    String type = request.getParameter(RestConstants.JOB_COORD_RANGE_TYPE_PARAM);
    String scope = request.getParameter(RestConstants.JOB_COORD_SCOPE_PARAM);
    String changeValue = "status=" + CoordinatorAction.Status.IGNORED;
    List<CoordinatorActionBean> coordActions = new ArrayList<CoordinatorActionBean>();
    try {
        if (type != null && !type.equals(RestConstants.JOB_COORD_SCOPE_ACTION)) {
            throw new CommandException(ErrorCode.E1024, "Currently ignore only support -action option");
        }
        CoordinatorActionInfo coordInfo = null;
        if (scope == null || scope.isEmpty()) {
            coordEngine.change(jobId, changeValue);
        } else {
            coordInfo = coordEngine.ignore(jobId, type, scope);
        }
        if (coordInfo != null) {
            coordActions = coordInfo.getCoordActions();
            json = new JSONObject();
            json.put(JsonTags.COORDINATOR_ACTIONS, CoordinatorActionBean.toJSONArray(coordActions, "GMT"));
        }
        return json;
    } catch (CommandException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    } catch (CoordinatorEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
}
Also used : CoordinatorActionInfo(org.apache.oozie.CoordinatorActionInfo) JSONObject(org.json.simple.JSONObject) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) CommandException(org.apache.oozie.command.CommandException) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException) CoordinatorEngineService(org.apache.oozie.service.CoordinatorEngineService)

Example 45 with CommandException

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

the class V2SLAServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    XLog.getLog(getClass()).debug("Got SLA GET request:" + request.getQueryString());
    try {
        stopCron();
        JSONObject json = getSLASummaryList(request, response);
        startCron();
        if (json == null) {
            response.setStatus(HttpServletResponse.SC_OK);
        } else {
            sendJsonResponse(response, HttpServletResponse.SC_OK, json);
        }
    } catch (CommandException ce) {
        XLog.getLog(getClass()).error("Command exception ", ce);
        throw new XServletException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ce);
    } catch (RuntimeException re) {
        XLog.getLog(getClass()).error("Runtime error ", re);
        throw new XServletException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ErrorCode.E0307, re.getMessage());
    }
}
Also used : JSONObject(org.json.simple.JSONObject) CommandException(org.apache.oozie.command.CommandException)

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