use of org.apache.oozie.XException in project oozie by apache.
the class XCommand method call.
/**
* Implements the XCommand life-cycle.
*
* @return the {link #execute} return value.
* @throws CommandException thrown if the command could not be executed.
*/
@Override
public final T call() throws CommandException {
setLogInfo();
CallableQueueService callableQueueService = Services.get().get(CallableQueueService.class);
Set<String> interruptTypes = callableQueueService.getInterruptTypes();
if (interruptTypes.contains(this.getType()) && used.get()) {
LOG.debug("Command [{0}] key [{1}] already used for [{2}]", getName(), getEntityKey(), this.toString());
return null;
}
commandQueue = null;
instrumentation.incr(INSTRUMENTATION_GROUP, getName() + ".executions", 1);
Instrumentation.Cron callCron = new Instrumentation.Cron();
try {
callCron.start();
eagerLoadState();
eagerVerifyPrecondition();
try {
T ret = null;
if (isLockRequired() && !this.inInterruptMode()) {
Instrumentation.Cron acquireLockCron = new Instrumentation.Cron();
acquireLockCron.start();
acquireLock();
acquireLockCron.stop();
instrumentation.addCron(INSTRUMENTATION_GROUP, getName() + ".acquireLock", acquireLockCron);
}
// executing interrupts only in case of the lock required commands
if (lock != null) {
this.executeInterrupts();
}
if (!isLockRequired() || (lock != null) || this.inInterruptMode()) {
if (interruptTypes.contains(this.getType()) && !used.compareAndSet(false, true)) {
LOG.debug("Command [{0}] key [{1}] already executed for [{2}]", getName(), getEntityKey(), this.toString());
return null;
}
LOG.trace("Load state for [{0}]", getEntityKey());
loadState();
LOG.trace("Precondition check for command [{0}] key [{1}]", getName(), getEntityKey());
verifyPrecondition();
LOG.debug("Execute command [{0}] key [{1}]", getName(), getEntityKey());
Instrumentation.Cron executeCron = new Instrumentation.Cron();
executeCron.start();
ret = execute();
executeCron.stop();
instrumentation.addCron(INSTRUMENTATION_GROUP, getName() + ".execute", executeCron);
}
if (commandQueue != null) {
for (Map.Entry<Long, List<XCommand<?>>> entry : commandQueue.entrySet()) {
LOG.debug("Queuing [{0}] commands with delay [{1}]ms", entry.getValue().size(), entry.getKey());
if (!callableQueueService.queueSerial(entry.getValue(), entry.getKey())) {
LOG.warn("Could not queue [{0}] commands with delay [{1}]ms, queue full", entry.getValue().size(), entry.getKey());
}
}
}
return ret;
} finally {
if (isLockRequired() && !this.inInterruptMode()) {
releaseLock();
}
}
} catch (PreconditionException pex) {
LOG.warn(pex.getMessage().toString() + ", Error Code: " + pex.getErrorCode().toString());
instrumentation.incr(INSTRUMENTATION_GROUP, getName() + ".preconditionfailed", 1);
return null;
} catch (XException ex) {
LOG.error("XException, ", ex);
instrumentation.incr(INSTRUMENTATION_GROUP, getName() + ".xexceptions", 1);
if (ex instanceof CommandException) {
throw (CommandException) ex;
} else {
throw new CommandException(ex);
}
} catch (Exception ex) {
LOG.error("Exception, ", ex);
instrumentation.incr(INSTRUMENTATION_GROUP, getName() + ".exceptions", 1);
throw new CommandException(ErrorCode.E0607, getName(), ex.getMessage(), ex);
} catch (Error er) {
LOG.error("Error, ", er);
instrumentation.incr(INSTRUMENTATION_GROUP, getName() + ".errors", 1);
throw er;
} finally {
FaultInjection.deactivate("org.apache.oozie.command.SkipCommitFaultInjection");
callCron.stop();
instrumentation.addCron(INSTRUMENTATION_GROUP, getName() + ".call", callCron);
}
}
use of org.apache.oozie.XException in project oozie by apache.
the class CoordUtils method getCoordActionsFromDates.
/**
* Get the list of actions for given date ranges
*
* @param jobId coordinator job id
* @param scope a comma-separated list of date ranges. Each date range element is specified with two dates separated by '::'
* @return the list of Coordinator actions for the date range
* @throws CommandException thrown if failed to get coordinator actions by given date range
*/
@VisibleForTesting
public static List<CoordinatorActionBean> getCoordActionsFromDates(String jobId, String scope, boolean active) throws CommandException {
JPAService jpaService = Services.get().get(JPAService.class);
ParamChecker.notEmpty(jobId, "jobId");
ParamChecker.notEmpty(scope, "scope");
Set<CoordinatorActionBean> actionSet = new LinkedHashSet<CoordinatorActionBean>();
String[] list = scope.split(",");
for (String s : list) {
s = s.trim();
// A date range is specified with two dates separated by '::'
if (s.contains("::")) {
List<CoordinatorActionBean> listOfActions;
try {
// Get list of actions within the range of date
listOfActions = CoordActionsInDateRange.getCoordActionsFromDateRange(jobId, s, active);
} catch (XException e) {
throw new CommandException(e);
}
actionSet.addAll(listOfActions);
} else {
try {
// Get action for the nominal time
Date date = DateUtils.parseDateOozieTZ(s.trim());
CoordinatorActionBean coordAction = jpaService.execute(new CoordJobGetActionForNominalTimeJPAExecutor(jobId, date));
if (coordAction != null) {
actionSet.add(coordAction);
} else {
throw new RuntimeException("This should never happen, Coordinator Action shouldn't be null");
}
} catch (ParseException e) {
throw new CommandException(ErrorCode.E0302, s.trim(), e);
} catch (JPAExecutorException e) {
if (e.getErrorCode() == ErrorCode.E0605) {
XLog.getLog(CoordUtils.class).info("No action for nominal time:" + s + ". Skipping over");
}
throw new CommandException(e);
}
}
}
List<CoordinatorActionBean> coordActions = new ArrayList<CoordinatorActionBean>();
for (CoordinatorActionBean coordAction : actionSet) {
coordActions.add(coordAction);
}
return coordActions;
}
use of org.apache.oozie.XException in project oozie by apache.
the class KillXCommand 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_KILL, wfId);
this.actionList = jpaService.execute(new WorkflowActionsGetForJobJPAExecutor(wfId));
LogUtils.setLogInfo(wfJob);
} else {
throw new CommandException(ErrorCode.E0610);
}
actionService = Services.get().get(ActionService.class);
} catch (XException ex) {
throw new CommandException(ex);
}
}
use of org.apache.oozie.XException in project oozie by apache.
the class SignalXCommand 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, jobId);
LogUtils.setLogInfo(wfJob);
if (actionId != null) {
this.wfAction = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION_SIGNAL, actionId);
LogUtils.setLogInfo(wfAction);
}
} else {
throw new CommandException(ErrorCode.E0610);
}
} catch (XException ex) {
throw new CommandException(ex);
}
}
use of org.apache.oozie.XException in project oozie by apache.
the class CoordActionsInDateRange method getCoordActionIdsFromDateRange.
/**
* Get the coordinator actions for a given date range
* @param jobId the coordinator job id
* @param range the date range separated by '::'
* @return the list of Coordinator actions for the date range
* @throws XException if range is not well formatted or invalid
*/
public static List<String> getCoordActionIdsFromDateRange(String jobId, String range) throws XException {
String[] dateRange = range.split("::");
// This block checks for errors in the format of specifying date range
if (dateRange.length != 2) {
throw new XException(ErrorCode.E0308, "'" + range + "'. Date value expected on both sides of the scope resolution operator '::' to signify start and end of range");
}
Date start;
Date end;
try {
// Get the start and end dates for the range
start = DateUtils.parseDateOozieTZ(dateRange[0].trim());
end = DateUtils.parseDateOozieTZ(dateRange[1].trim());
} catch (ParseException dx) {
throw new XException(ErrorCode.E0308, "Error in parsing start or end date. " + dx);
}
if (start.after(end)) {
throw new XException(ErrorCode.E0308, "'" + range + "'. Start date '" + start + "' is older than end date: '" + end + "'");
}
List<CoordinatorActionBean> listOfActions = CoordActionQueryExecutor.getInstance().getList(CoordActionQuery.GET_TERMINATED_ACTIONS_FOR_DATES, jobId, start, end);
List<String> idsList = new ArrayList<String>();
for (CoordinatorActionBean bean : listOfActions) {
idsList.add(bean.getId());
}
return idsList;
}
Aggregations