use of org.smartdata.model.action.ScheduleResult in project SSM by Intel-bigdata.
the class CmdletManager method scheduleCmdletActions.
private ScheduleResult scheduleCmdletActions(CmdletInfo info, LaunchCmdlet launchCmdlet) {
List<Long> actIds = info.getAids();
int idx = 0;
int schIdx = 0;
ActionInfo actionInfo;
LaunchAction launchAction;
List<ActionScheduler> actSchedulers;
boolean skipped = false;
ScheduleResult scheduleResult = ScheduleResult.SUCCESS_NO_EXECUTION;
ScheduleResult resultTmp;
for (idx = 0; idx < actIds.size(); idx++) {
actionInfo = idToActions.get(actIds.get(idx));
launchAction = launchCmdlet.getLaunchActions().get(idx);
actSchedulers = schedulers.get(actionInfo.getActionName());
if (actSchedulers == null || actSchedulers.size() == 0) {
skipped = true;
continue;
}
for (schIdx = 0; schIdx < actSchedulers.size(); schIdx++) {
ActionScheduler s = actSchedulers.get(schIdx);
try {
resultTmp = s.onSchedule(info, actionInfo, launchCmdlet, launchAction, idx);
} catch (Throwable t) {
actionInfo.appendLogLine("\nOnSchedule exception: " + t);
resultTmp = ScheduleResult.FAIL;
}
if (resultTmp != ScheduleResult.SUCCESS && resultTmp != ScheduleResult.SUCCESS_NO_EXECUTION) {
scheduleResult = resultTmp;
} else {
if (scheduleResult == ScheduleResult.SUCCESS_NO_EXECUTION) {
scheduleResult = resultTmp;
}
}
if (scheduleResult != ScheduleResult.SUCCESS && scheduleResult != ScheduleResult.SUCCESS_NO_EXECUTION) {
break;
}
}
if (scheduleResult != ScheduleResult.SUCCESS && scheduleResult != ScheduleResult.SUCCESS_NO_EXECUTION) {
break;
}
}
if (scheduleResult == ScheduleResult.SUCCESS || scheduleResult == ScheduleResult.SUCCESS_NO_EXECUTION) {
idx--;
schIdx--;
if (skipped) {
scheduleResult = ScheduleResult.SUCCESS;
}
}
postscheduleCmdletActions(info, actIds, scheduleResult, idx, schIdx);
return scheduleResult;
}
use of org.smartdata.model.action.ScheduleResult in project SSM by Intel-bigdata.
the class CmdletManager method scheduleCmdlet.
private int scheduleCmdlet() throws IOException {
int nScheduled = 0;
synchronized (pendingCmdlet) {
if (pendingCmdlet.size() > 0) {
schedulingCmdlet.addAll(pendingCmdlet);
pendingCmdlet.clear();
}
}
long curr = System.currentTimeMillis();
Iterator<Long> it = schedulingCmdlet.iterator();
while (it.hasNext() && !shouldStopSchedule()) {
long id = it.next();
if (nScheduled % 20 == 0) {
curr = System.currentTimeMillis();
}
CmdletInfo cmdlet = idToCmdlets.get(id);
if (cmdlet == null) {
it.remove();
continue;
}
synchronized (cmdlet) {
switch(cmdlet.getState()) {
case CANCELLED:
case DISABLED:
it.remove();
break;
case PENDING:
if (cmdlet.getDeferedToTime() > curr) {
break;
}
LaunchCmdlet launchCmdlet = createLaunchCmdlet(cmdlet);
ScheduleResult result;
try {
result = scheduleCmdletActions(cmdlet, launchCmdlet);
} catch (Throwable t) {
LOG.error("Schedule " + cmdlet + " failed.", t);
result = ScheduleResult.FAIL;
}
if (result != ScheduleResult.RETRY) {
it.remove();
} else {
continue;
}
try {
if (result == ScheduleResult.SUCCESS) {
idToLaunchCmdlet.put(cmdlet.getCid(), launchCmdlet);
cmdlet.setState(CmdletState.SCHEDULED);
cmdlet.setStateChangedTime(System.currentTimeMillis());
scheduledCmdlet.add(id);
nScheduled++;
} else if (result == ScheduleResult.FAIL) {
cmdlet.updateState(CmdletState.CANCELLED);
CmdletStatus cmdletStatus = new CmdletStatus(cmdlet.getCid(), cmdlet.getStateChangedTime(), cmdlet.getState());
// Mark all actions as finished
cmdletFinishedInternal(cmdlet, false);
onCmdletStatusUpdate(cmdletStatus);
} else if (result == ScheduleResult.SUCCESS_NO_EXECUTION) {
cmdlet.updateState(CmdletState.DONE);
cmdletFinishedInternal(cmdlet, true);
CmdletStatus cmdletStatus = new CmdletStatus(cmdlet.getCid(), cmdlet.getStateChangedTime(), cmdlet.getState());
onCmdletStatusUpdate(cmdletStatus);
}
} catch (Throwable t) {
LOG.error("Post schedule cmdlet " + cmdlet + " error.", t);
}
break;
}
}
}
return nScheduled;
}
Aggregations