use of org.smartdata.common.rule.RuleInfo in project SSM by Intel-bigdata.
the class TestSmartAdmin method test.
@Test
public void test() throws Exception {
final SmartConf conf = new SmartConf();
final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
// dfs not used , but datanode.ReplicaNotFoundException throws without dfs
final DistributedFileSystem dfs = cluster.getFileSystem();
final Collection<URI> namenodes = DFSUtil.getInternalNsRpcUris(conf);
List<URI> uriList = new ArrayList<>(namenodes);
conf.set(DFS_NAMENODE_HTTP_ADDRESS_KEY, uriList.get(0).toString());
conf.set(SmartConfKeys.DFS_SSM_NAMENODE_RPCSERVER_KEY, uriList.get(0).toString());
// Set db used
String dbFile = TestDBUtil.getUniqueEmptySqliteDBFile();
String dbUrl = Util.SQLITE_URL_PREFIX + dbFile;
conf.set(SmartConfKeys.DFS_SSM_DEFAULT_DB_URL_KEY, dbUrl);
// rpcServer start in SmartServer
SmartServer server = SmartServer.createSSM(null, conf);
SmartAdmin ssmClient = new SmartAdmin(conf);
while (true) {
//test getServiceStatus
String state = ssmClient.getServiceState().getName();
if ("ACTIVE".equals(state)) {
break;
}
Thread.sleep(1000);
}
//test listRulesInfo and submitRule
List<RuleInfo> ruleInfos = ssmClient.listRulesInfo();
int ruleCounts0 = ruleInfos.size();
long ruleId = ssmClient.submitRule("file: every 5s | path matches \"/foo*\"| cachefile", RuleState.DRYRUN);
ruleInfos = ssmClient.listRulesInfo();
int ruleCounts1 = ruleInfos.size();
assertEquals(1, ruleCounts1 - ruleCounts0);
//test checkRule
//if success ,no Exception throw
ssmClient.checkRule("file: every 5s | path matches \"/foo*\"| cachefile");
boolean caughtException = false;
try {
ssmClient.checkRule("file.path");
} catch (IOException e) {
caughtException = true;
}
assertTrue(caughtException);
//test getRuleInfo
RuleInfo ruleInfo = ssmClient.getRuleInfo(ruleId);
assertNotEquals(null, ruleInfo);
//test disableRule
ssmClient.disableRule(ruleId, true);
assertEquals(RuleState.DISABLED, ssmClient.getRuleInfo(ruleId).getState());
//test activateRule
ssmClient.activateRule(ruleId);
assertEquals(RuleState.ACTIVE, ssmClient.getRuleInfo(ruleId).getState());
//test deleteRule
ssmClient.deleteRule(ruleId, true);
assertEquals(RuleState.DELETED, ssmClient.getRuleInfo(ruleId).getState());
//test single SSM
caughtException = false;
try {
conf.set(SmartConfKeys.DFS_SSM_RPC_ADDRESS_KEY, "localhost:8043");
SmartServer.createSSM(null, conf);
} catch (IOException e) {
assertEquals("java.io.IOException: Another SmartServer is running", e.toString());
caughtException = true;
}
assertTrue(caughtException);
//test client close
caughtException = false;
ssmClient.close();
try {
ssmClient.getRuleInfo(ruleId);
} catch (IOException e) {
caughtException = true;
}
assertEquals(true, caughtException);
server.shutdown();
cluster.shutdown();
}
use of org.smartdata.common.rule.RuleInfo in project SSM by Intel-bigdata.
the class SmartAdminProtocolAdminSideTranslatorPB 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(PBHelper.convert(infoProto));
}
return ret;
} catch (ServiceException e) {
throw PBHelper.getRemoteException(e);
}
}
use of org.smartdata.common.rule.RuleInfo in project SSM by Intel-bigdata.
the class RuleContainer method getRuleInfo.
public RuleInfo getRuleInfo() {
lockRead();
RuleInfo ret = ruleInfo.newCopy();
unlockRead();
return ret;
}
use of org.smartdata.common.rule.RuleInfo in project SSM by Intel-bigdata.
the class TestRuleManager method testStopRule.
@Test
public void testStopRule() throws Exception {
String rule = "file: every 1s from now to now + 100s \n | " + "length > 300 | cachefile";
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 < 2; i++) {
Thread.sleep(1000);
info = ruleManager.getRuleInfo(id);
System.out.println(info);
}
ruleManager.deleteRule(ruleInfo.getId(), true);
Thread.sleep(3000);
RuleInfo endInfo = ruleManager.getRuleInfo(info.getId());
System.out.println(endInfo);
Assert.assertTrue(endInfo.getState() == RuleState.DELETED);
Assert.assertTrue(endInfo.getNumChecked() - info.getNumChecked() <= 1);
}
use of org.smartdata.common.rule.RuleInfo in project SSM by Intel-bigdata.
the class TestRuleManager method testSubmitNewMultiRules.
@Test
public void testSubmitNewMultiRules() throws Exception {
String rule = "file: every 1s \n | length > 300 | cachefile";
// id increasing
int nRules = 3;
long[] ids = new long[nRules];
for (int i = 0; i < nRules; i++) {
ids[i] = ruleManager.submitRule(rule, RuleState.DISABLED);
System.out.println(ruleManager.getRuleInfo(ids[i]));
if (i > 0) {
Assert.assertTrue(ids[i] - ids[i - 1] == 1);
}
}
for (int i = 0; i < nRules; i++) {
ruleManager.deleteRule(ids[i], true);
RuleInfo info = ruleManager.getRuleInfo(ids[i]);
Assert.assertTrue(info.getState() == RuleState.DELETED);
}
long[] ids2 = new long[nRules];
for (int i = 0; i < nRules; i++) {
ids2[i] = ruleManager.submitRule(rule, RuleState.DISABLED);
System.out.println(ruleManager.getRuleInfo(ids2[i]));
if (i > 0) {
Assert.assertTrue(ids2[i] - ids2[i - 1] == 1);
}
Assert.assertTrue(ids2[i] > ids[nRules - 1]);
}
System.out.println("\nFinal state:");
List<RuleInfo> allRules = ruleManager.listRulesInfo();
Assert.assertTrue(allRules.size() == 2 * nRules);
for (RuleInfo info : allRules) {
System.out.println(info);
}
}
Aggregations