mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
moved users in accounting db
This commit is contained in:
@@ -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("<UsersService> Could not start, error: %s", err.Error()))
|
||||
exitChan <- true
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user