Search in sources :

Example 81 with BundleJobBean

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

the class BundleJobsGetRunningOrPendingJPAExecutor method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager)
     */
@Override
@SuppressWarnings("unchecked")
public List<BundleJobBean> execute(EntityManager em) throws JPAExecutorException {
    List<BundleJobBean> bjBeans;
    try {
        Query q = em.createNamedQuery("GET_BUNDLE_JOBS_RUNNING_OR_PENDING");
        if (limit > 0) {
            q.setMaxResults(limit);
        }
        bjBeans = q.getResultList();
    } catch (Exception e) {
        throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
    }
    return bjBeans;
}
Also used : Query(javax.persistence.Query) BundleJobBean(org.apache.oozie.BundleJobBean)

Example 82 with BundleJobBean

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

the class BundleJobInfoGetJPAExecutor method getBeanForBundleJobFromArray.

private BundleJobBean getBeanForBundleJobFromArray(Object[] arr) {
    BundleJobBean bean = new BundleJobBean();
    bean.setId((String) arr[0]);
    if (arr[1] != null) {
        bean.setAppName((String) arr[1]);
    }
    if (arr[2] != null) {
        bean.setAppPath((String) arr[2]);
    }
    if (arr[3] != null) {
        bean.setConfBlob((StringBlob) arr[3]);
    }
    if (arr[4] != null) {
        bean.setStatus(Job.Status.valueOf((String) arr[4]));
    }
    if (arr[5] != null) {
        bean.setKickoffTime((Timestamp) arr[5]);
    }
    if (arr[6] != null) {
        bean.setStartTime((Timestamp) arr[6]);
    }
    if (arr[7] != null) {
        bean.setEndTime((Timestamp) arr[7]);
    }
    if (arr[8] != null) {
        bean.setPauseTime((Timestamp) arr[8]);
    }
    if (arr[9] != null) {
        bean.setCreatedTime((Timestamp) arr[9]);
    }
    if (arr[10] != null) {
        bean.setUser((String) arr[10]);
    }
    if (arr[11] != null) {
        bean.setGroup((String) arr[11]);
    }
    if (arr[12] != null) {
        bean.setTimeUnit(Timeunit.valueOf((String) arr[12]));
    }
    if (arr[13] != null) {
        bean.setTimeOut((Integer) arr[13]);
    }
    return bean;
}
Also used : BundleJobBean(org.apache.oozie.BundleJobBean)

Example 83 with BundleJobBean

use of org.apache.oozie.BundleJobBean 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 84 with BundleJobBean

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

the class BundleJobQueryExecutor method constructBean.

private BundleJobBean constructBean(BundleJobQuery namedQuery, Object ret, Object... parameters) throws JPAExecutorException {
    BundleJobBean bean;
    Object[] arr;
    switch(namedQuery) {
        case GET_BUNDLE_JOB:
            bean = (BundleJobBean) ret;
            break;
        case GET_BUNDLE_JOB_STATUS:
            bean = new BundleJobBean();
            bean.setId((String) parameters[0]);
            bean.setStatus((String) ret);
            break;
        case GET_BUNDLE_JOB_ID_STATUS_PENDING_MOD_PAUSE_SUSPEND_TIME:
            bean = new BundleJobBean();
            arr = (Object[]) ret;
            bean.setId((String) arr[0]);
            bean.setStatus((String) arr[1]);
            bean.setPending((Integer) arr[2]);
            bean.setLastModifiedTime(DateUtils.toDate((Timestamp) arr[3]));
            bean.setPauseTime(DateUtils.toDate((Timestamp) arr[4]));
            bean.setSuspendedTime(DateUtils.toDate((Timestamp) arr[5]));
            break;
        case GET_BUNDLE_JOB_ID_JOBXML_CONF:
            bean = new BundleJobBean();
            arr = (Object[]) ret;
            bean.setId((String) arr[0]);
            bean.setJobXmlBlob((StringBlob) arr[1]);
            bean.setConfBlob((StringBlob) arr[2]);
            break;
        case GET_BUNDLE_IDS_FOR_STATUS_TRANSIT:
            bean = new BundleJobBean();
            bean.setId((String) ret);
            break;
        default:
            throw new JPAExecutorException(ErrorCode.E0603, "QueryExecutor cannot construct job bean for " + namedQuery.name());
    }
    return bean;
}
Also used : BundleJobBean(org.apache.oozie.BundleJobBean) Timestamp(java.sql.Timestamp)

Example 85 with BundleJobBean

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

the class BundleJobsGetUnpausedJPAExecutor method execute.

@Override
@SuppressWarnings("unchecked")
public List<BundleJobBean> execute(EntityManager em) throws JPAExecutorException {
    List<BundleJobBean> bjBeans;
    try {
        Query q = em.createNamedQuery("GET_BUNDLE_JOBS_UNPAUSED");
        if (limit > 0) {
            q.setMaxResults(limit);
        }
        bjBeans = q.getResultList();
    } catch (Exception e) {
        throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
    }
    return bjBeans;
}
Also used : Query(javax.persistence.Query) BundleJobBean(org.apache.oozie.BundleJobBean)

Aggregations

BundleJobBean (org.apache.oozie.BundleJobBean)159 JPAService (org.apache.oozie.service.JPAService)78 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)69 BundleActionBean (org.apache.oozie.BundleActionBean)58 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)46 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)44 Date (java.util.Date)35 ArrayList (java.util.ArrayList)24 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)24 List (java.util.List)21 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)21 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)21 HashMap (java.util.HashMap)20 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)20 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)18 IOException (java.io.IOException)16 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)16 XConfiguration (org.apache.oozie.util.XConfiguration)16 Query (javax.persistence.Query)14 CommandException (org.apache.oozie.command.CommandException)14