use of org.apache.oozie.command.CommandException in project oozie by apache.
the class CoordSubmitXCommand method submitJob.
protected String submitJob() throws CommandException {
String jobId = null;
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
boolean exceptionOccured = false;
try {
mergeDefaultConfig();
String appXml = readAndValidateXml();
coordJob.setOrigJobXml(appXml);
LOG.debug("jobXml after initial validation " + XmlUtils.prettyPrint(appXml).toString());
Element eXml = XmlUtils.parseXml(appXml);
String appNamespace = readAppNamespace(eXml);
coordJob.setAppNamespace(appNamespace);
ParameterVerifier.verifyParameters(conf, eXml);
appXml = XmlUtils.removeComments(appXml);
initEvaluators();
Element eJob = basicResolveAndIncludeDS(appXml, conf, coordJob);
validateCoordinatorJob();
// checking if the coordinator application data input/output events
// specify multiple data instance values in erroneous manner
checkMultipleTimeInstances(eJob, COORD_INPUT_EVENTS, COORD_INPUT_EVENTS_DATA_IN);
checkMultipleTimeInstances(eJob, COORD_OUTPUT_EVENTS, COORD_OUTPUT_EVENTS_DATA_OUT);
LOG.debug("jobXml after all validation " + XmlUtils.prettyPrint(eJob).toString());
jobId = storeToDB(appXml, eJob, coordJob);
// log job info for coordinator job
LogUtils.setLogInfo(coordJob);
if (!dryrun) {
queueMaterializeTransitionXCommand(jobId);
} else {
return getDryRun(coordJob);
}
} catch (JDOMException jex) {
exceptionOccured = true;
LOG.warn("ERROR: ", jex);
throw new CommandException(ErrorCode.E0700, jex.getMessage(), jex);
} catch (CoordinatorJobException cex) {
exceptionOccured = true;
LOG.warn("ERROR: ", cex);
throw new CommandException(cex);
} catch (ParameterVerifierException pex) {
exceptionOccured = true;
LOG.warn("ERROR: ", pex);
throw new CommandException(pex);
} catch (IllegalArgumentException iex) {
exceptionOccured = true;
LOG.warn("ERROR: ", iex);
throw new CommandException(ErrorCode.E1003, iex.getMessage(), iex);
} catch (Exception ex) {
exceptionOccured = true;
LOG.warn("ERROR: ", ex);
throw new CommandException(ErrorCode.E0803, ex.getMessage(), ex);
} finally {
if (exceptionOccured) {
if (coordJob.getId() == null || coordJob.getId().equalsIgnoreCase("")) {
coordJob.setStatus(CoordinatorJob.Status.FAILED);
coordJob.resetPending();
}
}
}
return jobId;
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class CoordSubmitXCommand method storeToDB.
/**
* Write a coordinator job into database
*
*@param appXML : Coordinator definition xml
* @param eJob : XML element of job
* @param coordJob : Coordinator job bean
* @return Job id
* @throws CommandException thrown if unable to save coordinator job to db
*/
protected String storeToDB(String appXML, Element eJob, CoordinatorJobBean coordJob) throws CommandException {
String jobId = Services.get().get(UUIDService.class).generateId(ApplicationType.COORDINATOR);
coordJob.setId(jobId);
coordJob.setAppPath(conf.get(OozieClient.COORDINATOR_APP_PATH));
coordJob.setCreatedTime(new Date());
coordJob.setUser(conf.get(OozieClient.USER_NAME));
String group = ConfigUtils.getWithDeprecatedCheck(conf, OozieClient.JOB_ACL, OozieClient.GROUP_NAME, null);
coordJob.setGroup(group);
coordJob.setConf(XmlUtils.prettyPrint(conf).toString());
coordJob.setJobXml(XmlUtils.prettyPrint(eJob).toString());
coordJob.setLastActionNumber(0);
coordJob.setLastModifiedTime(new Date());
if (!dryrun) {
coordJob.setLastModifiedTime(new Date());
try {
CoordJobQueryExecutor.getInstance().insert(coordJob);
} catch (JPAExecutorException jpaee) {
coordJob.setId(null);
coordJob.setStatus(CoordinatorJob.Status.FAILED);
throw new CommandException(jpaee);
}
}
return jobId;
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class CoordSuspendXCommand method loadState.
@Override
protected void loadState() throws CommandException {
super.eagerLoadState();
try {
jpaService = Services.get().get(JPAService.class);
if (jpaService != null) {
this.coordJob = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB_SUSPEND_KILL, this.jobId);
prevStatus = coordJob.getStatus();
} else {
throw new CommandException(ErrorCode.E0610);
}
} catch (Exception ex) {
throw new CommandException(ErrorCode.E0603, ex.getMessage(), ex);
}
LogUtils.setLogInfo(this.coordJob);
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class CoordSuspendXCommand method suspendChildren.
@Override
public void suspendChildren() throws CommandException {
try {
// Get all running actions of a job to suspend them
List<CoordinatorActionBean> actionList = jpaService.execute(new CoordJobGetActionsRunningJPAExecutor(jobId));
for (CoordinatorActionBean action : actionList) {
// queue a SuspendXCommand
if (action.getExternalId() != null) {
queue(new SuspendXCommand(action.getExternalId()));
updateCoordAction(action);
LOG.debug("Suspend coord action = [{0}], new status = [{1}], pending = [{2}] and queue SuspendXCommand for [{3}]", action.getId(), action.getStatus(), action.getPending(), action.getExternalId());
} else {
updateCoordAction(action);
LOG.debug("Suspend coord action = [{0}], new status = [{1}], pending = [{2}] and external id is null", action.getId(), action.getStatus(), action.getPending());
}
}
LOG.debug("Suspended coordinator actions for the coordinator=[{0}]", jobId);
} catch (XException ex) {
exceptionOccured = true;
throw new CommandException(ex);
} finally {
if (exceptionOccured) {
coordJob.setStatus(CoordinatorJob.Status.FAILED);
coordJob.resetPending();
LOG.debug("Exception happened, fail coordinator job id = " + jobId + ", status = " + coordJob.getStatus());
updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_STATUS_PENDING_TIME, coordJob));
}
}
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class CoordUpdateXCommand method loadState.
@Override
protected void loadState() throws CommandException {
super.loadState();
jpaService = Services.get().get(JPAService.class);
if (jpaService == null) {
throw new CommandException(ErrorCode.E0610);
}
coordJob = new CoordinatorJobBean();
try {
oldCoordJob = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, jobId);
} catch (JPAExecutorException e) {
throw new CommandException(e);
}
LogUtils.setLogInfo(oldCoordJob);
if (!isConfChange || StringUtils.isEmpty(conf.get(OozieClient.COORDINATOR_APP_PATH))) {
try {
XConfiguration jobConf = new XConfiguration(new StringReader(oldCoordJob.getConf()));
if (!isConfChange) {
conf = jobConf;
} else {
for (String bundleConfKey : bundleConfList) {
if (jobConf.get(bundleConfKey) != null) {
conf.set(bundleConfKey, jobConf.get(bundleConfKey));
}
}
if (StringUtils.isEmpty(conf.get(OozieClient.COORDINATOR_APP_PATH))) {
conf.set(OozieClient.COORDINATOR_APP_PATH, jobConf.get(OozieClient.COORDINATOR_APP_PATH));
}
}
} catch (Exception e) {
throw new CommandException(ErrorCode.E1023, e.getMessage(), e);
}
}
coordJob.setConf(XmlUtils.prettyPrint(conf).toString());
setJob(coordJob);
LogUtils.setLogInfo(coordJob);
}
Aggregations