use of org.smartdata.model.RuleInfo 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.model.RuleInfo 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.model.RuleInfo 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();
}
use of org.smartdata.model.RuleInfo in project SSM by Intel-bigdata.
the class TestMetaStore method testMoveSyncRules.
@Test
public void testMoveSyncRules() throws Exception {
String pathString = "/src/1";
long length = 123L;
boolean isDir = false;
int blockReplication = 1;
long blockSize = 128 * 1024L;
long modTime = 123123123L;
long accessTime = 123123120L;
String owner = "root";
String group = "admin";
long fileId = 56L;
byte storagePolicy = 0;
byte erasureCodingPolicy = 0;
FileInfo fileInfo = new FileInfo(pathString, fileId, length, isDir, (short) blockReplication, blockSize, modTime, accessTime, (short) 1, owner, group, storagePolicy, erasureCodingPolicy);
metaStore.insertFile(fileInfo);
Map<String, String> args = new HashMap();
args.put("-file", "/src/1");
String rule = "file : accessCount(10m) > 20 \n\n" + "and length() > 3 | ";
long submitTime = System.currentTimeMillis();
RuleInfo ruleInfo = new RuleInfo(0, submitTime, rule + "sync -dest /dest/", RuleState.ACTIVE, 0, 0, 0);
metaStore.insertNewRule(ruleInfo);
metaStore.insertBackUpInfo(new BackUpInfo(ruleInfo.getId(), "/src/", "/dest/", 100));
metaStore.insertNewRule(new RuleInfo(1, submitTime, rule + "allssd", RuleState.ACTIVE, 0, 0, 0));
metaStore.insertNewRule(new RuleInfo(2, submitTime, rule + "archive", RuleState.ACTIVE, 0, 0, 0));
metaStore.insertNewRule(new RuleInfo(2, submitTime, rule + "onessd", RuleState.ACTIVE, 0, 0, 0));
metaStore.insertNewRule(new RuleInfo(2, submitTime, rule + "cache", RuleState.ACTIVE, 0, 0, 0));
Assert.assertTrue(metaStore.listMoveRules().size() == 3);
Assert.assertTrue(metaStore.listSyncRules().size() == 1);
CmdletInfo cmdletInfo = new CmdletInfo(1, ruleInfo.getId(), CmdletState.EXECUTING, "test", 123123333L, 232444444L);
cmdletInfo.setAids(Collections.singletonList(1L));
metaStore.insertCmdlet(cmdletInfo);
metaStore.insertAction(new ActionInfo(1, 1, "allssd", args, "Test", "Test", true, 123213213L, true, 123123L, 100));
Assert.assertTrue(metaStore.listFileActions(ruleInfo.getId(), 0).size() >= 0);
}
use of org.smartdata.model.RuleInfo in project SSM by Intel-bigdata.
the class TestMetaStore method testInsertRule.
@Test
public void testInsertRule() throws Exception {
String rule = "file : accessCount(10m) > 20 \n\n" + "and length() > 3 | cache";
long submitTime = System.currentTimeMillis();
RuleInfo info1 = new RuleInfo(0, submitTime, rule, RuleState.ACTIVE, 0, 0, 0);
Assert.assertTrue(metaStore.insertNewRule(info1));
RuleInfo info11 = metaStore.getRuleInfo(info1.getId());
Assert.assertTrue(info1.equals(info11));
long now = System.currentTimeMillis();
metaStore.updateRuleInfo(info1.getId(), RuleState.DELETED, now, 1, 1);
info1.setState(RuleState.DELETED);
info1.setLastCheckTime(now);
info1.setNumChecked(1);
info1.setNumCmdsGen(1);
RuleInfo info12 = metaStore.getRuleInfo(info1.getId());
Assert.assertTrue(info12.equals(info1));
RuleInfo info2 = new RuleInfo(0, submitTime, rule, RuleState.ACTIVE, 0, 0, 0);
Assert.assertTrue(metaStore.insertNewRule(info2));
RuleInfo info21 = metaStore.getRuleInfo(info2.getId());
Assert.assertFalse(info11.equals(info21));
List<RuleInfo> infos = metaStore.getRuleInfo();
Assert.assertTrue(infos.size() == 2);
}
Aggregations