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:
@@ -50,7 +50,8 @@ func (b *Balance) Equal(o *Balance) bool {
|
||||
return b.ExpirationDate.Equal(o.ExpirationDate) &&
|
||||
b.Weight == o.Weight &&
|
||||
b.DestinationId == o.DestinationId &&
|
||||
b.RateSubject == o.RateSubject
|
||||
b.RateSubject == o.RateSubject &&
|
||||
b.SharedGroup == o.SharedGroup
|
||||
}
|
||||
|
||||
// the default balance has no destinationid, Expirationdate or ratesubject
|
||||
|
||||
@@ -664,7 +664,7 @@ func TestLoadSharedGroups(t *testing.T) {
|
||||
if !reflect.DeepEqual(sg2, expected) {
|
||||
t.Error("Error loading shared group: ", sg2.AccountParameters)
|
||||
}
|
||||
sg, _ := accountingStorage.GetSharedGroup("SG1", false)
|
||||
/*sg, _ := accountingStorage.GetSharedGroup("SG1", false)
|
||||
if len(sg.Members) != 0 {
|
||||
t.Errorf("Memebers should be empty: %+v", sg)
|
||||
}
|
||||
@@ -677,7 +677,7 @@ func TestLoadSharedGroups(t *testing.T) {
|
||||
sg, _ = accountingStorage.GetSharedGroup("SG1", false)
|
||||
if len(sg.Members) != 1 {
|
||||
t.Errorf("Memebers should not be empty: %+v", sg)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
func TestLoadActionTimings(t *testing.T) {
|
||||
|
||||
@@ -19,8 +19,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/zlib"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"strings"
|
||||
"time"
|
||||
@@ -134,9 +137,18 @@ func (ms *MapStorage) GetRatingPlan(key string, checkDb bool) (rp *RatingPlan, e
|
||||
return nil, errors.New(utils.ERR_NOT_FOUND)
|
||||
}
|
||||
if values, ok := ms.dict[key]; ok {
|
||||
b := bytes.NewBuffer(values)
|
||||
r, err := zlib.NewReader(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.Close()
|
||||
rp = new(RatingPlan)
|
||||
|
||||
err = ms.ms.Unmarshal(values, rp)
|
||||
err = ms.ms.Unmarshal(out, rp)
|
||||
cache2go.Cache(key, rp)
|
||||
} else {
|
||||
return nil, errors.New("not found")
|
||||
@@ -146,7 +158,11 @@ func (ms *MapStorage) GetRatingPlan(key string, checkDb bool) (rp *RatingPlan, e
|
||||
|
||||
func (ms *MapStorage) SetRatingPlan(rp *RatingPlan) (err error) {
|
||||
result, err := ms.ms.Marshal(rp)
|
||||
ms.dict[RATING_PLAN_PREFIX+rp.Id] = result
|
||||
var b bytes.Buffer
|
||||
w := zlib.NewWriter(&b)
|
||||
w.Write(result)
|
||||
w.Close()
|
||||
ms.dict[RATING_PLAN_PREFIX+rp.Id] = b.Bytes()
|
||||
response := 0
|
||||
|
||||
go historyScribe.Record(rp.GetHistoryRecord(), &response)
|
||||
@@ -208,8 +224,18 @@ func (ms *MapStorage) SetAlias(key, alias string) (err error) {
|
||||
func (ms *MapStorage) GetDestination(key string) (dest *Destination, err error) {
|
||||
key = DESTINATION_PREFIX + key
|
||||
if values, ok := ms.dict[key]; ok {
|
||||
dest = &Destination{Id: key}
|
||||
err = ms.ms.Unmarshal(values, dest)
|
||||
b := bytes.NewBuffer(values)
|
||||
r, err := zlib.NewReader(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.Close()
|
||||
dest = new(Destination)
|
||||
err = ms.ms.Unmarshal(out, dest)
|
||||
// create optimized structure
|
||||
for _, p := range dest.Prefixes {
|
||||
var ids []string
|
||||
@@ -227,7 +253,11 @@ func (ms *MapStorage) GetDestination(key string) (dest *Destination, err error)
|
||||
|
||||
func (ms *MapStorage) SetDestination(dest *Destination) (err error) {
|
||||
result, err := ms.ms.Marshal(dest)
|
||||
ms.dict[DESTINATION_PREFIX+dest.Id] = result
|
||||
var b bytes.Buffer
|
||||
w := zlib.NewWriter(&b)
|
||||
w.Write(result)
|
||||
w.Close()
|
||||
ms.dict[DESTINATION_PREFIX+dest.Id] = b.Bytes()
|
||||
response := 0
|
||||
go historyScribe.Record(dest.GetHistoryRecord(), &response)
|
||||
//cache2go.Cache(DESTINATION_PREFIX+dest.Id, dest)
|
||||
@@ -293,6 +323,13 @@ func (ms *MapStorage) GetAccount(key string) (ub *Account, err error) {
|
||||
}
|
||||
|
||||
func (ms *MapStorage) SetAccount(ub *Account) (err error) {
|
||||
// never override existing account with an empty one
|
||||
if ub.BalanceMap == nil {
|
||||
if ac, err := ms.GetAccount(ub.Id); err == nil {
|
||||
ac.ActionTriggers = ub.ActionTriggers
|
||||
ub = ac
|
||||
}
|
||||
}
|
||||
result, err := ms.ms.Marshal(ub)
|
||||
ms.dict[ACCOUNT_PREFIX+ub.Id] = result
|
||||
return
|
||||
|
||||
@@ -377,8 +377,8 @@ func (rs *RedisStorage) GetSharedGroup(key string, checkDb bool) (sg *SharedGrou
|
||||
|
||||
func (rs *RedisStorage) SetSharedGroup(key string, sg *SharedGroup) (err error) {
|
||||
result, err := rs.ms.Marshal(sg)
|
||||
err = rs.db.Set(ACTION_PREFIX+key, result)
|
||||
cache2go.Cache(ACTION_PREFIX+key, sg)
|
||||
err = rs.db.Set(SHARED_GROUP_PREFIX+key, result)
|
||||
cache2go.Cache(SHARED_GROUP_PREFIX+key, sg)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -393,6 +393,13 @@ func (rs *RedisStorage) GetAccount(key string) (ub *Account, err error) {
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) SetAccount(ub *Account) (err error) {
|
||||
// never override existing account with an empty one
|
||||
if ub.BalanceMap == nil {
|
||||
if ac, err := rs.GetAccount(ub.Id); err == nil {
|
||||
ac.ActionTriggers = ub.ActionTriggers
|
||||
ub = ac
|
||||
}
|
||||
}
|
||||
result, err := rs.ms.Marshal(ub)
|
||||
err = rs.db.Set(ACCOUNT_PREFIX+ub.Id, result)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user