mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-23 08:08:45 +05:00
@@ -46,7 +46,6 @@ type ApierV1 struct {
|
||||
CdrDb engine.CdrStorage
|
||||
Config *config.CGRConfig
|
||||
Responder *engine.Responder
|
||||
Users rpcclient.RpcClientConnection
|
||||
CDRs rpcclient.RpcClientConnection // FixMe: populate it from cgr-engine
|
||||
ServManager *servmanager.ServiceManager // Need to have them capitalize so we can export in V2
|
||||
HTTPPoster *engine.HTTPPoster
|
||||
@@ -986,13 +985,6 @@ func (self *ApierV1) GetCacheStats(attrs utils.AttrCacheStats, reply *utils.Cach
|
||||
cs.ChargerProfiles = len(engine.Cache.GetItemIDs(utils.CacheChargerProfiles, ""))
|
||||
cs.DispatcherProfiles = len(engine.Cache.GetItemIDs(utils.CacheDispatcherProfiles, ""))
|
||||
|
||||
if self.Users != nil {
|
||||
var ups engine.UserProfiles
|
||||
if err := self.Users.Call("UsersV1.GetUsers", &engine.UserProfile{}, &ups); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
cs.Users = len(ups)
|
||||
}
|
||||
*reply = *cs
|
||||
return nil
|
||||
}
|
||||
@@ -1173,7 +1165,6 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
|
||||
path.Join(attrs.FolderPath, utils.ACTION_TRIGGERS_CSV),
|
||||
path.Join(attrs.FolderPath, utils.ACCOUNT_ACTIONS_CSV),
|
||||
path.Join(attrs.FolderPath, utils.DERIVED_CHARGERS_CSV),
|
||||
path.Join(attrs.FolderPath, utils.USERS_CSV),
|
||||
path.Join(attrs.FolderPath, utils.ResourcesCsv),
|
||||
path.Join(attrs.FolderPath, utils.StatsCsv),
|
||||
path.Join(attrs.FolderPath, utils.ThresholdsCsv),
|
||||
@@ -1214,7 +1205,6 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
|
||||
}
|
||||
}
|
||||
aps, _ := loader.GetLoadedIds(utils.ACTION_PLAN_PREFIX)
|
||||
userKeys, _ := loader.GetLoadedIds(utils.USERS_PREFIX)
|
||||
|
||||
// relase tp data
|
||||
loader.Init()
|
||||
@@ -1226,12 +1216,6 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
|
||||
sched.Reload()
|
||||
}
|
||||
}
|
||||
if len(userKeys) != 0 && self.Users != nil {
|
||||
var r string
|
||||
if err := self.Users.Call("UsersV1.ReloadUsers", "", &r); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -28,10 +28,6 @@ import (
|
||||
|
||||
// Returns MaxUsage (for calls in seconds), -1 for no limit
|
||||
func (self *ApierV1) GetMaxUsage(usageRecord engine.UsageRecord, maxUsage *int64) error {
|
||||
err := engine.LoadUserProfile(&usageRecord, "ExtraFields")
|
||||
if err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
if usageRecord.ToR == "" {
|
||||
usageRecord.ToR = utils.VOICE
|
||||
}
|
||||
|
||||
@@ -46,12 +46,6 @@ func (apier *ApierV1) DebitUsageWithOptions(args AttrDebitUsageWithOptions, repl
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
|
||||
err := engine.LoadUserProfile(args.UsageRecord, "")
|
||||
if err != nil {
|
||||
*reply = err.Error()
|
||||
return err
|
||||
}
|
||||
|
||||
// Set values for optional parameters
|
||||
if usageRecord.ToR == "" {
|
||||
usageRecord.ToR = utils.VOICE
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
// Creates a new alias within a tariff plan
|
||||
func (self *ApierV1) SetTPUser(attrs utils.TPUsers, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "UserName", "Tenant"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.SetTPUsers([]*utils.TPUsers{&attrs}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrGetTPUser struct {
|
||||
TPid string // Tariff plan id
|
||||
Tenant string
|
||||
UserName string
|
||||
}
|
||||
|
||||
// Queries specific User on Tariff plan
|
||||
func (self *ApierV1) GetTPUser(attr AttrGetTPUser, reply *utils.TPUsers) error {
|
||||
if missing := utils.MissingStructFields(&attr, []string{"TPid", "UserName", "Tenant"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
filter := &utils.TPUsers{TPid: attr.TPid, UserName: attr.UserName, Tenant: attr.Tenant}
|
||||
if tms, err := self.StorDb.GetTPUsers(filter); err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
*reply = *tms[0]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrGetTPUserIds struct {
|
||||
TPid string // Tariff plan id
|
||||
utils.Paginator
|
||||
}
|
||||
|
||||
// Queries alias identities on specific tariff plan.
|
||||
func (self *ApierV1) GetTPUserIds(attrs AttrGetTPUserIds, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPUsers, utils.TPDistinctIds{"tenant", "user_name"}, nil, &attrs.Paginator); err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
*reply = ids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Removes specific User on Tariff plan
|
||||
func (self *ApierV1) RemTPUser(attrs AttrGetTPUser, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Tenant", "UserName"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBLTPUsers, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "user_name": attrs.UserName}); err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
*reply = utils.OK
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,243 +0,0 @@
|
||||
// +build offline_tp
|
||||
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
tpUserCfgPath string
|
||||
tpUserCfg *config.CGRConfig
|
||||
tpUserRPC *rpc.Client
|
||||
tpUserDataDir = "/usr/share/cgrates"
|
||||
tpUser *utils.TPUsers
|
||||
tpUserDelay int
|
||||
tpUserConfigDIR string //run tests for specific configuration
|
||||
)
|
||||
|
||||
var sTestsTPUsers = []func(t *testing.T){
|
||||
testTPUsersInitCfg,
|
||||
testTPUsersResetStorDb,
|
||||
testTPUsersStartEngine,
|
||||
testTPUsersRpcConn,
|
||||
testTPUsersGetTPUserBeforeSet,
|
||||
testTPUsersSetTPUser,
|
||||
testTPUsersGetTPUserAfterSet,
|
||||
testTPUsersGetTPUserID,
|
||||
testTPUsersUpdateTPUser,
|
||||
testTPUsersGetTPUserAfterUpdate,
|
||||
testTPUsersRemTPUser,
|
||||
testTPUsersGetTPUserAfterRemove,
|
||||
testTPUsersKillEngine,
|
||||
}
|
||||
|
||||
//Test start here
|
||||
func TestTPUserITMySql(t *testing.T) {
|
||||
tpUserConfigDIR = "tutmysql"
|
||||
for _, stest := range sTestsTPUsers {
|
||||
t.Run(tpUserConfigDIR, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPUserITMongo(t *testing.T) {
|
||||
tpUserConfigDIR = "tutmongo"
|
||||
for _, stest := range sTestsTPUsers {
|
||||
t.Run(tpUserConfigDIR, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPUserITPG(t *testing.T) {
|
||||
tpUserConfigDIR = "tutpostgres"
|
||||
for _, stest := range sTestsTPUsers {
|
||||
t.Run(tpUserConfigDIR, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPUsersInitCfg(t *testing.T) {
|
||||
var err error
|
||||
tpUserCfgPath = path.Join(tpUserDataDir, "conf", "samples", tpUserConfigDIR)
|
||||
tpUserCfg, err = config.NewCGRConfigFromFolder(tpUserCfgPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tpUserCfg.DataFolderPath = tpUserDataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(tpUserCfg)
|
||||
switch tpUserConfigDIR {
|
||||
case "tutmongo": // Mongo needs more time to reset db
|
||||
tpUserDelay = 2000
|
||||
default:
|
||||
tpUserDelay = 1000
|
||||
}
|
||||
}
|
||||
|
||||
// Wipe out the cdr database
|
||||
func testTPUsersResetStorDb(t *testing.T) {
|
||||
if err := engine.InitStorDb(tpUserCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Start CGR Engine
|
||||
func testTPUsersStartEngine(t *testing.T) {
|
||||
if _, err := engine.StopStartEngine(tpUserCfgPath, tpUserDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Connect rpc client to rater
|
||||
func testTPUsersRpcConn(t *testing.T) {
|
||||
var err error
|
||||
tpUserRPC, err = jsonrpc.Dial("tcp", tpUserCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPUsersGetTPUserBeforeSet(t *testing.T) {
|
||||
var reply *utils.TPUsers
|
||||
if err := tpUserRPC.Call("ApierV1.GetTPUser", AttrGetTPUser{TPid: "TPU1", Tenant: "Tentant1", UserName: "User1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPUsersSetTPUser(t *testing.T) {
|
||||
tpUser = &utils.TPUsers{
|
||||
TPid: "TPU1",
|
||||
UserName: "User1",
|
||||
Tenant: "Tenant1",
|
||||
Masked: true,
|
||||
Weight: 20,
|
||||
Profile: []*utils.TPUserProfile{
|
||||
&utils.TPUserProfile{
|
||||
AttrName: "UserProfile1",
|
||||
AttrValue: "ValUP1",
|
||||
},
|
||||
&utils.TPUserProfile{
|
||||
AttrName: "UserProfile2",
|
||||
AttrValue: "ValUP2",
|
||||
},
|
||||
},
|
||||
}
|
||||
var result string
|
||||
if err := tpUserRPC.Call("ApierV1.SetTPUser", tpUser, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPUsersGetTPUserAfterSet(t *testing.T) {
|
||||
var respond *utils.TPUsers
|
||||
if err := tpUserRPC.Call("ApierV1.GetTPUser", &AttrGetTPUser{TPid: tpUser.TPid, UserName: tpUser.UserName, Tenant: tpUser.Tenant}, &respond); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tpUser.TPid, respond.TPid) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tpUser.TPid, respond.TPid)
|
||||
} else if !reflect.DeepEqual(tpUser.UserName, respond.UserName) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tpUser.UserName, respond.UserName)
|
||||
} else if !reflect.DeepEqual(tpUser.Tenant, respond.Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tpUser.Tenant, respond.Tenant)
|
||||
} else if !reflect.DeepEqual(tpUser.Weight, respond.Weight) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tpUser.Weight, respond.Weight)
|
||||
} else if !reflect.DeepEqual(len(tpUser.Profile), len(respond.Profile)) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", len(tpUser.Profile), len(respond.Profile))
|
||||
}
|
||||
}
|
||||
|
||||
func testTPUsersGetTPUserID(t *testing.T) {
|
||||
var result []string
|
||||
expectedTPID := []string{"Tenant1:User1"}
|
||||
if err := tpUserRPC.Call("ApierV1.GetTPUserIds", AttrGetTPUserIds{tpUser.TPid, utils.Paginator{}}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(result, expectedTPID) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", result, expectedTPID)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPUsersUpdateTPUser(t *testing.T) {
|
||||
var result string
|
||||
tpUser.Profile = []*utils.TPUserProfile{
|
||||
&utils.TPUserProfile{
|
||||
AttrName: "UserProfile1",
|
||||
AttrValue: "ValUp1",
|
||||
},
|
||||
&utils.TPUserProfile{
|
||||
AttrName: "UserProfile2",
|
||||
AttrValue: "ValUP2",
|
||||
},
|
||||
&utils.TPUserProfile{
|
||||
AttrName: "UserProfile3",
|
||||
AttrValue: "ValUP3",
|
||||
},
|
||||
}
|
||||
if err := tpUserRPC.Call("ApierV1.SetTPUser", tpUser, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPUsersGetTPUserAfterUpdate(t *testing.T) {
|
||||
var respond *utils.TPUsers
|
||||
if err := tpUserRPC.Call("ApierV1.GetTPUser", &AttrGetTPUser{TPid: tpUser.TPid, Tenant: tpUser.Tenant, UserName: tpUser.UserName}, &respond); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tpUser.TPid, respond.TPid) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tpUser.TPid, respond.TPid)
|
||||
} else if !reflect.DeepEqual(tpUser.UserName, respond.UserName) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tpUser.UserName, respond.UserName)
|
||||
} else if !reflect.DeepEqual(tpUser.Tenant, respond.Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tpUser.Tenant, respond.Tenant)
|
||||
} else if !reflect.DeepEqual(tpUser.Weight, respond.Weight) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tpUser.Weight, respond.Weight)
|
||||
} else if !reflect.DeepEqual(len(tpUser.Profile), len(respond.Profile)) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", len(tpUser.Profile), len(respond.Profile))
|
||||
}
|
||||
}
|
||||
|
||||
func testTPUsersRemTPUser(t *testing.T) {
|
||||
var resp string
|
||||
if err := tpUserRPC.Call("ApierV1.RemTPUser", &AttrGetTPUser{TPid: tpUser.TPid, Tenant: tpUser.Tenant, UserName: tpUser.UserName}, &resp); err != nil {
|
||||
t.Error(err)
|
||||
} else if resp != utils.OK {
|
||||
t.Error("Unexpected reply returned", resp)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPUsersGetTPUserAfterRemove(t *testing.T) {
|
||||
var respond *utils.TPUsers
|
||||
if err := tpUserRPC.Call("ApierV1.GetTPUser", &AttrGetTPUser{TPid: "TPU1", UserName: "User1", Tenant: "Tenant1"}, &respond); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPUsersKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(tpUserDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@ func testVrsStorDB(t *testing.T) {
|
||||
expectedVrs := engine.Versions{"TpDerivedChargers": 1, "TpDestinations": 1, "TpResource": 1, "TpThresholds": 1,
|
||||
"TpActions": 1, "TpDestinationRates": 1, "TpFilters": 1, "TpRates": 1, "CDRs": 2, "TpActionTriggers": 1, "TpRatingPlans": 1,
|
||||
"TpSharedGroups": 1, "TpSuppliers": 1, "SessionSCosts": 3, "TpDerivedCharges": 1, "TpRatingProfiles": 1, "TpStats": 1, "TpTiming": 1,
|
||||
"CostDetails": 2, "TpAccountActions": 1, "TpActionPlans": 1, "TpChargers": 1, "TpRatingProfile": 1, "TpUsers": 1,
|
||||
"CostDetails": 2, "TpAccountActions": 1, "TpActionPlans": 1, "TpChargers": 1, "TpRatingProfile": 1,
|
||||
"TpRatingPlan": 1, "TpResources": 1}
|
||||
if err := vrsRPC.Call("ApierV1.GetStorDBVersions", "", &result); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -136,7 +136,6 @@ func (self *ApierV2) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
|
||||
path.Join(attrs.FolderPath, utils.ACTION_TRIGGERS_CSV),
|
||||
path.Join(attrs.FolderPath, utils.ACCOUNT_ACTIONS_CSV),
|
||||
path.Join(attrs.FolderPath, utils.DERIVED_CHARGERS_CSV),
|
||||
path.Join(attrs.FolderPath, utils.USERS_CSV),
|
||||
path.Join(attrs.FolderPath, utils.ResourcesCsv),
|
||||
path.Join(attrs.FolderPath, utils.StatsCsv),
|
||||
path.Join(attrs.FolderPath, utils.ThresholdsCsv),
|
||||
@@ -178,7 +177,6 @@ func (self *ApierV2) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
|
||||
}
|
||||
}
|
||||
aps, _ := loader.GetLoadedIds(utils.ACTION_PLAN_PREFIX)
|
||||
userKeys, _ := loader.GetLoadedIds(utils.USERS_PREFIX)
|
||||
|
||||
// relase tp data
|
||||
loader.Init()
|
||||
@@ -190,12 +188,6 @@ func (self *ApierV2) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
|
||||
sched.Reload()
|
||||
}
|
||||
}
|
||||
if len(userKeys) != 0 && self.Users != nil {
|
||||
var r string
|
||||
if err := self.Users.Call("UsersV1.ReloadUsers", "", &r); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
loadHistList, err := self.DataManager.DataDB().GetLoadHistory(1, true, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user