use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.
the class CmdletManager method scheduleCmdletActions.
private ScheduleResult scheduleCmdletActions(CmdletInfo info, LaunchCmdlet launchCmdlet) {
List<Long> actIds = info.getAids();
int idx = 0;
int schIdx = 0;
ActionInfo actionInfo;
LaunchAction launchAction;
List<ActionScheduler> actSchedulers;
boolean skipped = false;
ScheduleResult scheduleResult = ScheduleResult.SUCCESS_NO_EXECUTION;
ScheduleResult resultTmp;
for (idx = 0; idx < actIds.size(); idx++) {
actionInfo = idToActions.get(actIds.get(idx));
launchAction = launchCmdlet.getLaunchActions().get(idx);
actSchedulers = schedulers.get(actionInfo.getActionName());
if (actSchedulers == null || actSchedulers.size() == 0) {
skipped = true;
continue;
}
for (schIdx = 0; schIdx < actSchedulers.size(); schIdx++) {
ActionScheduler s = actSchedulers.get(schIdx);
try {
resultTmp = s.onSchedule(info, actionInfo, launchCmdlet, launchAction, idx);
} catch (Throwable t) {
actionInfo.appendLogLine("\nOnSchedule exception: " + t);
resultTmp = ScheduleResult.FAIL;
}
if (resultTmp != ScheduleResult.SUCCESS && resultTmp != ScheduleResult.SUCCESS_NO_EXECUTION) {
scheduleResult = resultTmp;
} else {
if (scheduleResult == ScheduleResult.SUCCESS_NO_EXECUTION) {
scheduleResult = resultTmp;
}
}
if (scheduleResult != ScheduleResult.SUCCESS && scheduleResult != ScheduleResult.SUCCESS_NO_EXECUTION) {
break;
}
}
if (scheduleResult != ScheduleResult.SUCCESS && scheduleResult != ScheduleResult.SUCCESS_NO_EXECUTION) {
break;
}
}
if (scheduleResult == ScheduleResult.SUCCESS || scheduleResult == ScheduleResult.SUCCESS_NO_EXECUTION) {
idx--;
schIdx--;
if (skipped) {
scheduleResult = ScheduleResult.SUCCESS;
}
}
postscheduleCmdletActions(info, actIds, scheduleResult, idx, schIdx);
return scheduleResult;
}
use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.
the class CmdletManager method searchAction.
public ActionGroup searchAction(String path, long pageIndex, long numPerPage, List<String> orderBy, List<Boolean> isDesc) throws IOException {
try {
if (pageIndex == Long.parseLong("0")) {
if (tmpActions.totalNumOfActions != 0) {
return tmpActions;
} else {
pageIndex = 1;
}
}
long[] total = new long[1];
List<ActionInfo> infos = metaStore.searchAction(path, (pageIndex - 1) * numPerPage, numPerPage, orderBy, isDesc, total);
for (ActionInfo info : infos) {
LOG.debug("[metaStore search] " + info.getActionName());
ActionInfo memInfo = idToActions.get(info.getActionId());
if (memInfo != null) {
info.setCreateTime(memInfo.getCreateTime());
info.setProgress(memInfo.getProgress());
}
}
tmpActions = new ActionGroup(infos, total[0]);
return tmpActions;
} catch (MetaStoreException e) {
LOG.error("Search [ {} ], Get Finished Actions by search from DB error", path, e);
throw new IOException(e);
}
}
use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.
the class CmdletManager method listNewCreatedActions.
public List<ActionInfo> listNewCreatedActions(int actionNum) throws IOException {
try {
Map<Long, ActionInfo> actionInfos = new HashMap<>();
for (ActionInfo info : metaStore.getNewCreatedActions(actionNum)) {
actionInfos.put(info.getActionId(), info);
}
actionInfos.putAll(idToActions);
return Lists.newArrayList(actionInfos.values());
} catch (MetaStoreException e) {
LOG.error("Get Finished Actions from DB error", e);
throw new IOException(e);
}
}
use of org.smartdata.model.ActionInfo 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
}
}
use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.
the class CmdletManager method reloadCmdletsInDB.
private void reloadCmdletsInDB() throws IOException {
LOG.info("reloading the dispatched and pending cmdlets in DB.");
List<CmdletInfo> cmdletInfos;
try {
cmdletInfos = metaStore.getCmdlets(CmdletState.DISPATCHED);
if (cmdletInfos != null && cmdletInfos.size() != 0) {
for (CmdletInfo cmdletInfo : cmdletInfos) {
// track reload cmdlets
CmdletDescriptor cmdletDescriptor = CmdletDescriptor.fromCmdletString(cmdletInfo.getParameters());
cmdletDescriptor.setRuleId(cmdletInfo.getRid());
tracker.track(cmdletInfo.getCid(), cmdletDescriptor);
List<ActionInfo> actionInfos = getActions(cmdletInfo.getAids());
for (ActionInfo actionInfo : actionInfos) {
actionInfo.setCreateTime(cmdletInfo.getGenerateTime());
actionInfo.setFinishTime(System.currentTimeMillis());
// Recover scheduler status according to dispatched action.
recoverSchedulerStatus(actionInfo);
}
syncCmdAction(cmdletInfo, actionInfos);
}
}
cmdletInfos = metaStore.getCmdlets(CmdletState.PENDING);
if (cmdletInfos != null && cmdletInfos.size() != 0) {
for (CmdletInfo cmdletInfo : cmdletInfos) {
CmdletDescriptor cmdletDescriptor = CmdletDescriptor.fromCmdletString(cmdletInfo.getParameters());
cmdletDescriptor.setRuleId(cmdletInfo.getRid());
// Pending task also needs to be tracked.
tracker.track(cmdletInfo.getCid(), cmdletDescriptor);
LOG.debug(String.format("Reload pending cmdlet: {}", cmdletInfo));
List<ActionInfo> actionInfos = getActions(cmdletInfo.getAids());
syncCmdAction(cmdletInfo, actionInfos);
}
}
} catch (MetaStoreException e) {
LOG.error("DB connection error occurs when ssm is reloading cmdlets!");
return;
} catch (ParseException pe) {
LOG.error("Failed to parse cmdlet string for tracking task", pe);
}
}
Aggregations