mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Merge branch 'master' of https://github.com/cgrates/cgrates
This commit is contained in:
@@ -7,7 +7,7 @@ install:
|
||||
- go get github.com/Masterminds/glide
|
||||
- glide install
|
||||
|
||||
script: $TRAVIS_BUILD_DIR/test.sh
|
||||
script: go test -v $(glide novendor)
|
||||
|
||||
branches:
|
||||
only: master
|
||||
|
||||
@@ -318,7 +318,7 @@ func (self *ApierV1) GetAccounts(attr utils.AttrGetAccounts, reply *[]interface{
|
||||
var accountKeys []string
|
||||
var err error
|
||||
if len(attr.AccountIds) == 0 {
|
||||
if accountKeys, err = self.AccountDb.GetKeysForPrefix(utils.ACCOUNT_PREFIX + attr.Tenant); err != nil {
|
||||
if accountKeys, err = self.AccountDb.GetKeysForPrefix(utils.ACCOUNT_PREFIX+attr.Tenant, true); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -33,7 +33,7 @@ func (self *ApierV2) GetAccounts(attr utils.AttrGetAccounts, reply *[]*engine.Ac
|
||||
var accountKeys []string
|
||||
var err error
|
||||
if len(attr.AccountIds) == 0 {
|
||||
if accountKeys, err = self.AccountDb.GetKeysForPrefix(utils.ACCOUNT_PREFIX + utils.ConcatenatedKey(attr.Tenant)); err != nil {
|
||||
if accountKeys, err = self.AccountDb.GetKeysForPrefix(utils.ACCOUNT_PREFIX+utils.ConcatenatedKey(attr.Tenant), true); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -10,19 +10,19 @@
|
||||
"http": ":2080", // HTTP listening address
|
||||
},
|
||||
|
||||
//"tariffplan_db": { // database used to store offline tariff plans and CDRs
|
||||
// "db_type": "mongo", // stor database type to use: <mysql|postgres>
|
||||
// "db_host": "127.0.0.1", // the host to connect to
|
||||
// "db_port": 27017, // the port to reach the stordb
|
||||
// "db_name": "tpdb",
|
||||
//},
|
||||
//
|
||||
//"data_db": { // database used to store offline tariff plans and CDRs
|
||||
// "db_type": "mongo", // stor database type to use: <mysql|postgres>
|
||||
// "db_host": "127.0.0.1", // the host to connect to
|
||||
// "db_port": 27017, // the port to reach the stordb
|
||||
// "db_name": "datadb",
|
||||
//},
|
||||
"tariffplan_db": { // database used to store offline tariff plans and CDRs
|
||||
"db_type": "mongo", // stor database type to use: <mysql|postgres>
|
||||
"db_host": "127.0.0.1", // the host to connect to
|
||||
"db_port": 27017, // the port to reach the stordb
|
||||
"db_name": "tpdb",
|
||||
},
|
||||
|
||||
"data_db": { // database used to store offline tariff plans and CDRs
|
||||
"db_type": "mongo", // stor database type to use: <mysql|postgres>
|
||||
"db_host": "127.0.0.1", // the host to connect to
|
||||
"db_port": 27017, // the port to reach the stordb
|
||||
"db_name": "datadb",
|
||||
},
|
||||
|
||||
"stor_db": { // database used to store offline tariff plans and CDRs
|
||||
"db_type": "mongo", // stor database type to use: <mysql|postgres>
|
||||
|
||||
@@ -33,7 +33,7 @@ import (
|
||||
type Storage interface {
|
||||
Close()
|
||||
Flush(string) error
|
||||
GetKeysForPrefix(string) ([]string, error)
|
||||
GetKeysForPrefix(string, bool) ([]string, error)
|
||||
}
|
||||
|
||||
// Interface for storage providers.
|
||||
|
||||
@@ -53,14 +53,17 @@ func (ms *MapStorage) Flush(ignore string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetKeysForPrefix(prefix string) ([]string, error) {
|
||||
keysForPrefix := make([]string, 0)
|
||||
for key := range ms.dict {
|
||||
if strings.HasPrefix(key, prefix) {
|
||||
keysForPrefix = append(keysForPrefix, key)
|
||||
func (ms *MapStorage) GetKeysForPrefix(prefix string, skipCache bool) ([]string, error) {
|
||||
if skipCache {
|
||||
keysForPrefix := make([]string, 0)
|
||||
for key := range ms.dict {
|
||||
if strings.HasPrefix(key, prefix) {
|
||||
keysForPrefix = append(keysForPrefix, key)
|
||||
}
|
||||
}
|
||||
return keysForPrefix, nil
|
||||
}
|
||||
return keysForPrefix, nil
|
||||
return cache2go.GetEntriesKeys(prefix), nil
|
||||
}
|
||||
|
||||
func (ms *MapStorage) CacheRatingAll() error {
|
||||
|
||||
@@ -244,8 +244,60 @@ func (ms *MongoStorage) Close() {
|
||||
ms.session.Close()
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetKeysForPrefix(prefix string) ([]string, error) {
|
||||
return nil, nil
|
||||
func (ms *MongoStorage) GetKeysForPrefix(prefix string, skipCache bool) ([]string, error) {
|
||||
var category, subject string
|
||||
length := len(utils.DESTINATION_PREFIX)
|
||||
if len(prefix) >= length {
|
||||
category = prefix[:length] // prefix lenght
|
||||
subject = fmt.Sprintf("^%s", prefix[length:])
|
||||
} else {
|
||||
return nil, fmt.Errorf("unsupported prefix in GetKeysForPrefix: %s", prefix)
|
||||
}
|
||||
var result []string
|
||||
if skipCache {
|
||||
keyResult := struct{ Key string }{}
|
||||
idResult := struct{ Id string }{}
|
||||
switch category {
|
||||
case utils.DESTINATION_PREFIX:
|
||||
iter := ms.db.C(colDst).Find(bson.M{"key": bson.M{"$regex": bson.RegEx{Pattern: subject}}}).Select(bson.M{"key": 1}).Iter()
|
||||
for iter.Next(&keyResult) {
|
||||
result = append(result, utils.DESTINATION_PREFIX+keyResult.Key)
|
||||
}
|
||||
return result, nil
|
||||
case utils.RATING_PLAN_PREFIX:
|
||||
iter := ms.db.C(colRpl).Find(bson.M{"key": bson.M{"$regex": bson.RegEx{Pattern: subject}}}).Select(bson.M{"key": 1}).Iter()
|
||||
for iter.Next(&keyResult) {
|
||||
result = append(result, utils.RATING_PLAN_PREFIX+keyResult.Key)
|
||||
}
|
||||
return result, nil
|
||||
case utils.RATING_PROFILE_PREFIX:
|
||||
iter := ms.db.C(colRpf).Find(bson.M{"id": bson.M{"$regex": bson.RegEx{Pattern: subject}}}).Select(bson.M{"id": 1}).Iter()
|
||||
for iter.Next(&idResult) {
|
||||
result = append(result, utils.RATING_PROFILE_PREFIX+idResult.Id)
|
||||
}
|
||||
return result, nil
|
||||
case utils.ACTION_PREFIX:
|
||||
iter := ms.db.C(colAct).Find(bson.M{"key": bson.M{"$regex": bson.RegEx{Pattern: subject}}}).Select(bson.M{"key": 1}).Iter()
|
||||
for iter.Next(&keyResult) {
|
||||
result = append(result, utils.ACTION_PREFIX+keyResult.Key)
|
||||
}
|
||||
return result, nil
|
||||
case utils.ACTION_PLAN_PREFIX:
|
||||
iter := ms.db.C(colApl).Find(bson.M{"key": bson.M{"$regex": bson.RegEx{Pattern: subject}}}).Select(bson.M{"key": 1}).Iter()
|
||||
for iter.Next(&keyResult) {
|
||||
result = append(result, utils.ACTION_PLAN_PREFIX+keyResult.Key)
|
||||
}
|
||||
return result, nil
|
||||
case utils.ACCOUNT_PREFIX:
|
||||
iter := ms.db.C(colAcc).Find(bson.M{"id": bson.M{"$regex": bson.RegEx{Pattern: subject}}}).Select(bson.M{"id": 1}).Iter()
|
||||
for iter.Next(&idResult) {
|
||||
result = append(result, utils.ACCOUNT_PREFIX+idResult.Id)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
return result, fmt.Errorf("unsupported prefix in GetKeysForPrefix: %s", prefix)
|
||||
}
|
||||
return cache2go.GetEntriesKeys(prefix), nil
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) Flush(ignore string) (err error) {
|
||||
@@ -627,7 +679,7 @@ func (ms *MongoStorage) HasData(category, subject string) (bool, error) {
|
||||
count, err := ms.db.C(colAcc).Find(bson.M{"id": subject}).Count()
|
||||
return count > 0, err
|
||||
}
|
||||
return false, errors.New("Unsupported category in HasData")
|
||||
return false, errors.New("unsupported category in HasData")
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPlan, err error) {
|
||||
|
||||
@@ -84,12 +84,15 @@ func (rs *RedisStorage) Flush(ignore string) error {
|
||||
return rs.db.Cmd("FLUSHDB").Err
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetKeysForPrefix(prefix string) ([]string, error) {
|
||||
r := rs.db.Cmd("KEYS", prefix+"*")
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
func (rs *RedisStorage) GetKeysForPrefix(prefix string, skipCache bool) ([]string, error) {
|
||||
if skipCache {
|
||||
r := rs.db.Cmd("KEYS", prefix+"*")
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
return r.List()
|
||||
}
|
||||
return r.List()
|
||||
return cache2go.GetEntriesKeys(prefix), nil
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) CacheRatingAll() error {
|
||||
|
||||
@@ -55,7 +55,7 @@ func (self *SQLStorage) Flush(scriptsPath string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) GetKeysForPrefix(prefix string) ([]string, error) {
|
||||
func (self *SQLStorage) GetKeysForPrefix(prefix string, skipCache bool) ([]string, error) {
|
||||
return nil, utils.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -433,7 +433,7 @@ func (tpr *TpReader) LoadLCRs() (err error) {
|
||||
}
|
||||
}
|
||||
if !found && tpr.ratingStorage != nil {
|
||||
if keys, err := tpr.ratingStorage.GetKeysForPrefix(utils.RATING_PROFILE_PREFIX + ratingProfileSearchKey); err != nil {
|
||||
if keys, err := tpr.ratingStorage.GetKeysForPrefix(utils.RATING_PROFILE_PREFIX+ratingProfileSearchKey, true); err != nil {
|
||||
return fmt.Errorf("[LCR] error querying ratingDb %s", err.Error())
|
||||
} else if len(keys) != 0 {
|
||||
found = true
|
||||
|
||||
50
test.sh
50
test.sh
@@ -1,50 +1,4 @@
|
||||
#! /usr/bin/env sh
|
||||
./build.sh
|
||||
|
||||
go test -i github.com/cgrates/cgrates/apier/v1
|
||||
go test -i github.com/cgrates/cgrates/apier/v2
|
||||
go test -i github.com/cgrates/cgrates/engine
|
||||
go test -i github.com/cgrates/cgrates/sessionmanager
|
||||
go test -i github.com/cgrates/cgrates/config
|
||||
go test -i github.com/cgrates/cgrates/cmd/cgr-engine
|
||||
go test -i github.com/cgrates/cgrates/cache2go
|
||||
go test -i github.com/cgrates/cgrates/cdrc
|
||||
go test -i github.com/cgrates/cgrates/utils
|
||||
go test -i github.com/cgrates/cgrates/history
|
||||
go test -i github.com/cgrates/cgrates/cdre
|
||||
go test -i github.com/cgrates/cgrates/agents
|
||||
go test -i github.com/cgrates/cgrates/structmatcher
|
||||
|
||||
go test github.com/cgrates/cgrates/apier/v1
|
||||
v1=$?
|
||||
go test github.com/cgrates/cgrates/apier/v2
|
||||
v2=$?
|
||||
go test github.com/cgrates/cgrates/engine
|
||||
en=$?
|
||||
go test github.com/cgrates/cgrates/general_tests
|
||||
gt=$?
|
||||
go test github.com/cgrates/cgrates/sessionmanager
|
||||
sm=$?
|
||||
go test github.com/cgrates/cgrates/config
|
||||
cfg=$?
|
||||
go test github.com/cgrates/cgrates/cmd/cgr-engine
|
||||
cr=$?
|
||||
go test github.com/cgrates/cgrates/console
|
||||
con=$?
|
||||
go test github.com/cgrates/cgrates/cdrc
|
||||
cdrcs=$?
|
||||
go test github.com/cgrates/cgrates/utils
|
||||
ut=$?
|
||||
go test github.com/cgrates/cgrates/history
|
||||
hs=$?
|
||||
go test github.com/cgrates/cgrates/cache2go
|
||||
c2g=$?
|
||||
go test github.com/cgrates/cgrates/cdre
|
||||
cdre=$?
|
||||
go test github.com/cgrates/cgrates/agents
|
||||
ag=$?
|
||||
go test github.com/cgrates/cgrates/structmatcher
|
||||
sc=$?
|
||||
|
||||
|
||||
exit $v1 && $v2 && $en && $gt && $sm && $cfg && $bl && $cr && $con && $cdrc && $ut && $hs && $c2g && $cdre && $ag && $sc
|
||||
go test $(glide novendor)
|
||||
exit $?
|
||||
|
||||
Reference in New Issue
Block a user