TPDestination.DestinationId -> DestinationID

This commit is contained in:
DanB
2016-11-17 17:03:01 +01:00
parent 443c594edc
commit 6170f8cbf4
7 changed files with 35 additions and 40 deletions

View File

@@ -213,12 +213,12 @@ func TestApierTPDestination(t *testing.T) {
return
}
reply := ""
dstDe := &utils.TPDestination{TPid: utils.TEST_SQL, DestinationId: "GERMANY", Prefixes: []string{"+49"}}
dstDeMobile := &utils.TPDestination{TPid: utils.TEST_SQL, DestinationId: "GERMANY_MOBILE", Prefixes: []string{"+4915", "+4916", "+4917"}}
dstFs := &utils.TPDestination{TPid: utils.TEST_SQL, DestinationId: "FS_USERS", Prefixes: []string{"10"}}
dstDe := &utils.TPDestination{TPid: utils.TEST_SQL, DestinationID: "GERMANY", Prefixes: []string{"+49"}}
dstDeMobile := &utils.TPDestination{TPid: utils.TEST_SQL, DestinationID: "GERMANY_MOBILE", Prefixes: []string{"+4915", "+4916", "+4917"}}
dstFs := &utils.TPDestination{TPid: utils.TEST_SQL, DestinationID: "FS_USERS", Prefixes: []string{"10"}}
dstDe2 := new(utils.TPDestination)
*dstDe2 = *dstDe // Data which we use for remove, still keeping the sample data to check proper loading
dstDe2.DestinationId = "GERMANY2"
dstDe2.DestinationID = "GERMANY2"
for _, dst := range []*utils.TPDestination{dstDe, dstDeMobile, dstFs, dstDe2} {
if err := rater.Call("ApierV1.SetTPDestination", dst, &reply); err != nil {
t.Error("Got error on ApierV1.SetTPDestination: ", err.Error())
@@ -235,18 +235,18 @@ func TestApierTPDestination(t *testing.T) {
// Check missing params
if err := rater.Call("ApierV1.SetTPDestination", new(utils.TPDestination), &reply); err == nil {
t.Error("Calling ApierV1.SetTPDestination, expected error, received: ", reply)
} else if err.Error() != "MANDATORY_IE_MISSING:[TPid DestinationId Prefixes]" {
} else if err.Error() != "MANDATORY_IE_MISSING:[TPid DestinationID Prefixes]" {
t.Error("Calling ApierV1.SetTPDestination got unexpected error: ", err.Error())
}
// Test get
var rplyDstDe2 *utils.TPDestination
if err := rater.Call("ApierV1.GetTPDestination", AttrGetTPDestination{dstDe2.TPid, dstDe2.DestinationId}, &rplyDstDe2); err != nil {
if err := rater.Call("ApierV1.GetTPDestination", AttrGetTPDestination{dstDe2.TPid, dstDe2.DestinationID}, &rplyDstDe2); err != nil {
t.Error("Calling ApierV1.GetTPDestination, got error: ", err.Error())
} else if !reflect.DeepEqual(dstDe2, rplyDstDe2) {
t.Errorf("Calling ApierV1.GetTPDestination expected: %v, received: %v", dstDe2, rplyDstDe2)
}
// Test remove
if err := rater.Call("ApierV1.RemTPDestination", AttrGetTPDestination{dstDe2.TPid, dstDe2.DestinationId}, &reply); err != nil {
if err := rater.Call("ApierV1.RemTPDestination", AttrGetTPDestination{dstDe2.TPid, dstDe2.DestinationID}, &reply); err != nil {
t.Error("Calling ApierV1.RemTPTiming, got error: ", err.Error())
} else if reply != "OK" {
t.Error("Calling ApierV1.RemTPTiming received: ", reply)

View File

@@ -24,7 +24,7 @@ import (
// Creates a new destination within a tariff plan
func (self *ApierV1) SetTPDestination(attrs utils.TPDestination, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationId", "Prefixes"}); len(missing) != 0 { //Params missing
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationID", "Prefixes"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
ds := engine.APItoModelDestination(&attrs)
@@ -46,7 +46,6 @@ func (self *ApierV1) GetTPDestination(attrs AttrGetTPDestination, reply *utils.T
return utils.NewErrMandatoryIeMissing(missing...)
}
if storData, err := self.StorDb.GetTpDestinations(attrs.TPid, attrs.DestinationId); err != nil {
return utils.NewErrServerError(err)
} else if len(storData) == 0 {
return utils.ErrNotFound
@@ -57,7 +56,7 @@ func (self *ApierV1) GetTPDestination(attrs AttrGetTPDestination, reply *utils.T
}
*reply = utils.TPDestination{
TPid: attrs.TPid,
DestinationId: dsts[attrs.DestinationId].Id,
DestinationID: dsts[attrs.DestinationId].Id,
Prefixes: dsts[attrs.DestinationId].Prefixes}
}
return nil

View File

@@ -207,18 +207,18 @@ func testTPitTimings(t *testing.T) {
func testTPitDestinations(t *testing.T) {
var reply string
// DST_1002,1002
dst1002 := &utils.TPDestination{TPid: testTPid, DestinationId: "DST_1002", Prefixes: []string{"1002"}}
dst1002 := &utils.TPDestination{TPid: testTPid, DestinationID: "DST_1002", Prefixes: []string{"1002"}}
// DST_1003,1003
dst1003 := &utils.TPDestination{TPid: testTPid, DestinationId: "DST_1003", Prefixes: []string{"1003"}}
dst1003 := &utils.TPDestination{TPid: testTPid, DestinationID: "DST_1003", Prefixes: []string{"1003"}}
// DST_1007,1007
dst1007 := &utils.TPDestination{TPid: testTPid, DestinationId: "DST_1007", Prefixes: []string{"1007"}}
dst1007 := &utils.TPDestination{TPid: testTPid, DestinationID: "DST_1007", Prefixes: []string{"1007"}}
// DST_FS,10
dstFS := &utils.TPDestination{TPid: testTPid, DestinationId: "DST_FS", Prefixes: []string{"10"}}
dstFS := &utils.TPDestination{TPid: testTPid, DestinationID: "DST_FS", Prefixes: []string{"10"}}
// DST_DE_MOBILE,+49151
// DST_DE_MOBILE,+49161
// DST_DE_MOBILE,+49171
dstDEMobile := &utils.TPDestination{TPid: testTPid, DestinationId: "DST_DE_MOBILE", Prefixes: []string{"+49151", "+49161", "+49171"}}
dstDUMMY := &utils.TPDestination{TPid: testTPid, DestinationId: "DUMMY_REMOVE", Prefixes: []string{"999"}}
dstDEMobile := &utils.TPDestination{TPid: testTPid, DestinationID: "DST_DE_MOBILE", Prefixes: []string{"+49151", "+49161", "+49171"}}
dstDUMMY := &utils.TPDestination{TPid: testTPid, DestinationID: "DUMMY_REMOVE", Prefixes: []string{"999"}}
for _, dst := range []*utils.TPDestination{dst1002, dst1003, dst1007, dstFS, dstDEMobile, dstDUMMY} {
if err := tpRPC.Call("ApierV2.SetTPDestination", dst, &reply); err != nil {
t.Error("Got error on ApierV2.SetTPDestination: ", err.Error())
@@ -228,13 +228,13 @@ func testTPitDestinations(t *testing.T) {
}
// Test get
var rplyDst *utils.TPDestination
if err := tpRPC.Call("ApierV2.GetTPDestination", v1.AttrGetTPDestination{testTPid, dstDEMobile.DestinationId}, &rplyDst); err != nil {
if err := tpRPC.Call("ApierV2.GetTPDestination", v1.AttrGetTPDestination{testTPid, dstDEMobile.DestinationID}, &rplyDst); err != nil {
t.Error("Calling ApierV2.GetTPDestination, got error: ", err.Error())
} else if len(dstDEMobile.Prefixes) != len(rplyDst.Prefixes) {
t.Errorf("Calling ApierV2.GetTPDestination expected: %v, received: %v", dstDEMobile, rplyDst)
}
// Test remove
if err := tpRPC.Call("ApierV2.RemTPDestination", v1.AttrGetTPDestination{testTPid, dstDUMMY.DestinationId}, &reply); err != nil {
if err := tpRPC.Call("ApierV2.RemTPDestination", v1.AttrGetTPDestination{testTPid, dstDUMMY.DestinationID}, &reply); err != nil {
t.Error("Calling ApierV1.RemTPTiming, got error: ", err.Error())
} else if reply != utils.OK {
t.Error("Calling ApierV2.RemTPTiming received: ", reply)

View File

@@ -51,14 +51,14 @@ func APItoModelDestination(dest *utils.TPDestination) (result []TpDestination) {
for _, p := range dest.Prefixes {
result = append(result, TpDestination{
Tpid: dest.TPid,
Tag: dest.DestinationId,
Tag: dest.DestinationID,
Prefix: p,
})
}
if len(dest.Prefixes) == 0 {
result = append(result, TpDestination{
Tpid: dest.TPid,
Tag: dest.DestinationId,
Tag: dest.DestinationID,
})
}
return

View File

@@ -53,7 +53,7 @@ func TestModelHelperCsvDump(t *testing.T) {
func TestTPDestinationAsExportSlice(t *testing.T) {
tpDst := &utils.TPDestination{
TPid: "TEST_TPID",
DestinationId: "TEST_DEST",
DestinationID: "TEST_DEST",
Prefixes: []string{"49", "49176", "49151"},
}
expectedSlc := [][]string{

View File

@@ -95,7 +95,15 @@ func NewMongoStorage(host, port, db, user, pass, storageType string, cdrsIndexes
return nil, err
}
session.SetMode(mgo.Strong, true)
return &MongoStorage{db: db, session: session, storageType: storageType, ms: NewCodecMsgpackMarshaler(), cacheCfg: cacheCfg, loadHistorySize: loadHistorySize, cdrsIndexes: cdrsIndexes}, nil
ms = &MongoStorage{db: db, session: session, storageType: storageType, ms: NewCodecMsgpackMarshaler(), cacheCfg: cacheCfg, loadHistorySize: loadHistorySize, cdrsIndexes: cdrsIndexes}
if cNames, err := session.DB(ms.db).CollectionNames(); err != nil {
return nil, err
} else if len(cNames) == 0 { // create indexes only if database is empty
if err = ms.EnsureIndexes(); err != nil {
return nil, err
}
}
return
}
type MongoStorage struct {
@@ -113,8 +121,9 @@ func (ms *MongoStorage) conn(col string) (*mgo.Session, *mgo.Collection) {
return sessionCopy, sessionCopy.DB(ms.db).C(col)
}
// EnsureIndexes creates db indexes
func (ms *MongoStorage) EnsureIndexes() (err error) {
dbSession, _ := ms.conn("")
dbSession := ms.session.Copy()
defer dbSession.Close()
db := dbSession.DB(ms.db)
idx := mgo.Index{
@@ -305,22 +314,9 @@ func (ms *MongoStorage) Close() {
}
func (ms *MongoStorage) Flush(ignore string) (err error) {
session := ms.session.Copy()
defer session.Close()
db := session.DB(ms.db)
collections, err := db.CollectionNames()
if err != nil {
return err
}
for _, c := range collections {
if strings.HasPrefix(c, "system.") { // cannot drop system ns due to mongo errors
continue
}
if _, err = db.C(c).RemoveAll(bson.M{}); err != nil {
return err
}
}
return nil
dbSession := ms.session.Copy()
defer dbSession.Close()
return dbSession.DB(ms.db).DropDatabase()
}
func (ms *MongoStorage) RebuildReverseForPrefix(prefix string) error {

View File

@@ -40,7 +40,7 @@ type Paginator struct {
type TPDestination struct {
TPid string // Tariff plan id
DestinationId string // Destination id
DestinationID string // Destination id
Prefixes []string // Prefixes attached to this destination
}