use of org.apache.oozie.CoordinatorActionInfo 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.CoordinatorActionInfo in project oozie by apache.
the class CoordActionsKillXCommand method killChildren.
@Override
public void killChildren() throws CommandException {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
for (CoordinatorActionBean coordAction : coordActions) {
coordAction.setStatus(CoordinatorAction.Status.KILLED);
coordAction.setLastModifiedTime(new Date());
// kill Workflow job associated with this Coord action
if (coordAction.getExternalId() != null) {
queue(new KillXCommand(coordAction.getExternalId()));
coordAction.incrementAndGetPending();
} else {
coordAction.setPending(0);
}
updateList.add(new UpdateEntry(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, coordAction));
if (EventHandlerService.isEnabled()) {
CoordinatorXCommand.generateEvent(coordAction, coordJob.getUser(), coordJob.getAppName(), coordAction.getCreatedTime());
}
queue(new CoordActionNotificationXCommand(coordAction), 100);
}
CoordinatorActionInfo coordInfo = new CoordinatorActionInfo(coordActions);
ret = coordInfo;
}
use of org.apache.oozie.CoordinatorActionInfo in project oozie by apache.
the class CoordRerunXCommand method rerunChildren.
@Override
public void rerunChildren() throws CommandException {
boolean isError = false;
try {
CoordinatorActionInfo coordInfo = null;
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
List<CoordinatorActionBean> coordActions = CoordUtils.getCoordActions(rerunType, jobId, scope, false);
if (checkAllActionsRunnable(coordActions)) {
Map<String, Context> uriHandlerContextMap = new HashMap<String, Context>();
Configuration coordJobConf = null;
try {
coordJobConf = new XConfiguration(new StringReader(coordJob.getConf()));
} catch (IOException e) {
throw new CommandException(ErrorCode.E0907, "failed to read coord job conf to clean up output data");
}
try {
for (CoordinatorActionBean coordAction : coordActions) {
String actionXml = coordAction.getActionXml();
// Cleanup activity should not run when failed option has been provided
if (!noCleanup && !failed) {
Element eAction = XmlUtils.parseXml(actionXml);
cleanupOutputEvents(eAction, coordJobConf, uriHandlerContextMap);
}
if (refresh) {
refreshAction(coordJob, coordAction);
}
updateAction(coordJob, coordAction);
if (SLAService.isEnabled()) {
SLAOperations.updateRegistrationEvent(coordAction.getId());
}
queue(new CoordActionNotificationXCommand(coordAction), 100);
queue(new CoordActionInputCheckXCommand(coordAction.getId(), coordAction.getJobId()), 100);
if (coordAction.getPushMissingDependencies() != null) {
queue(new CoordPushDependencyCheckXCommand(coordAction.getId(), true), 100);
}
}
} finally {
Iterator<Entry<String, Context>> itr = uriHandlerContextMap.entrySet().iterator();
while (itr.hasNext()) {
Entry<String, Context> entry = itr.next();
entry.getValue().destroy();
itr.remove();
}
}
} else {
isError = true;
throw new CommandException(ErrorCode.E1018, "part or all actions are not eligible to rerun!");
}
coordInfo = new CoordinatorActionInfo(coordActions);
ret = coordInfo;
} catch (XException xex) {
isError = true;
throw new CommandException(xex);
} catch (JDOMException jex) {
isError = true;
throw new CommandException(ErrorCode.E0700, jex.getMessage(), jex);
} catch (Exception ex) {
isError = true;
throw new CommandException(ErrorCode.E1018, ex.getMessage(), ex);
} finally {
if (isError) {
transitToPrevious();
}
}
}
use of org.apache.oozie.CoordinatorActionInfo in project oozie by apache.
the class CoordActionsIgnoreXCommand method ignoreChildren.
@Override
public void ignoreChildren() throws CommandException {
for (CoordinatorActionBean action : coordActions) {
action.setStatus(Status.IGNORED);
action.setLastModifiedTime(new Date());
action.setPending(0);
updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action));
LOG.info("Ignore coord action = [{0}], new status = [{1}]", action.getId(), action.getStatus());
}
ret = new CoordinatorActionInfo(coordActions);
}
use of org.apache.oozie.CoordinatorActionInfo in project oozie by apache.
the class TestCoordActionsIgnoreXCommand method testCoordActionsIgnore.
public void testCoordActionsIgnore() throws Exception {
createDBRecords();
// positive test of single action - oozie job -ingore job1 -action 1
CoordinatorActionInfo retInfo = new CoordActionsIgnoreXCommand(coordJobs.get(0).getId(), "action", "1").call();
CoordinatorActionBean actionBean1 = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, coordActions.get(0).getId());
assertEquals(CoordinatorAction.Status.IGNORED, actionBean1.getStatus());
assertEquals(1, retInfo.getCoordActions().size());
assertEquals(actionBean1.getId(), retInfo.getCoordActions().get(0).getId());
// positive test of action range - oozie job -ignore job1 -action 2-3
retInfo = new CoordActionsIgnoreXCommand(coordJobs.get(0).getId(), "action", "2-3").call();
CoordinatorActionBean actionBean2 = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, coordActions.get(1).getId());
CoordinatorActionBean actionBean3 = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, coordActions.get(2).getId());
assertEquals(CoordinatorAction.Status.IGNORED, actionBean2.getStatus());
assertEquals(CoordinatorAction.Status.IGNORED, actionBean3.getStatus());
assertEquals(2, retInfo.getCoordActions().size());
String retId1 = retInfo.getCoordActions().get(0).getId();
String retId2 = retInfo.getCoordActions().get(1).getId();
assertTrue(actionBean2.getId().equals(retId1) || actionBean2.getId().equals(retId2));
assertTrue(actionBean3.getId().equals(retId1) || actionBean3.getId().equals(retId2));
// negative test when ignoring a coord action in RUNNING (@5 is running)
try {
new CoordActionsIgnoreXCommand(coordJobs.get(0).getId(), "action", "4-5").call();
} catch (CommandException ex) {
assertEquals(ex.getErrorCode(), ErrorCode.E1024);
assertTrue(ex.getMessage().indexOf("part or all actions are not eligible to ignore, check state of action number(s) [5]") > -1);
}
// negative test when ignore command on coordinator job in PREP
try {
new CoordActionsIgnoreXCommand(coordJobs.get(1).getId(), "action", "1").call();
} catch (CommandException ex) {
assertEquals(ex.getErrorCode(), ErrorCode.E1024);
assertTrue(ex.getMessage().indexOf("No actions are materialized to ignore") > -1);
}
}
Aggregations