Search in sources :

Example 6 with CmdletInfo

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());
        }
    }
}
Also used : CmdletManager(org.smartdata.server.engine.CmdletManager) CmdletState(org.smartdata.model.CmdletState) CmdletInfo(org.smartdata.model.CmdletInfo) IOException(java.io.IOException)

Example 7 with CmdletInfo

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

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);
        }
    }
}
Also used : CmdletStatus(org.smartdata.protocol.message.CmdletStatus) CmdletInfo(org.smartdata.model.CmdletInfo)

Example 9 with CmdletInfo

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);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) CmdletInfo(org.smartdata.model.CmdletInfo)

Example 10 with CmdletInfo

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
    }
}
Also used : ActionScheduler(org.smartdata.model.action.ActionScheduler) ActionInfo(org.smartdata.model.ActionInfo) CmdletInfo(org.smartdata.model.CmdletInfo)

Aggregations

CmdletInfo (org.smartdata.model.CmdletInfo)37 Test (org.junit.Test)18 ActionInfo (org.smartdata.model.ActionInfo)16 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 HashMap (java.util.HashMap)4 MetaStore (org.smartdata.metastore.MetaStore)3 CmdletDescriptor (org.smartdata.model.CmdletDescriptor)3 CmdletState (org.smartdata.model.CmdletState)3 RuleInfo (org.smartdata.model.RuleInfo)3 CmdletStatus (org.smartdata.protocol.message.CmdletStatus)3 ServiceException (com.google.protobuf.ServiceException)2 ParseException (java.text.ParseException)2 SmartAdmin (org.smartdata.admin.SmartAdmin)2 QueueFullException (org.smartdata.exception.QueueFullException)2 MetaStoreException (org.smartdata.metastore.MetaStoreException)2 FileInfo (org.smartdata.model.FileInfo)2 CmdletInfoProto (org.smartdata.protocol.AdminServerProto.CmdletInfoProto)2 ActionStatus (org.smartdata.protocol.message.ActionStatus)2