use of org.apache.oozie.XException in project oozie by apache.
the class ActionStartXCommand method execute.
@Override
protected ActionExecutorContext execute() throws CommandException {
LOG.debug("STARTED ActionStartXCommand for wf actionId=" + actionId);
Configuration conf = wfJob.getWorkflowInstance().getConf();
int maxRetries = 0;
long retryInterval = 0;
boolean execSynchronous = false;
if (!(executor instanceof ControlNodeActionExecutor)) {
maxRetries = conf.getInt(OozieClient.ACTION_MAX_RETRIES, executor.getMaxRetries());
retryInterval = conf.getLong(OozieClient.ACTION_RETRY_INTERVAL, executor.getRetryInterval());
}
executor.setMaxRetries(maxRetries);
executor.setRetryInterval(retryInterval);
try {
boolean isRetry = false;
if (wfAction.getStatus() == WorkflowActionBean.Status.START_RETRY || wfAction.getStatus() == WorkflowActionBean.Status.START_MANUAL) {
isRetry = true;
prepareForRetry(wfAction);
}
boolean isUserRetry = false;
if (wfAction.getStatus() == WorkflowActionBean.Status.USER_RETRY) {
isUserRetry = true;
prepareForRetry(wfAction);
}
context = getContext(isRetry, isUserRetry);
boolean caught = false;
try {
if (!(executor instanceof ControlNodeActionExecutor)) {
String tmpActionConf = XmlUtils.removeComments(wfAction.getConf());
String actionConf = context.getELEvaluator().evaluate(tmpActionConf, String.class);
wfAction.setConf(actionConf);
LOG.debug("Start, name [{0}] type [{1}] configuration{E}{E}{2}{E}", wfAction.getName(), wfAction.getType(), actionConf);
}
} catch (ELEvaluationException ex) {
caught = true;
throw new ActionExecutorException(ActionExecutorException.ErrorType.TRANSIENT, EL_EVAL_ERROR, ex.getMessage(), ex);
} catch (ELException ex) {
caught = true;
context.setErrorInfo(EL_ERROR, ex.getMessage());
LOG.warn("ELException in ActionStartXCommand ", ex.getMessage(), ex);
handleError(context, wfJob, wfAction);
} catch (org.jdom.JDOMException je) {
caught = true;
context.setErrorInfo("ParsingError", je.getMessage());
LOG.warn("JDOMException in ActionStartXCommand ", je.getMessage(), je);
handleError(context, wfJob, wfAction);
} catch (Exception ex) {
caught = true;
context.setErrorInfo(EL_ERROR, ex.getMessage());
LOG.warn("Exception in ActionStartXCommand ", ex.getMessage(), ex);
handleError(context, wfJob, wfAction);
}
if (!caught) {
wfAction.setErrorInfo(null, null);
incrActionCounter(wfAction.getType(), 1);
LOG.info("Start action [{0}] with user-retry state : userRetryCount [{1}], userRetryMax [{2}], userRetryInterval" + " [{3}]", wfAction.getId(), wfAction.getUserRetryCount(), wfAction.getUserRetryMax(), wfAction.getUserRetryInterval());
Instrumentation.Cron cron = new Instrumentation.Cron();
cron.start();
// do not override starttime for retries
if (wfAction.getStartTime() == null) {
context.setStartTime();
}
context.setVar(JobUtils.getRetryKey(wfAction, JsonTags.WORKFLOW_ACTION_START_TIME), String.valueOf(new Date().getTime()));
executor.start(context, wfAction);
cron.stop();
FaultInjection.activate("org.apache.oozie.command.SkipCommitFaultInjection");
addActionCron(wfAction.getType(), cron);
wfAction.setRetries(0);
if (wfAction.isExecutionComplete()) {
if (!context.isExecuted()) {
LOG.warn(XLog.OPS, "Action Completed, ActionExecutor [{0}] must call setExecutionData()", executor.getType());
wfAction.setErrorInfo(EXEC_DATA_MISSING, "Execution Complete, but Execution Data Missing from Action");
failJob(context);
} else {
wfAction.setPending();
if (!(executor instanceof ControlNodeActionExecutor)) {
queue(new ActionEndXCommand(wfAction.getId(), wfAction.getType()));
} else {
execSynchronous = true;
}
}
} else {
if (!context.isStarted()) {
LOG.warn(XLog.OPS, "Action Started, ActionExecutor [{0}] must call setStartData()", executor.getType());
wfAction.setErrorInfo(START_DATA_MISSING, "Execution Started, but Start Data Missing from Action");
failJob(context);
} else {
queue(new WorkflowNotificationXCommand(wfJob, wfAction));
}
}
LOG.info(XLog.STD, "[***" + wfAction.getId() + "***]" + "Action status=" + wfAction.getStatusStr());
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_START, wfAction));
updateJobLastModified();
// Add SLA status event (STARTED) for WF_ACTION
SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(wfAction.getSlaXml(), wfAction.getId(), Status.STARTED, SlaAppType.WORKFLOW_ACTION);
if (slaEvent != null) {
insertList.add(slaEvent);
}
LOG.info(XLog.STD, "[***" + wfAction.getId() + "***]" + "Action updated in DB!");
}
} catch (ActionExecutorException ex) {
LOG.warn("Error starting action [{0}]. ErrorType [{1}], ErrorCode [{2}], Message [{3}]", wfAction.getName(), ex.getErrorType(), ex.getErrorCode(), ex.getMessage(), ex);
wfAction.setErrorInfo(ex.getErrorCode(), ex.getMessage());
switch(ex.getErrorType()) {
case TRANSIENT:
if (!handleTransient(context, executor, WorkflowAction.Status.START_RETRY)) {
handleNonTransient(context, executor, WorkflowAction.Status.START_MANUAL);
wfAction.setPendingAge(new Date());
wfAction.setRetries(0);
wfAction.setStartTime(null);
}
break;
case NON_TRANSIENT:
handleNonTransient(context, executor, WorkflowAction.Status.START_MANUAL);
break;
case ERROR:
handleError(context, executor, WorkflowAction.Status.ERROR.toString(), true, WorkflowAction.Status.DONE);
break;
case FAILED:
try {
failJob(context);
endWF();
SLAEventBean slaEvent1 = SLADbXOperations.createStatusEvent(wfAction.getSlaXml(), wfAction.getId(), Status.FAILED, SlaAppType.WORKFLOW_ACTION);
if (slaEvent1 != null) {
insertList.add(slaEvent1);
}
} catch (XException x) {
LOG.warn("ActionStartXCommand - case:FAILED ", x.getMessage());
}
break;
}
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_START, wfAction));
updateJobLastModified();
} finally {
try {
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
if (!(executor instanceof ControlNodeActionExecutor) && EventHandlerService.isEnabled()) {
generateEvent(wfAction, wfJob.getUser());
}
if (execSynchronous) {
// Changing to synchronous call from asynchronous queuing to prevent
// undue delay from ::start:: to action due to queuing
callActionEnd();
}
} catch (JPAExecutorException e) {
throw new CommandException(e);
}
}
LOG.debug("ENDED ActionStartXCommand for wf actionId=" + actionId + ", jobId=" + jobId);
return null;
}
use of org.apache.oozie.XException in project oozie by apache.
the class DefinitionXCommand method loadState.
@Override
protected void loadState() throws CommandException {
try {
JPAService jpaService = Services.get().get(JPAService.class);
if (jpaService != null) {
this.wfJob = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_DEFINITION, jobId);
LogUtils.setLogInfo(wfJob);
} else {
LOG.error(ErrorCode.E0610);
}
} catch (XException ex) {
throw new CommandException(ex);
}
}
use of org.apache.oozie.XException in project oozie by apache.
the class BulkJobsXCommand method execute.
/* (non-Javadoc)
* @see org.apache.oozie.command.XCommand#execute()
*/
@Override
protected BulkResponseInfo execute() throws CommandException {
try {
JPAService jpaService = Services.get().get(JPAService.class);
BulkResponseInfo bulk = null;
if (jpaService != null) {
bulk = jpaService.execute(new BulkJPAExecutor(bulkParams, start, len));
} else {
LOG.error(ErrorCode.E0610);
}
return bulk;
} catch (XException ex) {
throw new CommandException(ex);
}
}
use of org.apache.oozie.XException in project oozie by apache.
the class CoordSLAAlertsXCommand method updateJobConf.
/**
* Update job conf.
*
* @param newConf the new conf
* @throws CommandException the command exception
*/
protected void updateJobConf(Configuration newConf) throws CommandException {
try {
CoordinatorJobBean job = new CoordinatorJobBean();
XConfiguration conf = null;
conf = getJobConf();
XConfiguration.copy(newConf, conf);
job.setId(getJobId());
job.setConf(XmlUtils.prettyPrint(conf).toString());
CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQueryExecutor.CoordJobQuery.UPDATE_COORD_JOB_CONF, job);
} catch (XException e) {
throw new CommandException(e);
}
}
use of org.apache.oozie.XException in project oozie by apache.
the class BundleSLAAlertsXCommand method getCoordJobsFromBundle.
/**
* Gets the coord jobs from bundle.
*
* @param id the bundle id
* @param coords the coords name/id
* @return the coord jobs from bundle
* @throws CommandException the command exception
*/
protected Set<String> getCoordJobsFromBundle(String id, String coords) throws CommandException {
Set<String> jobs = new HashSet<String>();
List<CoordinatorJobBean> coordJobs;
try {
if (coords == null) {
coordJobs = CoordJobQueryExecutor.getInstance().getList(CoordJobQuery.GET_COORD_JOBS_WITH_PARENT_ID, id);
} else {
coordJobs = CoordJobQueryExecutor.getInstance().getList(CoordJobQuery.GET_COORD_JOBS_FOR_BUNDLE_BY_APPNAME_ID, Arrays.asList(coords.split(",")), id);
}
} catch (XException e) {
throw new CommandException(e);
}
for (CoordinatorJobBean jobBean : coordJobs) {
jobs.add(jobBean.getId());
}
return jobs;
}
Aggregations