/** * Get coord job info * * @param request servlet request * @param response servlet response * @return JsonBean CoordinatorJobBean * @throws XServletException * @throws BaseEngineException */ private JsonBean getCoordinatorJob(HttpServletRequest request, HttpServletResponse response) throws XServletException, BaseEngineException { JsonBean jobBean = null; CoordinatorEngine coordEngine = Services.get() .get(CoordinatorEngineService.class) .getCoordinatorEngine(getUser(request), getAuthToken(request)); String jobId = getResourceName(request); String startStr = request.getParameter(RestConstants.OFFSET_PARAM); String lenStr = request.getParameter(RestConstants.LEN_PARAM); String filter = request.getParameter(RestConstants.JOB_FILTER_PARAM); int start = (startStr != null) ? Integer.parseInt(startStr) : 1; start = (start < 1) ? 1 : start; // Get default number of coordinator actions to be retrieved int defaultLen = Services.get().getConf().getInt(COORD_ACTIONS_DEFAULT_LENGTH, 1000); int len = (lenStr != null) ? Integer.parseInt(lenStr) : 0; len = (len < 1) ? defaultLen : len; try { JsonCoordinatorJob coordJob = coordEngine.getCoordJob(jobId, filter, start, len); jobBean = coordJob; } catch (CoordinatorEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } return jobBean; }
/** * 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 = new JSONObject(); try { String filter = request.getParameter(RestConstants.JOBS_FILTER_PARAM); String startStr = request.getParameter(RestConstants.OFFSET_PARAM); String lenStr = request.getParameter(RestConstants.LEN_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), getAuthToken(request)); CoordinatorJobInfo jobs = coordEngine.getCoordJobs(filter, start, len); List<CoordinatorJobBean> jsonJobs = jobs.getCoordJobs(); json.put(JsonTags.COORDINATOR_JOBS, CoordinatorJobBean.toJSONArray(jsonJobs)); json.put(JsonTags.COORD_JOB_TOTAL, jobs.getTotal()); json.put(JsonTags.COORD_JOB_OFFSET, jobs.getStart()); json.put(JsonTags.COORD_JOB_LEN, jobs.getLen()); } catch (CoordinatorEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } return json; }
/** * 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), getAuthToken(request)); String jobId = getResourceName(request); String rerunType = request.getParameter(RestConstants.JOB_COORD_RERUN_TYPE_PARAM); String scope = request.getParameter(RestConstants.JOB_COORD_RERUN_SCOPE_PARAM); String refresh = request.getParameter(RestConstants.JOB_COORD_RERUN_REFRESH_PARAM); String noCleanup = request.getParameter(RestConstants.JOB_COORD_RERUN_NOCLEANUP_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_RERUN_DATE) || rerunType.equals(RestConstants.JOB_COORD_RERUN_ACTION))) { throw new CommandException(ErrorCode.E1018, "date or action expected."); } CoordinatorActionInfo coordInfo = coordEngine.reRun( jobId, rerunType, scope, Boolean.valueOf(refresh), Boolean.valueOf(noCleanup)); List<CoordinatorActionBean> coordActions; if (coordInfo != null) { coordActions = coordInfo.getCoordActions(); } else { coordActions = CoordRerunXCommand.getCoordActions(rerunType, jobId, scope); } 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; }
/** * Kill a coord job * * @param request servlet request * @param response servlet response * @throws XServletException */ private void killCoordinatorJob(HttpServletRequest request, HttpServletResponse response) throws XServletException { CoordinatorEngine coordEngine = Services.get() .get(CoordinatorEngineService.class) .getCoordinatorEngine(getUser(request), getAuthToken(request)); String jobId = getResourceName(request); try { coordEngine.kill(jobId); } catch (CoordinatorEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } }
/** * Change a coordinator job * * @param request servlet request * @param response servlet response * @throws XServletException */ private void changeCoordinatorJob(HttpServletRequest request, HttpServletResponse response) throws XServletException { CoordinatorEngine coordEngine = Services.get() .get(CoordinatorEngineService.class) .getCoordinatorEngine(getUser(request), getAuthToken(request)); String jobId = getResourceName(request); String changeValue = request.getParameter(RestConstants.JOB_CHANGE_VALUE); try { coordEngine.change(jobId, changeValue); } catch (CoordinatorEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } }
/** * Get coordinator action * * @param request servlet request * @param response servlet response * @return JsonBean CoordinatorActionBean * @throws XServletException * @throws BaseEngineException */ private JsonBean getCoordinatorAction(HttpServletRequest request, HttpServletResponse response) throws XServletException, BaseEngineException { JsonBean actionBean = null; CoordinatorEngine coordEngine = Services.get() .get(CoordinatorEngineService.class) .getCoordinatorEngine(getUser(request), getAuthToken(request)); String actionId = getResourceName(request); try { actionBean = coordEngine.getCoordAction(actionId); } catch (CoordinatorEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } return actionBean; }
/** * Stream coordinator job log * * @param request servlet request * @param response servlet response * @throws XServletException * @throws IOException */ private void streamCoordinatorJobLog(HttpServletRequest request, HttpServletResponse response) throws XServletException, IOException { CoordinatorEngine coordEngine = Services.get() .get(CoordinatorEngineService.class) .getCoordinatorEngine(getUser(request), getAuthToken(request)); String jobId = getResourceName(request); String logRetrievalScope = request.getParameter(RestConstants.JOB_LOG_SCOPE_PARAM); String logRetrievalType = request.getParameter(RestConstants.JOB_LOG_TYPE_PARAM); try { coordEngine.streamLog(jobId, logRetrievalScope, logRetrievalType, response.getWriter()); } catch (BaseEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } catch (CommandException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } }
/** * Get coordinator job definition * * @param request servlet request * @param response servlet response * @return String coord definition * @throws XServletException */ private String getCoordinatorJobDefinition( HttpServletRequest request, HttpServletResponse response) throws XServletException { CoordinatorEngine coordEngine = Services.get() .get(CoordinatorEngineService.class) .getCoordinatorEngine(getUser(request), getAuthToken(request)); String jobId = getResourceName(request); String coordDefinition = null; try { coordDefinition = coordEngine.getDefinition(jobId); } catch (BaseEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } return coordDefinition; }
/** 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, getAuthToken(request)); String id = null; boolean dryrun = false; if (action != null) { dryrun = (action.equals(RestConstants.JOB_ACTION_DRYRUN)); } if (dryrun) { id = coordEngine.dryrunSubmit(conf, startJob); } 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; }