Search in sources :

Example 6 with MetaStoreException

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);
    }
}
Also used : MetaStoreException(org.smartdata.metastore.MetaStoreException) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActionSchedulerService(org.smartdata.hdfs.scheduler.ActionSchedulerService) IOException(java.io.IOException)

Example 7 with MetaStoreException

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);
            }
        }
    }
}
Also used : MetaStoreException(org.smartdata.metastore.MetaStoreException) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActionInfo(org.smartdata.model.ActionInfo) CmdletInfo(org.smartdata.model.CmdletInfo) ActionException(org.smartdata.action.ActionException) ParseException(java.text.ParseException) MetaStoreException(org.smartdata.metastore.MetaStoreException) IOException(java.io.IOException) QueueFullException(org.smartdata.exception.QueueFullException) LinkedList(java.util.LinkedList)

Example 8 with MetaStoreException

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);
    }
}
Also used : MetaStoreException(org.smartdata.metastore.MetaStoreException) IOException(java.io.IOException)

Example 9 with MetaStoreException

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);
    }
}
Also used : MetaStoreException(org.smartdata.metastore.MetaStoreException) ActionInfo(org.smartdata.model.ActionInfo) IOException(java.io.IOException)

Example 10 with MetaStoreException

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);
    }
}
Also used : MetaStoreException(org.smartdata.metastore.MetaStoreException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActionInfo(org.smartdata.model.ActionInfo) IOException(java.io.IOException)

Aggregations

MetaStoreException (org.smartdata.metastore.MetaStoreException)35 IOException (java.io.IOException)19 FileInfo (org.smartdata.model.FileInfo)9 ArrayList (java.util.ArrayList)8 SQLException (java.sql.SQLException)7 InvalidPropertiesFormatException (java.util.InvalidPropertiesFormatException)7 HashMap (java.util.HashMap)5 Statement (java.sql.Statement)4 SmartFilePermission (org.smartdata.SmartFilePermission)4 ActionInfo (org.smartdata.model.ActionInfo)4 Gson (com.google.gson.Gson)3 ResultSet (java.sql.ResultSet)3 LinkedHashMap (java.util.LinkedHashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 TypeToken (com.google.gson.reflect.TypeToken)2 File (java.io.File)2 ParseException (java.text.ParseException)2 Map (java.util.Map)2 CmdletDescriptor (org.smartdata.model.CmdletDescriptor)2