use of org.smartdata.server.metastore.DBAdapter in project SSM by Intel-bigdata.
the class TestNamespaceFetcher method testNamespaceFetcher.
@Test
public void testNamespaceFetcher() throws IOException, InterruptedException, MissingEventsException, SQLException {
final Configuration conf = new SmartConf();
final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
final DistributedFileSystem dfs = cluster.getFileSystem();
dfs.mkdir(new Path("/user"), new FsPermission("777"));
dfs.create(new Path("/user/user1"));
dfs.create(new Path("/user/user2"));
dfs.mkdir(new Path("/tmp"), new FsPermission("777"));
DFSClient client = dfs.getClient();
DBAdapter adapter = mock(DBAdapter.class);
NamespaceFetcher fetcher = new NamespaceFetcher(client, adapter, 100);
fetcher.startFetch();
List<String> expected = Arrays.asList("/", "/user", "/user/user1", "/user/user2", "/tmp");
Thread.sleep(1000);
verify(adapter).insertFiles(argThat(new FileStatusArgMatcher(expected)));
fetcher.stop();
cluster.shutdown();
}
use of org.smartdata.server.metastore.DBAdapter in project SSM by Intel-bigdata.
the class SmartServer method runSSMDaemons.
/**
* Bring up all the daemons threads needed.
*
* @throws Exception
*/
public void runSSMDaemons() throws Exception {
String nnRpcAddr = conf.get(SmartConfKeys.DFS_SSM_NAMENODE_RPCSERVER_KEY);
if (nnRpcAddr == null) {
throw new IOException("Can not find NameNode RPC server address. " + "Please configure it through '" + SmartConfKeys.DFS_SSM_NAMENODE_RPCSERVER_KEY + "'.");
}
namenodeURI = new URI(nnRpcAddr);
this.fs = (DistributedFileSystem) FileSystem.get(namenodeURI, conf);
outSSMIdFile = checkAndMarkRunning();
if (outSSMIdFile == null) {
// Exit if there is another one running.
throw new IOException("Another SmartServer is running");
}
// Init and start RPC server and REST server
rpcServer.start();
httpServer.start();
DBAdapter dbAdapter = getDBAdapter();
for (ModuleSequenceProto m : modules) {
m.init(dbAdapter);
}
for (ModuleSequenceProto m : modules) {
m.start();
}
// TODO: for simple here, refine it later
ssmServiceState = SmartServiceState.ACTIVE;
}
use of org.smartdata.server.metastore.DBAdapter in project SSM by Intel-bigdata.
the class SmartServer method getDBAdapter.
public DBAdapter getDBAdapter() throws Exception {
String fileName = "druid.xml";
URL urlPoolConf = getClass().getResource(fileName);
if (urlPoolConf != null) {
LOG.info("Using pool configure file: " + urlPoolConf.getFile());
Properties p = new Properties();
p.loadFromXML(getClass().getResourceAsStream(fileName));
return new DBAdapter(new DruidPool(p));
} else {
LOG.info(fileName + " NOT found.");
}
// TODO: keep it now for testing, remove it later.
Connection conn = getDBConnection();
return new DBAdapter(conn);
}
use of org.smartdata.server.metastore.DBAdapter in project SSM by Intel-bigdata.
the class TestRulesTable method testRuleInsert.
/**
* Insert rules into table and retrieve them back.
* @throws Exception
*/
@Test
public void testRuleInsert() throws Exception {
String dbFile = TestDBUtil.getUniqueDBFilePath();
Connection conn = null;
try {
conn = Util.createSqliteConnection(dbFile);
Util.initializeDataBase(conn);
String rule = "file : accessCountX(10m) > 20 \n\n" + "and length() > 3 | cachefile";
long submitTime = System.currentTimeMillis();
RuleInfo info1 = new RuleInfo(0, submitTime, rule, RuleState.ACTIVE, 0, 0, 0);
DBAdapter adapter = new DBAdapter(conn);
Assert.assertTrue(adapter.insertNewRule(info1));
RuleInfo info1_1 = adapter.getRuleInfo(info1.getId());
Assert.assertTrue(info1.equals(info1_1));
RuleInfo info2 = new RuleInfo(0, submitTime, rule, RuleState.ACTIVE, 0, 0, 0);
Assert.assertTrue(adapter.insertNewRule(info2));
RuleInfo info2_1 = adapter.getRuleInfo(info2.getId());
Assert.assertFalse(info1_1.equals(info2_1));
List<RuleInfo> infos = adapter.getRuleInfo();
assert (infos.size() == 2);
} finally {
if (conn != null) {
conn.close();
}
File file = new File(dbFile);
file.deleteOnExit();
}
}
use of org.smartdata.server.metastore.DBAdapter in project SSM by Intel-bigdata.
the class TestSqliteDB method testSqliteDBBlankStatements.
@Test
public void testSqliteDBBlankStatements() throws Exception {
String dbFile = TestDBUtil.getUniqueDBFilePath();
Connection conn = null;
try {
conn = Util.createSqliteConnection(dbFile);
Util.initializeDataBase(conn);
DBAdapter adapter = new DBAdapter(conn);
String[] presqls = new String[] { "INSERT INTO rules (state, rule_text, submit_time, checked_count, " + "commands_generated) VALUES (0, 'file: every 1s \n" + " | " + "accessCount(5s) > 3 | cachefile', 1494903787619, 0, 0);" };
for (int i = 0; i < presqls.length; i++) {
String sql = presqls[i];
adapter.execute(sql);
}
String[] sqls = new String[] { "DROP TABLE IF EXISTS 'VIR_ACC_CNT_TAB_1_accessCount_5000';", "CREATE TABLE 'VIR_ACC_CNT_TAB_1_accessCount_5000' " + "AS SELECT * FROM 'blank_access_count_info';", "SELECT fid from 'VIR_ACC_CNT_TAB_1_accessCount_5000';", "SELECT path FROM files WHERE (fid IN (SELECT fid FROM " + "'VIR_ACC_CNT_TAB_1_accessCount_5000' WHERE ((count > 3))));" };
for (int i = 0; i < sqls.length * 3; i++) {
int idx = i % sqls.length;
String sql = sqls[idx];
adapter.execute(sql);
}
} finally {
if (conn != null) {
conn.close();
}
File file = new File(dbFile);
file.deleteOnExit();
}
}
Aggregations