Search in sources :

Example 1 with CoordActionQuery

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

the class CoordKillXCommand method updateCoordAction.

private void updateCoordAction(CoordinatorActionBean action, boolean makePending) {
    CoordinatorAction.Status prevStatus = action.getStatus();
    action.setStatus(CoordinatorActionBean.Status.KILLED);
    if (makePending) {
        action.incrementAndGetPending();
    } else {
        // set pending to false
        action.setPending(0);
    }
    if (EventHandlerService.isEnabled() && prevStatus != CoordinatorAction.Status.RUNNING && prevStatus != CoordinatorAction.Status.SUSPENDED) {
        CoordinatorXCommand.generateEvent(action, coordJob.getUser(), coordJob.getAppName(), null);
    }
    action.setLastModifiedTime(new Date());
    updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action));
}
Also used : CoordinatorAction(org.apache.oozie.client.CoordinatorAction) Date(java.util.Date) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery)

Example 2 with CoordActionQuery

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

the class CoordSuspendXCommand method updateCoordAction.

private void updateCoordAction(CoordinatorActionBean action) {
    action.setStatus(CoordinatorActionBean.Status.SUSPENDED);
    action.incrementAndGetPending();
    action.setLastModifiedTime(new Date());
    updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action));
}
Also used : Date(java.util.Date) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery)

Example 3 with CoordActionQuery

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

the class CoordActionCheckXCommand method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
@Override
protected Void execute() throws CommandException {
    try {
        InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
        Status slaStatus = null;
        CoordinatorAction.Status initialStatus = coordAction.getStatus();
        if (workflowJob.getStatus() == WorkflowJob.Status.SUCCEEDED) {
            coordAction.setStatus(CoordinatorAction.Status.SUCCEEDED);
            // set pending to false as the status is SUCCEEDED
            coordAction.setPending(0);
            slaStatus = Status.SUCCEEDED;
        } else {
            if (workflowJob.getStatus() == WorkflowJob.Status.FAILED) {
                coordAction.setStatus(CoordinatorAction.Status.FAILED);
                slaStatus = Status.FAILED;
                // set pending to false as the status is FAILED
                coordAction.setPending(0);
            } else {
                if (workflowJob.getStatus() == WorkflowJob.Status.KILLED) {
                    coordAction.setStatus(CoordinatorAction.Status.KILLED);
                    slaStatus = Status.KILLED;
                    // set pending to false as the status is KILLED
                    coordAction.setPending(0);
                } else if (workflowJob.getStatus() == WorkflowJob.Status.SUSPENDED) {
                    coordAction.setStatus(CoordinatorAction.Status.SUSPENDED);
                    slaStatus = Status.FAILED;
                    // set pending to false as the status is SUSPENDED
                    coordAction.setPending(0);
                } else {
                    LOG.warn("Unexpected workflow " + workflowJob.getId() + " STATUS " + workflowJob.getStatus());
                    coordAction.setLastModifiedTime(new Date());
                    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQueryExecutor.CoordActionQuery.UPDATE_COORD_ACTION_FOR_MODIFIED_DATE, coordAction);
                    return null;
                }
            }
        }
        LOG.debug("Updating Coordinator actionId :" + coordAction.getId() + "status to =" + coordAction.getStatus());
        coordAction.setLastModifiedTime(new Date());
        updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, coordAction));
        if (slaStatus != null) {
            SLAEventBean slaEvent = SLADbOperations.createStatusEvent(coordAction.getSlaXml(), coordAction.getId(), slaStatus, SlaAppType.COORDINATOR_ACTION, LOG);
            if (slaEvent != null) {
                insertList.add(slaEvent);
            }
        }
        BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
        CoordinatorAction.Status endStatus = coordAction.getStatus();
        if (endStatus != initialStatus && EventHandlerService.isEnabled()) {
            generateEvent(coordAction, coordJob.getUser(), coordJob.getAppName(), workflowJob.getStartTime());
        }
    } catch (XException ex) {
        LOG.warn("CoordActionCheckCommand Failed ", ex);
        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 4 with CoordActionQuery

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

the class CoordRerunXCommand method updateAction.

/**
 * Update an action into database table
 *
 * @param coordJob coordinator job bean
 * @param coordAction coordinator action bean
 * @throws Exception thrown failed to update coordinator action bean or unable to write sla registration event
 */
private void updateAction(CoordinatorJobBean coordJob, CoordinatorActionBean coordAction) throws Exception {
    LOG.debug("updateAction for actionId=" + coordAction.getId());
    if (coordAction.getStatus() == CoordinatorAction.Status.TIMEDOUT) {
        LOG.debug("Updating created time for TIMEDOUT action id =" + coordAction.getId());
        coordAction.setCreatedTime(new Date());
    }
    coordAction.setStatus(CoordinatorAction.Status.WAITING);
    if (!failed) {
        coordAction.setExternalId(null);
    }
    coordAction.setExternalStatus(null);
    coordAction.setRerunTime(new Date());
    coordAction.setLastModifiedTime(new Date());
    coordAction.setErrorCode("");
    coordAction.setErrorMessage("");
    // Pushing the configuration which passed through rerun.
    if (actionRunConf != null && actionRunConf.size() > 0) {
        Configuration createdConf = null;
        if (coordAction.getCreatedConf() != null) {
            createdConf = new XConfiguration(new StringReader(coordAction.getCreatedConf()));
        } else {
            createdConf = new Configuration();
        }
        createdConf.set(RERUN_CONF, XmlUtils.prettyPrint(actionRunConf).toString());
        coordAction.setCreatedConf(XmlUtils.prettyPrint(createdConf).toString());
    }
    updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_RERUN, coordAction));
    writeActionRegistration(coordAction.getActionXml(), coordAction, coordJob.getUser(), coordJob.getGroup());
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) StringReader(java.io.StringReader) Date(java.util.Date) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery)

Example 5 with CoordActionQuery

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

the class CoordResumeXCommand method updateCoordAction.

private void updateCoordAction(CoordinatorActionBean action) {
    action.setStatus(CoordinatorActionBean.Status.RUNNING);
    action.incrementAndGetPending();
    action.setLastModifiedTime(new Date());
    updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action));
}
Also used : Date(java.util.Date) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery)

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