use of org.apache.oozie.CoordinatorEngine in project oozie by apache.
the class TestPastActionsTimeOut method _testTimeout.
/**
* The catch-up mode time up has been setup in {@link CoordActionMaterializeXCommand}
* @param jobId job id
* @throws Exception thrown if failed
*/
private void _testTimeout(final String jobId) throws Exception {
final CoordinatorEngine ce = new CoordinatorEngine(getTestUser());
waitFor(6000, new Predicate() {
public boolean evaluate() throws Exception {
CoordinatorJob job = ce.getCoordJob(jobId);
return !(job.getStatus().equals(CoordinatorJob.Status.PREP));
}
});
CoordinatorJob job = ce.getCoordJob(jobId);
assertTrue(!(job.getStatus().equals(CoordinatorJob.Status.PREP)));
waitFor(6000, new Predicate() {
public boolean evaluate() throws Exception {
CoordinatorJob job = ce.getCoordJob(jobId);
List<CoordinatorAction> actions = job.getActions();
return actions.size() > 0;
}
});
job = ce.getCoordJob(jobId);
List<CoordinatorAction> actions = job.getActions();
assertTrue(actions.size() > 0);
for (CoordinatorAction action : actions) {
CoordinatorActionBean json = (CoordinatorActionBean) action;
assertEquals(10, json.getTimeOut());
}
}
use of org.apache.oozie.CoordinatorEngine in project oozie by apache.
the class TestSLAAlertXCommand method testSLAChangeCommand.
public void testSLAChangeCommand() throws Exception {
setupSLAJobs();
String newParams = RestConstants.SLA_SHOULD_END + "=10";
String jobIdsStr = bundle.getId();
String coords = coord1.getAppName();
bundleEngine.changeSLA(jobIdsStr, null, null, coords, newParams);
assertEquals(getSLACalcStatus(coord1.getId() + "@1").getExpectedEnd().getTime(), getSLACalcStatus(coord1.getId() + "@1").getNominalTime().getTime() + 10 * timeInSec);
assertEquals(getSLACalcStatus(coord1.getId() + "@2").getExpectedEnd().getTime(), getSLACalcStatus(coord1.getId() + "@2").getNominalTime().getTime() + 10 * timeInSec);
assertEquals(getSLACalcStatus(coord1.getId() + "@5").getExpectedEnd().getTime(), getSLACalcStatus(coord1.getId() + "@5").getNominalTime().getTime() + 10 * timeInSec);
newParams = "non-valid-param=10";
try {
bundleEngine.changeSLA(jobIdsStr, null, null, coords, newParams);
fail("Should throw Exception");
} catch (BaseEngineException e) {
assertEquals(e.getErrorCode(), ErrorCode.E1027);
}
try {
new CoordinatorEngine().changeSLA(coord1.getId(), null, null, null, newParams);
fail("Should throw Exception");
} catch (BaseEngineException e) {
assertEquals(e.getErrorCode(), ErrorCode.E1027);
}
}
use of org.apache.oozie.CoordinatorEngine 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;
}
use of org.apache.oozie.CoordinatorEngine 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.CoordinatorEngine 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;
}
Aggregations