Search in sources :

Example 1 with CmdletStatus

use of org.smartdata.protocol.message.CmdletStatus in project SSM by Intel-bigdata.

the class CmdletManager method disableCmdlet.

public void disableCmdlet(long cid) throws IOException {
    if (idToCmdlets.containsKey(cid)) {
        CmdletInfo info = idToCmdlets.get(cid);
        onCmdletStatusUpdate(new CmdletStatus(info.getCid(), System.currentTimeMillis(), CmdletState.DISABLED));
        synchronized (pendingCmdlet) {
            if (pendingCmdlet.contains(cid)) {
                pendingCmdlet.remove(cid);
            }
        }
        if (schedulingCmdlet.contains(cid)) {
            schedulingCmdlet.remove(cid);
        }
        if (scheduledCmdlet.contains(cid)) {
            scheduledCmdlet.remove(cid);
        }
        // Wait status update from status reporter, so need to update to MetaStore
        if (runningCmdlets.contains(cid)) {
            dispatcher.stopCmdlet(cid);
        }
    }
}
Also used : CmdletStatus(org.smartdata.protocol.message.CmdletStatus) CmdletInfo(org.smartdata.model.CmdletInfo)

Example 2 with CmdletStatus

use of org.smartdata.protocol.message.CmdletStatus in project SSM by Intel-bigdata.

the class CmdletDispatcher method updateCmdActionStatus.

private void updateCmdActionStatus(LaunchCmdlet cmdlet, String host) {
    if (cmdletManager != null) {
        try {
            cmdletManager.updateCmdletExecHost(cmdlet.getCmdletId(), host);
        } catch (IOException e) {
        // Ignore this
        }
    }
    try {
        LaunchAction action;
        ActionStatus actionStatus;
        for (int i = 0; i < cmdlet.getLaunchActions().size(); i++) {
            action = cmdlet.getLaunchActions().get(i);
            actionStatus = new ActionStatus(cmdlet.getCmdletId(), i == cmdlet.getLaunchActions().size() - 1, action.getActionId(), System.currentTimeMillis());
            cmdletManager.onActionStatusUpdate(actionStatus);
        }
        CmdletStatus cmdletStatus = new CmdletStatus(cmdlet.getCmdletId(), System.currentTimeMillis(), CmdletState.DISPATCHED);
        cmdletManager.onCmdletStatusUpdate(cmdletStatus);
    } catch (IOException e) {
        LOG.info("update status failed.", e);
    } catch (ActionException e) {
        LOG.info("update action status failed.", e);
    }
}
Also used : LaunchAction(org.smartdata.model.LaunchAction) ActionException(org.smartdata.action.ActionException) CmdletStatus(org.smartdata.protocol.message.CmdletStatus) IOException(java.io.IOException) ActionStatus(org.smartdata.protocol.message.ActionStatus)

Example 3 with CmdletStatus

use of org.smartdata.protocol.message.CmdletStatus in project SSM by Intel-bigdata.

the class CmdletManager method inferCmdletStatus.

private void inferCmdletStatus(ActionInfo actionInfo) throws IOException, ActionException {
    if (actionInfo == null) {
        return;
    }
    if (!actionInfo.isFinished()) {
        return;
    }
    long actionId = actionInfo.getActionId();
    long cmdletId = actionInfo.getCmdletId();
    CmdletInfo cmdletInfo = idToCmdlets.get(cmdletId);
    List<Long> aids = cmdletInfo.getAids();
    int index = aids.indexOf(actionId);
    if (!actionInfo.isSuccessful()) {
        for (int i = index + 1; i < aids.size(); i++) {
            // Use current action's finish time to set start/finish time for
            // subsequent action(s).
            ActionStatus actionStatus = ActionStatusFactory.createSkipActionStatus(cmdletId, i == aids.size() - 1, aids.get(i), actionInfo.getFinishTime(), actionInfo.getFinishTime());
            onActionStatusUpdate(actionStatus);
        }
        CmdletStatus cmdletStatus = new CmdletStatus(cmdletId, actionInfo.getFinishTime(), CmdletState.FAILED);
        onCmdletStatusUpdate(cmdletStatus);
    } else {
        if (index == aids.size() - 1) {
            CmdletStatus cmdletStatus = new CmdletStatus(cmdletId, actionInfo.getFinishTime(), CmdletState.DONE);
            onCmdletStatusUpdate(cmdletStatus);
        }
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CmdletStatus(org.smartdata.protocol.message.CmdletStatus) CmdletInfo(org.smartdata.model.CmdletInfo) ActionStatus(org.smartdata.protocol.message.ActionStatus)

Example 4 with CmdletStatus

use of org.smartdata.protocol.message.CmdletStatus 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

CmdletStatus (org.smartdata.protocol.message.CmdletStatus)4 CmdletInfo (org.smartdata.model.CmdletInfo)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 ActionStatus (org.smartdata.protocol.message.ActionStatus)2 IOException (java.io.IOException)1 ActionException (org.smartdata.action.ActionException)1 LaunchAction (org.smartdata.model.LaunchAction)1 ScheduleResult (org.smartdata.model.action.ScheduleResult)1 LaunchCmdlet (org.smartdata.protocol.message.LaunchCmdlet)1