use of com.creditease.uav.datastore.core.AbstractDataStore in project uavstack by uavorg.
the class AbstractMessageHandler method handle.
@Override
public void handle(Message msg) {
String msgKey = getMsgTypeName();
if (log.isDebugEnable()) {
log.debug(this, "CONSUME MSG[" + msgKey + "]: " + JSONHelper.toString(msg));
}
@SuppressWarnings("rawtypes") AbstractDataStore store = DataStoreFactory.getInstance().get(msgKey);
if (store != null) {
if (!store.isStarted()) {
store.start();
if (!store.isStarted()) {
if (log.isTraceEnable()) {
log.warn(this, "DataStore[" + msgKey + "] CAN NOT START.");
}
return;
}
}
DataStoreMsg dsMsg = new DataStoreMsg();
dsMsg.put(msgKey, msg.getParam(msgKey));
// pre insert to process DataStoreMsg
preInsert(dsMsg);
// do insert
boolean insertR = store.doInsert(dsMsg);
if (log.isDebugEnable()) {
String state = (insertR) ? "SUCCESS" : "FAIL";
log.debug(this, "DataStore[" + msgKey + "] INSERT DATA " + state);
}
} else {
if (log.isTraceEnable()) {
log.warn(this, "DataStore[" + msgKey + "] NO EXIST");
}
}
}
use of com.creditease.uav.datastore.core.AbstractDataStore in project uavstack by uavorg.
the class AbstractAHDataStoreHandler method handle.
@Override
@SuppressWarnings({ "rawtypes" })
public void handle(UAVHttpMessage httpMsg) {
String storeName = httpMsg.getRequest(DataStoreProtocol.DATASTORE_NAME);
AbstractDataStore store = DataStoreFactory.getInstance().get(storeName);
Object resp = null;
if (null != store) {
if (!store.isStarted()) {
store.start();
if (!store.isStarted()) {
resp = "DataStore[" + storeName + "] CAN NOT START.";
if (log.isTraceEnable()) {
log.warn(this, (String) resp);
}
}
} else {
resp = run(httpMsg, store, getCollectionName(), log);
}
} else {
resp = "DataStore[" + storeName + "] NO EXIST.";
}
httpMsg.putResponse(UAVHttpMessage.RESULT, createRespJson(resp));
}
use of com.creditease.uav.datastore.core.AbstractDataStore 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.core.AbstractDataStore 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.core.AbstractDataStore 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();
}
}
Aggregations