Search in sources :

Example 11 with CoordinatorJobInfo

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

the class TestCoordJobInfoGetJPAExecutor method testGetJobInfoForStartCreatedTime.

public void testGetJobInfoForStartCreatedTime() throws Exception {
    CoordinatorJobBean coordinatorJob1 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
    CoordinatorJobBean coordinatorJob2 = addRecordToCoordJobTable(CoordinatorJob.Status.KILLED, false, false);
    Date createTime1 = DateUtils.parseDateUTC("2012-01-01T10:00Z");
    Date createTime2 = DateUtils.parseDateUTC("2012-01-05T10:00Z");
    coordinatorJob1.setCreatedTime(createTime1);
    coordinatorJob2.setCreatedTime(createTime2);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQueryExecutor.CoordJobQuery.UPDATE_COORD_JOB, coordinatorJob1);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQueryExecutor.CoordJobQuery.UPDATE_COORD_JOB, coordinatorJob2);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    Map<String, List<String>> filter = new HashMap<String, List<String>>();
    CoordJobInfoGetJPAExecutor coordInfoGetCmd = new CoordJobInfoGetJPAExecutor(filter, 1, 20);
    CoordinatorJobInfo ret = jpaService.execute(coordInfoGetCmd);
    assertNotNull(ret);
    assertEquals(2, ret.getCoordJobs().size());
    filter.clear();
    filter.put(OozieClient.FILTER_CREATED_TIME_START, Arrays.asList("2012-01-02T10:00Z"));
    coordInfoGetCmd = new CoordJobInfoGetJPAExecutor(filter, 1, 20);
    ret = jpaService.execute(coordInfoGetCmd);
    assertNotNull(ret);
    assertEquals(1, ret.getCoordJobs().size());
    CoordinatorJobBean jobBean = ret.getCoordJobs().get(0);
    assertEquals(coordinatorJob2.getStatus(), jobBean.getStatus());
    assertEquals(coordinatorJob2.getCreatedTime(), jobBean.getCreatedTime());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorJobInfo(org.apache.oozie.CoordinatorJobInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 12 with CoordinatorJobInfo

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

the class TestCoordJobInfoGetJPAExecutor method _testGetJobInfoForStatus.

private void _testGetJobInfoForStatus() throws Exception {
    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("RUNNING");
    list.add("KILLED");
    filter.put(OozieClient.FILTER_STATUS, list);
    CoordJobInfoGetJPAExecutor coordInfoGetCmd = new CoordJobInfoGetJPAExecutor(filter, 1, 20);
    CoordinatorJobInfo ret = jpaService.execute(coordInfoGetCmd);
    assertNotNull(ret);
    assertEquals(ret.getCoordJobs().size(), 2);
}
Also used : CoordinatorJobInfo(org.apache.oozie.CoordinatorJobInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JPAService(org.apache.oozie.service.JPAService)

Example 13 with CoordinatorJobInfo

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

the class CoordJobInfoGetJPAExecutor method execute.

@Override
@SuppressWarnings("unchecked")
public CoordinatorJobInfo execute(EntityManager em) throws JPAExecutorException {
    List<String> orArray = new ArrayList<String>();
    List<String> colArray = new ArrayList<String>();
    List<Object> valArray = new ArrayList<Object>();
    StringBuilder sb = new StringBuilder("");
    String orderBy = DEFAULT_ORDER_BY;
    StoreStatusFilter.filter(filter, orArray, colArray, valArray, sb, StoreStatusFilter.coordSeletStr, StoreStatusFilter.coordCountStr);
    orderBy = StoreStatusFilter.getSortBy(filter, orderBy);
    int realLen = 0;
    Query q = null;
    Query qTotal = null;
    if (orArray.size() == 0 && orderBy.equals(DEFAULT_ORDER_BY)) {
        q = em.createNamedQuery("GET_COORD_JOBS_COLUMNS");
        q.setFirstResult(start - 1);
        q.setMaxResults(len);
        qTotal = em.createNamedQuery("GET_COORD_JOBS_COUNT");
    } else {
        sb = sb.toString().trim().length() == 0 ? sb.append(StoreStatusFilter.coordSeletStr) : sb;
        String sbTotal = sb.toString();
        sb.append(orderBy);
        q = em.createQuery(sb.toString());
        q.setFirstResult(start - 1);
        q.setMaxResults(len);
        qTotal = em.createQuery(sbTotal.replace(StoreStatusFilter.coordSeletStr, StoreStatusFilter.coordCountStr));
    }
    for (int i = 0; i < orArray.size(); i++) {
        q.setParameter(colArray.get(i), valArray.get(i));
        qTotal.setParameter(colArray.get(i), valArray.get(i));
    }
    OpenJPAQuery kq = OpenJPAPersistence.cast(q);
    JDBCFetchPlan fetch = (JDBCFetchPlan) kq.getFetchPlan();
    fetch.setFetchBatchSize(20);
    fetch.setResultSetType(ResultSetType.SCROLL_INSENSITIVE);
    fetch.setFetchDirection(FetchDirection.FORWARD);
    fetch.setLRSSizeAlgorithm(LRSSizeAlgorithm.LAST);
    List<?> resultList = q.getResultList();
    List<Object[]> objectArrList = (List<Object[]>) resultList;
    List<CoordinatorJobBean> coordBeansList = new ArrayList<CoordinatorJobBean>();
    for (Object[] arr : objectArrList) {
        CoordinatorJobBean ww = getBeanForCoordinatorJobFromArray(arr);
        coordBeansList.add(ww);
    }
    realLen = ((Long) qTotal.getSingleResult()).intValue();
    return new CoordinatorJobInfo(coordBeansList, start, len, realLen);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) Query(javax.persistence.Query) OpenJPAQuery(org.apache.openjpa.persistence.OpenJPAQuery) CoordinatorJobInfo(org.apache.oozie.CoordinatorJobInfo) JDBCFetchPlan(org.apache.openjpa.persistence.jdbc.JDBCFetchPlan) ArrayList(java.util.ArrayList) OpenJPAQuery(org.apache.openjpa.persistence.OpenJPAQuery) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with CoordinatorJobInfo

use of org.apache.oozie.CoordinatorJobInfo 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;
}
Also used : JSONObject(org.json.simple.JSONObject) CoordinatorJobInfo(org.apache.oozie.CoordinatorJobInfo) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException) CoordinatorEngineService(org.apache.oozie.service.CoordinatorEngineService)

Example 15 with CoordinatorJobInfo

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

the class TestCoordJobsXCommand method _testGetJobsForStatus.

private void _testGetJobsForStatus() throws Exception {
    Map<String, List<String>> filter = new HashMap<String, List<String>>();
    List<String> list = new ArrayList<String>();
    list.add("RUNNING");
    list.add("KILLED");
    filter.put(OozieClient.FILTER_STATUS, 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)

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