Search in sources :

Example 11 with XException

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

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

the class CoordActionsKillXCommand method loadState.

@Override
protected void loadState() throws CommandException {
    try {
        jpaService = Services.get().get(JPAService.class);
        if (jpaService != null) {
            coordJob = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB_ACTION_KILL, jobId);
            LogUtils.setLogInfo(coordJob);
            coordActions = CoordUtils.getCoordActions(rangeType, coordJob.getId(), scope, true);
        } 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)

Example 13 with XException

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

the class CoordJobsXCommand method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
@Override
protected CoordinatorJobInfo execute() throws CommandException {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        CoordinatorJobInfo coordInfo = null;
        if (jpaService != null) {
            coordInfo = jpaService.execute(new CoordJobInfoGetJPAExecutor(filter, start, len));
        } else {
            LOG.error(ErrorCode.E0610);
        }
        return coordInfo;
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : CoordinatorJobInfo(org.apache.oozie.CoordinatorJobInfo) CoordJobInfoGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobInfoGetJPAExecutor) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService)

Example 14 with XException

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

the class ExternalIdXCommand method execute.

@Override
protected String execute() throws CommandException {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        String wfId = null;
        if (jpaService != null) {
            wfId = jpaService.execute(new WorkflowIdGetForExternalIdJPAExecutor(externalId));
        } else {
            LOG.error(ErrorCode.E0610);
        }
        return wfId;
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : WorkflowIdGetForExternalIdJPAExecutor(org.apache.oozie.executor.jpa.WorkflowIdGetForExternalIdJPAExecutor) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService)

Example 15 with XException

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

the class CoordRerunXCommand method rerunChildren.

@Override
public void rerunChildren() throws CommandException {
    boolean isError = false;
    try {
        CoordinatorActionInfo coordInfo = null;
        InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
        List<CoordinatorActionBean> coordActions = CoordUtils.getCoordActions(rerunType, jobId, scope, false);
        if (checkAllActionsRunnable(coordActions)) {
            Map<String, Context> uriHandlerContextMap = new HashMap<String, Context>();
            Configuration coordJobConf = null;
            try {
                coordJobConf = new XConfiguration(new StringReader(coordJob.getConf()));
            } catch (IOException e) {
                throw new CommandException(ErrorCode.E0907, "failed to read coord job conf to clean up output data");
            }
            try {
                for (CoordinatorActionBean coordAction : coordActions) {
                    String actionXml = coordAction.getActionXml();
                    // Cleanup activity should not run when failed option has been provided
                    if (!noCleanup && !failed) {
                        Element eAction = XmlUtils.parseXml(actionXml);
                        cleanupOutputEvents(eAction, coordJobConf, uriHandlerContextMap);
                    }
                    if (refresh) {
                        refreshAction(coordJob, coordAction);
                    }
                    updateAction(coordJob, coordAction);
                    if (SLAService.isEnabled()) {
                        SLAOperations.updateRegistrationEvent(coordAction.getId());
                    }
                    queue(new CoordActionNotificationXCommand(coordAction), 100);
                    queue(new CoordActionInputCheckXCommand(coordAction.getId(), coordAction.getJobId()), 100);
                    if (coordAction.getPushMissingDependencies() != null) {
                        queue(new CoordPushDependencyCheckXCommand(coordAction.getId(), true), 100);
                    }
                }
            } finally {
                Iterator<Entry<String, Context>> itr = uriHandlerContextMap.entrySet().iterator();
                while (itr.hasNext()) {
                    Entry<String, Context> entry = itr.next();
                    entry.getValue().destroy();
                    itr.remove();
                }
            }
        } else {
            isError = true;
            throw new CommandException(ErrorCode.E1018, "part or all actions are not eligible to rerun!");
        }
        coordInfo = new CoordinatorActionInfo(coordActions);
        ret = coordInfo;
    } catch (XException xex) {
        isError = true;
        throw new CommandException(xex);
    } catch (JDOMException jex) {
        isError = true;
        throw new CommandException(ErrorCode.E0700, jex.getMessage(), jex);
    } catch (Exception ex) {
        isError = true;
        throw new CommandException(ErrorCode.E1018, ex.getMessage(), ex);
    } finally {
        if (isError) {
            transitToPrevious();
        }
    }
}
Also used : Context(org.apache.oozie.dependency.URIHandler.Context) CoordinatorActionInfo(org.apache.oozie.CoordinatorActionInfo) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) HashMap(java.util.HashMap) Element(org.jdom.Element) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) JDOMException(org.jdom.JDOMException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException) URIHandlerException(org.apache.oozie.dependency.URIHandlerException) IOException(java.io.IOException) XException(org.apache.oozie.XException) XConfiguration(org.apache.oozie.util.XConfiguration) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) Entry(java.util.Map.Entry) XException(org.apache.oozie.XException) StringReader(java.io.StringReader)

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