Search in sources :

Example 1 with CoordinatorJobInfo

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

the class TestCoordJobsXCommand method _testGetJobInfoForUser.

private void _testGetJobInfoForUser() throws Exception {
    Map<String, List<String>> filter = new HashMap<String, List<String>>();
    List<String> list = new ArrayList<String>();
    list.add(getTestUser());
    filter.put(OozieClient.FILTER_USER, list);
    CoordJobsXCommand coordsGetCmd = new CoordJobsXCommand(filter, 1, 20);
    CoordinatorJobInfo ret = coordsGetCmd.call();
    assertNotNull(ret);
    assertEquals(ret.getCoordJobs().size(), 3);
}
Also used : CoordinatorJobInfo(org.apache.oozie.CoordinatorJobInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with CoordinatorJobInfo

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

the class TestCoordJobsXCommand method _testGetJobsForGroup.

private void _testGetJobsForGroup() throws Exception {
    Map<String, List<String>> filter = new HashMap<String, List<String>>();
    List<String> list = new ArrayList<String>();
    list.add(getTestGroup());
    filter.put(OozieClient.FILTER_GROUP, list);
    CoordJobsXCommand coordsGetCmd = new CoordJobsXCommand(filter, 1, 20);
    CoordinatorJobInfo ret = coordsGetCmd.call();
    assertNotNull(ret);
    assertEquals(ret.getCoordJobs().size(), 2);
}
Also used : CoordinatorJobInfo(org.apache.oozie.CoordinatorJobInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with CoordinatorJobInfo

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

the class TestCoordJobsXCommand method _testGetJobCount.

private void _testGetJobCount() throws Exception {
    // With no Filter and different offset/len
    Map<String, List<String>> filter = new HashMap<String, List<String>>();
    CoordJobsXCommand coordsGetCmd = new CoordJobsXCommand(filter, 1, 1);
    CoordinatorJobInfo ret = coordsGetCmd.call();
    assertNotNull(ret);
    assertEquals(ret.getTotal(), 6);
    coordsGetCmd = new CoordJobsXCommand(filter, 3, 6);
    ret = coordsGetCmd.call();
    assertNotNull(ret);
    assertEquals(ret.getTotal(), 6);
    coordsGetCmd = new CoordJobsXCommand(filter, 5, 20);
    ret = coordsGetCmd.call();
    assertNotNull(ret);
    assertEquals(ret.getTotal(), 6);
    // With User and status
    List<String> list1 = new ArrayList<String>();
    list1.add(getTestUser());
    filter.put(OozieClient.FILTER_USER, list1);
    List<String> list2 = new ArrayList<String>();
    list2.add("RUNNING");
    filter.put(OozieClient.FILTER_STATUS, list2);
    coordsGetCmd = new CoordJobsXCommand(filter, 1, 20);
    ret = coordsGetCmd.call();
    assertNotNull(ret);
    assertEquals(ret.getTotal(), 4);
    coordsGetCmd = new CoordJobsXCommand(filter, 2, 1);
    ret = coordsGetCmd.call();
    assertNotNull(ret);
    assertEquals(ret.getTotal(), 4);
}
Also used : CoordinatorJobInfo(org.apache.oozie.CoordinatorJobInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with CoordinatorJobInfo

use of org.apache.oozie.CoordinatorJobInfo 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;
}
Also used : CoordinatorJobInfo(org.apache.oozie.CoordinatorJobInfo) ArrayList(java.util.ArrayList) BundleJobInfo(org.apache.oozie.BundleJobInfo) BundleEngine(org.apache.oozie.BundleEngine) DagEngineService(org.apache.oozie.service.DagEngineService) DagEngineException(org.apache.oozie.DagEngineException) DagEngine(org.apache.oozie.DagEngine) JSONObject(org.json.simple.JSONObject) WorkflowsInfo(org.apache.oozie.WorkflowsInfo) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) BundleEngineException(org.apache.oozie.BundleEngineException) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException)

Example 5 with CoordinatorJobInfo

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

the class CoordJobsXCommand method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
@Override
protected CoordinatorJobInfo execute() throws CommandException {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        CoordinatorJobInfo coordInfo = null;
        if (jpaService != null) {
            coordInfo = jpaService.execute(new CoordJobInfoGetJPAExecutor(filter, start, len));
        } else {
            LOG.error(ErrorCode.E0610);
        }
        return coordInfo;
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : CoordinatorJobInfo(org.apache.oozie.CoordinatorJobInfo) CoordJobInfoGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobInfoGetJPAExecutor) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService)

Aggregations

CoordinatorJobInfo (org.apache.oozie.CoordinatorJobInfo)25 ArrayList (java.util.ArrayList)23 List (java.util.List)22 HashMap (java.util.HashMap)21 JPAService (org.apache.oozie.service.JPAService)16 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)6 Date (java.util.Date)2 CoordinatorEngine (org.apache.oozie.CoordinatorEngine)2 CoordinatorEngineException (org.apache.oozie.CoordinatorEngineException)2 XException (org.apache.oozie.XException)2 JSONObject (org.json.simple.JSONObject)2 Query (javax.persistence.Query)1 BundleEngine (org.apache.oozie.BundleEngine)1 BundleEngineException (org.apache.oozie.BundleEngineException)1 BundleJobInfo (org.apache.oozie.BundleJobInfo)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 CoordJobInfoGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobInfoGetJPAExecutor)1