Search in sources :

Example 6 with AbstractDataStore

use of com.creditease.uav.datastore.core.AbstractDataStore in project uavstack by uavorg.

the class HealthManager method exchange.

@SuppressWarnings("rawtypes")
@Override
public Object exchange(String eventKey, Object... data) {
    log.info(this, "HM got exchange event");
    if (null == data) {
        log.err(this, "the exchange data is empty");
        return null;
    }
    DataStoreMsg msg = (DataStoreMsg) data[0];
    AbstractDataStore dataStore = DataStoreFactory.getInstance().get((String) msg.get(DataStoreProtocol.DATASTORE_NAME));
    Object rst = null;
    switch(eventKey) {
        case HealthManagerConstants.QUERY:
            rst = dataStore.doQuery(msg);
            return rst;
        case HealthManagerConstants.INSERT:
            rst = dataStore.doUpdate(msg);
            return rst;
        case HealthManagerConstants.UPDATE:
            rst = dataStore.doUpdate(msg);
            return rst;
    }
    throw new RuntimeException("Exchange Event [" + eventKey + "] handle FAIL: data=" + data);
}
Also used : DataStoreMsg(com.creditease.uav.datastore.api.DataStoreMsg) AbstractDataStore(com.creditease.uav.datastore.core.AbstractDataStore)

Example 7 with AbstractDataStore

use of com.creditease.uav.datastore.core.AbstractDataStore in project uavstack by uavorg.

the class DoTestNotifyData4Mongo method testInsertNotifyMongoDB.

@SuppressWarnings({ "rawtypes" })
public static void testInsertNotifyMongoDB() {
    DataStoreMsg msg = new DataStoreMsg();
    // MongoDBHandler
    String rawData = DataStoreUnitTest.getData(insertJson);
    msg.put(MonitorDataFrame.MessageType.Notification.toString(), rawData);
    msg.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();
    boolean rst = store.doInsert(msg);
    store.stop();
    DataStoreUnitTest.printTestResult("testInsertNotifyMongoDB", rst);
}
Also used : DataStoreConnection(com.creditease.uav.datastore.api.DataStoreConnection) NotifyDataAdpater(com.creditease.uav.feature.healthmanager.datastore.adaptors.NotifyDataAdpater) DataStoreMsg(com.creditease.uav.datastore.api.DataStoreMsg) AbstractDataStore(com.creditease.uav.datastore.core.AbstractDataStore)

Example 8 with AbstractDataStore

use of com.creditease.uav.datastore.core.AbstractDataStore in project uavstack by uavorg.

the class DoTestProfileData method testupdateMongoDB.

@SuppressWarnings({ "rawtypes", "unused" })
public static void testupdateMongoDB() {
    for (int i = 0; i < updatefileName.length; i++) {
        System.out.println("test update : " + updatefileName[i]);
        String update = DataStoreUnitTest.getData(queryJsonDir + updatefileName[i]);
        DataStoreMsg request = new DataStoreMsg();
        request.put(DataStoreProtocol.MONGO_QUERY_SQL, update.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();
        boolean rst = store.doUpdate(request);
        long stop = System.currentTimeMillis();
        StringBuffer sb = new StringBuffer();
        sb.append("update " + updatefileName[i] + ": " + (stop - start));
        try {
            fileWrite(sb);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        store.stop();
    // DataStoreUnitTest.printTestResult("MongoDB:"+updatefileName[i], rst);
    }
}
Also used : DataStoreConnection(com.creditease.uav.datastore.api.DataStoreConnection) DataStoreMsg(com.creditease.uav.datastore.api.DataStoreMsg) IOException(java.io.IOException) AbstractDataStore(com.creditease.uav.datastore.core.AbstractDataStore) ProfileDataAdpater(com.creditease.uav.feature.healthmanager.datastore.adaptors.ProfileDataAdpater)

Example 9 with AbstractDataStore

use of com.creditease.uav.datastore.core.AbstractDataStore in project uavstack by uavorg.

the class HMDataStoreQueryHandler method handle.

@SuppressWarnings({ "rawtypes" })
@Override
public void handle(UAVHttpMessage data) {
    String storeName = data.getRequest(DataStoreProtocol.DATASTORE_NAME);
    AbstractDataStore store = DataStoreFactory.getInstance().get(storeName);
    if (store != null) {
        if (!store.isStarted()) {
            store.start();
            if (!store.isStarted()) {
                String warnMsg = "DataStore[" + storeName + "] CAN NOT START.";
                if (log.isTraceEnable()) {
                    log.warn(this, warnMsg);
                }
                // put err to response
                data.putResponse(UAVHttpMessage.ERR, warnMsg);
                return;
            }
        }
        DataStoreMsg dsmsg = new DataStoreMsg();
        // put all request params into DataStoreMsg for adaptor usage
        dsmsg.putAll(data.getRequest());
        List result = store.doQuery(dsmsg);
        String jsonString = JSONHelper.toString(result);
        // put result to response
        data.putResponse(UAVHttpMessage.RESULT, jsonString);
    } else {
        String warnMsg = "DataStore[" + storeName + "] NO EXIST.";
        if (log.isTraceEnable()) {
            log.warn(this, warnMsg);
        }
        // put err to response
        data.putResponse(UAVHttpMessage.ERR, warnMsg);
    }
}
Also used : DataStoreMsg(com.creditease.uav.datastore.api.DataStoreMsg) List(java.util.List) AbstractDataStore(com.creditease.uav.datastore.core.AbstractDataStore)

Aggregations

AbstractDataStore (com.creditease.uav.datastore.core.AbstractDataStore)9 DataStoreMsg (com.creditease.uav.datastore.api.DataStoreMsg)8 DataStoreConnection (com.creditease.uav.datastore.api.DataStoreConnection)5 ProfileDataAdpater (com.creditease.uav.feature.healthmanager.datastore.adaptors.ProfileDataAdpater)3 IOException (java.io.IOException)3 NotifyDataAdpater (com.creditease.uav.feature.healthmanager.datastore.adaptors.NotifyDataAdpater)2 List (java.util.List)1