use of org.smartdata.metastore.MetaStoreException in project SSM by Intel-bigdata.
the class CmdletManager method init.
@Override
public void init() throws IOException {
LOG.info("Initializing ...");
try {
maxActionId = new AtomicLong(metaStore.getMaxActionId());
maxCmdletId = new AtomicLong(metaStore.getMaxCmdletId());
numCmdletsFinished.addAndGet(metaStore.getNumCmdletsInTerminiatedStates());
schedulerServices = AbstractServiceFactory.createActionSchedulerServices(getContext().getConf(), (ServerContext) getContext(), metaStore, false);
for (ActionSchedulerService s : schedulerServices) {
s.init();
List<String> actions = s.getSupportedActions();
for (String a : actions) {
schedulers.put(a, s);
}
}
recover();
LOG.info("Initialized.");
} catch (MetaStoreException e) {
LOG.error("DB Connection error! Failed to get Max CmdletId/ActionId!", e);
throw new IOException(e);
} catch (IOException e) {
throw e;
} catch (Throwable t) {
throw new IOException(t);
}
}
use of org.smartdata.metastore.MetaStoreException 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.metastore.MetaStoreException in project SSM by Intel-bigdata.
the class CmdletManager method deleteCmdlet.
public void deleteCmdlet(long cid) throws IOException {
this.disableCmdlet(cid);
try {
metaStore.deleteCmdlet(cid);
metaStore.deleteCmdletActions(cid);
} catch (MetaStoreException e) {
LOG.error("CmdletId -> [ {} ], delete from DB error", cid, e);
throw new IOException(e);
}
}
use of org.smartdata.metastore.MetaStoreException 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.metastore.MetaStoreException 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);
}
}
Aggregations