Search in sources :

Example 11 with DataStoreMsg

use of com.creditease.uav.datastore.api.DataStoreMsg 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 12 with DataStoreMsg

use of com.creditease.uav.datastore.api.DataStoreMsg 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

DataStoreMsg (com.creditease.uav.datastore.api.DataStoreMsg)12 AbstractDataStore (com.creditease.uav.datastore.core.AbstractDataStore)8 DataStoreConnection (com.creditease.uav.datastore.api.DataStoreConnection)7 ProfileDataAdpater (com.creditease.uav.feature.healthmanager.datastore.adaptors.ProfileDataAdpater)3 IOException (java.io.IOException)3 LogDataAdapter (com.creditease.uav.feature.healthmanager.datastore.adaptors.LogDataAdapter)2 NotifyDataAdpater (com.creditease.uav.feature.healthmanager.datastore.adaptors.NotifyDataAdpater)2 Connection (org.apache.hadoop.hbase.client.Connection)2 AgentFeatureComponent (com.creditease.agent.spi.AgentFeatureComponent)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1