Search in sources :

Example 6 with CoordActionQuery

use of org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery in project oozie by apache.

the class CoordActionUpdateXCommand method execute.

@Override
protected Void execute() throws CommandException {
    try {
        LOG.debug("STARTED CoordActionUpdateXCommand for wfId=[{0}]", workflow.getId());
        final CoordinatorAction.Status formerCoordinatorStatus = coordAction.getStatus();
        final int formerCoordinatorPending = coordAction.getPending();
        Status slaStatus = null;
        if (workflow.getStatus() == WorkflowJob.Status.SUCCEEDED) {
            coordAction.setStatus(CoordinatorAction.Status.SUCCEEDED);
            coordAction.setPending(0);
            slaStatus = Status.SUCCEEDED;
        } else if (workflow.getStatus() == WorkflowJob.Status.FAILED) {
            coordAction.setStatus(CoordinatorAction.Status.FAILED);
            coordAction.setPending(0);
            slaStatus = Status.FAILED;
        } else if (workflow.getStatus() == WorkflowJob.Status.KILLED) {
            coordAction.setStatus(CoordinatorAction.Status.KILLED);
            coordAction.setPending(0);
            slaStatus = Status.KILLED;
        } else if (workflow.getStatus() == WorkflowJob.Status.SUSPENDED) {
            coordAction.setStatus(CoordinatorAction.Status.SUSPENDED);
            coordAction.decrementAndGetPending();
        } else if (workflow.getStatus() == WorkflowJob.Status.RUNNING || workflow.getStatus() == WorkflowJob.Status.PREP) {
            // resume workflow job and update coord action accordingly
            coordAction.setStatus(CoordinatorAction.Status.RUNNING);
            coordAction.decrementAndGetPending();
        } else {
            LOG.warn("Unexpected workflow [{0}] STATUS [{1}]", workflow.getId(), workflow.getStatus());
            // update lastModifiedTime
            coordAction.setLastModifiedTime(new Date());
            CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQueryExecutor.CoordActionQuery.UPDATE_COORD_ACTION_FOR_MODIFIED_DATE, coordAction);
            /* CoordinatorJobBean coordJob = jpaService.execute(new CoordJobGetJPAExecutor(coordAction.getJobId()));
                if (!coordJob.isPending()) {
                    coordJob.setPending();
                    jpaService.execute(new CoordJobUpdateJPAExecutor(coordJob));
                }*/
            return null;
        }
        LOG.info("Updating Coordinator action id: [{0}] status [{1}] to [{2}] pending [{3}] to [{4}]", coordAction.getId(), formerCoordinatorStatus, coordAction.getStatus(), formerCoordinatorPending, coordAction.getPending());
        coordAction.setLastModifiedTime(new Date());
        updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, coordAction));
        /*CoordinatorJobBean coordJob = jpaService.execute(new CoordJobGetJPAExecutor(coordAction.getJobId()));
            if (!coordJob.isPending()) {
                coordJob.setPending();
                jpaService.execute(new CoordJobUpdateJPAExecutor(coordJob));
                LOG.info("Updating Coordinator job "+ coordJob.getId() + "pending to true");
            }*/
        if (slaStatus != null) {
            SLAEventBean slaEvent = SLADbOperations.createStatusEvent(coordAction.getSlaXml(), coordAction.getId(), slaStatus, SlaAppType.COORDINATOR_ACTION, LOG);
            if (slaEvent != null) {
                insertList.add(slaEvent);
            }
        }
        if (workflow.getStatus() != WorkflowJob.Status.SUSPENDED && workflow.getStatus() != WorkflowJob.Status.RUNNING) {
            queue(new CoordActionReadyXCommand(coordAction.getJobId()));
        }
        BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
        if (EventHandlerService.isEnabled()) {
            generateEvent(coordAction, coordJob.getUser(), coordJob.getAppName(), workflow.getStartTime());
        }
        LOG.debug("ENDED CoordActionUpdateXCommand for wfId= [{0}]", workflow.getId());
    } catch (XException ex) {
        LOG.warn("CoordActionUpdate Failed [{0}]", ex.getMessage());
        throw new CommandException(ex);
    }
    return null;
}
Also used : Status(org.apache.oozie.client.SLAEvent.Status) XException(org.apache.oozie.XException) CoordinatorAction(org.apache.oozie.client.CoordinatorAction) CommandException(org.apache.oozie.command.CommandException) Date(java.util.Date) SLAEventBean(org.apache.oozie.SLAEventBean) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery)

Example 7 with CoordActionQuery

use of org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery in project oozie by apache.

the class CoordActionStartXCommand method execute.

@Override
protected Void execute() throws CommandException {
    boolean makeFail = true;
    String errCode = "";
    String errMsg = "";
    ParamChecker.notEmpty(user, "user");
    log.debug("actionid=" + actionId + ", status=" + coordAction.getStatus());
    if (coordAction.getStatus() == CoordinatorAction.Status.SUBMITTED) {
        // log.debug("getting.. job id: " + coordAction.getJobId());
        // create merged runConf to pass to WF Engine
        Configuration runConf = mergeConfig(coordAction);
        coordAction.setRunConf(XmlUtils.prettyPrint(runConf).toString());
        // log.debug("%%% merged runconf=" +
        // XmlUtils.prettyPrint(runConf).toString());
        DagEngine dagEngine = Services.get().get(DagEngineService.class).getDagEngine(user);
        try {
            Configuration conf = new XConfiguration(new StringReader(coordAction.getRunConf()));
            SLAEventBean slaEvent = SLADbOperations.createStatusEvent(coordAction.getSlaXml(), coordAction.getId(), Status.STARTED, SlaAppType.COORDINATOR_ACTION, log);
            if (slaEvent != null) {
                insertList.add(slaEvent);
            }
            if (OozieJobInfo.isJobInfoEnabled()) {
                conf.set(OozieJobInfo.COORD_ID, actionId);
                conf.set(OozieJobInfo.COORD_NAME, appName);
                conf.set(OozieJobInfo.COORD_NOMINAL_TIME, coordAction.getNominalTimestamp().toString());
            }
            // Normalize workflow appPath here;
            JobUtils.normalizeAppPath(conf.get(OozieClient.USER_NAME), conf.get(OozieClient.GROUP_NAME), conf);
            if (coordAction.getExternalId() != null) {
                conf.setBoolean(OozieClient.RERUN_FAIL_NODES, true);
                dagEngine.reRun(coordAction.getExternalId(), conf);
            } else {
                // Pushing the nominal time in conf to use for launcher tag search
                conf.set(OOZIE_COORD_ACTION_NOMINAL_TIME, String.valueOf(coordAction.getNominalTime().getTime()));
                String wfId = dagEngine.submitJobFromCoordinator(conf, actionId);
                coordAction.setExternalId(wfId);
            }
            coordAction.setStatus(CoordinatorAction.Status.RUNNING);
            coordAction.incrementAndGetPending();
            // store.updateCoordinatorAction(coordAction);
            JPAService jpaService = Services.get().get(JPAService.class);
            if (jpaService != null) {
                log.debug("Updating WF record for WFID :" + coordAction.getExternalId() + " with parent id: " + actionId);
                WorkflowJobBean wfJob = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_STARTTIME, coordAction.getExternalId());
                wfJob.setParentId(actionId);
                wfJob.setLastModifiedTime(new Date());
                BatchQueryExecutor executor = BatchQueryExecutor.getInstance();
                updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW_PARENT_MODIFIED, wfJob));
                updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_FOR_START, coordAction));
                try {
                    executor.executeBatchInsertUpdateDelete(insertList, updateList, null);
                    queue(new CoordActionNotificationXCommand(coordAction), 100);
                    if (EventHandlerService.isEnabled()) {
                        generateEvent(coordAction, user, appName, wfJob.getStartTime());
                    }
                } catch (JPAExecutorException je) {
                    throw new CommandException(je);
                }
            } else {
                log.error(ErrorCode.E0610);
            }
            makeFail = false;
        } catch (DagEngineException dee) {
            errMsg = dee.getMessage();
            errCode = dee.getErrorCode().toString();
            log.warn("can not create DagEngine for submitting jobs", dee);
        } catch (CommandException ce) {
            errMsg = ce.getMessage();
            errCode = ce.getErrorCode().toString();
            log.warn("command exception occurred ", ce);
        } catch (java.io.IOException ioe) {
            errMsg = ioe.getMessage();
            errCode = "E1005";
            log.warn("Configuration parse error. read from DB :" + coordAction.getRunConf(), ioe);
        } catch (Exception ex) {
            errMsg = ex.getMessage();
            errCode = "E1005";
            log.warn("can not create DagEngine for submitting jobs", ex);
        } finally {
            if (makeFail == true) {
                // No DB exception occurs
                log.error("Failing the action " + coordAction.getId() + ". Because " + errCode + " : " + errMsg);
                coordAction.setStatus(CoordinatorAction.Status.FAILED);
                if (errMsg.length() > 254) {
                    // Because table column size is 255
                    errMsg = errMsg.substring(0, 255);
                }
                coordAction.setErrorMessage(errMsg);
                coordAction.setErrorCode(errCode);
                updateList = new ArrayList<UpdateEntry>();
                updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_FOR_START, coordAction));
                insertList = new ArrayList<JsonBean>();
                SLAEventBean slaEvent = SLADbOperations.createStatusEvent(coordAction.getSlaXml(), coordAction.getId(), Status.FAILED, SlaAppType.COORDINATOR_ACTION, log);
                if (slaEvent != null) {
                    // Update SLA events
                    insertList.add(slaEvent);
                }
                try {
                    // call JPAExecutor to do the bulk writes
                    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
                    if (EventHandlerService.isEnabled()) {
                        generateEvent(coordAction, user, appName, null);
                    }
                } catch (JPAExecutorException je) {
                    throw new CommandException(je);
                }
                queue(new CoordActionReadyXCommand(coordAction.getJobId()));
            }
        }
    }
    return null;
}
Also used : UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) JsonBean(org.apache.oozie.client.rest.JsonBean) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) DagEngine(org.apache.oozie.DagEngine) BatchQueryExecutor(org.apache.oozie.executor.jpa.BatchQueryExecutor) StringReader(java.io.StringReader) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery) IOException(java.io.IOException) DagEngineService(org.apache.oozie.service.DagEngineService) CommandException(org.apache.oozie.command.CommandException) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) SLAEventBean(org.apache.oozie.SLAEventBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) DagEngineException(org.apache.oozie.DagEngineException) JDOMException(org.jdom.JDOMException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngineException(org.apache.oozie.DagEngineException) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) JPAService(org.apache.oozie.service.JPAService)

Example 8 with CoordActionQuery

use of org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery in project oozie by apache.

the class CoordActionsIgnoreXCommand method ignoreChildren.

@Override
public void ignoreChildren() throws CommandException {
    for (CoordinatorActionBean action : coordActions) {
        action.setStatus(Status.IGNORED);
        action.setLastModifiedTime(new Date());
        action.setPending(0);
        updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action));
        LOG.info("Ignore coord action = [{0}], new status = [{1}]", action.getId(), action.getStatus());
    }
    ret = new CoordinatorActionInfo(coordActions);
}
Also used : CoordinatorActionInfo(org.apache.oozie.CoordinatorActionInfo) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) Date(java.util.Date) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery)

Example 9 with CoordActionQuery

use of org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery 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)

Aggregations

CoordActionQuery (org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery)9 Date (java.util.Date)8 SLAEventBean (org.apache.oozie.SLAEventBean)3 CoordinatorAction (org.apache.oozie.client.CoordinatorAction)3 CommandException (org.apache.oozie.command.CommandException)3 StringReader (java.io.StringReader)2 Configuration (org.apache.hadoop.conf.Configuration)2 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)2 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)2 XException (org.apache.oozie.XException)2 Status (org.apache.oozie.client.SLAEvent.Status)2 JsonBean (org.apache.oozie.client.rest.JsonBean)2 WorkflowJobQuery (org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)2 JPAService (org.apache.oozie.service.JPAService)2 XConfiguration (org.apache.oozie.util.XConfiguration)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 EntityManager (javax.persistence.EntityManager)1 Query (javax.persistence.Query)1 BundleActionBean (org.apache.oozie.BundleActionBean)1