Search in sources :

Example 1 with ScheduleResult

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;
}
Also used : ScheduleResult(org.smartdata.model.action.ScheduleResult) LaunchAction(org.smartdata.model.LaunchAction) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActionScheduler(org.smartdata.model.action.ActionScheduler) ActionInfo(org.smartdata.model.ActionInfo)

Example 2 with 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;
}
Also used : ScheduleResult(org.smartdata.model.action.ScheduleResult) AtomicLong(java.util.concurrent.atomic.AtomicLong) LaunchCmdlet(org.smartdata.protocol.message.LaunchCmdlet) CmdletStatus(org.smartdata.protocol.message.CmdletStatus) CmdletInfo(org.smartdata.model.CmdletInfo)

Aggregations

AtomicLong (java.util.concurrent.atomic.AtomicLong)2 ScheduleResult (org.smartdata.model.action.ScheduleResult)2 ActionInfo (org.smartdata.model.ActionInfo)1 CmdletInfo (org.smartdata.model.CmdletInfo)1 LaunchAction (org.smartdata.model.LaunchAction)1 ActionScheduler (org.smartdata.model.action.ActionScheduler)1 CmdletStatus (org.smartdata.protocol.message.CmdletStatus)1 LaunchCmdlet (org.smartdata.protocol.message.LaunchCmdlet)1