Search in sources :

Example 1 with LaunchCmdlet

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

the class CmdletDispatcher method onCmdletFinished.

public void onCmdletFinished(long cmdletId) {
    synchronized (dispatchedToSrvs) {
        if (dispatchedToSrvs.containsKey(cmdletId)) {
            LaunchCmdlet cmdlet = idToLaunchCmdlet.get(cmdletId);
            if (cmdlet == null) {
                return;
            }
            if (regNodes.get(cmdlet.getNodeId()) != null) {
                regNodes.get(cmdlet.getNodeId()).incrementAndGet();
            }
            NodeCmdletMetrics metrics = regNodeInfos.get(cmdlet.getNodeId());
            if (metrics != null) {
                metrics.finishCmdlet();
            }
            ExecutorType t = dispatchedToSrvs.remove(cmdletId);
            updateSlotsLeft(t.ordinal(), 1);
            completeOn[t.ordinal()] = cmdlet.getNodeId();
        }
    }
}
Also used : ActiveServerNodeCmdletMetrics(org.smartdata.server.cluster.ActiveServerNodeCmdletMetrics) NodeCmdletMetrics(org.smartdata.server.cluster.NodeCmdletMetrics) ExecutorType(org.smartdata.model.ExecutorType) LaunchCmdlet(org.smartdata.protocol.message.LaunchCmdlet)

Example 2 with LaunchCmdlet

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

the class CmdletFactory method createCmdlet.

public Cmdlet createCmdlet(LaunchCmdlet launchCmdlet) throws ActionException {
    List<SmartAction> actions = new ArrayList<>();
    int idx = 0;
    for (LaunchAction action : launchCmdlet.getLaunchActions()) {
        idx++;
        actions.add(createAction(launchCmdlet.getCmdletId(), idx == launchCmdlet.getLaunchActions().size(), action));
    }
    Cmdlet cmdlet = new Cmdlet(actions);
    cmdlet.setId(launchCmdlet.getCmdletId());
    return cmdlet;
}
Also used : LaunchCmdlet(org.smartdata.protocol.message.LaunchCmdlet) LaunchAction(org.smartdata.model.LaunchAction) ArrayList(java.util.ArrayList) SmartAction(org.smartdata.action.SmartAction)

Example 3 with LaunchCmdlet

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

Example 4 with LaunchCmdlet

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

the class CmdletManager method syncCmdAction.

/**
 * Insert cmdletinfo and actions to metastore and cache.
 *
 * @param cmdletInfo
 * @param actionInfos
 * @throws IOException
 */
private void syncCmdAction(CmdletInfo cmdletInfo, List<ActionInfo> actionInfos) throws IOException {
    LOG.debug("Cache cmd {}", cmdletInfo);
    for (ActionInfo actionInfo : actionInfos) {
        idToActions.put(actionInfo.getActionId(), actionInfo);
    }
    idToCmdlets.put(cmdletInfo.getCid(), cmdletInfo);
    if (cmdletInfo.getState() == CmdletState.PENDING) {
        numCmdletsGen.incrementAndGet();
        cacheCmd.put(cmdletInfo.getCid(), cmdletInfo);
        synchronized (pendingCmdlet) {
            pendingCmdlet.add(cmdletInfo.getCid());
        }
    } else if (cmdletInfo.getState() == CmdletState.DISPATCHED) {
        runningCmdlets.add(cmdletInfo.getCid());
        LaunchCmdlet launchCmdlet = createLaunchCmdlet(cmdletInfo);
        idToLaunchCmdlet.put(cmdletInfo.getCid(), launchCmdlet);
    }
}
Also used : LaunchCmdlet(org.smartdata.protocol.message.LaunchCmdlet) ActionInfo(org.smartdata.model.ActionInfo)

Example 5 with LaunchCmdlet

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

the class CmdletManager method createLaunchCmdlet.

private LaunchCmdlet createLaunchCmdlet(CmdletInfo cmdletInfo) {
    if (cmdletInfo == null) {
        return null;
    }
    Map<String, String> args;
    List<LaunchAction> launchActions = new ArrayList<>();
    for (Long aid : cmdletInfo.getAids()) {
        if (idToActions.containsKey(aid)) {
            ActionInfo toLaunch = idToActions.get(aid);
            args = new HashMap<>();
            args.putAll(toLaunch.getArgs());
            launchActions.add(new LaunchAction(toLaunch.getActionId(), toLaunch.getActionName(), args));
        }
    }
    return new LaunchCmdlet(cmdletInfo.getCid(), launchActions);
}
Also used : LaunchAction(org.smartdata.model.LaunchAction) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) LaunchCmdlet(org.smartdata.protocol.message.LaunchCmdlet) ActionInfo(org.smartdata.model.ActionInfo)

Aggregations

LaunchCmdlet (org.smartdata.protocol.message.LaunchCmdlet)6 ArrayList (java.util.ArrayList)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 ActionInfo (org.smartdata.model.ActionInfo)2 LaunchAction (org.smartdata.model.LaunchAction)2 SmartAction (org.smartdata.action.SmartAction)1 CmdletInfo (org.smartdata.model.CmdletInfo)1 ExecutorType (org.smartdata.model.ExecutorType)1 ScheduleResult (org.smartdata.model.action.ScheduleResult)1 CmdletStatus (org.smartdata.protocol.message.CmdletStatus)1 ActiveServerNodeCmdletMetrics (org.smartdata.server.cluster.ActiveServerNodeCmdletMetrics)1 NodeCmdletMetrics (org.smartdata.server.cluster.NodeCmdletMetrics)1