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