Search in sources :

Example 1 with RuleInfo

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);
        }
    }
}
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 2 with RuleInfo

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.");
}
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 3 with RuleInfo

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

Example 4 with RuleInfo

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);
}
Also used : FileInfo(org.smartdata.model.FileInfo) HashMap(java.util.HashMap) BackUpInfo(org.smartdata.model.BackUpInfo) ActionInfo(org.smartdata.model.ActionInfo) RuleInfo(org.smartdata.model.RuleInfo) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Example 5 with RuleInfo

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);
}
Also used : RuleInfo(org.smartdata.model.RuleInfo) Test(org.junit.Test)

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