use of org.apache.oozie.SLAEventBean 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.SLAEventBean in project oozie by apache.
the class TestSLADbOperations method testCreateSlaRegistrationEventMinReqFields.
@SuppressWarnings("deprecation")
public void testCreateSlaRegistrationEventMinReqFields() throws Exception {
Date nomDate = DateUtils.parseDateOozieTZ("2014-01-01T01:01Z");
String slaXML = " <sla:info xmlns:sla='uri:oozie:sla:0.2'>" + " <sla:nominal-time>" + DateUtils.formatDateOozieTZ(nomDate) + "</sla:nominal-time>" + " <sla:should-end>5</sla:should-end>" + "</sla:info>";
Element eSla = XmlUtils.parseXml(slaXML);
SLAEventBean regEvent = SLADbOperations.createSlaRegistrationEvent(eSla, null, "id1", SLAEvent.SlaAppType.WORKFLOW_JOB, "user1", "group1");
assertEquals(SLAEvent.SlaAppType.WORKFLOW_JOB, regEvent.getAppType());
assertEquals(new Date(nomDate.getTime() + 5 * 60 * 1000), regEvent.getExpectedEnd());
assertEquals("group1", regEvent.getGroupName());
assertEquals("id1", regEvent.getSlaId());
assertEquals("user1", regEvent.getUser());
regEvent = SLADbOperations.createSlaRegistrationEvent(eSla, "id1", SLAEvent.SlaAppType.WORKFLOW_JOB, "user1", "group1", null);
assertEquals(SLAEvent.SlaAppType.WORKFLOW_JOB, regEvent.getAppType());
assertEquals(new Date(nomDate.getTime() + 5 * 60 * 1000), regEvent.getExpectedEnd());
assertEquals("group1", regEvent.getGroupName());
assertEquals("id1", regEvent.getSlaId());
assertEquals("user1", regEvent.getUser());
}
use of org.apache.oozie.SLAEventBean in project oozie by apache.
the class CoordActionCheckXCommand method execute.
/* (non-Javadoc)
* @see org.apache.oozie.command.XCommand#execute()
*/
@Override
protected Void execute() throws CommandException {
try {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
Status slaStatus = null;
CoordinatorAction.Status initialStatus = coordAction.getStatus();
if (workflowJob.getStatus() == WorkflowJob.Status.SUCCEEDED) {
coordAction.setStatus(CoordinatorAction.Status.SUCCEEDED);
// set pending to false as the status is SUCCEEDED
coordAction.setPending(0);
slaStatus = Status.SUCCEEDED;
} else {
if (workflowJob.getStatus() == WorkflowJob.Status.FAILED) {
coordAction.setStatus(CoordinatorAction.Status.FAILED);
slaStatus = Status.FAILED;
// set pending to false as the status is FAILED
coordAction.setPending(0);
} else {
if (workflowJob.getStatus() == WorkflowJob.Status.KILLED) {
coordAction.setStatus(CoordinatorAction.Status.KILLED);
slaStatus = Status.KILLED;
// set pending to false as the status is KILLED
coordAction.setPending(0);
} else if (workflowJob.getStatus() == WorkflowJob.Status.SUSPENDED) {
coordAction.setStatus(CoordinatorAction.Status.SUSPENDED);
slaStatus = Status.FAILED;
// set pending to false as the status is SUSPENDED
coordAction.setPending(0);
} else {
LOG.warn("Unexpected workflow " + workflowJob.getId() + " STATUS " + workflowJob.getStatus());
coordAction.setLastModifiedTime(new Date());
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQueryExecutor.CoordActionQuery.UPDATE_COORD_ACTION_FOR_MODIFIED_DATE, coordAction);
return null;
}
}
}
LOG.debug("Updating Coordinator actionId :" + coordAction.getId() + "status to =" + coordAction.getStatus());
coordAction.setLastModifiedTime(new Date());
updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, coordAction));
if (slaStatus != null) {
SLAEventBean slaEvent = SLADbOperations.createStatusEvent(coordAction.getSlaXml(), coordAction.getId(), slaStatus, SlaAppType.COORDINATOR_ACTION, LOG);
if (slaEvent != null) {
insertList.add(slaEvent);
}
}
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
CoordinatorAction.Status endStatus = coordAction.getStatus();
if (endStatus != initialStatus && EventHandlerService.isEnabled()) {
generateEvent(coordAction, coordJob.getUser(), coordJob.getAppName(), workflowJob.getStartTime());
}
} catch (XException ex) {
LOG.warn("CoordActionCheckCommand Failed ", ex);
throw new CommandException(ex);
}
return null;
}
use of org.apache.oozie.SLAEventBean in project oozie by apache.
the class KillXCommand method execute.
@Override
protected Void execute() throws CommandException {
LOG.info("STARTED WorkflowKillXCommand for jobId=" + wfId);
wfJob.setEndTime(new Date());
if (wfJob.getStatus() != WorkflowJob.Status.FAILED) {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
wfJob.setStatus(WorkflowJob.Status.KILLED);
SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(wfJob.getSlaXml(), wfJob.getId(), Status.KILLED, SlaAppType.WORKFLOW_JOB);
if (slaEvent != null) {
insertList.add(slaEvent);
}
try {
wfJob.getWorkflowInstance().kill();
} catch (WorkflowException e) {
throw new CommandException(ErrorCode.E0725, e.getMessage(), e);
}
WorkflowInstance wfInstance = wfJob.getWorkflowInstance();
((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.KILLED);
wfJob.setWorkflowInstance(wfInstance);
}
try {
for (WorkflowActionBean action : actionList) {
if (action.getStatus() == WorkflowActionBean.Status.RUNNING || action.getStatus() == WorkflowActionBean.Status.DONE) {
if (!(actionService.getExecutor(action.getType()) instanceof ControlNodeActionExecutor)) {
action.setPending();
}
action.setStatus(WorkflowActionBean.Status.KILLED);
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_STATUS_PENDING, action));
queue(new ActionKillXCommand(action.getId(), action.getType()));
} else if (action.getStatus() == WorkflowActionBean.Status.PREP || action.getStatus() == WorkflowActionBean.Status.START_RETRY || action.getStatus() == WorkflowActionBean.Status.START_MANUAL || action.getStatus() == WorkflowActionBean.Status.END_RETRY || action.getStatus() == WorkflowActionBean.Status.END_MANUAL || action.getStatus() == WorkflowActionBean.Status.USER_RETRY) {
action.setStatus(WorkflowActionBean.Status.KILLED);
action.resetPending();
SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(action.getSlaXml(), action.getId(), Status.KILLED, SlaAppType.WORKFLOW_ACTION);
if (slaEvent != null) {
insertList.add(slaEvent);
}
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_STATUS_PENDING, action));
if (EventHandlerService.isEnabled() && !(actionService.getExecutor(action.getType()) instanceof ControlNodeActionExecutor)) {
generateEvent(action, wfJob.getUser());
}
}
}
wfJob.setLastModifiedTime(new Date());
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_END, wfJob));
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
if (EventHandlerService.isEnabled()) {
generateEvent(wfJob);
}
queue(new WorkflowNotificationXCommand(wfJob));
} catch (JPAExecutorException e) {
throw new CommandException(e);
} finally {
if (wfJob.getStatus() == WorkflowJob.Status.KILLED) {
// To delete the WF temp dir
new WfEndXCommand(wfJob).call();
}
updateParentIfNecessary(wfJob);
}
LOG.info("ENDED WorkflowKillXCommand for jobId=" + wfId);
return null;
}
use of org.apache.oozie.SLAEventBean in project oozie by apache.
the class SignalXCommand method endWF.
private void endWF(List<JsonBean> insertList) throws CommandException {
updateParentIfNecessary(wfJob, 3);
// To delete the WF temp dir
new WfEndXCommand(wfJob).call();
SLAEventBean slaEvent2 = SLADbXOperations.createStatusEvent(wfJob.getSlaXml(), wfJob.getId(), Status.FAILED, SlaAppType.WORKFLOW_JOB);
if (slaEvent2 != null) {
insertList.add(slaEvent2);
}
}
Aggregations