Search in sources :

Example 6 with BundleJobInfo

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());
}
Also used : BundleJobBean(org.apache.oozie.BundleJobBean) HashMap(java.util.HashMap) BundleJobInfo(org.apache.oozie.BundleJobInfo) ArrayList(java.util.ArrayList) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 7 with BundleJobInfo

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);
}
Also used : BundleJobBean(org.apache.oozie.BundleJobBean) HashMap(java.util.HashMap) XException(org.apache.oozie.XException) BundleJobInfo(org.apache.oozie.BundleJobInfo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JPAService(org.apache.oozie.service.JPAService)

Example 8 with BundleJobInfo

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());
}
Also used : BundleJobBean(org.apache.oozie.BundleJobBean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BundleJobInfo(org.apache.oozie.BundleJobInfo) ArrayList(java.util.ArrayList) List(java.util.List) JPAService(org.apache.oozie.service.JPAService)

Example 9 with BundleJobInfo

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);
}
Also used : Query(javax.persistence.Query) OpenJPAQuery(org.apache.openjpa.persistence.OpenJPAQuery) JDBCFetchPlan(org.apache.openjpa.persistence.jdbc.JDBCFetchPlan) ArrayList(java.util.ArrayList) BundleJobInfo(org.apache.oozie.BundleJobInfo) OpenJPAQuery(org.apache.openjpa.persistence.OpenJPAQuery) BundleJobBean(org.apache.oozie.BundleJobBean) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with BundleJobInfo

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());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BundleJobInfo(org.apache.oozie.BundleJobInfo) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

BundleJobInfo (org.apache.oozie.BundleJobInfo)20 ArrayList (java.util.ArrayList)18 List (java.util.List)17 HashMap (java.util.HashMap)16 JPAService (org.apache.oozie.service.JPAService)12 BundleJobBean (org.apache.oozie.BundleJobBean)6 Date (java.util.Date)2 BundleEngine (org.apache.oozie.BundleEngine)2 BundleEngineException (org.apache.oozie.BundleEngineException)2 XException (org.apache.oozie.XException)2 JSONObject (org.json.simple.JSONObject)2 Query (javax.persistence.Query)1 CoordinatorEngine (org.apache.oozie.CoordinatorEngine)1 CoordinatorEngineException (org.apache.oozie.CoordinatorEngineException)1 CoordinatorJobInfo (org.apache.oozie.CoordinatorJobInfo)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 BundleJobInfoGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobInfoGetJPAExecutor)1