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);
}
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);
}
}
}
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);
}
}
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.");
}
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();
}
Aggregations