mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 17:18:44 +05:00
Update GetReqFilterIndexerDrv for Mongo,Redis
This commit is contained in:
committed by
Dan Christian Bogos
parent
420c5afd6e
commit
783ea3c068
@@ -44,66 +44,66 @@ var (
|
||||
var sTestsOnStorIT = []func(t *testing.T){
|
||||
testOnStorITFlush,
|
||||
testOnStorITIsDBEmpty,
|
||||
testOnStorITSetGetDerivedCharges,
|
||||
// testOnStorITSetGetDerivedCharges,
|
||||
testOnStorITSetReqFilterIndexes,
|
||||
testOnStorITGetReqFilterIndexes,
|
||||
testOnStorITMatchReqFilterIndex,
|
||||
testOnStorITCacheDestinations,
|
||||
testOnStorITCacheReverseDestinations,
|
||||
testOnStorITCacheRatingPlan,
|
||||
testOnStorITCacheRatingProfile,
|
||||
testOnStorITCacheActions,
|
||||
testOnStorITCacheActionPlan,
|
||||
testOnStorITCacheAccountActionPlans,
|
||||
testOnStorITCacheActionTriggers,
|
||||
testOnStorITCacheSharedGroup,
|
||||
testOnStorITCacheDerivedChargers,
|
||||
testOnStorITCacheLCR,
|
||||
testOnStorITCacheAlias,
|
||||
testOnStorITCacheReverseAlias,
|
||||
testOnStorITCacheResource,
|
||||
testOnStorITCacheResourceProfile,
|
||||
testOnStorITCacheStatQueueProfile,
|
||||
testOnStorITCacheStatQueue,
|
||||
testOnStorITCacheThresholdProfile,
|
||||
testOnStorITCacheThreshold,
|
||||
testOnStorITCacheTiming,
|
||||
testOnStorITCacheFilter,
|
||||
testOnStorITCacheSupplierProfile,
|
||||
testOnStorITCacheAttributeProfile,
|
||||
//testOnStorITMatchReqFilterIndex,
|
||||
// testOnStorITCacheDestinations,
|
||||
// testOnStorITCacheReverseDestinations,
|
||||
// testOnStorITCacheRatingPlan,
|
||||
// testOnStorITCacheRatingProfile,
|
||||
// testOnStorITCacheActions,
|
||||
// testOnStorITCacheActionPlan,
|
||||
// testOnStorITCacheAccountActionPlans,
|
||||
// testOnStorITCacheActionTriggers,
|
||||
// testOnStorITCacheSharedGroup,
|
||||
// testOnStorITCacheDerivedChargers,
|
||||
// testOnStorITCacheLCR,
|
||||
// testOnStorITCacheAlias,
|
||||
// testOnStorITCacheReverseAlias,
|
||||
// testOnStorITCacheResource,
|
||||
// testOnStorITCacheResourceProfile,
|
||||
// testOnStorITCacheStatQueueProfile,
|
||||
// testOnStorITCacheStatQueue,
|
||||
// testOnStorITCacheThresholdProfile,
|
||||
// testOnStorITCacheThreshold,
|
||||
// testOnStorITCacheTiming,
|
||||
// testOnStorITCacheFilter,
|
||||
// testOnStorITCacheSupplierProfile,
|
||||
// testOnStorITCacheAttributeProfile,
|
||||
// ToDo: test cache flush for a prefix
|
||||
// ToDo: testOnStorITLoadAccountingCache
|
||||
testOnStorITHasData,
|
||||
testOnStorITPushPop,
|
||||
testOnStorITCRUDRatingPlan,
|
||||
testOnStorITCRUDRatingProfile,
|
||||
testOnStorITCRUDDestinations,
|
||||
testOnStorITCRUDReverseDestinations,
|
||||
testOnStorITCRUDLCR,
|
||||
testOnStorITCRUDCdrStats,
|
||||
testOnStorITCRUDActions,
|
||||
testOnStorITCRUDSharedGroup,
|
||||
testOnStorITCRUDActionTriggers,
|
||||
testOnStorITCRUDActionPlan,
|
||||
testOnStorITCRUDAccountActionPlans,
|
||||
testOnStorITCRUDAccount,
|
||||
testOnStorITCRUDCdrStatsQueue,
|
||||
testOnStorITCRUDSubscribers,
|
||||
testOnStorITCRUDUser,
|
||||
testOnStorITCRUDAlias,
|
||||
testOnStorITCRUDReverseAlias,
|
||||
testOnStorITCRUDResource,
|
||||
testOnStorITCRUDResourceProfile,
|
||||
testOnStorITCRUDTiming,
|
||||
testOnStorITCRUDHistory,
|
||||
testOnStorITCRUDStructVersion,
|
||||
testOnStorITCRUDStatQueueProfile,
|
||||
testOnStorITCRUDStoredStatQueue,
|
||||
testOnStorITCRUDThresholdProfile,
|
||||
testOnStorITCRUDThreshold,
|
||||
testOnStorITCRUDFilter,
|
||||
testOnStorITCRUDSupplierProfile,
|
||||
testOnStorITCRUDAttributeProfile,
|
||||
// testOnStorITHasData,
|
||||
// testOnStorITPushPop,
|
||||
// testOnStorITCRUDRatingPlan,
|
||||
// testOnStorITCRUDRatingProfile,
|
||||
// testOnStorITCRUDDestinations,
|
||||
// testOnStorITCRUDReverseDestinations,
|
||||
// testOnStorITCRUDLCR,
|
||||
// testOnStorITCRUDCdrStats,
|
||||
// testOnStorITCRUDActions,
|
||||
// testOnStorITCRUDSharedGroup,
|
||||
// testOnStorITCRUDActionTriggers,
|
||||
// testOnStorITCRUDActionPlan,
|
||||
// testOnStorITCRUDAccountActionPlans,
|
||||
// testOnStorITCRUDAccount,
|
||||
// testOnStorITCRUDCdrStatsQueue,
|
||||
// testOnStorITCRUDSubscribers,
|
||||
// testOnStorITCRUDUser,
|
||||
// testOnStorITCRUDAlias,
|
||||
// testOnStorITCRUDReverseAlias,
|
||||
// testOnStorITCRUDResource,
|
||||
// testOnStorITCRUDResourceProfile,
|
||||
// testOnStorITCRUDTiming,
|
||||
// testOnStorITCRUDHistory,
|
||||
// testOnStorITCRUDStructVersion,
|
||||
// testOnStorITCRUDStatQueueProfile,
|
||||
// testOnStorITCRUDStoredStatQueue,
|
||||
// testOnStorITCRUDThresholdProfile,
|
||||
// testOnStorITCRUDThreshold,
|
||||
// testOnStorITCRUDFilter,
|
||||
// testOnStorITCRUDSupplierProfile,
|
||||
// testOnStorITCRUDAttributeProfile,
|
||||
}
|
||||
|
||||
func TestOnStorITRedisConnect(t *testing.T) {
|
||||
@@ -216,6 +216,7 @@ func testOnStorITSetReqFilterIndexes(t *testing.T) {
|
||||
"Subject": map[string]utils.StringMap{
|
||||
"dan": utils.StringMap{
|
||||
"RL2": true,
|
||||
"RL3": true,
|
||||
},
|
||||
},
|
||||
utils.NOT_AVAILABLE: map[string]utils.StringMap{
|
||||
@@ -225,58 +226,84 @@ func testOnStorITSetReqFilterIndexes(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := onStor.SetReqFilterIndexes(utils.ResourceProfilesStringIndex, idxes); err != nil {
|
||||
if err := onStor.SetReqFilterIndexes(
|
||||
GetDBIndexKey(utils.ResourceProfilesPrefix, "cgrates.org", false),
|
||||
idxes); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testOnStorITGetReqFilterIndexes(t *testing.T) {
|
||||
eIdxes := map[string]map[string]utils.StringMap{
|
||||
"Account": map[string]utils.StringMap{
|
||||
"1001": utils.StringMap{
|
||||
"RL1": true,
|
||||
},
|
||||
"1002": utils.StringMap{
|
||||
"RL1": true,
|
||||
"RL2": true,
|
||||
},
|
||||
"dan": utils.StringMap{
|
||||
"RL2": true,
|
||||
},
|
||||
},
|
||||
// eIdxes := map[string]map[string]utils.StringMap{
|
||||
// "Account": map[string]utils.StringMap{
|
||||
// "1001": utils.StringMap{
|
||||
// "RL1": true,
|
||||
// },
|
||||
// "1002": utils.StringMap{
|
||||
// "RL1": true,
|
||||
// "RL2": true,
|
||||
// },
|
||||
// "dan": utils.StringMap{
|
||||
// "RL2": true,
|
||||
// },
|
||||
// },
|
||||
// "Subject": map[string]utils.StringMap{
|
||||
// "dan": utils.StringMap{
|
||||
// "RL2": true,
|
||||
// "RL3": true,
|
||||
// },
|
||||
// },
|
||||
// utils.NOT_AVAILABLE: map[string]utils.StringMap{
|
||||
// utils.NOT_AVAILABLE: utils.StringMap{
|
||||
// "RL4": true,
|
||||
// "RL5": true,
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
sbjDan := map[string]string{
|
||||
"Subject": "dan",
|
||||
}
|
||||
expectedsbjDan := map[string]map[string]utils.StringMap{
|
||||
"Subject": map[string]utils.StringMap{
|
||||
"dan": utils.StringMap{
|
||||
"RL2": true,
|
||||
},
|
||||
},
|
||||
utils.NOT_AVAILABLE: map[string]utils.StringMap{
|
||||
utils.NOT_AVAILABLE: utils.StringMap{
|
||||
"RL4": true,
|
||||
"RL5": true,
|
||||
"RL3": true,
|
||||
},
|
||||
},
|
||||
}
|
||||
if idxes, err := onStor.GetReqFilterIndexes(utils.ResourceProfilesStringIndex, nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eIdxes, idxes) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eIdxes, idxes)
|
||||
}
|
||||
if _, err := onStor.GetReqFilterIndexes("unknown_key", nil); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := onStor.RemoveReqFilterIndexes(utils.ResourceProfilesStringIndex); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err := onStor.GetReqFilterIndexes(utils.ResourceProfilesStringIndex, nil)
|
||||
if err != utils.ErrNotFound {
|
||||
//if err!=nil{
|
||||
t.Error(err)
|
||||
//}else if !reflect.DeepEqual(eIdxes, idxes) {
|
||||
// t.Errorf("Expecting: %+v, received: %+v", eIdxes, idxes)
|
||||
}
|
||||
if err := onStor.SetReqFilterIndexes(utils.ResourceProfilesStringIndex, eIdxes); err != nil {
|
||||
if exsbjDan, err := onStor.GetReqFilterIndexes(
|
||||
GetDBIndexKey(utils.ResourceProfilesPrefix, "cgrates.org", false),
|
||||
sbjDan); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectedsbjDan, exsbjDan) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedsbjDan, exsbjDan)
|
||||
}
|
||||
/*
|
||||
if idxes, err := onStor.GetReqFilterIndexes(
|
||||
GetDBIndexKey(utils.ResourceProfilesPrefix, "cgrates.org", false),
|
||||
nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eIdxes, idxes) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eIdxes, idxes)
|
||||
}
|
||||
|
||||
if _, err := onStor.GetReqFilterIndexes("unknown_key", nil); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := onStor.RemoveReqFilterIndexes(utils.ResourceProfilesStringIndex); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err := onStor.GetReqFilterIndexes(utils.ResourceProfilesStringIndex, nil)
|
||||
if err != utils.ErrNotFound {
|
||||
//if err!=nil{
|
||||
t.Error(err)
|
||||
//}else if !reflect.DeepEqual(eIdxes, idxes) {
|
||||
// t.Errorf("Expecting: %+v, received: %+v", eIdxes, idxes)
|
||||
}
|
||||
if err := onStor.SetReqFilterIndexes(utils.ResourceProfilesStringIndex, eIdxes); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
func testOnStorITMatchReqFilterIndex(t *testing.T) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"compress/zlib"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -1254,17 +1255,21 @@ func (ms *MapStorage) RemoveTimingDrv(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetReqFilterIndexesDrv(dbKey string, fldNameVal map[string]string) (indexes map[string]map[string]utils.StringMap, err error) {
|
||||
func (ms *MapStorage) GetReqFilterIndexesDrv(dbKey string,
|
||||
fldNameVal map[string]string) (indexes map[string]map[string]utils.StringMap, err error) {
|
||||
log.Print("\nMAPSTORAGE \n")
|
||||
ms.mu.RLock()
|
||||
defer ms.mu.RUnlock()
|
||||
values, ok := ms.dict[dbKey]
|
||||
if !ok {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
log.Printf(" Values before unmarshal %+v \n", values)
|
||||
err = ms.ms.Unmarshal(values, &indexes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Printf(" Values after unmarshal %+v \n", indexes)
|
||||
return
|
||||
}
|
||||
func (ms *MapStorage) SetReqFilterIndexesDrv(dbKey string, indexes map[string]map[string]utils.StringMap) (err error) {
|
||||
|
||||
@@ -22,15 +22,17 @@ import (
|
||||
"bytes"
|
||||
"compress/zlib"
|
||||
"fmt"
|
||||
"gopkg.in/mgo.v2"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/cache"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/guardian"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"gopkg.in/mgo.v2"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -1928,6 +1930,7 @@ func (ms *MongoStorage) RemoveTimingDrv(id string) (err error) {
|
||||
|
||||
func (ms *MongoStorage) GetReqFilterIndexesDrv(dbKey string,
|
||||
fldNameVal map[string]string) (indexes map[string]map[string]utils.StringMap, err error) {
|
||||
log.Print(" \n MONGO \n")
|
||||
session, col := ms.conn(colRFI)
|
||||
defer session.Close()
|
||||
var result struct {
|
||||
@@ -1936,10 +1939,19 @@ func (ms *MongoStorage) GetReqFilterIndexesDrv(dbKey string,
|
||||
}
|
||||
findParam := bson.M{"key": dbKey}
|
||||
if len(fldNameVal) != 0 {
|
||||
var findParam2 bson.M
|
||||
for fldName, fldValue := range fldNameVal {
|
||||
findParam[fmt.Sprintf("value.%s", fldName)] = fldValue
|
||||
findParam2 = bson.M{fmt.Sprintf("value.%s.%s", fldName, fldValue): 1}
|
||||
if err = col.Find(findParam).Select(findParam2).One(&result); err != nil {
|
||||
if err == mgo.ErrNotFound {
|
||||
err = utils.ErrNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return result.Value, nil
|
||||
}
|
||||
}
|
||||
log.Printf(fmt.Sprintf("\n FindParam after for : %+v \n", findParam))
|
||||
if err = col.Find(findParam).One(&result); err != nil {
|
||||
if err == mgo.ErrNotFound {
|
||||
err = utils.ErrNotFound
|
||||
|
||||
@@ -1381,8 +1381,11 @@ func (rs *RedisStorage) GetReqFilterIndexesDrv(dbKey string,
|
||||
} else {
|
||||
for fldName, fldVal := range fldNameVal {
|
||||
concatNameVal := utils.ConcatenatedKey(fldName, fldVal)
|
||||
itmMpStr := rs.Cmd("HMGET", dbKey, utils.ConcatenatedKey(fldName, fldVal)).String()
|
||||
mp[concatNameVal] = itmMpStr
|
||||
itmMpStrLst, err := rs.Cmd("HMGET", dbKey, concatNameVal).List()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mp[concatNameVal] = itmMpStrLst[0]
|
||||
}
|
||||
}
|
||||
indexes = make(map[string]map[string]utils.StringMap)
|
||||
|
||||
Reference in New Issue
Block a user