use of org.apache.oozie.command.CommandException in project oozie by apache.
the class SLADbXOperations method createSlaRegistrationEvent.
/**
* Create SLA registration event
*
* @param eSla SLA xml element
* @param slaId SLA Id
* @param appType SLA app type
* @param user user name
* @param groupName group name
* @return the event
* @throws Exception in case of error
*/
public static SLAEventBean createSlaRegistrationEvent(Element eSla, String slaId, SlaAppType appType, String user, String groupName) throws Exception {
if (eSla == null) {
return null;
}
SLAEventBean sla = new SLAEventBean();
// sla.setClientId(getTagElement( eSla, "client-id"));
// sla.setClientId(getClientId());
sla.setAppName(getTagElement(eSla, "app-name"));
sla.setParentClientId(getTagElement(eSla, "parent-child-id"));
sla.setParentSlaId(getTagElement(eSla, "parent-sla-id"));
String strNominalTime = getTagElement(eSla, "nominal-time");
if (strNominalTime == null || strNominalTime.length() == 0) {
throw new CommandException(ErrorCode.E1101);
}
Date nominalTime = DateUtils.parseDateOozieTZ(strNominalTime);
// Setting expected start time
String strRelExpectedStart = getTagElement(eSla, "should-start");
if (strRelExpectedStart != null && strRelExpectedStart.length() > 0) {
int relExpectedStart = Integer.parseInt(strRelExpectedStart);
if (relExpectedStart < 0) {
sla.setExpectedStart(null);
} else {
Date expectedStart = new Date(nominalTime.getTime() + relExpectedStart * 60 * 1000);
sla.setExpectedStart(expectedStart);
}
} else {
sla.setExpectedStart(null);
}
// Setting expected end time
String strRelExpectedEnd = getTagElement(eSla, "should-end");
if (strRelExpectedEnd == null || strRelExpectedEnd.length() == 0) {
throw new RuntimeException("should-end can't be empty");
}
int relExpectedEnd = Integer.parseInt(strRelExpectedEnd);
if (relExpectedEnd < 0) {
sla.setExpectedEnd(null);
} else {
Date expectedEnd = new Date(nominalTime.getTime() + relExpectedEnd * 60 * 1000);
sla.setExpectedEnd(expectedEnd);
}
sla.setNotificationMsg(getTagElement(eSla, "notification-msg"));
sla.setAlertContact(getTagElement(eSla, "alert-contact"));
sla.setDevContact(getTagElement(eSla, "dev-contact"));
sla.setQaContact(getTagElement(eSla, "qa-contact"));
sla.setSeContact(getTagElement(eSla, "se-contact"));
sla.setAlertFrequency(getTagElement(eSla, "alert-frequency"));
sla.setAlertPercentage(getTagElement(eSla, "alert-percentage"));
sla.setUpstreamApps(getTagElement(eSla, "upstream-apps"));
// Oozie defined
sla.setSlaId(slaId);
sla.setAppType(appType);
sla.setUser(user);
sla.setGroupName(groupName);
sla.setJobStatus(Status.CREATED);
sla.setStatusTimestamp(new Date());
return sla;
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class TestSLAEventGeneration method testCoordRerunNoSLA.
/**
* Test coord rerun with no SLA config works as before
*
* @throws Exception
*/
@Test
public void testCoordRerunNoSLA() throws Exception {
CoordinatorJobBean job = this.addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.FAILED, "coord-rerun-action1.xml", 0);
try {
new CoordRerunXCommand(job.getId(), RestConstants.JOB_COORD_SCOPE_DATE, "2009-12-15T01:00Z", false, true, false, null).call();
} catch (CommandException ce) {
if (ce.getErrorCode() == ErrorCode.E0604) {
fail("Coord Rerun with no SLA should not throw " + ce.getMessage() + " exception");
}
}
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class CoordMaterializeTransitionXCommand method materializeActions.
/**
* Create action instances starting from "startMatdTime" to "endMatdTime" and store them into coord action table.
*
* @param dryrun if this is a dry run
* @throws Exception thrown if failed to materialize actions
*/
protected String materializeActions(boolean dryrun) throws Exception {
Configuration jobConf = null;
try {
jobConf = new XConfiguration(new StringReader(coordJob.getConf()));
} catch (IOException ioe) {
LOG.warn("Configuration parse error. read from DB :" + coordJob.getConf(), ioe);
throw new CommandException(ErrorCode.E1005, ioe.getMessage(), ioe);
}
String jobXml = coordJob.getJobXml();
Element eJob = XmlUtils.parseXml(jobXml);
TimeZone appTz = DateUtils.getTimeZone(coordJob.getTimeZone());
String frequency = coordJob.getFrequency();
TimeUnit freqTU = TimeUnit.valueOf(coordJob.getTimeUnitStr());
TimeUnit endOfFlag = TimeUnit.valueOf(eJob.getAttributeValue("end_of_duration"));
Calendar start = Calendar.getInstance(appTz);
start.setTime(startMatdTime);
DateUtils.moveToEnd(start, endOfFlag);
Calendar end = Calendar.getInstance(appTz);
end.setTime(endMatdTime);
lastActionNumber = coordJob.getLastActionNumber();
// Intentionally printing dates in their own timezone, not Oozie timezone
LOG.info("materialize actions for tz=" + appTz.getDisplayName() + ",\n start=" + start.getTime() + ", end=" + end.getTime() + ",\n timeUnit " + freqTU.getCalendarUnit() + ",\n frequency :" + frequency + ":" + freqTU + ",\n lastActionNumber " + lastActionNumber);
// Keep the actual start time
Calendar origStart = Calendar.getInstance(appTz);
origStart.setTime(coordJob.getStartTimestamp());
// Move to the End of duration, if needed.
DateUtils.moveToEnd(origStart, endOfFlag);
StringBuilder actionStrings = new StringBuilder();
Date jobPauseTime = coordJob.getPauseTime();
Calendar pause = null;
if (jobPauseTime != null) {
pause = Calendar.getInstance(appTz);
pause.setTime(DateUtils.convertDateToTimestamp(jobPauseTime));
}
String action = null;
int numWaitingActions = dryrun ? 0 : jpaService.execute(new CoordActionsActiveCountJPAExecutor(coordJob.getId()));
int maxActionToBeCreated = coordJob.getMatThrottling() - numWaitingActions;
// If LAST_ONLY and all materialization is in the past, ignore maxActionsToBeCreated
boolean ignoreMaxActions = (coordJob.getExecutionOrder().equals(CoordinatorJob.Execution.LAST_ONLY) || coordJob.getExecutionOrder().equals(CoordinatorJob.Execution.NONE)) && endMatdTime.before(new Date());
LOG.debug("Coordinator job :" + coordJob.getId() + ", maxActionToBeCreated :" + maxActionToBeCreated + ", Mat_Throttle :" + coordJob.getMatThrottling() + ", numWaitingActions :" + numWaitingActions);
boolean isCronFrequency = false;
Calendar effStart = (Calendar) start.clone();
try {
int intFrequency = Integer.parseInt(coordJob.getFrequency());
effStart = (Calendar) origStart.clone();
effStart.add(freqTU.getCalendarUnit(), lastActionNumber * intFrequency);
} catch (NumberFormatException e) {
isCronFrequency = true;
}
boolean firstMater = true;
end = new DaylightOffsetCalculator(startMatdTime, endMatdTime).calculate(appTz, end);
while (effStart.compareTo(end) < 0 && (ignoreMaxActions || maxActionToBeCreated-- > 0)) {
if (pause != null && effStart.compareTo(pause) >= 0) {
break;
}
Date nextTime = effStart.getTime();
if (isCronFrequency) {
if (effStart.getTime().compareTo(startMatdTime) == 0 && firstMater) {
effStart.add(Calendar.MINUTE, -1);
firstMater = false;
}
nextTime = CoordCommandUtils.getNextValidActionTimeForCronFrequency(effStart.getTime(), coordJob);
effStart.setTime(nextTime);
}
if (effStart.compareTo(end) < 0) {
if (pause != null && effStart.compareTo(pause) >= 0) {
break;
}
CoordinatorActionBean actionBean = new CoordinatorActionBean();
lastActionNumber++;
int timeout = coordJob.getTimeout();
LOG.debug("Materializing action for time=" + DateUtils.formatDateOozieTZ(effStart.getTime()) + ", lastactionnumber=" + lastActionNumber + " timeout=" + timeout + " minutes");
Date actualTime = new Date();
action = CoordCommandUtils.materializeOneInstance(jobId, dryrun, (Element) eJob.clone(), nextTime, actualTime, lastActionNumber, jobConf, actionBean);
actionBean.setTimeOut(timeout);
if (!dryrun) {
// Storing to table
storeToDB(actionBean, action, jobConf);
} else {
actionStrings.append("action for new instance");
actionStrings.append(action);
}
} else {
break;
}
if (!isCronFrequency) {
effStart = (Calendar) origStart.clone();
effStart.add(freqTU.getCalendarUnit(), lastActionNumber * Integer.parseInt(coordJob.getFrequency()));
}
}
if (isCronFrequency) {
if (effStart.compareTo(end) < 0 && !(ignoreMaxActions || maxActionToBeCreated-- > 0)) {
// to avoid creating duplicate actions
if (!firstMater) {
effStart.setTime(CoordCommandUtils.getNextValidActionTimeForCronFrequency(effStart.getTime(), coordJob));
}
}
}
endMatdTime = effStart.getTime();
if (!dryrun) {
return action;
} else {
return actionStrings.toString();
}
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class CoordMaterializeTransitionXCommand method materialize.
/* (non-Javadoc)
* @see org.apache.oozie.command.MaterializeTransitionXCommand#materialize()
*/
@Override
protected void materialize() throws CommandException {
Instrumentation.Cron cron = new Instrumentation.Cron();
cron.start();
try {
materializeActions(false);
updateJobMaterializeInfo(coordJob);
} catch (CommandException ex) {
LOG.warn("Exception occurred:" + ex.getMessage() + " Making the job failed ", ex);
coordJob.setStatus(Job.Status.FAILED);
coordJob.resetPending();
// remove any materialized actions and slaEvents
insertList.clear();
} catch (Exception e) {
LOG.error("Exception occurred:" + e.getMessage() + " Making the job failed ", e);
coordJob.setStatus(Job.Status.FAILED);
try {
CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_MATERIALIZE, coordJob);
} catch (JPAExecutorException jex) {
throw new CommandException(ErrorCode.E1011, jex);
}
throw new CommandException(ErrorCode.E1012, e.getMessage(), e);
} finally {
cron.stop();
instrumentation.addCron(INSTRUMENTATION_GROUP, getName() + ".materialize", cron);
}
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class CoordPushDependencyCheckXCommand method updateCoordAction.
protected void updateCoordAction(CoordinatorActionBean coordAction, boolean isChangeInDependency) throws CommandException {
coordAction.setLastModifiedTime(new Date());
if (jpaService != null) {
try {
if (isChangeInDependency) {
coordAction.setPushMissingDependencies(coordAction.getPushInputDependencies().serialize());
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_FOR_PUSH_INPUTCHECK, coordAction);
if (EventHandlerService.isEnabled() && coordAction.getStatus() != CoordinatorAction.Status.READY) {
// since event is not to be generated unless action
// RUNNING via StartX
generateEvent(coordAction, coordJob.getUser(), coordJob.getAppName(), null);
}
} else {
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_FOR_MODIFIED_DATE, coordAction);
}
} catch (JPAExecutorException jex) {
throw new CommandException(ErrorCode.E1021, jex.getMessage(), jex);
} catch (IOException ioe) {
throw new CommandException(ErrorCode.E1021, ioe.getMessage(), ioe);
}
}
}
Aggregations