Search in sources :

Example 1 with CoordinatorEngineException

use of org.apache.oozie.CoordinatorEngineException in project oozie by apache.

the class V1JobsServlet method bulkModifyJobs.

private JSONObject bulkModifyJobs(HttpServletRequest request, HttpServletResponse response) throws XServletException, IOException {
    String action = request.getParameter(RestConstants.ACTION_PARAM);
    String jobType = request.getParameter(RestConstants.JOBTYPE_PARAM);
    String filter = request.getParameter(RestConstants.JOBS_FILTER_PARAM);
    String startStr = request.getParameter(RestConstants.OFFSET_PARAM);
    String lenStr = request.getParameter(RestConstants.LEN_PARAM);
    String timeZoneId = request.getParameter(RestConstants.TIME_ZONE_PARAM) == null ? "GMT" : request.getParameter(RestConstants.TIME_ZONE_PARAM);
    int start = (startStr != null) ? Integer.parseInt(startStr) : 1;
    start = (start < 1) ? 1 : start;
    int len = (lenStr != null) ? Integer.parseInt(lenStr) : 50;
    len = (len < 1) ? 50 : len;
    JSONObject json;
    List<String> ids = new ArrayList<String>();
    if (jobType.equals("wf")) {
        WorkflowsInfo jobs;
        DagEngine dagEngine = Services.get().get(DagEngineService.class).getDagEngine(getUser(request));
        try {
            switch(action) {
                case RestConstants.JOB_ACTION_KILL:
                    jobs = dagEngine.killJobs(filter, start, len);
                    break;
                case RestConstants.JOB_ACTION_SUSPEND:
                    jobs = dagEngine.suspendJobs(filter, start, len);
                    break;
                case RestConstants.JOB_ACTION_RESUME:
                    jobs = dagEngine.resumeJobs(filter, start, len);
                    break;
                default:
                    throw new DagEngineException(ErrorCode.E0301, action);
            }
        } catch (DagEngineException ex) {
            throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
        }
        json = OozieJsonFactory.getWFJSONObject(jobs, timeZoneId);
    } else if (jobType.equals("bundle")) {
        BundleJobInfo jobs;
        BundleEngine bundleEngine = Services.get().get(BundleEngineService.class).getBundleEngine(getUser(request));
        try {
            switch(action) {
                case RestConstants.JOB_ACTION_KILL:
                    jobs = bundleEngine.killJobs(filter, start, len);
                    break;
                case RestConstants.JOB_ACTION_SUSPEND:
                    jobs = bundleEngine.suspendJobs(filter, start, len);
                    break;
                case RestConstants.JOB_ACTION_RESUME:
                    jobs = bundleEngine.resumeJobs(filter, start, len);
                    break;
                default:
                    throw new BundleEngineException(ErrorCode.E0301, action);
            }
        } catch (BundleEngineException ex) {
            throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
        }
        json = OozieJsonFactory.getBundleJSONObject(jobs, timeZoneId);
    } else {
        CoordinatorJobInfo jobs;
        CoordinatorEngine coordEngine = Services.get().get(CoordinatorEngineService.class).getCoordinatorEngine(getUser(request));
        try {
            switch(action) {
                case RestConstants.JOB_ACTION_KILL:
                    jobs = coordEngine.killJobs(filter, start, len);
                    break;
                case RestConstants.JOB_ACTION_SUSPEND:
                    jobs = coordEngine.suspendJobs(filter, start, len);
                    break;
                case RestConstants.JOB_ACTION_RESUME:
                    jobs = coordEngine.resumeJobs(filter, start, len);
                    break;
                default:
                    throw new CoordinatorEngineException(ErrorCode.E0301, action);
            }
        } catch (CoordinatorEngineException ex) {
            throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
        }
        json = OozieJsonFactory.getCoordJSONObject(jobs, timeZoneId);
    }
    json.put(JsonTags.JOB_IDS, toJSONArray(ids));
    return json;
}
Also used : CoordinatorJobInfo(org.apache.oozie.CoordinatorJobInfo) ArrayList(java.util.ArrayList) BundleJobInfo(org.apache.oozie.BundleJobInfo) BundleEngine(org.apache.oozie.BundleEngine) DagEngineService(org.apache.oozie.service.DagEngineService) DagEngineException(org.apache.oozie.DagEngineException) DagEngine(org.apache.oozie.DagEngine) JSONObject(org.json.simple.JSONObject) WorkflowsInfo(org.apache.oozie.WorkflowsInfo) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) BundleEngineException(org.apache.oozie.BundleEngineException) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException)

Example 2 with CoordinatorEngineException

use of org.apache.oozie.CoordinatorEngineException 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 3 with CoordinatorEngineException

use of org.apache.oozie.CoordinatorEngineException in project oozie by apache.

the class V1JobsServlet method getCoordinatorJobs.

/**
 * v1 service implementation to get a list of workflows, with filtering or interested windows embedded in the
 * request object
 */
@SuppressWarnings("unchecked")
private JSONObject getCoordinatorJobs(HttpServletRequest request) throws XServletException {
    JSONObject json;
    try {
        String filter = request.getParameter(RestConstants.JOBS_FILTER_PARAM);
        String startStr = request.getParameter(RestConstants.OFFSET_PARAM);
        String lenStr = request.getParameter(RestConstants.LEN_PARAM);
        String timeZoneId = request.getParameter(RestConstants.TIME_ZONE_PARAM) == null ? "GMT" : request.getParameter(RestConstants.TIME_ZONE_PARAM);
        int start = (startStr != null) ? Integer.parseInt(startStr) : 1;
        start = (start < 1) ? 1 : start;
        int len = (lenStr != null) ? Integer.parseInt(lenStr) : 50;
        len = (len < 1) ? 50 : len;
        CoordinatorEngine coordEngine = Services.get().get(CoordinatorEngineService.class).getCoordinatorEngine(getUser(request));
        CoordinatorJobInfo jobs = coordEngine.getCoordJobs(filter, start, len);
        json = OozieJsonFactory.getCoordJSONObject(jobs, timeZoneId);
    } catch (CoordinatorEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return json;
}
Also used : JSONObject(org.json.simple.JSONObject) CoordinatorJobInfo(org.apache.oozie.CoordinatorJobInfo) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException) CoordinatorEngineService(org.apache.oozie.service.CoordinatorEngineService)

Example 4 with CoordinatorEngineException

use of org.apache.oozie.CoordinatorEngineException in project oozie by apache.

the class V1JobsServlet method submitCoordinatorJob.

/**
 * v1 service implementation to submit a coordinator job
 */
@SuppressWarnings("unchecked")
private JSONObject submitCoordinatorJob(HttpServletRequest request, Configuration conf) throws XServletException {
    JSONObject json = new JSONObject();
    XLog.getLog(getClass()).warn("submitCoordinatorJob " + XmlUtils.prettyPrint(conf).toString());
    try {
        String action = request.getParameter(RestConstants.ACTION_PARAM);
        if (action != null && !action.equals(RestConstants.JOB_ACTION_START) && !action.equals(RestConstants.JOB_ACTION_DRYRUN)) {
            throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0303, RestConstants.ACTION_PARAM, action);
        }
        boolean startJob = (action != null);
        String user = conf.get(OozieClient.USER_NAME);
        CoordinatorEngine coordEngine = Services.get().get(CoordinatorEngineService.class).getCoordinatorEngine(user);
        String id = null;
        boolean dryrun = false;
        if (action != null) {
            dryrun = (action.equals(RestConstants.JOB_ACTION_DRYRUN));
        }
        if (dryrun) {
            id = coordEngine.dryRunSubmit(conf);
        } else {
            id = coordEngine.submitJob(conf, startJob);
        }
        json.put(JsonTags.JOB_ID, id);
    } catch (CoordinatorEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return json;
}
Also used : JSONObject(org.json.simple.JSONObject) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException) CoordinatorEngineService(org.apache.oozie.service.CoordinatorEngineService)

Example 5 with CoordinatorEngineException

use of org.apache.oozie.CoordinatorEngineException in project oozie by apache.

the class V2JobServlet method updateJob.

/**
 * Update coord job.
 *
 * @param request the request
 * @param response the response
 * @return the JSON object
 * @throws XServletException the x servlet exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
@SuppressWarnings("unchecked")
@Override
protected JSONObject updateJob(HttpServletRequest request, HttpServletResponse response, Configuration conf) throws XServletException, IOException {
    CoordinatorEngine coordEngine = Services.get().get(CoordinatorEngineService.class).getCoordinatorEngine(getUser(request));
    JSONObject json = new JSONObject();
    try {
        String jobId = getResourceName(request);
        boolean dryrun = StringUtils.isEmpty(request.getParameter(RestConstants.JOB_ACTION_DRYRUN)) ? false : Boolean.parseBoolean(request.getParameter(RestConstants.JOB_ACTION_DRYRUN));
        boolean showDiff = StringUtils.isEmpty(request.getParameter(RestConstants.JOB_ACTION_SHOWDIFF)) ? true : Boolean.parseBoolean(request.getParameter(RestConstants.JOB_ACTION_SHOWDIFF));
        String diff = coordEngine.updateJob(conf, jobId, dryrun, showDiff);
        JSONObject diffJson = new JSONObject();
        diffJson.put(JsonTags.COORD_UPDATE_DIFF, diff);
        json.put(JsonTags.COORD_UPDATE, diffJson);
    } catch (CoordinatorEngineException e) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, e);
    }
    return json;
}
Also used : JSONObject(org.json.simple.JSONObject) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException) CoordinatorEngineService(org.apache.oozie.service.CoordinatorEngineService)

Aggregations

CoordinatorEngine (org.apache.oozie.CoordinatorEngine)6 CoordinatorEngineException (org.apache.oozie.CoordinatorEngineException)6 JSONObject (org.json.simple.JSONObject)6 CoordinatorEngineService (org.apache.oozie.service.CoordinatorEngineService)5 ArrayList (java.util.ArrayList)2 CoordinatorJobInfo (org.apache.oozie.CoordinatorJobInfo)2 BundleEngine (org.apache.oozie.BundleEngine)1 BundleEngineException (org.apache.oozie.BundleEngineException)1 BundleJobInfo (org.apache.oozie.BundleJobInfo)1 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)1 CoordinatorActionInfo (org.apache.oozie.CoordinatorActionInfo)1 CoordinatorWfActionBean (org.apache.oozie.CoordinatorWfActionBean)1 DagEngine (org.apache.oozie.DagEngine)1 DagEngineException (org.apache.oozie.DagEngineException)1 WorkflowsInfo (org.apache.oozie.WorkflowsInfo)1 CommandException (org.apache.oozie.command.CommandException)1 DagEngineService (org.apache.oozie.service.DagEngineService)1 JSONArray (org.json.simple.JSONArray)1