use of com.creditease.uav.datastore.api.DataStoreConnection in project uavstack by uavorg.
the class HealthManager method buildDataStore.
/**
* buildDataStore
*
* @param icm
* @param dsName
* @param type
* @param adaptor
* @param context
*/
private void buildDataStore(IConfigurationManager icm, String dsName, DataStoreType type, DataStoreAdapter adaptor, Map<String, Object> context) {
boolean enable = false;
enable = Boolean.parseBoolean(icm.getFeatureConfiguration(this.feature, dsName + ".ds.enable"));
if (enable) {
String serverlist = icm.getFeatureConfiguration(this.feature, dsName + ".ds.servers");
if (serverlist == null) {
log.warn(this, "Config[ds.servers] of DataStore[" + dsName + "] is NULL.");
return;
}
String dbName = icm.getFeatureConfiguration(this.feature, dsName + ".ds.db");
String dbPower = icm.getFeatureConfiguration(this.feature, dsName + ".ds.power");
String userName = icm.getFeatureConfiguration(this.feature, dsName + ".ds.usr");
String password = icm.getFeatureConfiguration(this.feature, dsName + ".ds.pwd");
int retry = DataConvertHelper.toInt(icm.getFeatureConfiguration(this.feature, dsName + ".ds.retry"), 3);
int expire = DataConvertHelper.toInt(icm.getFeatureConfiguration(this.feature, dsName + ".ds.expire"), 3);
List<String> servers = DataConvertHelper.toList(serverlist, ",");
DataStoreConnection conn = new DataStoreConnection(userName, password, dbName, dbPower, servers, type);
conn.setRetryTimes(retry);
conn.setBlackExpireTime(expire);
if (context != null) {
conn.putContextAll(context);
}
DataStoreFactory.getInstance().build(dsName, conn, adaptor, this.feature);
}
}
use of com.creditease.uav.datastore.api.DataStoreConnection in project uavstack by uavorg.
the class DoTestNotifyData4Mongo method testquerytNotifyMongoDB.
@SuppressWarnings("rawtypes")
public static void testquerytNotifyMongoDB() {
String query = DataStoreUnitTest.getData(queryJson);
DataStoreMsg request = new DataStoreMsg();
request.put(DataStoreProtocol.MONGO_QUERY_SQL, query.toString());
request.put(DataStoreProtocol.MONGO_COLLECTION_NAME, HealthManagerConstants.MONGO_COLLECTION_NOTIFY);
DataStoreConnection obj = new DataStoreConnection(userName, password, dbName, serverlist, DataStoreType.MONGODB);
AbstractDataStore store = DataStoreFactory.getInstance().build(HealthManagerConstants.DataStore_Notification, obj, new NotifyDataAdpater(), "");
store.start();
@SuppressWarnings("unchecked") List<Object> list = store.doQuery(request);
store.stop();
DataStoreUnitTest.printTestResult("testquerytNotifyMongoDB", list, query);
}
use of com.creditease.uav.datastore.api.DataStoreConnection in project uavstack by uavorg.
the class DoTestProfileData method testInsertMongoDB.
@SuppressWarnings({ "rawtypes" })
public static void testInsertMongoDB() {
// MongoDBHandler
DataStoreMsg msg = new DataStoreMsg();
String rawData = DataStoreUnitTest.getData(insertJson);
msg.put(MonitorDataFrame.MessageType.Profile.toString(), rawData);
msg.put(DataStoreProtocol.MONGO_COLLECTION_NAME, HealthManagerConstants.MONGO_COLLECTION_PROFILE);
DataStoreConnection obj = new DataStoreConnection(userName, password, dbName, serverlist, DataStoreType.MONGODB);
AbstractDataStore store = DataStoreFactory.getInstance().build(HealthManagerConstants.DataStore_Profile, obj, new ProfileDataAdpater(), "");
store.start();
long start = System.currentTimeMillis();
// boolean rst = store.doInsert(msg);
for (int i = 0; i < 1; i++) {
boolean rst = store.doInsert(msg);
if (false == rst)
break;
}
long stop = System.currentTimeMillis();
StringBuffer sb = new StringBuffer();
sb.append("insert time : " + (stop - start));
try {
fileWrite(sb);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
store.stop();
// DataStoreUnitTest.printTestResult("testInsertMongoDB",rst);
}
use of com.creditease.uav.datastore.api.DataStoreConnection in project uavstack by uavorg.
the class DoTestProfileData method testquerytMongoDB.
@SuppressWarnings("rawtypes")
public static void testquerytMongoDB() {
// String[] fileName = { "DSAggregatequery.json", "DSAggregatequeryGtLt.json", "DSAggregatequeryMKV.json",
// "DSAggregatequeryRegex_GtInOR.json", "DSAggregatequeryRegex.json", "DSAggregatequeryRegexInOR.json",
// "DSAggregatequeryRegexMKVInOR.json", "DSfind.json" };
String[] fileName = { "DSfind.json" };
// "DSAggregatequeryMKV.json", "DSAggregatequeryRegex_GtInOR.json",
// "DSAggregatequeryRegex.json", "DSAggregatequeryRegexInOR.json",
// "DSAggregatequeryRegexMKVInOR.json" ,"DSfind.json" };
// String[] fileName = { "group.json" };
long total = 0;
for (int i = 0; i < fileName.length; i++) {
// System.out.println("test query : " + fileName[i]);
String query = DataStoreUnitTest.getData(queryJsonDir + fileName[i]);
DataStoreMsg request = new DataStoreMsg();
request.put(DataStoreProtocol.MONGO_QUERY_SQL, query.toString());
request.put(DataStoreProtocol.MONGO_COLLECTION_NAME, HealthManagerConstants.MONGO_COLLECTION_PROFILE);
DataStoreConnection obj = new DataStoreConnection(userName, password, dbName, serverlist, DataStoreType.MONGODB);
AbstractDataStore store = DataStoreFactory.getInstance().build(HealthManagerConstants.DataStore_Profile, obj, new ProfileDataAdpater(), "");
store.start();
long start = System.currentTimeMillis();
@SuppressWarnings("unchecked") List<Object> list = store.doQuery(request);
long stop = System.currentTimeMillis();
total = total + (stop - start);
StringBuffer sb = new StringBuffer();
sb.append("query " + fileName[i] + ": " + (stop - start));
try {
fileWrite(sb);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
store.stop();
DataStoreUnitTest.printTestResult("MongoDB:" + fileName[i], list, queryJsonDir);
}
StringBuffer sb = new StringBuffer();
sb.append("query total: " + total);
try {
fileWrite(sb);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of com.creditease.uav.datastore.api.DataStoreConnection in project uavstack by uavorg.
the class MongoDBDataStore method query.
/**
* 1)满足隔离性,adaptor里面不能使用MongoClient的类 2)使得datastore中query逻辑更加通用
*/
@SuppressWarnings({ "rawtypes" })
@Override
protected List query(DataStoreMsg msg) {
// init
String collectionName = (String) msg.get(DataStoreProtocol.MONGO_COLLECTION_NAME);
DataStoreConnection connection = this.datasource.getDataStoreConnection();
MongoCollection<Document> collection = this.datasource.getSourceConnect().getCollection(collectionName);
if (null == collection) {
log.warn(this, "MongoDBDataStore [" + connection.getDbName() + "] Collection[" + collectionName + "] NO EXIST.");
return adaptor.handleQueryResult(Collections.emptyList(), msg, connection);
} else {
log.info(this, "MongoDBDataStore [" + connection.getDbName() + "] Collection[" + collectionName + "] ");
}
// action
Object queryObj = adaptor.prepareQueryObj(msg, connection);
List<Map> result = Collections.emptyList();
if (queryObj instanceof List) {
result = aggregateAction(queryObj, collection);
} else if (queryObj instanceof Map) {
Map queryparmes = (Map) queryObj;
if (queryparmes.containsKey(DataStoreProtocol.COUNT)) {
result = countAction(msg, queryparmes, collection);
} else {
result = findAction(queryparmes, collection);
}
} else {
log.warn(this, "MongoDBDataStore Query Action Is Not Find. ");
}
// return result
if (log.isDebugEnable()) {
log.debug(this, "MongoDBDataStore Query Result :" + result.toString());
}
return adaptor.handleQueryResult(result, msg, connection);
}
Aggregations