mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-23 16:18:44 +05:00
working variant for history server and gob enc
This commit is contained in:
@@ -96,9 +96,6 @@ func SetDebitPeriod(d time.Duration) {
|
||||
|
||||
// Exported method to set the history scribe.
|
||||
func SetHistoryScribe(scribe history.Scribe) {
|
||||
history.RegisterRecordFilename(&Destination{})
|
||||
history.RegisterRecordFilename(&RatingPlan{})
|
||||
history.RegisterRecordFilename(&RatingProfile{})
|
||||
historyScribe = scribe
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package engine
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/history"
|
||||
)
|
||||
|
||||
/*
|
||||
Structure that gathers multiple destination prefixes under a common id.
|
||||
@@ -55,6 +60,11 @@ func (d *Destination) AddPrefix(pfx string) {
|
||||
}
|
||||
|
||||
// history record method
|
||||
func (d *Destination) GetId() string {
|
||||
return d.Id
|
||||
func (d *Destination) GetHistoryRecord() history.Record {
|
||||
js, _ := json.Marshal(d)
|
||||
return history.Record{
|
||||
Id: d.Id,
|
||||
Filename: history.DESTINATIONS_FN,
|
||||
Payload: js,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
|
||||
func TestHistoryRatinPlans(t *testing.T) {
|
||||
scribe := historyScribe.(*history.MockScribe)
|
||||
buf := scribe.BufMap["ratingprofiles.json"]
|
||||
buf := scribe.BufMap[history.RATING_PROFILES_FN]
|
||||
if !strings.Contains(buf.String(), `{"Id":"*out:vdf:0:minu","RatingPlanActivations":[{"ActivationTime":"2012-01-01T00:00:00Z","RatingPlanId":"EVENING","FallbackKeys":null}]}`) {
|
||||
t.Error("Error in destination history content:", buf.String())
|
||||
}
|
||||
@@ -35,7 +35,7 @@ func TestHistoryRatinPlans(t *testing.T) {
|
||||
|
||||
func TestHistoryDestinations(t *testing.T) {
|
||||
scribe := historyScribe.(*history.MockScribe)
|
||||
buf := scribe.BufMap["destinations.json"]
|
||||
buf := scribe.BufMap[history.DESTINATIONS_FN]
|
||||
expected := `[{"Id":"ALL","Prefixes":["49","41","43"]},
|
||||
{"Id":"GERMANY","Prefixes":["49"]},
|
||||
{"Id":"GERMANY_O2","Prefixes":["41"]},
|
||||
|
||||
@@ -18,6 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package engine
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/cgrates/cgrates/history"
|
||||
)
|
||||
|
||||
/*
|
||||
The struture that is saved to storage.
|
||||
*/
|
||||
@@ -99,6 +105,11 @@ func (rp *RatingPlan) Equal(o *RatingPlan) bool {
|
||||
}
|
||||
|
||||
// history record method
|
||||
func (rp *RatingPlan) GetId() string {
|
||||
return rp.Id
|
||||
func (rp *RatingPlan) GetHistoryRecord() history.Record {
|
||||
js, _ := json.Marshal(rp)
|
||||
return history.Record{
|
||||
Id: rp.Id,
|
||||
Filename: history.RATING_PLANS_FN,
|
||||
Payload: js,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/cache2go"
|
||||
"github.com/cgrates/cgrates/history"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
@@ -148,6 +150,11 @@ func (rp *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error)
|
||||
}
|
||||
|
||||
// history record method
|
||||
func (rpf *RatingProfile) GetId() string {
|
||||
return rpf.Id
|
||||
func (rpf *RatingProfile) GetHistoryRecord() history.Record {
|
||||
js, _ := json.Marshal(rpf)
|
||||
return history.Record{
|
||||
Id: rpf.Id,
|
||||
Filename: history.RATING_PROFILES_FN,
|
||||
Payload: js,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ func (ms *MapStorage) SetRatingPlan(rp *RatingPlan) (err error) {
|
||||
result, err := ms.ms.Marshal(rp)
|
||||
ms.dict[RATING_PLAN_PREFIX+rp.Id] = result
|
||||
response := 0
|
||||
go historyScribe.Record(rp, &response)
|
||||
go historyScribe.Record(rp.GetHistoryRecord(), &response)
|
||||
cache2go.Cache(RATING_PLAN_PREFIX+rp.Id, rp)
|
||||
return
|
||||
}
|
||||
@@ -150,7 +150,7 @@ func (ms *MapStorage) SetRatingProfile(rpf *RatingProfile) (err error) {
|
||||
result, err := ms.ms.Marshal(rpf)
|
||||
ms.dict[RATING_PROFILE_PREFIX+rpf.Id] = result
|
||||
response := 0
|
||||
go historyScribe.Record(rpf, &response)
|
||||
go historyScribe.Record(rpf.GetHistoryRecord(), &response)
|
||||
cache2go.Cache(RATING_PROFILE_PREFIX+rpf.Id, rpf)
|
||||
return
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func (ms *MapStorage) SetDestination(dest *Destination) (err error) {
|
||||
result, err := ms.ms.Marshal(dest)
|
||||
ms.dict[DESTINATION_PREFIX+dest.Id] = result
|
||||
response := 0
|
||||
go historyScribe.Record(dest, &response)
|
||||
go historyScribe.Record(dest.GetHistoryRecord(), &response)
|
||||
cache2go.Cache(DESTINATION_PREFIX+dest.Id, dest)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"labix.org/v2/mgo"
|
||||
"labix.org/v2/mgo/bson"
|
||||
)
|
||||
@@ -136,7 +137,7 @@ func (ms *MongoStorage) GetRatingPlan(key string) (rp *RatingPlan, err error) {
|
||||
func (ms *MongoStorage) SetRatingPlan(rp *RatingPlan) error {
|
||||
if historyScribe != nil {
|
||||
response := 0
|
||||
historyScribe.Record(rp, &response)
|
||||
historyScribe.Record(rp.GetHistoryRecord(), &response)
|
||||
}
|
||||
return ms.db.C("ratingplans").Insert(rp)
|
||||
}
|
||||
@@ -150,7 +151,7 @@ func (ms *MongoStorage) GetRatingProfile(key string) (rp *RatingProfile, err err
|
||||
func (ms *MongoStorage) SetRatingProfile(rp *RatingProfile) error {
|
||||
if historyScribe != nil {
|
||||
response := 0
|
||||
historyScribe.Record(rp, &response)
|
||||
historyScribe.Record(rp.GetHistoryRecord(), &response)
|
||||
}
|
||||
return ms.db.C("ratingprofiles").Insert(rp)
|
||||
}
|
||||
@@ -167,7 +168,7 @@ func (ms *MongoStorage) GetDestination(key string) (result *Destination, err err
|
||||
func (ms *MongoStorage) SetDestination(dest *Destination) error {
|
||||
if historyScribe != nil {
|
||||
response := 0
|
||||
historyScribe.Record(dest, &response)
|
||||
historyScribe.Record(dest.GetHistoryRecord(), &response)
|
||||
}
|
||||
return ms.db.C("destinations").Insert(dest)
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ func (rs *RedisStorage) SetRatingPlan(rp *RatingPlan) (err error) {
|
||||
err = rs.db.Set(RATING_PLAN_PREFIX+rp.Id, b.Bytes())
|
||||
if err == nil && historyScribe != nil {
|
||||
response := 0
|
||||
go historyScribe.Record(rp, &response)
|
||||
go historyScribe.Record(rp.GetHistoryRecord(), &response)
|
||||
}
|
||||
//cache2go.Cache(RATING_PLAN_PREFIX+rp.Id, rp)
|
||||
return
|
||||
@@ -222,7 +222,7 @@ func (rs *RedisStorage) SetRatingProfile(rpf *RatingProfile) (err error) {
|
||||
err = rs.db.Set(RATING_PROFILE_PREFIX+rpf.Id, result)
|
||||
if err == nil && historyScribe != nil {
|
||||
response := 0
|
||||
go historyScribe.Record(rpf, &response)
|
||||
go historyScribe.Record(rpf.GetHistoryRecord(), &response)
|
||||
}
|
||||
//cache2go.Cache(RATING_PROFILE_PREFIX+rpf.Id, rpf)
|
||||
return
|
||||
@@ -271,7 +271,7 @@ func (rs *RedisStorage) SetDestination(dest *Destination) (err error) {
|
||||
err = rs.db.Set(DESTINATION_PREFIX+dest.Id, b.Bytes())
|
||||
if err == nil && historyScribe != nil {
|
||||
response := 0
|
||||
go historyScribe.Record(dest, &response)
|
||||
go historyScribe.Record(dest.GetHistoryRecord(), &response)
|
||||
}
|
||||
//cache2go.Cache(DESTINATION_PREFIX+dest.Id, dest)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user