Search in sources :

Example 6 with CoordinatorEngineException

use of org.apache.oozie.CoordinatorEngineException in project oozie by apache.

the class V2JobServlet method getWfActionByJobIdAndName.

@Override
protected JSONObject getWfActionByJobIdAndName(HttpServletRequest request, HttpServletResponse response) throws XServletException, IOException {
    CoordinatorEngine coordEngine = Services.get().get(CoordinatorEngineService.class).getCoordinatorEngine(getUser(request));
    String jobId = getResourceName(request);
    String action = request.getParameter(RestConstants.ACTION_NAME_PARAM);
    String startStr = request.getParameter(RestConstants.OFFSET_PARAM);
    String lenStr = request.getParameter(RestConstants.LEN_PARAM);
    String timeZoneId = request.getParameter(RestConstants.TIME_ZONE_PARAM);
    timeZoneId = (timeZoneId == null) ? "GMT" : timeZoneId;
    if (action == null) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0305, RestConstants.ACTION_NAME_PARAM);
    }
    int offset = (startStr != null) ? Integer.parseInt(startStr) : 1;
    offset = (offset < 1) ? 1 : offset;
    /**
     * set default number of wf actions to be retrieved to
     * default number of coordinator actions to be retrieved
     */
    int defaultLen = ConfigurationService.getInt(COORD_ACTIONS_DEFAULT_LENGTH);
    int len = (lenStr != null) ? Integer.parseInt(lenStr) : 0;
    len = getCoordinatorJobLength(defaultLen, len);
    try {
        JSONObject json = new JSONObject();
        List<CoordinatorWfActionBean> coordWfActions = coordEngine.getWfActionByJobIdAndName(jobId, action, offset, len);
        JSONArray array = new JSONArray();
        for (CoordinatorWfActionBean coordWfAction : coordWfActions) {
            array.add(coordWfAction.toJSONObject(timeZoneId));
        }
        json.put(JsonTags.COORDINATOR_JOB_ID, jobId);
        json.put(JsonTags.COORDINATOR_WF_ACTIONS, array);
        return json;
    } catch (CoordinatorEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
}
Also used : JSONObject(org.json.simple.JSONObject) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) JSONArray(org.json.simple.JSONArray) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException) CoordinatorEngineService(org.apache.oozie.service.CoordinatorEngineService) CoordinatorWfActionBean(org.apache.oozie.CoordinatorWfActionBean)

Aggregations

CoordinatorEngine (org.apache.oozie.CoordinatorEngine)6 CoordinatorEngineException (org.apache.oozie.CoordinatorEngineException)6 JSONObject (org.json.simple.JSONObject)6 CoordinatorEngineService (org.apache.oozie.service.CoordinatorEngineService)5 ArrayList (java.util.ArrayList)2 CoordinatorJobInfo (org.apache.oozie.CoordinatorJobInfo)2 BundleEngine (org.apache.oozie.BundleEngine)1 BundleEngineException (org.apache.oozie.BundleEngineException)1 BundleJobInfo (org.apache.oozie.BundleJobInfo)1 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)1 CoordinatorActionInfo (org.apache.oozie.CoordinatorActionInfo)1 CoordinatorWfActionBean (org.apache.oozie.CoordinatorWfActionBean)1 DagEngine (org.apache.oozie.DagEngine)1 DagEngineException (org.apache.oozie.DagEngineException)1 WorkflowsInfo (org.apache.oozie.WorkflowsInfo)1 CommandException (org.apache.oozie.command.CommandException)1 DagEngineService (org.apache.oozie.service.DagEngineService)1 JSONArray (org.json.simple.JSONArray)1