use of org.apache.oozie.BaseEngineException in project oozie by apache.
the class TestSLAAlertXCommand method testBundleSLAAlertCommands.
public void testBundleSLAAlertCommands() throws Exception {
setupSLAJobs();
String jobIdsStr = bundle.getId();
String actions = "1,2";
String coords = null;
bundleEngine.disableSLAAlert(jobIdsStr, actions, null, coords);
checkSLAStatus(coord1.getId() + "@1", true);
checkSLAStatus(coord1.getId() + "@2", true);
checkSLAStatus(coord1.getId() + "@3", false);
checkSLAStatus(coord1.getId() + "@5", false);
checkSLAStatus(coord1.getId() + "@4", false);
checkSLAStatus(coord2.getId() + "@1", true);
checkSLAStatus(coord2.getId() + "@1", true);
bundleEngine.enableSLAAlert(jobIdsStr, null, null, null);
checkSLAStatus(coord1.getId() + "@1", false);
checkSLAStatus(coord1.getId() + "@2", false);
checkSLAStatus(coord1.getId() + "@3", false);
checkSLAStatus(coord1.getId() + "@5", false);
checkSLAStatus(coord1.getId() + "@4", false);
checkSLAStatus(coord2.getId() + "@1", false);
checkSLAStatus(coord2.getId() + "@2", false);
CoordinatorJobBean job1 = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, coord1.getId());
XConfiguration xConf = new XConfiguration(new StringReader(job1.getConf()));
assertEquals(xConf.get(OozieClient.SLA_DISABLE_ALERT), null);
CoordinatorJobBean job2 = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, coord2.getId());
xConf = new XConfiguration(new StringReader(job2.getConf()));
assertEquals(xConf.get(OozieClient.SLA_DISABLE_ALERT), null);
bundleEngine.disableSLAAlert(jobIdsStr, null, null, "coord1");
checkSLAStatus(coord1.getId() + "@1", true);
checkSLAStatus(coord1.getId() + "@2", true);
checkSLAStatus(coord1.getId() + "@3", true);
checkSLAStatus(coord1.getId() + "@4", true);
checkSLAStatus(coord1.getId() + "@5", true);
checkSLAStatus(coord2.getId() + "@1", false);
checkSLAStatus(coord2.getId() + "@2", false);
job1 = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, coord1.getId());
xConf = new XConfiguration(new StringReader(job1.getConf()));
assertEquals(xConf.get(OozieClient.SLA_DISABLE_ALERT), SLAOperations.ALL_VALUE);
bundleEngine.disableSLAAlert(jobIdsStr, null, null, "coord2");
// with multiple coordID.
String dates = "2014-01-01T00:00Z::2014-01-03T00:00Z";
bundleEngine.enableSLAAlert(jobIdsStr, null, dates, "coord1," + coord2.getId());
checkSLAStatus(coord1.getId() + "@1", false);
checkSLAStatus(coord1.getId() + "@2", false);
checkSLAStatus(coord1.getId() + "@3", false);
checkSLAStatus(coord1.getId() + "@4", true);
checkSLAStatus(coord1.getId() + "@5", true);
checkSLAStatus(coord2.getId() + "@1", false);
checkSLAStatus(coord2.getId() + "@2", false);
checkSLAStatus(coord2.getId() + "@3", false);
checkSLAStatus(coord2.getId() + "@4", true);
try {
bundleEngine.disableSLAAlert(jobIdsStr, null, null, "dummy");
fail("Should throw Exception");
} catch (BaseEngineException e) {
assertEquals(e.getErrorCode(), ErrorCode.E1026);
}
}
use of org.apache.oozie.BaseEngineException 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.BaseEngineException in project oozie by apache.
the class V2JobServlet method getActionRetries.
@SuppressWarnings("unchecked")
@Override
JSONArray getActionRetries(HttpServletRequest request, HttpServletResponse response) throws XServletException, IOException {
JSONArray jsonArray = new JSONArray();
String jobId = getResourceName(request);
try {
jsonArray.addAll(Services.get().get(DagEngineService.class).getDagEngine(getUser(request)).getWorkflowActionRetries(jobId));
return jsonArray;
} catch (BaseEngineException ex) {
throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
}
}
use of org.apache.oozie.BaseEngineException in project oozie by apache.
the class BaseJobServlet method doGet.
/**
* Return information about jobs.
*/
@Override
@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String jobId = getResourceName(request);
String show = request.getParameter(RestConstants.JOB_SHOW_PARAM);
String timeZoneId = request.getParameter(RestConstants.TIME_ZONE_PARAM) == null ? "GMT" : request.getParameter(RestConstants.TIME_ZONE_PARAM);
try {
AuthorizationService auth = Services.get().get(AuthorizationService.class);
auth.authorizeForJob(getUser(request), jobId, false);
} catch (AuthorizationException ex) {
throw new XServletException(HttpServletResponse.SC_UNAUTHORIZED, ex);
}
if (show == null || show.equals(RestConstants.JOB_SHOW_INFO)) {
stopCron();
JsonBean job = null;
try {
job = getJob(request, response);
} catch (BaseEngineException e) {
throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, e);
}
startCron();
sendJsonResponse(response, HttpServletResponse.SC_OK, job, timeZoneId);
} else if (show.equals(RestConstants.ALL_WORKFLOWS_FOR_COORD_ACTION)) {
stopCron();
JSONObject json = getJobsByParentId(request, response);
startCron();
sendJsonResponse(response, HttpServletResponse.SC_OK, json);
} else if (show.equals(RestConstants.JOB_SHOW_JMS_TOPIC)) {
stopCron();
String jmsTopicName = getJMSTopicName(request, response);
JSONObject json = new JSONObject();
json.put(JsonTags.JMS_TOPIC_NAME, jmsTopicName);
startCron();
sendJsonResponse(response, HttpServletResponse.SC_OK, json);
} else if (show.equals(RestConstants.JOB_SHOW_LOG)) {
response.setContentType(TEXT_UTF8);
streamJobLog(request, response);
} else if (show.equals(RestConstants.JOB_SHOW_ERROR_LOG)) {
response.setContentType(TEXT_UTF8);
streamJobErrorLog(request, response);
} else if (show.equals(RestConstants.JOB_SHOW_AUDIT_LOG)) {
response.setContentType(TEXT_UTF8);
streamJobAuditLog(request, response);
} else if (show.equals(RestConstants.JOB_SHOW_DEFINITION)) {
stopCron();
response.setContentType(XML_UTF8);
String wfDefinition = getJobDefinition(request, response);
startCron();
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write(wfDefinition);
} else if (show.equals(RestConstants.JOB_SHOW_GRAPH)) {
stopCron();
streamJobGraph(request, response);
// -- should happen before you stream anything in response?
startCron();
} else if (show.equals(RestConstants.JOB_SHOW_STATUS)) {
stopCron();
String status = getJobStatus(request, response);
JSONObject json = new JSONObject();
json.put(JsonTags.STATUS, status);
startCron();
sendJsonResponse(response, HttpServletResponse.SC_OK, json);
} else if (show.equals(RestConstants.JOB_SHOW_ACTION_RETRIES_PARAM)) {
stopCron();
JSONArray retries = getActionRetries(request, response);
JSONObject json = new JSONObject();
json.put(JsonTags.WORKFLOW_ACTION_RETRIES, retries);
startCron();
sendJsonResponse(response, HttpServletResponse.SC_OK, json);
} else if (show.equals(RestConstants.COORD_ACTION_MISSING_DEPENDENCIES)) {
stopCron();
JSONObject json = getCoordActionMissingDependencies(request, response);
startCron();
sendJsonResponse(response, HttpServletResponse.SC_OK, json);
} else if (show.equals(RestConstants.JOB_SHOW_WF_ACTIONS_IN_COORD)) {
stopCron();
JSONObject json = getWfActionByJobIdAndName(request, response);
startCron();
sendJsonResponse(response, HttpServletResponse.SC_OK, json);
} else {
throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0303, RestConstants.JOB_SHOW_PARAM, show);
}
}
use of org.apache.oozie.BaseEngineException in project oozie by apache.
the class V1JobsServlet method getBulkJobs.
@SuppressWarnings("unchecked")
private JSONObject getBulkJobs(HttpServletRequest request) throws XServletException, IOException {
JSONObject json = new JSONObject();
try {
// REST API
String bulkFilter = request.getParameter(RestConstants.JOBS_BULK_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;
BundleEngine bundleEngine = Services.get().get(BundleEngineService.class).getBundleEngine(getUser(request));
BulkResponseInfo bulkResponse = bundleEngine.getBulkJobs(bulkFilter, start, len);
List<BulkResponseImpl> responsesToJson = bulkResponse.getResponses();
json.put(JsonTags.BULK_RESPONSES, BulkResponseImpl.toJSONArray(responsesToJson, timeZoneId));
json.put(JsonTags.BULK_RESPONSE_TOTAL, bulkResponse.getTotal());
json.put(JsonTags.BULK_RESPONSE_OFFSET, bulkResponse.getStart());
json.put(JsonTags.BULK_RESPONSE_LEN, bulkResponse.getLen());
} catch (BaseEngineException ex) {
throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
}
return json;
}
Aggregations