use of org.apache.oozie.BundleJobInfo in project oozie by apache.
the class TestBundleJobInfoGetJPAExecutor method testGetJobInfoForEndCreatedTime.
public void testGetJobInfoForEndCreatedTime() throws Exception {
BundleJobBean bundleJob1 = addRecordToBundleJobTable(BundleJob.Status.RUNNING, false);
BundleJobBean bundleJob2 = addRecordToBundleJobTable(BundleJob.Status.KILLED, false);
BundleJobBean bundleJob3 = addRecordToBundleJobTable(BundleJob.Status.FAILED, false);
Date createTime1 = DateUtils.parseDateUTC("2012-01-03T10:00Z");
Date createTime2 = DateUtils.parseDateUTC("2012-01-05T10:00Z");
Date createTime3 = DateUtils.parseDateUTC("2012-01-010T10:00Z");
bundleJob1.setCreatedTime(createTime1);
bundleJob2.setCreatedTime(createTime2);
bundleJob3.setCreatedTime(createTime3);
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB, bundleJob1);
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB, bundleJob2);
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB, bundleJob3);
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
Map<String, List<String>> filter = new HashMap<String, List<String>>();
BundleJobInfoGetJPAExecutor bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
BundleJobInfo ret = jpaService.execute(bundleInfoGetCmd);
assertNotNull(ret);
assertEquals(3, ret.getBundleJobs().size());
filter.clear();
filter.put(OozieClient.FILTER_CREATED_TIME_START, Arrays.asList("2012-01-02T10:00Z"));
filter.put(OozieClient.FILTER_CREATED_TIME_END, Arrays.asList("2012-01-07T10:00Z"));
bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
ret = jpaService.execute(bundleInfoGetCmd);
assertNotNull(ret);
assertEquals(2, ret.getBundleJobs().size());
// default, expected order of results is by createTime DESC
BundleJobBean jobBean = ret.getBundleJobs().get(0);
assertEquals(bundleJob2.getStatus(), jobBean.getStatus());
assertEquals(bundleJob2.getCreatedTime(), jobBean.getCreatedTime());
BundleJobBean jobBean1 = ret.getBundleJobs().get(1);
assertEquals(bundleJob1.getStatus(), jobBean1.getStatus());
assertEquals(bundleJob1.getCreatedTime(), jobBean1.getCreatedTime());
}
use of org.apache.oozie.BundleJobInfo in project oozie by apache.
the class TestBundleJobInfoGetJPAExecutor method testGetJobInfoForText.
public void testGetJobInfoForText() throws Exception {
BundleJobBean bundleJob1 = addRecordToBundleJobTable(BundleJob.Status.RUNNING, false);
BundleJobBean bundleJob2 = addRecordToBundleJobTable(BundleJob.Status.KILLED, false);
bundleJob1.setAppName("oozie-bundle1");
bundleJob2.setAppName("oozie-bundle2");
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB, bundleJob1);
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB, bundleJob2);
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
Map<String, List<String>> filter = new HashMap<String, List<String>>();
BundleJobInfoGetJPAExecutor bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
BundleJobInfo ret = jpaService.execute(bundleInfoGetCmd);
assertNotNull(ret);
assertEquals(2, ret.getBundleJobs().size());
filter.clear();
ArrayList<String> textList = new ArrayList<String>();
textList.add("tes");
filter.put(OozieClient.FILTER_TEXT, textList);
bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
ret = jpaService.execute(bundleInfoGetCmd);
assertNotNull(ret);
assertEquals(ret.getBundleJobs().size(), 2);
textList.clear();
textList.add("oozie-bundle1");
filter.put(OozieClient.FILTER_TEXT, textList);
bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
ret = jpaService.execute(bundleInfoGetCmd);
assertNotNull(ret);
assertEquals(ret.getBundleJobs().size(), 1);
textList.clear();
textList.add("random");
filter.put(OozieClient.FILTER_TEXT, textList);
bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
ret = jpaService.execute(bundleInfoGetCmd);
assertNotNull(ret);
assertEquals(ret.getBundleJobs().size(), 0);
textList.clear();
textList.add("oozie-bundle");
filter.put(OozieClient.FILTER_TEXT, textList);
bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
ret = jpaService.execute(bundleInfoGetCmd);
assertNotNull(ret);
assertEquals(ret.getBundleJobs().size(), 2);
textList.add("tes");
filter.put(OozieClient.FILTER_TEXT, textList);
bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
try {
jpaService.execute(bundleInfoGetCmd);
fail("BundleJobInfoGetJPAExecutor 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]");
}
// Update bundle appName, user and validate text filter
bundleJob1.setAppName("updated-app-name1");
bundleJob2.setAppName("updated-app-name2");
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB, bundleJob1);
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB, bundleJob2);
textList.clear();
textList.add("oozie-bundle");
filter.put(OozieClient.FILTER_TEXT, textList);
bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
ret = jpaService.execute(bundleInfoGetCmd);
assertNotNull(ret);
assertEquals(ret.getBundleJobs().size(), 0);
textList.clear();
textList.add("updated-app");
filter.put(OozieClient.FILTER_TEXT, textList);
bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
ret = jpaService.execute(bundleInfoGetCmd);
assertNotNull(ret);
assertEquals(ret.getBundleJobs().size(), 2);
textList.clear();
textList.add("updated-app-name1");
bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
ret = jpaService.execute(bundleInfoGetCmd);
assertNotNull(ret);
assertEquals(ret.getBundleJobs().size(), 1);
}
use of org.apache.oozie.BundleJobInfo in project oozie by apache.
the class TestBundleJobInfoGetJPAExecutor method testGetJobInfoForTextAndStatus.
public void testGetJobInfoForTextAndStatus() throws Exception {
BundleJobBean bundleJob = addRecordToBundleJobTable(BundleJob.Status.RUNNING, false);
bundleJob.setAppName("bundle-job-1");
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB, bundleJob);
Map<String, List<String>> filter = new HashMap<String, List<String>>();
List<String> textFilterList = new ArrayList<String>();
textFilterList.add("bundle-job-1");
List<String> textStatusList = new ArrayList<String>();
textStatusList.add(BundleJob.Status.RUNNING.toString());
filter.put(OozieClient.FILTER_TEXT, textFilterList);
filter.put(OozieClient.FILTER_STATUS, textStatusList);
JPAService jpaService = Services.get().get(JPAService.class);
BundleJobInfoGetJPAExecutor bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
BundleJobInfo bundleJobsInfo = jpaService.execute(bundleInfoGetCmd);
assertEquals(1, bundleJobsInfo.getBundleJobs().size());
}
use of org.apache.oozie.BundleJobInfo in project oozie by apache.
the class BundleJobInfoGetJPAExecutor method execute.
/* (non-Javadoc)
* @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager)
*/
@Override
@SuppressWarnings("unchecked")
public BundleJobInfo 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.bundleSeletStr, StoreStatusFilter.bundleCountStr);
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_BUNDLE_JOBS_COLUMNS");
q.setFirstResult(start - 1);
q.setMaxResults(len);
qTotal = em.createNamedQuery("GET_BUNDLE_JOBS_COUNT");
} else {
sb = sb.toString().trim().length() == 0 ? sb.append(StoreStatusFilter.bundleSeletStr) : 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.bundleSeletStr, StoreStatusFilter.bundleCountStr));
}
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<BundleJobBean> bundleBeansList = new ArrayList<BundleJobBean>();
for (Object[] arr : objectArrList) {
BundleJobBean bean = getBeanForBundleJobFromArray(arr);
bundleBeansList.add(bean);
}
realLen = ((Long) qTotal.getSingleResult()).intValue();
return new BundleJobInfo(bundleBeansList, start, len, realLen);
}
use of org.apache.oozie.BundleJobInfo in project oozie by apache.
the class TestBundleJobsXCommand 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("PREP");
filter.put(OozieClient.FILTER_STATUS, list);
BundleJobsXCommand bundlesGetCmd = new BundleJobsXCommand(filter, 1, 20);
BundleJobInfo ret = bundlesGetCmd.call();
assertNotNull(ret);
assertEquals(4, ret.getBundleJobs().size());
}
Aggregations