use of com.creditease.uav.datastore.api.DataStoreMsg in project uavstack by uavorg.
the class PersistentTask method updateDatabase.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void updateDatabase(NotificationEvent event) {
DataStoreMsg msg = new DataStoreMsg();
Map<String, Map> condition = new LinkedHashMap<String, Map>();
Map<String, Object> where = new LinkedHashMap<String, Object>();
Map<String, Object> update = new LinkedHashMap<String, Object>();
Map<String, Object> set = new LinkedHashMap<String, Object>();
Map<String, Object> ntfargs = JSONHelper.toObject(event.getArg(NCConstant.NTFVALUE), Map.class);
// 如果当前预警是第一条数据,如果不是第一条数据,只更新第一条
if (event.getArg(NCConstant.NCFirstEvent).equals("true")) {
if (log.isDebugEnable()) {
log.debug(this, "the Event is new for key:" + event.getArg(NCConstant.NTFKEY));
log.debug(this, "the Event is new for start Time :" + event.getTime());
}
where.put(NCConstant.COLUMN_NTFKEY, event.getArg(NCConstant.NTFKEY));
// fix bug
where.put("time", event.getTime());
set.put(NCConstant.COLUMN_FIRSTRECORD, "true");
} else {
if (log.isDebugEnable()) {
log.debug(this, "the Event exists for key:" + event.getArgs(true).get(NCConstant.NTFKEY));
log.debug(this, "the Event exists for start Time :" + event.getArg(NCConstant.COLUMN_STARTTIME));
}
where.put(NCConstant.COLUMN_NTFKEY, event.getArg(NCConstant.NTFKEY));
where.put("time", ntfargs.get(NCConstant.COLUMN_STARTTIME));
where.put(NCConstant.COLUMN_FIRSTRECORD, "true");
}
set.put(NCConstant.COLUMN_STATE, ntfargs.get(NCConstant.COLUMN_STATE));
if (ntfargs.get(NCConstant.COLUMN_RETRY_COUNT) != null) {
set.put(NCConstant.COLUMN_RETRY_COUNT, ntfargs.get(NCConstant.COLUMN_RETRY_COUNT));
}
if (ntfargs.get(NCConstant.COLUMN_VIEWTIME) != null) {
set.put(NCConstant.COLUMN_VIEWTIME, ntfargs.get(NCConstant.COLUMN_VIEWTIME));
}
if (ntfargs.get(NCConstant.COLUMN_LATESTIME) != null) {
set.put(NCConstant.COLUMN_LATESTIME, ntfargs.get(NCConstant.COLUMN_LATESTIME));
}
if (ntfargs.get(NCConstant.COLUMN_LATESTRECORDTIME) != null) {
set.put(NCConstant.COLUMN_LATESTRECORDTIME, ntfargs.get(NCConstant.COLUMN_LATESTRECORDTIME));
}
if (ntfargs.get(NCConstant.EVENT_COUNT) != null) {
set.put(NCConstant.EVENT_COUNT, ntfargs.get(NCConstant.EVENT_COUNT));
}
update.put("set", set);
condition.put("where", where);
condition.put("update", update);
msg.put(DataStoreProtocol.DATASTORE_NAME, MonitorDataFrame.MessageType.Notification.toString());
msg.put(DataStoreProtocol.MONGO_QUERY_SQL, JSONHelper.toString(condition));
msg.put(DataStoreProtocol.MONGO_COLLECTION_NAME, NCConstant.MONGO_COLLECTION_NOTIFY);
if (log.isDebugEnable()) {
log.debug(this, "NC Update Mongodb condition: " + JSONHelper.toString(condition));
}
// Exchange消息给HM做数据库更新
AgentFeatureComponent afc = (AgentFeatureComponent) ConfigurationManager.getInstance().getComponent("healthmanager", "HealthManager");
if (null != afc) {
boolean flag = (boolean) afc.exchange("opt.update", msg);
if (log.isDebugEnable()) {
log.debug(this, "NC Update Mongodb result: " + flag);
}
}
}
use of com.creditease.uav.datastore.api.DataStoreMsg 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.api.DataStoreMsg in project uavstack by uavorg.
the class AbstractAHDataStoreHandler method run.
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object run(UAVHttpMessage httpMsg, AbstractDataStore store, String collectionName, ISystemLogger log) {
Object result = null;
String requestData = httpMsg.getRequest(DataStoreProtocol.MONGO_REQUEST_DATA);
Map<String, Object> requestJson = JSONHelper.toObject(requestData, Map.class);
String type = String.valueOf(requestJson.get("type"));
String data = String.valueOf(requestJson.get("data"));
DataStoreMsg msg = new DataStoreMsg();
msg.put(DataStoreProtocol.MONGO_COLLECTION_NAME, collectionName);
msg.put(DataStoreProtocol.MONGO_REQUEST_DATA, data);
try {
if (requestType.create.toString().equals(type)) {
result = store.doInsert(msg);
} else if (requestType.modify.toString().equals(type)) {
result = store.doUpdate(msg);
} else if (requestType.query.toString().equals(type)) {
result = store.doQuery(msg);
}
} catch (Exception e) {
log.err(AbstractAHDataStoreHandler.class, " AppHubMgt DataStore do [" + type + "] FAIL: data=" + data, e);
}
return result;
}
use of com.creditease.uav.datastore.api.DataStoreMsg 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.DataStoreMsg 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);
}
Aggregations