/** * Rerun bundle job * * @param request servlet request * @param response servlet response * @param conf configration object * @throws XServletException */ private void rerunBundleJob( HttpServletRequest request, HttpServletResponse response, Configuration conf) throws XServletException { JSONObject json = new JSONObject(); BundleEngine bundleEngine = Services.get() .get(BundleEngineService.class) .getBundleEngine(getUser(request), getAuthToken(request)); String jobId = getResourceName(request); String coordScope = request.getParameter(RestConstants.JOB_BUNDLE_RERUN_COORD_SCOPE_PARAM); String dateScope = request.getParameter(RestConstants.JOB_BUNDLE_RERUN_DATE_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 Bundle for jobId=" + jobId + ", coordScope=" + coordScope + ", dateScope=" + dateScope + ", refresh=" + refresh + ", noCleanup=" + noCleanup); try { bundleEngine.reRun( jobId, coordScope, dateScope, Boolean.valueOf(refresh), Boolean.valueOf(noCleanup)); } catch (BaseEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } }
@SuppressWarnings("unchecked") private JSONObject getBundleJobs(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; BundleEngine bundleEngine = Services.get() .get(BundleEngineService.class) .getBundleEngine(getUser(request), getAuthToken(request)); BundleJobInfo jobs = bundleEngine.getBundleJobs(filter, start, len); List<BundleJobBean> jsonJobs = jobs.getBundleJobs(); json.put(JsonTags.BUNDLE_JOBS, BundleJobBean.toJSONArray(jsonJobs)); json.put(JsonTags.BUNDLE_JOB_TOTAL, jobs.getTotal()); json.put(JsonTags.BUNDLE_JOB_OFFSET, jobs.getStart()); json.put(JsonTags.BUNDLE_JOB_LEN, jobs.getLen()); } catch (BundleEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } return json; }
/** * Stream bundle job log * * @param request servlet request * @param response servlet response * @throws XServletException */ private void streamBundleJob(HttpServletRequest request, HttpServletResponse response) throws XServletException, IOException { BundleEngine bundleEngine = Services.get() .get(BundleEngineService.class) .getBundleEngine(getUser(request), getAuthToken(request)); String jobId = getResourceName(request); try { bundleEngine.streamLog(jobId, response.getWriter()); } catch (BundleEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } }
/** * Change a bundle job * * @param request servlet request * @param response servlet response * @throws XServletException */ private void changeBundleJob(HttpServletRequest request, HttpServletResponse response) throws XServletException { BundleEngine bundleEngine = Services.get() .get(BundleEngineService.class) .getBundleEngine(getUser(request), getAuthToken(request)); String jobId = getResourceName(request); String changeValue = request.getParameter(RestConstants.JOB_CHANGE_VALUE); try { bundleEngine.change(jobId, changeValue); } catch (BundleEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } }
/** * Get bundle job definition * * @param request servlet request * @param response servlet response * @return String bundle definition * @throws XServletException */ private String getBundleJobDefinition(HttpServletRequest request, HttpServletResponse response) throws XServletException { BundleEngine bundleEngine = Services.get() .get(BundleEngineService.class) .getBundleEngine(getUser(request), getAuthToken(request)); String bundleDefinition; String jobId = getResourceName(request); try { bundleDefinition = bundleEngine.getDefinition(jobId); } catch (BundleEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } return bundleDefinition; }
/** * Get bundle job info * * @param request servlet request * @param response servlet response * @return JsonBean bundle job bean * @throws XServletException * @throws BaseEngineException */ private JsonBean getBundleJob(HttpServletRequest request, HttpServletResponse response) throws XServletException, BaseEngineException { JsonBean jobBean = null; BundleEngine bundleEngine = Services.get() .get(BundleEngineService.class) .getBundleEngine(getUser(request), getAuthToken(request)); String jobId = getResourceName(request); try { jobBean = (JsonBean) bundleEngine.getBundleJob(jobId); return jobBean; } catch (BundleEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } }
/** v1 service implementation to submit a bundle job */ @SuppressWarnings("unchecked") private JSONObject submitBundleJob(HttpServletRequest request, Configuration conf) throws XServletException { JSONObject json = new JSONObject(); XLog.getLog(getClass()).warn("submitBundleJob " + 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); BundleEngine bundleEngine = Services.get() .get(BundleEngineService.class) .getBundleEngine(user, getAuthToken(request)); String id = null; boolean dryrun = false; if (action != null) { dryrun = (action.equals(RestConstants.JOB_ACTION_DRYRUN)); } if (dryrun) { id = bundleEngine.dryrunSubmit(conf, startJob); } else { id = bundleEngine.submitJob(conf, startJob); } json.put(JsonTags.JOB_ID, id); } catch (BundleEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } return json; }