diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index c4a37ebbf..1acc1077c 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -483,7 +483,7 @@ func main() { server.RpcRegisterName("ScribeV1", scribeServer) } if cfg.UserServerEnabled { - userServer, err = engine.NewUserMap(ratingDb) + userServer, err = engine.NewUserMap(accountDb) if err != nil { engine.Logger.Crit(fmt.Sprintf(" Could not start, error: %s", err.Error())) exitChan <- true diff --git a/engine/storage_interface.go b/engine/storage_interface.go index 6c05d287e..f06851e87 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -71,10 +71,6 @@ type RatingStorage interface { SetAccAlias(string, string) error RemoveAccAliases([]*TenantAccount, bool) error GetAccountAliases(string, string, bool) ([]string, error) - SetUser(*UserProfile) error - GetUser(string) (*UserProfile, error) - GetUsers() ([]*UserProfile, error) - RemoveUser(string) error } type AccountingStorage interface { @@ -87,6 +83,10 @@ type AccountingStorage interface { GetSubscribers() (map[string]*SubscriberData, error) SetSubscriber(string, *SubscriberData) error RemoveSubscriber(string) error + SetUser(*UserProfile) error + GetUser(string) (*UserProfile, error) + GetUsers() ([]*UserProfile, error) + RemoveUser(string) error } type CdrStorage interface { diff --git a/engine/tp_reader.go b/engine/tp_reader.go index 32d53df70..ce737c131 100644 --- a/engine/tp_reader.go +++ b/engine/tp_reader.go @@ -1063,7 +1063,7 @@ func (tpr *TpReader) LoadUsersFiltered(filter *TpUser) (bool, error) { for _, tpUser := range tpUsers { user.Profile[tpUser.AttributeName] = tpUser.AttributeValue } - tpr.ratingStorage.SetUser(user) + tpr.accountingStorage.SetUser(user) return len(tpUsers) > 0, err } @@ -1306,7 +1306,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) { log.Print("Users:") } for _, u := range tpr.users { - err = tpr.ratingStorage.SetUser(u) + err = tpr.accountingStorage.SetUser(u) if err != nil { return err } diff --git a/engine/users.go b/engine/users.go index 0cf821c74..4c06d3824 100644 --- a/engine/users.go +++ b/engine/users.go @@ -58,17 +58,17 @@ type UserService interface { } type UserMap struct { - table map[string]map[string]string - index map[string]map[string]bool - indexKeys []string - ratingDb RatingStorage - mu sync.RWMutex + table map[string]map[string]string + index map[string]map[string]bool + indexKeys []string + accountingDb AccountingStorage + mu sync.RWMutex } -func NewUserMap(ratingDb RatingStorage) (*UserMap, error) { - um := newUserMap(ratingDb) +func NewUserMap(accountingDb AccountingStorage) (*UserMap, error) { + um := newUserMap(accountingDb) // load from rating db - if ups, err := um.ratingDb.GetUsers(); err == nil { + if ups, err := um.accountingDb.GetUsers(); err == nil { for _, up := range ups { um.table[up.GetId()] = up.Profile } @@ -78,18 +78,18 @@ func NewUserMap(ratingDb RatingStorage) (*UserMap, error) { return um, nil } -func newUserMap(ratingDb RatingStorage) *UserMap { +func newUserMap(accountingDb AccountingStorage) *UserMap { return &UserMap{ - table: make(map[string]map[string]string), - index: make(map[string]map[string]bool), - ratingDb: ratingDb, + table: make(map[string]map[string]string), + index: make(map[string]map[string]bool), + accountingDb: accountingDb, } } func (um *UserMap) SetUser(up UserProfile, reply *string) error { um.mu.Lock() defer um.mu.Unlock() - if err := um.ratingDb.SetUser(&up); err != nil { + if err := um.accountingDb.SetUser(&up); err != nil { *reply = err.Error() return err } @@ -102,7 +102,7 @@ func (um *UserMap) SetUser(up UserProfile, reply *string) error { func (um *UserMap) RemoveUser(up UserProfile, reply *string) error { um.mu.Lock() defer um.mu.Unlock() - if err := um.ratingDb.RemoveUser(up.GetId()); err != nil { + if err := um.accountingDb.RemoveUser(up.GetId()); err != nil { *reply = err.Error() return err } @@ -140,7 +140,7 @@ func (um *UserMap) UpdateUser(up UserProfile, reply *string) error { UserName: up.UserName, Profile: m, } - if err := um.ratingDb.SetUser(finalUp); err != nil { + if err := um.accountingDb.SetUser(finalUp); err != nil { *reply = err.Error() return err } diff --git a/engine/users_test.go b/engine/users_test.go index 86699a9cb..2cfcc4f11 100644 --- a/engine/users_test.go +++ b/engine/users_test.go @@ -19,7 +19,7 @@ var testMap = UserMap{ } func TestUsersAdd(t *testing.T) { - tm := newUserMap(ratingStorage) + tm := newUserMap(accountingStorage) var r string up := UserProfile{ Tenant: "test", @@ -40,7 +40,7 @@ func TestUsersAdd(t *testing.T) { } func TestUsersUpdate(t *testing.T) { - tm := newUserMap(ratingStorage) + tm := newUserMap(accountingStorage) var r string up := UserProfile{ Tenant: "test", @@ -71,7 +71,7 @@ func TestUsersUpdate(t *testing.T) { } func TestUsersUpdateNotFound(t *testing.T) { - tm := newUserMap(ratingStorage) + tm := newUserMap(accountingStorage) var r string up := UserProfile{ Tenant: "test", @@ -89,7 +89,7 @@ func TestUsersUpdateNotFound(t *testing.T) { } func TestUsersUpdateInit(t *testing.T) { - tm := newUserMap(ratingStorage) + tm := newUserMap(accountingStorage) var r string up := UserProfile{ Tenant: "test", @@ -115,7 +115,7 @@ func TestUsersUpdateInit(t *testing.T) { } func TestUsersRemove(t *testing.T) { - tm := newUserMap(ratingStorage) + tm := newUserMap(accountingStorage) var r string up := UserProfile{ Tenant: "test", @@ -445,7 +445,7 @@ func TestUsersGetMissingIdTwoINdex(t *testing.T) { } func TestUsersAddUpdateRemoveIndexes(t *testing.T) { - tm := newUserMap(ratingStorage) + tm := newUserMap(accountingStorage) var r string tm.AddIndex([]string{"t"}, &r) if len(tm.index) != 0 {