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();
}
}
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations