Search in sources :

Example 16 with XException

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

the class CoordSLAAlertsXCommand method updateJobSLA.

/**
 * Update job sla.
 *
 * @param newParams the new params
 * @throws CommandException the command exception
 */
protected void updateJobSLA(Map<String, String> newParams) throws CommandException {
    try {
        CoordinatorJobBean job = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB_XML, getJobId());
        Element eAction;
        try {
            eAction = XmlUtils.parseXml(job.getJobXml());
        } catch (JDOMException e) {
            throw new CommandException(ErrorCode.E1005, e.getMessage(), e);
        }
        Element eSla = eAction.getChild("action", eAction.getNamespace()).getChild("info", eAction.getNamespace("sla"));
        if (newParams != null) {
            if (newParams.get(RestConstants.SLA_NOMINAL_TIME) != null) {
                updateSlaTagElement(eSla, SLAOperations.NOMINAL_TIME, newParams.get(RestConstants.SLA_NOMINAL_TIME));
            }
            if (newParams.get(RestConstants.SLA_SHOULD_START) != null) {
                updateSlaTagElement(eSla, SLAOperations.SHOULD_START, newParams.get(RestConstants.SLA_SHOULD_START));
            }
            if (newParams.get(RestConstants.SLA_SHOULD_END) != null) {
                updateSlaTagElement(eSla, SLAOperations.SHOULD_END, newParams.get(RestConstants.SLA_SHOULD_END));
            }
            if (newParams.get(RestConstants.SLA_MAX_DURATION) != null) {
                updateSlaTagElement(eSla, SLAOperations.MAX_DURATION, newParams.get(RestConstants.SLA_MAX_DURATION));
            }
        }
        String actualXml = XmlUtils.prettyPrint(eAction).toString();
        job.setJobXml(actualXml);
        job.setId(getJobId());
        CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQueryExecutor.CoordJobQuery.UPDATE_COORD_JOB_XML, job);
    } catch (XException e) {
        throw new CommandException(e);
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) Element(org.jdom.Element) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JDOMException(org.jdom.JDOMException)

Example 17 with XException

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

the class ActionEndXCommand 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_END, 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)

Example 18 with XException

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

the class ActionStartXCommand method loadState.

@Override
protected void loadState() throws CommandException {
    try {
        jpaService = Services.get().get(JPAService.class);
        if (jpaService != null) {
            if (wfJob == null) {
                this.wfJob = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, 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)

Example 19 with XException

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

the class BundleJobsXCommand method execute.

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

Example 20 with XException

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

the class BundleStartXCommand method loadState.

@Override
public void loadState() throws CommandException {
    try {
        this.bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB, jobId);
        LogUtils.setLogInfo(bundleJob);
        super.setJob(bundleJob);
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException)

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