Search in sources :

Example 26 with XException

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

the class CoordActionCheckXCommand method loadState.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#loadState()
     */
@Override
protected void loadState() throws CommandException {
    try {
        jpaService = Services.get().get(JPAService.class);
        if (jpaService != null) {
            coordAction = jpaService.execute(new CoordActionGetForCheckJPAExecutor(actionId));
            coordJob = jpaService.execute(new CoordinatorJobGetForUserAppnameJPAExecutor(coordAction.getJobId()));
            workflowJob = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_FOR_SLA, coordAction.getExternalId());
            LogUtils.setLogInfo(coordAction);
        } else {
            throw new CommandException(ErrorCode.E0610);
        }
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) CoordActionGetForCheckJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetForCheckJPAExecutor) CoordinatorJobGetForUserAppnameJPAExecutor(org.apache.oozie.executor.jpa.CoordinatorJobGetForUserAppnameJPAExecutor)

Example 27 with XException

use of org.apache.oozie.XException 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 28 with XException

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

the class CoordJobXCommand method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
@Override
protected CoordinatorJobBean execute() throws CommandException {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        CoordinatorJobBean coordJob = null;
        if (jpaService != null) {
            coordJob = jpaService.execute(new CoordJobGetJPAExecutor(id));
            if (getActionInfo) {
                int numAction = jpaService.execute(new CoordActionsCountForJobIdJPAExecutor(id, filterMap));
                List<CoordinatorActionBean> coordActions = null;
                if (len == 0) {
                    coordActions = new ArrayList<CoordinatorActionBean>();
                } else {
                    coordActions = jpaService.execute(new CoordJobGetActionsSubsetJPAExecutor(id, filterMap, offset, len, desc));
                }
                coordJob.setActions(coordActions);
                coordJob.setNumActions(numAction);
            }
        } else {
            LOG.error(ErrorCode.E0610);
        }
        return coordJob;
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordActionsCountForJobIdJPAExecutor(org.apache.oozie.executor.jpa.CoordActionsCountForJobIdJPAExecutor) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) XException(org.apache.oozie.XException) CoordJobGetActionsSubsetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetActionsSubsetJPAExecutor) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService)

Example 29 with XException

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

the class CoordKillXCommand method loadState.

@Override
protected void loadState() throws CommandException {
    try {
        jpaService = Services.get().get(JPAService.class);
        if (jpaService != null) {
            this.coordJob = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB_SUSPEND_KILL, jobId);
            // Get actions which are not succeeded, failed, timed out or killed
            this.actionList = jpaService.execute(new CoordJobGetActionsNotCompletedJPAExecutor(jobId));
            prevStatus = coordJob.getStatus();
            LogUtils.setLogInfo(coordJob);
        } else {
            throw new CommandException(ErrorCode.E0610);
        }
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : CoordJobGetActionsNotCompletedJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetActionsNotCompletedJPAExecutor) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService)

Example 30 with XException

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

the class ActionKillXCommand method loadState.

@Override
protected void loadState() throws CommandException {
    try {
        jpaService = Services.get().get(JPAService.class);
        if (jpaService != null) {
            this.wfJob = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_ACTION_OP, jobId);
            this.wfAction = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, actionId);
            LogUtils.setLogInfo(wfJob);
            LogUtils.setLogInfo(wfAction);
        } else {
            throw new CommandException(ErrorCode.E0610);
        }
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService)

Aggregations

XException (org.apache.oozie.XException)45 CommandException (org.apache.oozie.command.CommandException)32 JPAService (org.apache.oozie.service.JPAService)25 Date (java.util.Date)9 ArrayList (java.util.ArrayList)8 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)8 HashMap (java.util.HashMap)7 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)7 List (java.util.List)6 ParseException (java.text.ParseException)4 BundleJobBean (org.apache.oozie.BundleJobBean)4 SLAEventBean (org.apache.oozie.SLAEventBean)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)4 Configuration (org.apache.hadoop.conf.Configuration)3 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)3 PreconditionException (org.apache.oozie.command.PreconditionException)3 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)3 Map (java.util.Map)2 BundleJobInfo (org.apache.oozie.BundleJobInfo)2 CoordinatorJobInfo (org.apache.oozie.CoordinatorJobInfo)2