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("-->"));
}
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;
}
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;
}
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);
}
}
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());
}
}
Aggregations