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());
}
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);
}
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);
}
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;
}
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);
}
Aggregations