Search in sources :

Example 36 with BundleActionBean

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

the class BundleStatusTransitXCommand method loadState.

@Override
protected void loadState() throws CommandException {
    try {
        bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB_ID_STATUS_PENDING_MOD_PAUSE_SUSPEND_TIME, jobId);
        bundleActions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_UNIGNORED_ACTION_STATUS_PENDING_FOR_BUNDLE, jobId);
        for (BundleActionBean bAction : bundleActions) {
            int counter = 0;
            if (bundleActionStatus.containsKey(bAction.getStatus())) {
                counter = getActionStatusCount(bAction.getStatus()) + 1;
            } else {
                ++counter;
            }
            bundleActionStatus.put(bAction.getStatus(), counter);
            if (bAction.getCoordId() == null && (bAction.getStatus() == Job.Status.FAILED || bAction.getStatus() == Job.Status.KILLED)) {
                new BundleKillXCommand(jobId).call();
                bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB_ID_STATUS_PENDING_MOD_PAUSE_SUSPEND_TIME, jobId);
                bundleJob.setStatus(Job.Status.FAILED);
                bundleJob.setLastModifiedTime(new Date());
                BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQuery.UPDATE_BUNDLE_JOB_STATUS, bundleJob);
            }
            if (bAction.isPending()) {
                LOG.debug(bAction + " has pending flag set");
                foundPending = true;
            }
        }
        LogUtils.setLogInfo(bundleJob);
    } catch (JPAExecutorException e) {
        throw new CommandException(ErrorCode.E1322, e);
    }
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CommandException(org.apache.oozie.command.CommandException) BundleActionBean(org.apache.oozie.BundleActionBean) Date(java.util.Date)

Example 37 with BundleActionBean

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

the class BundleStartXCommand method insertBundleActions.

/**
 * Insert bundle actions
 *
 * @throws CommandException thrown if failed to create bundle actions
 */
@SuppressWarnings("unchecked")
private void insertBundleActions() throws CommandException {
    if (bundleJob != null) {
        Map<String, Boolean> map = new HashMap<String, Boolean>();
        try {
            Element bAppXml = XmlUtils.parseXml(bundleJob.getJobXml());
            List<Element> coordElems = bAppXml.getChildren("coordinator", bAppXml.getNamespace());
            for (Element elem : coordElems) {
                Attribute name = elem.getAttribute("name");
                Attribute critical = elem.getAttribute("critical");
                if (name != null) {
                    if (map.containsKey(name.getValue())) {
                        throw new CommandException(ErrorCode.E1304, name);
                    }
                    Configuration coordConf = mergeConfig(elem);
                    // skip coord job if it is not enabled
                    if (!isEnabled(elem, coordConf)) {
                        continue;
                    }
                    boolean isCritical = false;
                    if (critical != null && Boolean.parseBoolean(critical.getValue())) {
                        isCritical = true;
                    }
                    map.put(name.getValue(), isCritical);
                } else {
                    throw new CommandException(ErrorCode.E1305);
                }
            }
        } catch (JDOMException jex) {
            throw new CommandException(ErrorCode.E1301, jex.getMessage(), jex);
        }
        // if there is no coordinator for this bundle, failed it.
        if (map.isEmpty()) {
            bundleJob.setStatus(Job.Status.FAILED);
            bundleJob.resetPending();
            try {
                BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQuery.UPDATE_BUNDLE_JOB_STATUS_PENDING, bundleJob);
            } catch (JPAExecutorException jex) {
                throw new CommandException(jex);
            }
            LOG.debug("No coord jobs for the bundle=[{0}], failed it!!", jobId);
            throw new CommandException(ErrorCode.E1318, jobId);
        }
        for (Entry<String, Boolean> coordName : map.entrySet()) {
            BundleActionBean action = createBundleAction(jobId, coordName.getKey(), coordName.getValue());
            insertList.add(action);
        }
    } else {
        throw new CommandException(ErrorCode.E0604, jobId);
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) HashMap(java.util.HashMap) Attribute(org.jdom.Attribute) Element(org.jdom.Element) CommandException(org.apache.oozie.command.CommandException) JDOMException(org.jdom.JDOMException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 38 with BundleActionBean

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

the class BundleStartXCommand method updateBundleAction.

private void updateBundleAction() throws JPAExecutorException {
    for (JsonBean bAction : insertList) {
        BundleActionBean action = (BundleActionBean) bAction;
        action.incrementAndGetPending();
        action.setLastModifiedTime(new Date());
    }
}
Also used : JsonBean(org.apache.oozie.client.rest.JsonBean) BundleActionBean(org.apache.oozie.BundleActionBean) Date(java.util.Date)

Example 39 with BundleActionBean

use of org.apache.oozie.BundleActionBean 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 40 with BundleActionBean

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

the class BundleActionGetJPAExecutor method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager)
     */
@Override
@SuppressWarnings("unchecked")
public BundleActionBean execute(EntityManager em) throws JPAExecutorException {
    List<BundleActionBean> baBeans;
    try {
        Query q = em.createNamedQuery("GET_BUNDLE_ACTION");
        q.setParameter("bundleActionId", bundleActionId);
        baBeans = q.getResultList();
    } catch (Exception e) {
        throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
    }
    BundleActionBean bean = null;
    if (baBeans != null && baBeans.size() > 0) {
        bean = baBeans.get(0);
        return bean;
    } else {
        throw new JPAExecutorException(ErrorCode.E0605, bundleActionId);
    }
}
Also used : Query(javax.persistence.Query) BundleActionBean(org.apache.oozie.BundleActionBean)

Aggregations

BundleActionBean (org.apache.oozie.BundleActionBean)76 BundleJobBean (org.apache.oozie.BundleJobBean)58 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)36 JPAService (org.apache.oozie.service.JPAService)35 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)33 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)30 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)24 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)20 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)20 Date (java.util.Date)19 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)19 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)16 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)13 IOException (java.io.IOException)10 CommandException (org.apache.oozie.command.CommandException)10 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)10 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)9 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)9 XConfiguration (org.apache.oozie.util.XConfiguration)8 ArrayList (java.util.ArrayList)6