use of org.smartdata.model.CmdletInfo in project SSM by Intel-bigdata.
the class TestCompressDecompress method waitTillActionDone.
private void waitTillActionDone(long cmdId) throws Exception {
int n = 0;
while (true) {
Thread.sleep(1000);
CmdletManager cmdletManager = ssm.getCmdletManager();
CmdletInfo info = cmdletManager.getCmdletInfo(cmdId);
if (info == null) {
continue;
}
CmdletState state = info.getState();
if (state == CmdletState.DONE) {
return;
} else if (state == CmdletState.FAILED) {
// Reasonably assume that there is only one action wrapped by a given cmdlet.
long aid = cmdletManager.getCmdletInfo(cmdId).getAids().get(0);
Assert.fail("Action failed. " + cmdletManager.getActionInfo(aid).getLog());
} else {
System.out.println(state);
}
// Wait for 20s.
if (++n == 20) {
throw new Exception("Time out in waiting for cmdlet: " + cmdletManager.getCmdletInfo(cmdId).toString());
}
}
}
use of org.smartdata.model.CmdletInfo in project SSM by Intel-bigdata.
the class CmdletManager method batchSyncCmdAction.
private void batchSyncCmdAction() throws Exception {
if (cacheCmd.size() == 0 && tobeDeletedCmd.size() == 0) {
return;
}
List<CmdletInfo> cmdletInfos = new ArrayList<>();
List<ActionInfo> actionInfos = new ArrayList<>();
List<CmdletInfo> cmdletFinished = new ArrayList<>();
LOG.debug("Number of cached cmds {}", cacheCmd.size());
int todelSize;
synchronized (cacheCmd) {
synchronized (tobeDeletedCmd) {
todelSize = tobeDeletedCmd.size();
for (Long cid : tobeDeletedCmd) {
cacheCmd.remove(cid);
}
}
for (Long cid : cacheCmd.keySet()) {
CmdletInfo cmdletInfo = cacheCmd.remove(cid);
if (cmdletInfo.getState() != CmdletState.DISABLED) {
cmdletInfos.add(cmdletInfo);
for (Long aid : cmdletInfo.getAids()) {
ActionInfo actionInfo = idToActions.get(aid);
if (actionInfo != null) {
actionInfos.add(actionInfo);
}
}
}
if (CmdletState.isTerminalState(cmdletInfo.getState())) {
cmdletFinished.add(cmdletInfo);
}
if (cmdletInfos.size() >= cacheCmdTh) {
break;
}
}
for (CmdletInfo cmdletInfo : cmdletFinished) {
idToCmdlets.remove(cmdletInfo.getCid());
try {
tracker.untrack(cmdletInfo.getCid());
} catch (Exception e) {
LOG.warn("Failed to untrack task!", e);
}
for (Long aid : cmdletInfo.getAids()) {
idToActions.remove(aid);
}
}
}
if (cmdletInfos.size() > 0) {
LOG.debug("Number of cmds {} to submit", cmdletInfos.size());
try {
metaStore.insertActions(actionInfos.toArray(new ActionInfo[actionInfos.size()]));
metaStore.insertCmdlets(cmdletInfos.toArray(new CmdletInfo[cmdletInfos.size()]));
} catch (MetaStoreException e) {
LOG.error("CmdletIds -> [ {} ], submit to DB error", cmdletInfos, e);
}
}
if (todelSize > 0) {
List<Long> del = new LinkedList<>();
synchronized (tobeDeletedCmd) {
del.addAll(tobeDeletedCmd.subList(0, todelSize > cacheCmdTh ? cacheCmdTh : todelSize));
tobeDeletedCmd.removeAll(del);
}
if (del.size() > 0) {
LOG.debug("Number of cmds {} to delete", del.size());
try {
metaStore.batchDeleteCmdlet(del);
metaStore.batchDeleteCmdletActions(del);
} catch (MetaStoreException e) {
LOG.error("CmdletIds -> [ {} ], delete from DB error", del, e);
}
}
}
}
use of org.smartdata.model.CmdletInfo 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.model.CmdletInfo in project SSM by Intel-bigdata.
the class CmdletManager method deleteCmdletByRule.
/**
* Delete all cmdlets related with rid.
* @param rid
* @throws IOException
*/
public void deleteCmdletByRule(long rid) throws IOException {
List<CmdletInfo> cmdletInfoList = listCmdletsInfo(rid, null);
if (cmdletInfoList == null || cmdletInfoList.size() == 0) {
return;
}
List<Long> cids = new ArrayList<>();
for (CmdletInfo cmdletInfo : cmdletInfoList) {
cids.add(cmdletInfo.getCid());
}
batchDeleteCmdlet(cids);
}
use of org.smartdata.model.CmdletInfo in project SSM by Intel-bigdata.
the class CmdletManager method onActionStatusUpdate.
public void onActionStatusUpdate(ActionStatus status) throws IOException, ActionException {
if (status == null) {
return;
}
long actionId = status.getActionId();
if (idToActions.containsKey(actionId)) {
ActionInfo actionInfo = idToActions.get(actionId);
CmdletInfo cmdletInfo = idToCmdlets.get(status.getCmdletId());
synchronized (actionInfo) {
if (!actionInfo.isFinished()) {
actionInfo.setLog(status.getLog());
actionInfo.setResult(status.getResult());
if (!status.isFinished()) {
actionInfo.setProgress(status.getPercentage());
if (actionInfo.getCreateTime() == 0) {
actionInfo.setCreateTime(cmdletInfo.getGenerateTime());
}
actionInfo.setFinishTime(System.currentTimeMillis());
} else {
actionInfo.setProgress(1.0F);
actionInfo.setFinished(true);
actionInfo.setCreateTime(status.getStartTime());
actionInfo.setFinishTime(status.getFinishTime());
if (status.getThrowable() != null) {
actionInfo.setSuccessful(false);
} else {
actionInfo.setSuccessful(true);
updateStorageIfNeeded(actionInfo);
}
int actionIndex = 0;
for (long id : cmdletInfo.getAids()) {
if (id == actionId) {
break;
}
actionIndex++;
}
for (ActionScheduler p : schedulers.get(actionInfo.getActionName())) {
p.onActionFinished(cmdletInfo, actionInfo, actionIndex);
}
}
}
}
} else {
// Updating action info which is not pending or running
}
}
Aggregations