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