Search in sources :

Example 1 with RuleInfoRepo

use of org.smartdata.server.engine.rule.RuleInfoRepo in project SSM by Intel-bigdata.

the class RuleManager method updateRuleInfo.

public void updateRuleInfo(long ruleId, RuleState rs, long lastCheckTime, long checkedCount, int cmdletsGen) throws IOException {
    RuleInfoRepo infoRepo = checkIfExists(ruleId);
    infoRepo.updateRuleInfo(rs, lastCheckTime, checkedCount, cmdletsGen);
}
Also used : RuleInfoRepo(org.smartdata.server.engine.rule.RuleInfoRepo)

Example 2 with RuleInfoRepo

use of org.smartdata.server.engine.rule.RuleInfoRepo in project SSM by Intel-bigdata.

the class RuleManager method init.

/**
 * Init RuleManager, this includes: 1. Load related data from local storage or HDFS 2. Initial
 *
 * @throws IOException
 */
@Override
public void init() throws IOException {
    LOG.info("Initializing ...");
    // Load rules table
    List<RuleInfo> rules = null;
    try {
        rules = metaStore.getRuleInfo();
    } catch (MetaStoreException e) {
        LOG.error("Can not load rules from database:\n" + e.getMessage());
    }
    for (RuleInfo rule : rules) {
        mapRules.put(rule.getId(), new RuleInfoRepo(rule, metaStore, serverContext.getConf()));
    }
    LOG.info("Initialized. Totally " + rules.size() + " rules loaded from DataBase.");
    if (LOG.isDebugEnabled()) {
        for (RuleInfo info : rules) {
            LOG.debug("\t" + info);
        }
    }
}
Also used : RuleInfoRepo(org.smartdata.server.engine.rule.RuleInfoRepo) MetaStoreException(org.smartdata.metastore.MetaStoreException) DetailedRuleInfo(org.smartdata.model.DetailedRuleInfo) RuleInfo(org.smartdata.model.RuleInfo)

Example 3 with RuleInfoRepo

use of org.smartdata.server.engine.rule.RuleInfoRepo in project SSM by Intel-bigdata.

the class RuleManager method disableRule.

public void disableRule(long ruleID, boolean dropPendingCmdlets) throws IOException {
    RuleInfoRepo infoRepo = checkIfExists(ruleID);
    infoRepo.disable();
    if (dropPendingCmdlets && getCmdletManager() != null) {
        getCmdletManager().dropRuleCmdlets(ruleID);
    }
}
Also used : RuleInfoRepo(org.smartdata.server.engine.rule.RuleInfoRepo)

Example 4 with RuleInfoRepo

use of org.smartdata.server.engine.rule.RuleInfoRepo in project SSM by Intel-bigdata.

the class RuleManager method start.

/**
 * Start services.
 */
@Override
public void start() throws IOException {
    LOG.info("Starting ...");
    // after StateManager be ready
    int numLaunched = 0;
    // Submit runnable rules to scheduler
    for (RuleInfoRepo infoRepo : mapRules.values()) {
        RuleInfo rule = infoRepo.getRuleInfoRef();
        if (rule.getState() == RuleState.ACTIVE || rule.getState() == RuleState.DRYRUN) {
            RuleExecutor ruleExecutor = infoRepo.launchExecutor(this);
            TranslateResult tr = ruleExecutor.getTranslateResult();
            TimeBasedScheduleInfo si = tr.getTbScheduleInfo();
            if (rule.getLastCheckTime() != 0) {
                si.setFirstCheckTime(rule.getLastCheckTime());
            }
            boolean sub = submitRuleToScheduler(ruleExecutor);
            numLaunched += sub ? 1 : 0;
        }
    }
    LOG.info("Started. " + numLaunched + " rules launched for execution.");
}
Also used : RuleInfoRepo(org.smartdata.server.engine.rule.RuleInfoRepo) RuleExecutor(org.smartdata.server.engine.rule.RuleExecutor) TranslateResult(org.smartdata.model.rule.TranslateResult) DetailedRuleInfo(org.smartdata.model.DetailedRuleInfo) RuleInfo(org.smartdata.model.RuleInfo) TimeBasedScheduleInfo(org.smartdata.model.rule.TimeBasedScheduleInfo)

Example 5 with RuleInfoRepo

use of org.smartdata.server.engine.rule.RuleInfoRepo in project SSM by Intel-bigdata.

the class RuleManager method submitRule.

/**
 * Submit a rule to RuleManger.
 *
 * @param rule
 * @param initState
 * @return
 * @throws IOException
 */
public long submitRule(String rule, RuleState initState) throws IOException {
    LOG.debug("Received Rule -> [" + rule + "]");
    if (initState != RuleState.ACTIVE && initState != RuleState.DISABLED && initState != RuleState.DRYRUN) {
        throw new IOException("Invalid initState = " + initState + ", it MUST be one of [" + RuleState.ACTIVE + ", " + RuleState.DRYRUN + ", " + RuleState.DISABLED + "]");
    }
    TranslateResult tr = doCheckRule(rule, null);
    doCheckActions(tr.getCmdDescriptor());
    // check whitelist
    if (WhitelistHelper.isEnabled(serverContext.getConf())) {
        for (String path : tr.getGlobPathCheck()) {
            if (!WhitelistHelper.isInWhitelist(path, serverContext.getConf())) {
                throw new IOException("Path " + path + " is not in the whitelist.");
            }
        }
    }
    RuleInfo.Builder builder = RuleInfo.newBuilder();
    builder.setRuleText(rule).setState(initState);
    RuleInfo ruleInfo = builder.build();
    RulePluginManager.onAddingNewRule(ruleInfo, tr);
    try {
        metaStore.insertNewRule(ruleInfo);
    } catch (MetaStoreException e) {
        throw new IOException("RuleText = " + rule, e);
    }
    RuleInfoRepo infoRepo = new RuleInfoRepo(ruleInfo, metaStore, serverContext.getConf());
    mapRules.put(ruleInfo.getId(), infoRepo);
    submitRuleToScheduler(infoRepo.launchExecutor(this));
    RulePluginManager.onNewRuleAdded(ruleInfo, tr);
    return ruleInfo.getId();
}
Also used : RuleInfoRepo(org.smartdata.server.engine.rule.RuleInfoRepo) MetaStoreException(org.smartdata.metastore.MetaStoreException) TranslateResult(org.smartdata.model.rule.TranslateResult) IOException(java.io.IOException) DetailedRuleInfo(org.smartdata.model.DetailedRuleInfo) RuleInfo(org.smartdata.model.RuleInfo)

Aggregations

RuleInfoRepo (org.smartdata.server.engine.rule.RuleInfoRepo)7 DetailedRuleInfo (org.smartdata.model.DetailedRuleInfo)4 RuleInfo (org.smartdata.model.RuleInfo)4 MetaStoreException (org.smartdata.metastore.MetaStoreException)2 TranslateResult (org.smartdata.model.rule.TranslateResult)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 TimeBasedScheduleInfo (org.smartdata.model.rule.TimeBasedScheduleInfo)1 RuleExecutor (org.smartdata.server.engine.rule.RuleExecutor)1