Search in sources :

Example 76 with BundleJobBean

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

the class BundleJobXCommand method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
@Override
protected BundleJobBean execute() throws CommandException {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        BundleJobBean bundleJob = null;
        if (jpaService != null) {
            bundleJob = jpaService.execute(new BundleJobGetJPAExecutor(id));
            List<CoordinatorJobBean> coordinators = jpaService.execute(new BundleJobGetCoordinatorsJPAExecutor(id));
            bundleJob.setCoordJobs(coordinators);
        } else {
            LOG.error(ErrorCode.E0610);
        }
        return bundleJob;
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) BundleJobBean(org.apache.oozie.BundleJobBean) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) BundleJobGetCoordinatorsJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetCoordinatorsJPAExecutor)

Example 77 with BundleJobBean

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

the class BulkBundleXCommand method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
@Override
protected BundleJobInfo execute() throws CommandException {
    List<BundleJobBean> jobs = this.bundleJobInfo.getBundleJobs();
    for (BundleJobBean job : jobs) {
        switch(operation) {
            case Kill:
                if (job.getStatus() != Job.Status.SUCCEEDED && job.getStatus() != Job.Status.FAILED && job.getStatus() != Job.Status.DONEWITHERROR && job.getStatus() != Job.Status.KILLED) {
                    new BundleKillXCommand(job.getId()).call();
                }
                break;
            case Suspend:
                if (job.getStatus() != Job.Status.SUCCEEDED && job.getStatus() != Job.Status.FAILED && job.getStatus() != Job.Status.KILLED && job.getStatus() != Job.Status.DONEWITHERROR) {
                    new BundleJobSuspendXCommand(job.getId()).call();
                }
                break;
            case Resume:
                if (job.getStatus() == Job.Status.SUSPENDED || job.getStatus() == Job.Status.SUSPENDEDWITHERROR || job.getStatus() == Job.Status.PREPSUSPENDED) {
                    new BundleJobResumeXCommand(job.getId()).call();
                }
                break;
            default:
                throw new CommandException(ErrorCode.E1102, operation);
        }
    }
    loadBundleJobs();
    return this.bundleJobInfo;
}
Also used : BundleJobBean(org.apache.oozie.BundleJobBean) CommandException(org.apache.oozie.command.CommandException)

Example 78 with BundleJobBean

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

the class BatchQueryExecutor method executeBatchInsertUpdateDelete.

@SuppressWarnings("rawtypes")
public void executeBatchInsertUpdateDelete(Collection<JsonBean> insertList, Collection<UpdateEntry> updateList, Collection<JsonBean> deleteList) throws JPAExecutorException {
    List<QueryEntry> queryList = new ArrayList<QueryEntry>();
    JPAService jpaService = Services.get().get(JPAService.class);
    EntityManager em = jpaService.getEntityManager();
    if (updateList != null) {
        for (UpdateEntry entry : updateList) {
            Query query = null;
            JsonBean bean = entry.getBean();
            if (bean instanceof WorkflowJobBean) {
                query = WorkflowJobQueryExecutor.getInstance().getUpdateQuery((WorkflowJobQuery) entry.getQueryName(), (WorkflowJobBean) entry.getBean(), em);
            } else if (bean instanceof WorkflowActionBean) {
                query = WorkflowActionQueryExecutor.getInstance().getUpdateQuery((WorkflowActionQuery) entry.getQueryName(), (WorkflowActionBean) entry.getBean(), em);
            } else if (bean instanceof CoordinatorJobBean) {
                query = CoordJobQueryExecutor.getInstance().getUpdateQuery((CoordJobQuery) entry.getQueryName(), (CoordinatorJobBean) entry.getBean(), em);
            } else if (bean instanceof CoordinatorActionBean) {
                query = CoordActionQueryExecutor.getInstance().getUpdateQuery((CoordActionQuery) entry.getQueryName(), (CoordinatorActionBean) entry.getBean(), em);
            } else if (bean instanceof BundleJobBean) {
                query = BundleJobQueryExecutor.getInstance().getUpdateQuery((BundleJobQuery) entry.getQueryName(), (BundleJobBean) entry.getBean(), em);
            } else if (bean instanceof BundleActionBean) {
                query = BundleActionQueryExecutor.getInstance().getUpdateQuery((BundleActionQuery) entry.getQueryName(), (BundleActionBean) entry.getBean(), em);
            } else if (bean instanceof SLARegistrationBean) {
                query = SLARegistrationQueryExecutor.getInstance().getUpdateQuery((SLARegQuery) entry.getQueryName(), (SLARegistrationBean) entry.getBean(), em);
            } else if (bean instanceof SLASummaryBean) {
                query = SLASummaryQueryExecutor.getInstance().getUpdateQuery((SLASummaryQuery) entry.getQueryName(), (SLASummaryBean) entry.getBean(), em);
            } else {
                throw new JPAExecutorException(ErrorCode.E0603, "BatchQueryExecutor failed to construct a query");
            }
            queryList.add(new QueryEntry(entry.getQueryName(), query));
        }
    }
    jpaService.executeBatchInsertUpdateDelete(insertList, queryList, deleteList, em);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JsonBean(org.apache.oozie.client.rest.JsonBean) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery) SLARegQuery(org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery) BundleJobQuery(org.apache.oozie.executor.jpa.BundleJobQueryExecutor.BundleJobQuery) SLASummaryQuery(org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery) Query(javax.persistence.Query) WorkflowActionQuery(org.apache.oozie.executor.jpa.WorkflowActionQueryExecutor.WorkflowActionQuery) BundleActionQuery(org.apache.oozie.executor.jpa.BundleActionQueryExecutor.BundleActionQuery) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) SLARegQuery(org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleJobQuery(org.apache.oozie.executor.jpa.BundleJobQueryExecutor.BundleJobQuery) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) QueryEntry(org.apache.oozie.service.JPAService.QueryEntry) EntityManager(javax.persistence.EntityManager) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) BundleJobBean(org.apache.oozie.BundleJobBean) JPAService(org.apache.oozie.service.JPAService) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery) BundleActionBean(org.apache.oozie.BundleActionBean) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 79 with BundleJobBean

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

the class BulkJPAExecutor method execute.

@Override
public BulkResponseInfo execute(EntityManager em) throws JPAExecutorException {
    List<BulkResponseImpl> responseList = new ArrayList<BulkResponseImpl>();
    Map<String, Timestamp> actionTimes = new HashMap<String, Timestamp>();
    try {
        List<String> coords = bulkFilter.get(BulkResponseImpl.BULK_FILTER_COORD);
        List<String> statuses = bulkFilter.get(BulkResponseImpl.BULK_FILTER_STATUS);
        List<String> params = new ArrayList<String>();
        // Lightweight Query 1 on Bundle level to fetch the bundle job(s)
        // corresponding to names or ids
        List<BundleJobBean> bundleBeans = bundleQuery(em);
        // Join query between coordinator job and coordinator action tables
        // to get entries for specific bundleId only
        String conditions = actionQuery(coords, params, statuses, em, bundleBeans, actionTimes, responseList);
        // Query to get the count of records
        long total = countQuery(statuses, params, conditions, em, bundleBeans, actionTimes);
        BulkResponseInfo bulk = new BulkResponseInfo(responseList, start, len, total);
        return bulk;
    } catch (Exception e) {
        throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) BulkResponseInfo(org.apache.oozie.BulkResponseInfo) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) ParseException(java.text.ParseException) BulkResponseImpl(org.apache.oozie.client.rest.BulkResponseImpl) BundleJobBean(org.apache.oozie.BundleJobBean)

Example 80 with BundleJobBean

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

the class BulkJPAExecutor method bundleQuery.

/**
 * build the bundle level query to get bundle beans for the specified ids or appnames
 * @param em
 * @return List BundleJobBeans
 * @throws JPAExecutorException
 */
@SuppressWarnings("unchecked")
private List<BundleJobBean> bundleQuery(EntityManager em) throws JPAExecutorException {
    Query q = em.createNamedQuery("BULK_MONITOR_BUNDLE_QUERY");
    StringBuilder bundleQuery = new StringBuilder(q.toString());
    StringBuilder whereClause = null;
    List<String> bundles = bulkFilter.get(BulkResponseImpl.BULK_FILTER_BUNDLE);
    if (bundles != null) {
        PARAM_TYPE type = getParamType(bundles.get(0), 'B');
        if (type == PARAM_TYPE.NAME) {
            whereClause = inClause(bundles.size(), "appName", 'b', "bundles");
        } else if (type == PARAM_TYPE.ID) {
            whereClause = inClause(bundles.size(), "id", 'b', "bundles");
        }
        // Query: select <columns> from BundleJobBean b where b.id IN (...) _or_ b.appName IN (...)
        bundleQuery.append(whereClause.replace(whereClause.indexOf("AND"), whereClause.indexOf("AND") + 3, "WHERE"));
        Query tmp = em.createQuery(bundleQuery.toString());
        fillParameters(tmp, "bundles", bundles);
        List<Object[]> bundleObjs = (List<Object[]>) tmp.getResultList();
        if (bundleObjs.isEmpty()) {
            throw new JPAExecutorException(ErrorCode.E0603, "No entries found for given bundle(s)");
        }
        List<BundleJobBean> bundleBeans = new ArrayList<BundleJobBean>();
        for (Object[] bundleElem : bundleObjs) {
            bundleBeans.add(constructBundleBean(bundleElem));
        }
        return bundleBeans;
    }
    return null;
}
Also used : Query(javax.persistence.Query) ArrayList(java.util.ArrayList) BundleJobBean(org.apache.oozie.BundleJobBean) ArrayList(java.util.ArrayList) List(java.util.List)

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