Search in sources :

Example 6 with WorkflowsInfo

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

the class V1JobsServlet method getWorkflowJobs.

/**
 * v1 service implementation to get a list of workflows, with filtering or interested windows embedded in the
 * request object
 */
private JSONObject getWorkflowJobs(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;
        DagEngine dagEngine = Services.get().get(DagEngineService.class).getDagEngine(getUser(request));
        WorkflowsInfo jobs = dagEngine.getJobs(filter, start, len);
        json = OozieJsonFactory.getWFJSONObject(jobs, timeZoneId);
    } catch (DagEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return json;
}
Also used : DagEngineException(org.apache.oozie.DagEngineException) DagEngine(org.apache.oozie.DagEngine) JSONObject(org.json.simple.JSONObject) WorkflowsInfo(org.apache.oozie.WorkflowsInfo) DagEngineService(org.apache.oozie.service.DagEngineService)

Example 7 with WorkflowsInfo

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

the class TestWorkflowsJobGetJPAExecutor method _testGetWFInfoForId.

private void _testGetWFInfoForId(WorkflowJobBean wfBean) throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    Map<String, List<String>> filter = new HashMap<String, List<String>>();
    wfBean.setParentId("test-parent-C");
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_PARENT_MODIFIED, wfBean);
    List<String> jobIdList = new ArrayList<String>();
    jobIdList.add(wfBean.getId());
    filter.put(OozieClient.FILTER_ID, jobIdList);
    WorkflowsJobGetJPAExecutor wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 1);
    WorkflowsInfo wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(wfInfo.getWorkflows().size(), 1);
    WorkflowJobBean retBean = wfInfo.getWorkflows().get(0);
    compareWf(wfBean, retBean);
}
Also used : WorkflowsInfo(org.apache.oozie.WorkflowsInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 8 with WorkflowsInfo

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

the class TestWorkflowsJobGetJPAExecutor method testGetWFInfoForText.

public void testGetWFInfoForText() throws Exception {
    WorkflowJobBean workflowJob1 = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    WorkflowJobBean workflowJob2 = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    workflowJob1.setAppName("wf-name-1");
    workflowJob2.setAppName("wf-name-2");
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, workflowJob1);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, workflowJob2);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    Map<String, List<String>> filter = new HashMap<String, List<String>>();
    List<String> list = new ArrayList<String>();
    WorkflowsJobGetJPAExecutor wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 20);
    WorkflowsInfo wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(2, wfInfo.getWorkflows().size());
    WorkflowJobBean retBean = wfInfo.getWorkflows().get(0);
    compareWf(workflowJob2, retBean);
    list.add("wf-name");
    filter.put(OozieClient.FILTER_TEXT, list);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 20);
    wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(2, wfInfo.getWorkflows().size());
    list.clear();
    list.add("wf-name-1");
    filter.put(OozieClient.FILTER_TEXT, list);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 20);
    wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(1, wfInfo.getWorkflows().size());
    list.add("extra-param");
    filter.put(OozieClient.FILTER_TEXT, list);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 2);
    try {
        jpaService.execute(wfGetCmd);
        fail("WorkflowsJobGetJPAExecutor should have thrown E0302 exception.");
    } catch (XException e) {
        assertEquals(ErrorCode.E0302, e.getErrorCode());
        assertEquals(e.getMessage(), "E0302: Invalid parameter [cannot specify multiple strings to search]");
    }
    workflowJob1.setAppName("updated-name-1");
    workflowJob2.setAppName("updated-name-2");
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, workflowJob1);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, workflowJob2);
    list.clear();
    list.add("wf-name-1");
    filter.put(OozieClient.FILTER_TEXT, list);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 20);
    wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(0, wfInfo.getWorkflows().size());
    list.clear();
    list.add("updated-name");
    filter.put(OozieClient.FILTER_TEXT, list);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 20);
    wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(2, wfInfo.getWorkflows().size());
}
Also used : WorkflowsInfo(org.apache.oozie.WorkflowsInfo) HashMap(java.util.HashMap) XException(org.apache.oozie.XException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 9 with WorkflowsInfo

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

the class TestWorkflowsJobGetJPAExecutor method testWfJobsSortBy.

public void testWfJobsSortBy() throws Exception {
    WorkflowJobBean workflowJob1 = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    WorkflowJobBean workflowJob2 = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    workflowJob1.setAppName("update-app-name-1");
    workflowJob1.setLastModifiedTime(DateUtils.parseDateUTC("2012-01-04T10:00Z"));
    workflowJob1.setCreatedTime(DateUtils.parseDateUTC("2012-01-03T10:00Z"));
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, workflowJob1);
    workflowJob2.setAppName("update-app-name-2");
    workflowJob2.setLastModifiedTime(DateUtils.parseDateUTC("2012-01-05T10:00Z"));
    workflowJob2.setCreatedTime(DateUtils.parseDateUTC("2012-01-02T10:00Z"));
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, workflowJob2);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    Map<String, List<String>> filter = new HashMap<String, List<String>>();
    List<String> list = new ArrayList<String>();
    list.add("lastModifiedTime");
    filter.put(OozieClient.FILTER_SORT_BY, list);
    WorkflowsJobGetJPAExecutor wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 20);
    WorkflowsInfo wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(2, wfInfo.getWorkflows().size());
    WorkflowJobBean retBean = wfInfo.getWorkflows().get(0);
    compareWf(workflowJob2, retBean);
    // test default behavior
    filter.clear();
    list.clear();
    list.add("dummyField");
    filter.put(OozieClient.FILTER_SORT_BY, list);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 20);
    wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(2, wfInfo.getWorkflows().size());
    retBean = wfInfo.getWorkflows().get(0);
    compareWf(workflowJob1, retBean);
}
Also used : WorkflowsInfo(org.apache.oozie.WorkflowsInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 10 with WorkflowsInfo

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

the class TestWorkflowsJobGetJPAExecutor method testWfJobsGetWithCreatedTime.

public void testWfJobsGetWithCreatedTime() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    Date createdTime1 = DateUtils.parseDateUTC("2012-01-01T10:00Z");
    Date createdTime2 = DateUtils.parseDateUTC("2012-02-01T10:00Z");
    Date createdTime3 = DateUtils.parseDateUTC("2012-03-01T10:00Z");
    Date createdTime4 = DateUtils.parseDateUTC("2012-04-01T10:00Z");
    Date createdTime5 = org.apache.commons.lang.time.DateUtils.addHours(new Date(), -5);
    WorkflowJobBean wrkJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    wrkJob.setCreatedTime(createdTime1);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, wrkJob);
    wrkJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    wrkJob.setCreatedTime(createdTime2);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, wrkJob);
    wrkJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    wrkJob.setCreatedTime(createdTime3);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, wrkJob);
    wrkJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    wrkJob.setCreatedTime(createdTime4);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, wrkJob);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, wrkJob);
    wrkJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    wrkJob.setCreatedTime(createdTime5);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, wrkJob);
    // filter 2012-02-01T00:00Z <= createdTimeStamp <= 2012-03-02T00:00Z
    Map<String, List<String>> filter = new HashMap<String, List<String>>();
    List<String> timeList = new ArrayList<String>();
    timeList.add("2012-02-01T00:00Z");
    filter.put(OozieClient.FILTER_CREATED_TIME_START, timeList);
    timeList = new ArrayList<String>();
    timeList.add("2012-03-02T00:00Z");
    filter.put(OozieClient.FILTER_CREATED_TIME_END, timeList);
    WorkflowsJobGetJPAExecutor wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 10);
    WorkflowsInfo wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(2, wfInfo.getWorkflows().size());
    for (WorkflowJobBean jobBean : wfInfo.getWorkflows()) {
        assertTrue(jobBean.getCreatedTime().equals(createdTime2) || jobBean.getCreatedTime().equals(createdTime3));
    }
    // createdTime specified in wrong format
    filter = new HashMap<String, List<String>>();
    timeList = new ArrayList<String>();
    // not correct ISO8601_UTC_MASK format
    timeList.add("2012-02-01T00:00");
    filter.put(OozieClient.FILTER_CREATED_TIME_START, timeList);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 10);
    try {
        wfInfo = jpaService.execute(wfGetCmd);
    } catch (XException e) {
        assertEquals(ErrorCode.E0302, e.getErrorCode());
    }
    // filter 2012-04-01T00:00Z <= createdTimeStamp
    filter = new HashMap<String, List<String>>();
    timeList = new ArrayList<String>();
    timeList.add("2012-04-01T00:00Z");
    filter.put(OozieClient.FILTER_CREATED_TIME_START, timeList);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 10);
    wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(2, wfInfo.getWorkflows().size());
    for (WorkflowJobBean jobBean : wfInfo.getWorkflows()) {
        assertTrue(jobBean.getCreatedTime().equals(createdTime4) || jobBean.getCreatedTime().equals(createdTime5));
    }
    // filter 2012-02-01T00:00Z >= createdTimeStamp
    filter = new HashMap<String, List<String>>();
    timeList = new ArrayList<String>();
    timeList.add("2012-02-01T00:00Z");
    filter.put(OozieClient.FILTER_CREATED_TIME_END, timeList);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 10);
    wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(1, wfInfo.getWorkflows().size());
    assertTrue(wfInfo.getWorkflows().get(0).getCreatedTime().equals(createdTime1));
    // when createdTimeStamp specified multiple times
    filter = new HashMap<String, List<String>>();
    timeList = new ArrayList<String>();
    timeList.add("2012-02-01T00:00Z");
    timeList.add("2012-04-01T00:00Z");
    filter.put(OozieClient.FILTER_CREATED_TIME_END, timeList);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 10);
    try {
        wfInfo = jpaService.execute(wfGetCmd);
    } catch (XException e) {
        assertEquals(ErrorCode.E0302, e.getErrorCode());
    }
    // filter createdTimeStamp > currentTime - 2 days
    filter = new HashMap<String, List<String>>();
    timeList = new ArrayList<String>();
    timeList.add("-2d");
    filter.put(OozieClient.FILTER_CREATED_TIME_START, timeList);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 10);
    wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(1, wfInfo.getWorkflows().size());
    assertTrue(wfInfo.getWorkflows().get(0).getCreatedTime().equals(createdTime5));
    // filter createdTimeStamp > currentTime - 10 hour
    filter = new HashMap<String, List<String>>();
    timeList = new ArrayList<String>();
    timeList.add("-10h");
    filter.put(OozieClient.FILTER_CREATED_TIME_START, timeList);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 10);
    wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(1, wfInfo.getWorkflows().size());
    assertTrue(wfInfo.getWorkflows().get(0).getCreatedTime().equals(createdTime5));
    // filter createdTimeStamp > currentTime - 600 min
    filter = new HashMap<String, List<String>>();
    timeList = new ArrayList<String>();
    timeList.add("-600m");
    filter.put(OozieClient.FILTER_CREATED_TIME_START, timeList);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 10);
    wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(1, wfInfo.getWorkflows().size());
    assertTrue(wfInfo.getWorkflows().get(0).getCreatedTime().equals(createdTime5));
    // filter createdTimeStamp < currentTime - 3 days
    filter = new HashMap<String, List<String>>();
    timeList = new ArrayList<String>();
    timeList.add("-3d");
    filter.put(OozieClient.FILTER_CREATED_TIME_END, timeList);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 10);
    wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(4, wfInfo.getWorkflows().size());
    for (WorkflowJobBean jobBean : wfInfo.getWorkflows()) {
        assertTrue(jobBean.getCreatedTime().equals(createdTime1) || jobBean.getCreatedTime().equals(createdTime2) || jobBean.getCreatedTime().equals(createdTime3) || jobBean.getCreatedTime().equals(createdTime4));
    }
    // filter createdTimeStamp < currentTime - 2 hours
    filter = new HashMap<String, List<String>>();
    timeList = new ArrayList<String>();
    timeList.add("-2h");
    filter.put(OozieClient.FILTER_CREATED_TIME_END, timeList);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 10);
    wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(5, wfInfo.getWorkflows().size());
    for (WorkflowJobBean jobBean : wfInfo.getWorkflows()) {
        assertTrue(jobBean.getCreatedTime().equals(createdTime1) || jobBean.getCreatedTime().equals(createdTime2) || jobBean.getCreatedTime().equals(createdTime3) || jobBean.getCreatedTime().equals(createdTime4) || jobBean.getCreatedTime().equals(createdTime5));
    }
    // filter createdTimeStamp < currentTime - 60 min
    filter = new HashMap<String, List<String>>();
    timeList = new ArrayList<String>();
    timeList.add("-60m");
    filter.put(OozieClient.FILTER_CREATED_TIME_END, timeList);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 10);
    wfInfo = jpaService.execute(wfGetCmd);
    assertNotNull(wfInfo);
    assertEquals(5, wfInfo.getWorkflows().size());
    for (WorkflowJobBean jobBean : wfInfo.getWorkflows()) {
        assertTrue(jobBean.getCreatedTime().equals(createdTime1) || jobBean.getCreatedTime().equals(createdTime2) || jobBean.getCreatedTime().equals(createdTime3) || jobBean.getCreatedTime().equals(createdTime4) || jobBean.getCreatedTime().equals(createdTime5));
    }
    // when offset is in wrong format
    filter = new HashMap<String, List<String>>();
    timeList = new ArrayList<String>();
    timeList.add("-5M");
    filter.put(OozieClient.FILTER_CREATED_TIME_END, timeList);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 10);
    try {
        wfInfo = jpaService.execute(wfGetCmd);
    } catch (XException e) {
        assertEquals(ErrorCode.E0302, e.getErrorCode());
    }
    // when offset is in wrong format
    filter = new HashMap<String, List<String>>();
    timeList = new ArrayList<String>();
    timeList.add("5D");
    filter.put(OozieClient.FILTER_CREATED_TIME_END, timeList);
    wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 10);
    try {
        wfInfo = jpaService.execute(wfGetCmd);
    } catch (XException e) {
        assertEquals(ErrorCode.E0302, e.getErrorCode());
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) WorkflowsInfo(org.apache.oozie.WorkflowsInfo) XException(org.apache.oozie.XException) ArrayList(java.util.ArrayList) List(java.util.List) JPAService(org.apache.oozie.service.JPAService)

Aggregations

WorkflowsInfo (org.apache.oozie.WorkflowsInfo)11 ArrayList (java.util.ArrayList)8 List (java.util.List)8 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)8 HashMap (java.util.HashMap)7 JPAService (org.apache.oozie.service.JPAService)6 DagEngine (org.apache.oozie.DagEngine)3 DagEngineException (org.apache.oozie.DagEngineException)3 DagEngineService (org.apache.oozie.service.DagEngineService)3 JSONObject (org.json.simple.JSONObject)3 Date (java.util.Date)2 XException (org.apache.oozie.XException)2 Timestamp (java.sql.Timestamp)1 Map (java.util.Map)1 Query (javax.persistence.Query)1 BundleEngine (org.apache.oozie.BundleEngine)1 BundleEngineException (org.apache.oozie.BundleEngineException)1 BundleJobInfo (org.apache.oozie.BundleJobInfo)1 CoordinatorEngine (org.apache.oozie.CoordinatorEngine)1 CoordinatorEngineException (org.apache.oozie.CoordinatorEngineException)1