Search in sources :

Example 16 with RuleInfo

use of org.smartdata.model.RuleInfo in project SSM by Intel-bigdata.

the class ServerProtocolsServerSideTranslator method listRulesInfo.

@Override
public ListRulesInfoResponseProto listRulesInfo(RpcController controller, ListRulesInfoRequestProto req) throws ServiceException {
    try {
        List<RuleInfo> infos = server.listRulesInfo();
        List<RuleInfoProto> infoProtos = new ArrayList<>();
        for (RuleInfo info : infos) {
            infoProtos.add(ProtoBufferHelper.convert(info));
        }
        return ListRulesInfoResponseProto.newBuilder().addAllRulesInfo(infoProtos).build();
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.google.protobuf.ServiceException) ArrayList(java.util.ArrayList) RuleInfoProto(org.smartdata.protocol.AdminServerProto.RuleInfoProto) IOException(java.io.IOException) RuleInfo(org.smartdata.model.RuleInfo)

Example 17 with RuleInfo

use of org.smartdata.model.RuleInfo in project SSM by Intel-bigdata.

the class RuleManager method listRulesInfo.

public List<RuleInfo> listRulesInfo() throws IOException {
    Collection<RuleInfoRepo> infoRepos = mapRules.values();
    List<RuleInfo> retInfos = new ArrayList<>();
    for (RuleInfoRepo infoRepo : infoRepos) {
        RuleInfo info = infoRepo.getRuleInfo();
        if (info.getState() != RuleState.DELETED) {
            retInfos.add(info);
        }
    }
    return retInfos;
}
Also used : RuleInfoRepo(org.smartdata.server.engine.rule.RuleInfoRepo) ArrayList(java.util.ArrayList) DetailedRuleInfo(org.smartdata.model.DetailedRuleInfo) RuleInfo(org.smartdata.model.RuleInfo)

Example 18 with RuleInfo

use of org.smartdata.model.RuleInfo in project SSM by Intel-bigdata.

the class RuleInfoRepo method getRuleInfo.

public RuleInfo getRuleInfo() {
    lockRead();
    RuleInfo ret = ruleInfo.newCopy();
    unlockRead();
    return ret;
}
Also used : RuleInfo(org.smartdata.model.RuleInfo)

Example 19 with RuleInfo

use of org.smartdata.model.RuleInfo in project SSM by Intel-bigdata.

the class RuleExecutor method run.

@Override
public void run() {
    long startCheckTime = System.currentTimeMillis();
    if (exited) {
        exitSchedule();
    }
    if (!tr.getTbScheduleInfo().isExecutable(startCheckTime)) {
        return;
    }
    List<RuleExecutorPlugin> plugins = RuleExecutorPluginManager.getPlugins();
    long rid = ctx.getRuleId();
    try {
        if (ruleManager.isClosed()) {
            exitSchedule();
        }
        long endCheckTime;
        int numCmdSubmitted = 0;
        List<String> files = new ArrayList<>();
        RuleInfo info = ruleManager.getRuleInfo(rid);
        boolean doExec = true;
        for (RuleExecutorPlugin plugin : plugins) {
            doExec &= plugin.preExecution(info, tr);
            if (!doExec) {
                break;
            }
        }
        RuleState state = info.getState();
        if (exited || state == RuleState.DELETED || state == RuleState.FINISHED || state == RuleState.DISABLED) {
            exitSchedule();
        }
        TimeBasedScheduleInfo scheduleInfo = tr.getTbScheduleInfo();
        if (!scheduleInfo.isOnce() && scheduleInfo.getEndTime() != TimeBasedScheduleInfo.FOR_EVER) {
            boolean befExit = false;
            if (scheduleInfo.isOneShot()) {
                // The subScheduleTime is set in triggering time.
                if (scheduleInfo.getSubScheduleTime() > scheduleInfo.getEndTime()) {
                    befExit = true;
                }
            } else if (startCheckTime - scheduleInfo.getEndTime() > 0) {
                befExit = true;
            }
            if (befExit) {
                LOG.info("Rule " + ctx.getRuleId() + " exit rule executor due to time passed");
                ruleManager.updateRuleInfo(rid, RuleState.FINISHED, startCheckTime, 0, 0);
                exitSchedule();
            }
        }
        if (doExec) {
            files = executeFileRuleQuery();
            if (exited) {
                exitSchedule();
            }
        }
        endCheckTime = System.currentTimeMillis();
        if (doExec) {
            for (RuleExecutorPlugin plugin : plugins) {
                files = plugin.preSubmitCmdlet(info, files);
            }
            numCmdSubmitted = submitCmdlets(info, files);
        }
        ruleManager.updateRuleInfo(rid, null, startCheckTime, 1, numCmdSubmitted);
        long endProcessTime = System.currentTimeMillis();
        if (endProcessTime - startCheckTime > 2000 || LOG.isDebugEnabled()) {
            LOG.warn("Rule " + ctx.getRuleId() + " execution took " + (endProcessTime - startCheckTime) + "ms. QueryTime = " + (endCheckTime - startCheckTime) + "ms, SubmitTime = " + (endProcessTime - endCheckTime) + "ms, fileNum = " + numCmdSubmitted + ".");
        }
        if (scheduleInfo.isOneShot()) {
            ruleManager.updateRuleInfo(rid, RuleState.FINISHED, startCheckTime, 0, 0);
            exitSchedule();
        }
        if (endProcessTime + scheduleInfo.getBaseEvery() > scheduleInfo.getEndTime()) {
            LOG.info("Rule " + ctx.getRuleId() + " exit rule executor due to finished");
            ruleManager.updateRuleInfo(rid, RuleState.FINISHED, startCheckTime, 0, 0);
            exitSchedule();
        }
        if (exited) {
            exitSchedule();
        }
    } catch (IOException e) {
        LOG.error("Rule " + ctx.getRuleId() + " exception", e);
    }
}
Also used : RuleState(org.smartdata.model.RuleState) ArrayList(java.util.ArrayList) RuleExecutorPlugin(org.smartdata.model.rule.RuleExecutorPlugin) IOException(java.io.IOException) RuleInfo(org.smartdata.model.RuleInfo) TimeBasedScheduleInfo(org.smartdata.model.rule.TimeBasedScheduleInfo)

Example 20 with RuleInfo

use of org.smartdata.model.RuleInfo in project SSM by Intel-bigdata.

the class MetaStore method listMoveRules.

public List<DetailedRuleInfo> listMoveRules() throws MetaStoreException {
    List<RuleInfo> ruleInfos = getRuleInfo();
    List<DetailedRuleInfo> detailedRuleInfos = new ArrayList<>();
    for (RuleInfo ruleInfo : ruleInfos) {
        int lastIndex = ruleInfo.getRuleText().lastIndexOf("|");
        String lastPart = ruleInfo.getRuleText().substring(lastIndex + 1);
        if (lastPart.contains("sync")) {
            continue;
        } else if (lastPart.contains("allssd") || lastPart.contains("onessd") || lastPart.contains("archive") || lastPart.contains("alldisk") || lastPart.contains("onedisk") || lastPart.contains("ramdisk")) {
            DetailedRuleInfo detailedRuleInfo = new DetailedRuleInfo(ruleInfo);
            // Add mover progress
            List<CmdletInfo> cmdletInfos = cmdletDao.getByRid(ruleInfo.getId());
            int currPos = 0;
            for (CmdletInfo cmdletInfo : cmdletInfos) {
                if (cmdletInfo.getState().getValue() <= 4) {
                    break;
                }
                currPos += 1;
            }
            int countRunning = 0;
            for (CmdletInfo cmdletInfo : cmdletInfos) {
                if (cmdletInfo.getState().getValue() <= 4) {
                    countRunning++;
                }
            }
            detailedRuleInfo.setBaseProgress(cmdletInfos.size() - currPos);
            detailedRuleInfo.setRunningProgress(countRunning);
            if (detailedRuleInfo.getState() != RuleState.DELETED) {
                detailedRuleInfos.add(detailedRuleInfo);
            }
        }
    }
    return detailedRuleInfos;
}
Also used : DetailedRuleInfo(org.smartdata.model.DetailedRuleInfo) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DetailedRuleInfo(org.smartdata.model.DetailedRuleInfo) RuleInfo(org.smartdata.model.RuleInfo) CmdletInfo(org.smartdata.model.CmdletInfo)

Aggregations

RuleInfo (org.smartdata.model.RuleInfo)28 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)6 DetailedRuleInfo (org.smartdata.model.DetailedRuleInfo)6 IOException (java.io.IOException)5 SmartAdmin (org.smartdata.admin.SmartAdmin)4 RuleInfoRepo (org.smartdata.server.engine.rule.RuleInfoRepo)4 CmdletInfo (org.smartdata.model.CmdletInfo)3 ServiceException (com.google.protobuf.ServiceException)2 MetaStoreException (org.smartdata.metastore.MetaStoreException)2 ActionInfo (org.smartdata.model.ActionInfo)2 BackUpInfo (org.smartdata.model.BackUpInfo)2 FileInfo (org.smartdata.model.FileInfo)2 TimeBasedScheduleInfo (org.smartdata.model.rule.TimeBasedScheduleInfo)2 TranslateResult (org.smartdata.model.rule.TranslateResult)2 RuleInfoProto (org.smartdata.protocol.AdminServerProto.RuleInfoProto)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Properties (java.util.Properties)1