Search in sources :

Example 6 with RuleInfo

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

the class TestDruid method test.

@Test
public void test() throws Exception {
    InputStream in = getClass().getClassLoader().getResourceAsStream("druid-template.xml");
    Properties p = new Properties();
    p.loadFromXML(in);
    String dbFile = TestDBUtil.getUniqueEmptySqliteDBFile();
    String url = MetaStoreUtils.SQLITE_URL_PREFIX + dbFile;
    p.setProperty("url", url);
    DruidPool druidPool = new DruidPool(p);
    MetaStore adapter = new MetaStore(druidPool);
    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(adapter.insertNewRule(info1));
    RuleInfo info11 = adapter.getRuleInfo(info1.getId());
    Assert.assertTrue(info1.equals(info11));
    long now = System.currentTimeMillis();
    adapter.updateRuleInfo(info1.getId(), RuleState.DELETED, now, 1, 1);
    RuleInfo info12 = adapter.getRuleInfo(info1.getId());
    Assert.assertTrue(info12.getLastCheckTime() == now);
    druidPool.close();
}
Also used : InputStream(java.io.InputStream) Properties(java.util.Properties) RuleInfo(org.smartdata.model.RuleInfo) Test(org.junit.Test)

Example 7 with RuleInfo

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

the class AdminProtocolClientSideTranslator method listRulesInfo.

@Override
public List<RuleInfo> listRulesInfo() throws IOException {
    try {
        ListRulesInfoRequestProto req = ListRulesInfoRequestProto.newBuilder().build();
        List<RuleInfoProto> infoProtos = rpcProxy.listRulesInfo(null, req).getRulesInfoList();
        if (infoProtos == null) {
            return null;
        }
        List<RuleInfo> ret = new ArrayList<>();
        for (RuleInfoProto infoProto : infoProtos) {
            ret.add(ProtoBufferHelper.convert(infoProto));
        }
        return ret;
    } catch (ServiceException e) {
        throw ProtoBufferHelper.getRemoteException(e);
    }
}
Also used : ListRulesInfoRequestProto(org.smartdata.protocol.AdminServerProto.ListRulesInfoRequestProto) ServiceException(com.google.protobuf.ServiceException) ArrayList(java.util.ArrayList) RuleInfoProto(org.smartdata.protocol.AdminServerProto.RuleInfoProto) RuleInfo(org.smartdata.model.RuleInfo)

Example 8 with RuleInfo

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

the class MetaStore method listSyncRules.

public List<DetailedRuleInfo> listSyncRules() throws MetaStoreException {
    List<RuleInfo> ruleInfos = getRuleInfo();
    List<DetailedRuleInfo> detailedRuleInfos = new ArrayList<>();
    for (RuleInfo ruleInfo : ruleInfos) {
        if (ruleInfo.getState() == RuleState.DELETED) {
            continue;
        }
        int lastIndex = ruleInfo.getRuleText().lastIndexOf("|");
        String lastPart = ruleInfo.getRuleText().substring(lastIndex + 1);
        if (lastPart.contains("sync")) {
            DetailedRuleInfo detailedRuleInfo = new DetailedRuleInfo(ruleInfo);
            // Add sync progress
            BackUpInfo backUpInfo = getBackUpInfo(ruleInfo.getId());
            // Get total matched files
            if (backUpInfo != null) {
                detailedRuleInfo.setBaseProgress(getFilesByPrefix(backUpInfo.getSrc()).size());
                long count = fileDiffDao.getPendingDiff(backUpInfo.getSrc()).size();
                count += fileDiffDao.getByState(backUpInfo.getSrc(), FileDiffState.RUNNING).size();
                if (count > detailedRuleInfo.baseProgress) {
                    count = detailedRuleInfo.baseProgress;
                }
                detailedRuleInfo.setRunningProgress(count);
            } else {
                detailedRuleInfo.setBaseProgress(0);
                detailedRuleInfo.setRunningProgress(0);
            }
            if (detailedRuleInfo.getState() != RuleState.DELETED) {
                detailedRuleInfos.add(detailedRuleInfo);
            }
        }
    }
    return detailedRuleInfos;
}
Also used : DetailedRuleInfo(org.smartdata.model.DetailedRuleInfo) BackUpInfo(org.smartdata.model.BackUpInfo) ArrayList(java.util.ArrayList) DetailedRuleInfo(org.smartdata.model.DetailedRuleInfo) RuleInfo(org.smartdata.model.RuleInfo)

Example 9 with RuleInfo

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

the class TestRuleManager method testSubmitNewActiveRule.

@Test
public void testSubmitNewActiveRule() throws Exception {
    String rule = "file: every 1s \n | accessCount(5s) > 3 | cache";
    long id = ruleManager.submitRule(rule, RuleState.ACTIVE);
    RuleInfo ruleInfo = ruleManager.getRuleInfo(id);
    Assert.assertTrue(ruleInfo.getRuleText().equals(rule));
    RuleInfo info = ruleInfo;
    for (int i = 0; i < 5; i++) {
        Thread.sleep(1000);
        info = ruleManager.getRuleInfo(id);
        System.out.println(info);
    }
    Assert.assertTrue(info.getNumChecked() - ruleInfo.getNumChecked() > 3);
}
Also used : RuleInfo(org.smartdata.model.RuleInfo) Test(org.junit.Test)

Example 10 with RuleInfo

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

the class TestRuleDao method testInsertGetRule.

@Test
public void testInsertGetRule() 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);
    ruleDao.insert(info1);
    RuleInfo info11 = ruleDao.getById(info1.getId());
    Assert.assertTrue(info1.equals(info11));
    RuleInfo info2 = new RuleInfo(1, submitTime, rule, RuleState.ACTIVE, 0, 0, 0);
    ruleDao.insert(info2);
    RuleInfo info21 = ruleDao.getById(info2.getId());
    Assert.assertFalse(info11.equals(info21));
    List<RuleInfo> infos = ruleDao.getAll();
    Assert.assertTrue(infos.size() == 2);
    ruleDao.delete(info1.getId());
    infos = ruleDao.getAll();
    Assert.assertTrue(infos.size() == 1);
    ruleDao.deleteAll();
    infos = ruleDao.getAll();
    Assert.assertTrue(infos.size() == 0);
}
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