Search in sources :

Example 1 with DataStoreConnection

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);
    }
}
Also used : DataStoreConnection(com.creditease.uav.datastore.api.DataStoreConnection)

Example 2 with DataStoreConnection

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);
}
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 3 with DataStoreConnection

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);
}
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 4 with DataStoreConnection

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();
    }
}
Also used : DataStoreMsg(com.creditease.uav.datastore.api.DataStoreMsg) IOException(java.io.IOException) ProfileDataAdpater(com.creditease.uav.feature.healthmanager.datastore.adaptors.ProfileDataAdpater) DataStoreConnection(com.creditease.uav.datastore.api.DataStoreConnection) AbstractDataStore(com.creditease.uav.datastore.core.AbstractDataStore)

Example 5 with DataStoreConnection

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);
}
Also used : DataStoreConnection(com.creditease.uav.datastore.api.DataStoreConnection) BasicDBObject(com.mongodb.BasicDBObject) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.bson.Document) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

DataStoreConnection (com.creditease.uav.datastore.api.DataStoreConnection)11 DataStoreMsg (com.creditease.uav.datastore.api.DataStoreMsg)7 AbstractDataStore (com.creditease.uav.datastore.core.AbstractDataStore)5 IOException (java.io.IOException)4 ProfileDataAdpater (com.creditease.uav.feature.healthmanager.datastore.adaptors.ProfileDataAdpater)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 BasicDBObject (com.mongodb.BasicDBObject)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1 Result (org.apache.hadoop.hbase.client.Result)1 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)1 Scan (org.apache.hadoop.hbase.client.Scan)1 Table (org.apache.hadoop.hbase.client.Table)1 FilterList (org.apache.hadoop.hbase.filter.FilterList)1 PageFilter (org.apache.hadoop.hbase.filter.PageFilter)1