Remove in progress

This commit is contained in:
Trial97
2021-03-30 09:03:41 +03:00
committed by Dan Christian Bogos
parent c0b66f42aa
commit 7b5f6154ed
108 changed files with 44 additions and 15370 deletions

View File

@@ -106,7 +106,6 @@ type ResponderInterface interface {
GetCost(arg *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) (err error)
Debit(arg *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) (err error)
MaxDebit(arg *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) (err error)
RefundIncrements(arg *engine.CallDescriptorWithAPIOpts, reply *engine.Account) (err error)
RefundRounding(arg *engine.CallDescriptorWithAPIOpts, reply *float64) (err error)
GetMaxSessionTime(arg *engine.CallDescriptorWithAPIOpts, reply *time.Duration) (err error)
Shutdown(arg *utils.TenantWithAPIOpts, reply *string) (err error)
@@ -163,11 +162,6 @@ type ServiceManagerV1Interface interface {
Ping(ign *utils.CGREvent, reply *string) error
}
type RALsV1Interface interface {
GetRatingPlansCost(arg *utils.RatingPlanCostArg, reply *dispatchers.RatingPlanCost) error
Ping(ign *utils.CGREvent, reply *string) error
}
type ConfigSv1Interface interface {
GetConfig(section *config.SectionWithAPIOpts, reply *map[string]interface{}) (err error)
ReloadConfig(section *config.ReloadArgs, reply *string) (err error)
@@ -193,7 +187,6 @@ type RateProfileSv1Interface interface {
type ReplicatorSv1Interface interface {
Ping(ign *utils.CGREvent, reply *string) error
GetAccount(args *utils.StringWithAPIOpts, reply *engine.Account) error
GetDestination(key *utils.StringWithAPIOpts, reply *engine.Destination) error
GetReverseDestination(key *utils.StringWithAPIOpts, reply *[]string) error
GetStatQueue(tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) error
@@ -204,14 +197,6 @@ type ReplicatorSv1Interface interface {
GetTiming(id *utils.StringWithAPIOpts, reply *utils.TPTiming) error
GetResource(tntID *utils.TenantIDWithAPIOpts, reply *engine.Resource) error
GetResourceProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ResourceProfile) error
GetActionTriggers(id *utils.StringWithAPIOpts, reply *engine.ActionTriggers) error
GetSharedGroup(id *utils.StringWithAPIOpts, reply *engine.SharedGroup) error
GetActions(id *utils.StringWithAPIOpts, reply *engine.Actions) error
GetActionPlan(id *utils.StringWithAPIOpts, reply *engine.ActionPlan) error
GetAllActionPlans(_ *utils.StringWithAPIOpts, reply *map[string]*engine.ActionPlan) error
GetAccountActionPlans(id *utils.StringWithAPIOpts, reply *[]string) error
GetRatingPlan(id *utils.StringWithAPIOpts, reply *engine.RatingPlan) error
GetRatingProfile(id *utils.StringWithAPIOpts, reply *engine.RatingProfile) error
GetRouteProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) error
GetAttributeProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) error
GetChargerProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ChargerProfile) error
@@ -221,7 +206,6 @@ type ReplicatorSv1Interface interface {
GetItemLoadIDs(itemID *utils.StringWithAPIOpts, reply *map[string]int64) error
SetThresholdProfile(th *engine.ThresholdProfileWithAPIOpts, reply *string) error
SetThreshold(th *engine.ThresholdWithAPIOpts, reply *string) error
SetAccount(acc *engine.AccountWithAPIOpts, reply *string) error
SetDestination(dst *engine.DestinationWithAPIOpts, reply *string) error
SetReverseDestination(dst *engine.DestinationWithAPIOpts, reply *string) error
SetStatQueue(ssq *engine.StatQueueWithAPIOpts, reply *string) error
@@ -230,23 +214,16 @@ type ReplicatorSv1Interface interface {
SetTiming(tm *utils.TPTimingWithAPIOpts, reply *string) error
SetResource(rs *engine.ResourceWithAPIOpts, reply *string) error
SetResourceProfile(rs *engine.ResourceProfileWithAPIOpts, reply *string) error
SetActionTriggers(args *engine.SetActionTriggersArgWithAPIOpts, reply *string) error
SetSharedGroup(shg *engine.SharedGroupWithAPIOpts, reply *string) error
SetActions(args *engine.SetActionsArgsWithAPIOpts, reply *string) error
SetRatingPlan(rp *engine.RatingPlanWithAPIOpts, reply *string) error
SetRatingProfile(rp *engine.RatingProfileWithAPIOpts, reply *string) error
SetRouteProfile(sp *engine.RouteProfileWithAPIOpts, reply *string) error
SetAttributeProfile(ap *engine.AttributeProfileWithAPIOpts, reply *string) error
SetChargerProfile(cp *engine.ChargerProfileWithAPIOpts, reply *string) error
SetDispatcherProfile(dpp *engine.DispatcherProfileWithAPIOpts, reply *string) error
SetRateProfile(dpp *utils.RateProfileWithAPIOpts, reply *string) error
SetActionPlan(args *engine.SetActionPlanArgWithAPIOpts, reply *string) error
SetAccountActionPlans(args *engine.SetAccountActionPlansArgWithAPIOpts, reply *string) error
SetDispatcherHost(dpp *engine.DispatcherHostWithAPIOpts, reply *string) error
RemoveThreshold(args *utils.TenantIDWithAPIOpts, reply *string) error
SetLoadIDs(args *utils.LoadIDsWithAPIOpts, reply *string) error
RemoveDestination(id *utils.StringWithAPIOpts, reply *string) error
RemoveAccount(id *utils.StringWithAPIOpts, reply *string) error
RemoveStatQueue(args *utils.TenantIDWithAPIOpts, reply *string) error
RemoveFilter(args *utils.TenantIDWithAPIOpts, reply *string) error
RemoveThresholdProfile(args *utils.TenantIDWithAPIOpts, reply *string) error
@@ -254,13 +231,7 @@ type ReplicatorSv1Interface interface {
RemoveTiming(id *utils.StringWithAPIOpts, reply *string) error
RemoveResource(args *utils.TenantIDWithAPIOpts, reply *string) error
RemoveResourceProfile(args *utils.TenantIDWithAPIOpts, reply *string) error
RemoveActionTriggers(id *utils.StringWithAPIOpts, reply *string) error
RemoveSharedGroup(id *utils.StringWithAPIOpts, reply *string) error
RemoveActions(id *utils.StringWithAPIOpts, reply *string) error
RemoveActionPlan(id *utils.StringWithAPIOpts, reply *string) error
RemAccountActionPlans(args *engine.RemAccountActionPlansArgsWithAPIOpts, reply *string) error
RemoveRatingPlan(id *utils.StringWithAPIOpts, reply *string) error
RemoveRatingProfile(id *utils.StringWithAPIOpts, reply *string) error
RemoveRouteProfile(args *utils.TenantIDWithAPIOpts, reply *string) error
RemoveAttributeProfile(args *utils.TenantIDWithAPIOpts, reply *string) error
RemoveChargerProfile(args *utils.TenantIDWithAPIOpts, reply *string) error

View File

@@ -89,11 +89,6 @@ func TestServiceManagerV1Interface(t *testing.T) {
_ = ServiceManagerV1Interface(NewServiceManagerV1(nil))
}
func TestRALsV1Interface(t *testing.T) {
_ = RALsV1Interface(NewDispatcherRALsV1(nil))
_ = RALsV1Interface(NewRALsV1())
}
func TestConfigSv1Interface(t *testing.T) {
_ = ConfigSv1Interface(NewDispatcherConfigSv1(nil))
_ = ConfigSv1Interface(NewConfigSv1(nil))

View File

@@ -20,7 +20,6 @@ package v1
import (
"encoding/csv"
"errors"
"fmt"
"os"
"path"
@@ -30,7 +29,6 @@ import (
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/guardian"
"github.com/cgrates/cgrates/utils"
)
@@ -39,12 +37,10 @@ type APIerSv1 struct {
CdrDb engine.CdrStorage
DataManager *engine.DataManager
Config *config.CGRConfig
Responder *engine.Responder
FilterS *engine.FilterS //Used for CDR Exporter
ConnMgr *engine.ConnManager
StorDBChan chan engine.StorDB
ResponderChan chan *engine.Responder
StorDBChan chan engine.StorDB
}
// Call implements rpcclient.ClientConnector interface for internal RPC
@@ -139,26 +135,6 @@ func (apierSv1 *APIerSv1) ComputeReverseDestinations(ignr *string, reply *string
return
}
// ComputeAccountActionPlans will rebuild complete reverse accountActions data
func (apierSv1 *APIerSv1) ComputeAccountActionPlans(ignr *string, reply *string) (err error) {
if err = apierSv1.DataManager.RebuildReverseForPrefix(utils.AccountActionPlansPrefix); err != nil {
return
}
*reply = utils.OK
return
}
func (apierSv1 *APIerSv1) GetSharedGroup(sgId *string, reply *engine.SharedGroup) error {
if sg, err := apierSv1.DataManager.GetSharedGroup(*sgId, false, utils.NonTransactional); err != nil && err != utils.ErrNotFound { // Not found is not an error here
return err
} else {
if sg != nil {
*reply = *sg
}
}
return nil
}
func (apierSv1 *APIerSv1) SetDestination(attrs *utils.AttrSetDestination, reply *string) (err error) {
if missing := utils.MissingStructFields(attrs, []string{"Id", "Prefixes"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
@@ -189,59 +165,6 @@ func (apierSv1 *APIerSv1) SetDestination(attrs *utils.AttrSetDestination, reply
return nil
}
func (apierSv1 *APIerSv1) GetRatingPlan(rplnId *string, reply *engine.RatingPlan) error {
rpln, err := apierSv1.DataManager.GetRatingPlan(*rplnId, false, utils.NonTransactional)
if err != nil {
if err.Error() == utils.ErrNotFound.Error() {
return err
}
return utils.NewErrServerError(err)
}
*reply = *rpln
return nil
}
func (apierSv1 *APIerSv1) RemoveRatingPlan(ID *string, reply *string) error {
if len(*ID) == 0 {
return utils.NewErrMandatoryIeMissing("ID")
}
err := apierSv1.DataManager.RemoveRatingPlan(*ID, utils.NonTransactional)
if err != nil {
return utils.NewErrServerError(err)
}
if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil,
utils.CacheSv1ReloadCache, utils.AttrReloadCacheWithAPIOpts{
ArgsCache: map[string][]string{utils.RatingPlanIDs: {*ID}},
}, reply); err != nil {
return err
}
//generate a loadID for CacheRatingPlans and store it in database
if err := apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheRatingPlans: time.Now().UnixNano()}); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
return nil
}
func (apierSv1 *APIerSv1) ExecuteAction(attr *utils.AttrExecuteAction, reply *string) error {
at := &engine.ActionTiming{
ActionsID: attr.ActionsId,
}
tnt := attr.Tenant
if tnt == utils.EmptyString {
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
}
if attr.Account != "" {
at.SetAccountIDs(utils.StringMap{utils.ConcatenatedKey(tnt, attr.Account): true})
}
if err := at.Execute(nil, nil); err != nil {
*reply = err.Error()
return err
}
*reply = utils.OK
return nil
}
type AttrLoadDestination struct {
TPid string
ID string
@@ -274,90 +197,11 @@ func (apierSv1 *APIerSv1) LoadDestination(attrs *AttrLoadDestination, reply *str
return nil
}
type AttrLoadRatingPlan struct {
TPid string
RatingPlanId string
}
// Process dependencies and load a specific rating plan from storDb into dataDb.
func (apierSv1 *APIerSv1) LoadRatingPlan(attrs *AttrLoadRatingPlan, reply *string) error {
if len(attrs.TPid) == 0 {
return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader, err := engine.NewTpReader(apierSv1.DataManager.DataDB(), apierSv1.StorDb,
attrs.TPid, apierSv1.Config.GeneralCfg().DefaultTimezone,
apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionConns,
apierSv1.Config.DataDbCfg().Type == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
if loaded, err := dbReader.LoadRatingPlansFiltered(attrs.RatingPlanId); err != nil {
return utils.NewErrServerError(err)
} else if !loaded {
return utils.ErrNotFound
}
*reply = utils.OK
return nil
}
// Process dependencies and load a specific rating profile from storDb into dataDb.
func (apierSv1 *APIerSv1) LoadRatingProfile(attrs *utils.TPRatingProfile, reply *string) error {
if len(attrs.TPid) == 0 {
return utils.NewErrMandatoryIeMissing("TPid")
}
if attrs.Tenant == utils.EmptyString {
attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
}
dbReader, err := engine.NewTpReader(apierSv1.DataManager.DataDB(), apierSv1.StorDb,
attrs.TPid, apierSv1.Config.GeneralCfg().DefaultTimezone,
apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionConns,
apierSv1.Config.DataDbCfg().Type == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
if err := dbReader.LoadRatingProfilesFiltered(attrs); err != nil {
return utils.NewErrServerError(err)
}
if err := apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheRatingProfiles: time.Now().UnixNano()}); err != nil {
return utils.APIErrorHandler(err)
}
if err = dbReader.ReloadCache(config.CgrConfig().GeneralCfg().DefaultCaching, true, make(map[string]interface{})); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
type AttrLoadSharedGroup struct {
TPid string
SharedGroupId string
}
// Load destinations from storDb into dataDb.
func (apierSv1 *APIerSv1) LoadSharedGroup(attrs *AttrLoadSharedGroup, reply *string) error {
if len(attrs.TPid) == 0 {
return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader, err := engine.NewTpReader(apierSv1.DataManager.DataDB(), apierSv1.StorDb,
attrs.TPid, apierSv1.Config.GeneralCfg().DefaultTimezone,
apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionConns,
apierSv1.Config.DataDbCfg().Type == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
if err := dbReader.LoadSharedGroupsFiltered(attrs.SharedGroupId, true); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
type AttrLoadTpFromStorDb struct {
TPid string
DryRun bool // Only simulate, no write
Validate bool // Run structural checks
APIOpts map[string]interface{}
Caching *string // Caching strategy
TPid string
DryRun bool // Only simulate, no write
APIOpts map[string]interface{}
Caching *string // Caching strategy
}
// Loads complete data in a TP from storDb
@@ -375,12 +219,6 @@ func (apierSv1 *APIerSv1) LoadTariffPlanFromStorDb(attrs *AttrLoadTpFromStorDb,
if err := dbReader.LoadAll(); err != nil {
return utils.NewErrServerError(err)
}
if attrs.Validate {
if !dbReader.IsValid() {
*reply = utils.OK
return errors.New("invalid data")
}
}
if attrs.DryRun {
*reply = utils.OK
return nil // Mission complete, no errors
@@ -440,106 +278,6 @@ func (apierSv1 *APIerSv1) ImportTariffPlanFromFolder(attrs *utils.AttrImportTPFr
return nil
}
// SetRatingProfile sets a specific rating profile working with data directly in the DataDB without involving storDb
func (apierSv1 *APIerSv1) SetRatingProfile(attrs *utils.AttrSetRatingProfile, reply *string) (err error) {
if missing := utils.MissingStructFields(attrs, []string{"ToR", "Subject", "RatingPlanActivations"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
for _, rpa := range attrs.RatingPlanActivations {
if missing := utils.MissingStructFields(rpa, []string{"ActivationTimes", "RatingPlanId"}); len(missing) != 0 {
return fmt.Errorf("%s:RatingPlanActivation:%v", utils.ErrMandatoryIeMissing.Error(), missing)
}
}
tnt := attrs.Tenant
if tnt == utils.EmptyString {
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
}
keyID := utils.ConcatenatedKey(utils.MetaOut,
tnt, attrs.Category, attrs.Subject)
var rpfl *engine.RatingProfile
if !attrs.Overwrite {
if rpfl, err = apierSv1.DataManager.GetRatingProfile(keyID, false, utils.NonTransactional); err != nil && err != utils.ErrNotFound {
return utils.NewErrServerError(err)
}
}
if rpfl == nil {
rpfl = &engine.RatingProfile{Id: keyID, RatingPlanActivations: make(engine.RatingPlanActivations, 0)}
}
for _, ra := range attrs.RatingPlanActivations {
at, err := utils.ParseTimeDetectLayout(ra.ActivationTime,
apierSv1.Config.GeneralCfg().DefaultTimezone)
if err != nil {
return fmt.Errorf(fmt.Sprintf("%s:Cannot parse activation time from %v", utils.ErrServerError.Error(), ra.ActivationTime))
}
if exists, err := apierSv1.DataManager.HasData(utils.RatingPlanPrefix,
ra.RatingPlanId, ""); err != nil {
return utils.NewErrServerError(err)
} else if !exists {
return fmt.Errorf(fmt.Sprintf("%s:RatingPlanId:%s", utils.ErrNotFound.Error(), ra.RatingPlanId))
}
rpfl.RatingPlanActivations = append(rpfl.RatingPlanActivations,
&engine.RatingPlanActivation{
ActivationTime: at,
RatingPlanId: ra.RatingPlanId,
FallbackKeys: utils.FallbackSubjKeys(tnt,
attrs.Category, ra.FallbackSubjects)})
}
if err := apierSv1.DataManager.SetRatingProfile(rpfl, utils.NonTransactional); err != nil {
return utils.NewErrServerError(err)
}
//CacheReload
if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil,
utils.CacheSv1ReloadCache, utils.AttrReloadCacheWithAPIOpts{
ArgsCache: map[string][]string{utils.RatingProfileIDs: {rpfl.Id}},
}, reply); err != nil {
return err
}
//generate a loadID for CacheRatingProfiles and store it in database
if err := apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheRatingProfiles: time.Now().UnixNano()}); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
return nil
}
// GetRatingProfileIDs returns list of resourceProfile IDs registered for a tenant
func (apierSv1 *APIerSv1) GetRatingProfileIDs(args *utils.PaginatorWithTenant, rsPrfIDs *[]string) error {
tnt := args.Tenant
if tnt == utils.EmptyString {
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
}
prfx := utils.RatingProfilePrefix + "*out:" + tnt + utils.ConcatenatedKeySep
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx)
if err != nil {
return err
}
if len(keys) == 0 {
return utils.ErrNotFound
}
retIDs := make([]string, len(keys))
for i, key := range keys {
retIDs[i] = key[len(prfx):]
}
*rsPrfIDs = args.PaginateStringSlice(retIDs)
return nil
}
func (apierSv1 *APIerSv1) GetRatingProfile(attrs *utils.AttrGetRatingProfile, reply *engine.RatingProfile) (err error) {
if missing := utils.MissingStructFields(attrs, []string{utils.Category, utils.Subject}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if attrs.Tenant == utils.EmptyString {
attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
}
if rpPrf, err := apierSv1.DataManager.GetRatingProfile(attrs.GetID(),
false, utils.NonTransactional); err != nil {
return utils.APIErrorHandler(err)
} else {
*reply = *rpPrf
}
return
}
// Deprecated attrs
type V1AttrSetActions struct {
ActionsId string // Actions id
@@ -572,58 +310,6 @@ type V1TPAction struct {
Weight float64 // Action's weight
}
type AttrSetActionPlan struct {
Id string // Profile id
ActionPlan []*AttrActionPlan // Set of actions this Actions profile will perform
Overwrite bool // If previously defined, will be overwritten
}
type AttrActionPlan struct {
ActionsId string // Actions id
TimingID string // timingID is used to specify the ID of the timing for a corner case ( e.g. *monthly_estimated )
Years string // semicolon separated list of years this timing is valid on, *any or empty supported
Months string // semicolon separated list of months this timing is valid on, *any or empty supported
MonthDays string // semicolon separated list of month's days this timing is valid on, *any or empty supported
WeekDays string // semicolon separated list of week day names this timing is valid on *any or empty supported
Time string // String representing the time this timing starts on, *asap supported
Weight float64 // Binding's weight
}
func (attr *AttrActionPlan) getRITiming(dm *engine.DataManager) (timing *engine.RITiming, err error) {
if dfltTiming, isDefault := checkDefaultTiming(attr.Time); isDefault {
return dfltTiming, nil
}
timing = new(engine.RITiming)
if attr.TimingID != utils.EmptyString &&
!strings.HasPrefix(attr.TimingID, utils.Meta) { // in case of dynamic timing
if dbTiming, err := dm.GetTiming(attr.TimingID, false, utils.NonTransactional); err != nil {
if err != utils.ErrNotFound { // if not found let the user to populate all the timings values
return nil, err
}
} else {
timing.ID = dbTiming.ID
timing.Years = dbTiming.Years
timing.Months = dbTiming.Months
timing.MonthDays = dbTiming.MonthDays
timing.WeekDays = dbTiming.WeekDays
timing.StartTime = dbTiming.StartTime
timing.EndTime = dbTiming.EndTime
}
}
timing.ID = attr.TimingID
timing.Years.Parse(attr.Years, ";")
timing.Months.Parse(attr.Months, ";")
timing.MonthDays.Parse(attr.MonthDays, ";")
timing.WeekDays.Parse(attr.WeekDays, ";")
if !verifyFormat(attr.Time) {
err = fmt.Errorf("%s:%s", utils.ErrUnsupportedFormat.Error(), attr.Time)
return
}
timing.StartTime = attr.Time
return
}
func verifyFormat(tStr string) bool {
if tStr == utils.EmptyString ||
tStr == utils.MetaASAP {
@@ -647,157 +333,6 @@ func verifyFormat(tStr string) bool {
return true
}
// checkDefaultTiming will check the tStr if it's of the the default timings ( the same as in TPReader )
// and will compute it properly
func checkDefaultTiming(tStr string) (rTm *engine.RITiming, isDefault bool) {
startTime := time.Now().Format("15:04:05")
switch tStr {
case utils.MetaEveryMinute:
return &engine.RITiming{
ID: utils.MetaEveryMinute,
Years: utils.Years{},
Months: utils.Months{},
MonthDays: utils.MonthDays{},
WeekDays: utils.WeekDays{},
StartTime: utils.ConcatenatedKey(utils.Meta, utils.Meta, strconv.Itoa(time.Now().Second())),
EndTime: "",
}, true
case utils.MetaHourly:
return &engine.RITiming{
ID: utils.MetaHourly,
Years: utils.Years{},
Months: utils.Months{},
MonthDays: utils.MonthDays{},
WeekDays: utils.WeekDays{},
StartTime: utils.ConcatenatedKey(utils.Meta, strconv.Itoa(time.Now().Minute()), strconv.Itoa(time.Now().Second())),
EndTime: "",
}, true
case utils.MetaDaily:
return &engine.RITiming{
ID: utils.MetaDaily,
Years: utils.Years{},
Months: utils.Months{},
MonthDays: utils.MonthDays{},
WeekDays: utils.WeekDays{},
StartTime: startTime,
EndTime: ""}, true
case utils.MetaWeekly:
return &engine.RITiming{
ID: utils.MetaWeekly,
Years: utils.Years{},
Months: utils.Months{},
MonthDays: utils.MonthDays{},
WeekDays: utils.WeekDays{time.Now().Weekday()},
StartTime: startTime,
EndTime: "",
}, true
case utils.MetaMonthly:
return &engine.RITiming{
ID: utils.MetaMonthly,
Years: utils.Years{},
Months: utils.Months{},
MonthDays: utils.MonthDays{time.Now().Day()},
WeekDays: utils.WeekDays{},
StartTime: startTime,
EndTime: "",
}, true
case utils.MetaMonthlyEstimated:
return &engine.RITiming{
ID: utils.MetaMonthlyEstimated,
Years: utils.Years{},
Months: utils.Months{},
MonthDays: utils.MonthDays{time.Now().Day()},
WeekDays: utils.WeekDays{},
StartTime: startTime,
EndTime: "",
}, true
case utils.MetaMonthEnd:
return &engine.RITiming{
ID: utils.MetaMonthEnd,
Years: utils.Years{},
Months: utils.Months{},
MonthDays: utils.MonthDays{-1},
WeekDays: utils.WeekDays{},
StartTime: startTime,
EndTime: "",
}, true
case utils.MetaYearly:
return &engine.RITiming{
ID: utils.MetaYearly,
Years: utils.Years{},
Months: utils.Months{time.Now().Month()},
MonthDays: utils.MonthDays{time.Now().Day()},
WeekDays: utils.WeekDays{},
StartTime: startTime,
EndTime: "",
}, true
default:
return nil, false
}
}
type AttrGetActionPlan struct {
ID string
}
func (apierSv1 *APIerSv1) GetActionPlan(attr *AttrGetActionPlan, reply *[]*engine.ActionPlan) error {
var result []*engine.ActionPlan
if attr.ID == "" || attr.ID == "*" {
result = make([]*engine.ActionPlan, 0)
aplsMap, err := apierSv1.DataManager.GetAllActionPlans()
if err != nil {
return err
}
for _, apls := range aplsMap {
result = append(result, apls)
}
} else {
apls, err := apierSv1.DataManager.GetActionPlan(attr.ID, false, utils.NonTransactional)
if err != nil {
return err
}
result = append(result, apls)
}
*reply = result
return nil
}
func (apierSv1 *APIerSv1) RemoveActionPlan(attr *AttrGetActionPlan, reply *string) (err error) {
if missing := utils.MissingStructFields(attr, []string{"ID"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if _, err = guardian.Guardian.Guard(func() (interface{}, error) {
var prevAccountIDs utils.StringMap
if prevAP, err := apierSv1.DataManager.GetActionPlan(attr.ID, false, utils.NonTransactional); err != nil && err != utils.ErrNotFound {
return 0, err
} else if prevAP != nil {
prevAccountIDs = prevAP.AccountIDs
}
if err := apierSv1.DataManager.RemoveActionPlan(attr.ID, utils.NonTransactional); err != nil {
return 0, err
}
for acntID := range prevAccountIDs {
if err := apierSv1.DataManager.RemAccountActionPlans(acntID, []string{attr.ID}); err != nil {
return 0, utils.NewErrServerError(err)
}
}
if len(prevAccountIDs) != 0 {
sl := prevAccountIDs.Slice()
if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil,
utils.CacheSv1ReloadCache, utils.AttrReloadCacheWithAPIOpts{
ArgsCache: map[string][]string{utils.AccountActionPlanIDs: sl},
}, reply); err != nil {
return 0, err
}
}
return 0, nil
}, config.CgrConfig().GeneralCfg().LockingTimeout, utils.ActionPlanPrefix); err != nil {
return err
}
*reply = utils.OK
return nil
}
func (apierSv1 *APIerSv1) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFolder, reply *string) error {
// verify if FolderPath is present
if len(attrs.FolderPath) == 0 {
@@ -831,12 +366,6 @@ func (apierSv1 *APIerSv1) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFo
return nil // Mission complete, no errors
}
if attrs.Validate {
if !loader.IsValid() {
return errors.New("invalid data")
}
}
// write data intro Database
if err := loader.WriteToDatabase(false, false); err != nil {
return utils.NewErrServerError(err)
@@ -897,12 +426,6 @@ func (apierSv1 *APIerSv1) RemoveTPFromFolder(attrs *utils.AttrLoadTpFromFolder,
return nil // Mission complete, no errors
}
if attrs.Validate {
if !loader.IsValid() {
return errors.New("invalid data")
}
}
// remove data from Database
if err := loader.RemoveFromDatabase(false, false); err != nil {
return utils.NewErrServerError(err)
@@ -945,12 +468,6 @@ func (apierSv1 *APIerSv1) RemoveTPFromStorDB(attrs *AttrLoadTpFromStorDb, reply
if err := dbReader.LoadAll(); err != nil {
return utils.NewErrServerError(err)
}
if attrs.Validate {
if !dbReader.IsValid() {
*reply = utils.OK
return errors.New("invalid data")
}
}
if attrs.DryRun {
*reply = utils.OK
return nil // Mission complete, no errors
@@ -1006,35 +523,6 @@ func (arrp *AttrRemoveRatingProfile) GetId() (result string) {
return
}
func (apierSv1 *APIerSv1) RemoveRatingProfile(attr *AttrRemoveRatingProfile, reply *string) error {
if attr.Tenant == utils.EmptyString {
attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
}
if (attr.Subject != "" && utils.IsSliceMember([]string{attr.Tenant, attr.Category}, "")) ||
(attr.Category != "" && attr.Tenant == "") {
return utils.ErrMandatoryIeMissing
}
_, err := guardian.Guardian.Guard(func() (interface{}, error) {
return 0, apierSv1.DataManager.RemoveRatingProfile(attr.GetId(), utils.NonTransactional)
}, config.CgrConfig().GeneralCfg().LockingTimeout, "RemoveRatingProfile")
if err != nil {
*reply = err.Error()
return utils.NewErrServerError(err)
}
if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil,
utils.CacheSv1ReloadCache, utils.AttrReloadCacheWithAPIOpts{
ArgsCache: map[string][]string{utils.RatingProfileIDs: {attr.GetId()}},
}, reply); err != nil {
return err
}
//generate a loadID for CacheActionPlans and store it in database
if err := apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheRatingProfiles: time.Now().UnixNano()}); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
return nil
}
func (apierSv1 *APIerSv1) GetLoadHistory(attrs *utils.Paginator, reply *[]*utils.LoadInstance) error {
nrItems := -1
offset := 0
@@ -1234,42 +722,6 @@ func (apierSv1 *APIerSv1) ComputeActionPlanIndexes(_ string, reply *string) (err
return nil
}
// GetActionPlanIDs returns list of ActionPlan IDs registered for a tenant
func (apierSv1 *APIerSv1) GetActionPlanIDs(args *utils.PaginatorWithTenant, attrPrfIDs *[]string) error {
prfx := utils.ActionPlanPrefix
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(utils.ActionPlanPrefix)
if err != nil {
return err
}
if len(keys) == 0 {
return utils.ErrNotFound
}
retIDs := make([]string, len(keys))
for i, key := range keys {
retIDs[i] = key[len(prfx):]
}
*attrPrfIDs = args.PaginateStringSlice(retIDs)
return nil
}
// GetRatingPlanIDs returns list of RatingPlan IDs registered for a tenant
func (apierSv1 *APIerSv1) GetRatingPlanIDs(args *utils.PaginatorWithTenant, attrPrfIDs *[]string) error {
prfx := utils.RatingPlanPrefix
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(utils.RatingPlanPrefix)
if err != nil {
return err
}
if len(keys) == 0 {
return utils.ErrNotFound
}
retIDs := make([]string, len(keys))
for i, key := range keys {
retIDs[i] = key[len(prfx):]
}
*attrPrfIDs = args.PaginateStringSlice(retIDs)
return nil
}
// ListenAndServe listen for storbd reload
func (apierSv1 *APIerSv1) ListenAndServe(stopChan chan struct{}) {
utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.ApierS))
@@ -1283,8 +735,6 @@ func (apierSv1 *APIerSv1) ListenAndServe(stopChan chan struct{}) {
}
apierSv1.CdrDb = stordb
apierSv1.StorDb = stordb
case resp := <-apierSv1.ResponderChan:
apierSv1.Responder = resp
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,73 +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 (
"strconv"
"time"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
// Returns MaxUsage (for calls in seconds), -1 for no limit
func (apierSv1 *APIerSv1) GetMaxUsage(usageRecord *engine.UsageRecordWithAPIOpts, maxUsage *int64) error {
if apierSv1.Responder == nil {
return utils.NewErrNotConnected(utils.RALService)
}
if usageRecord.ToR == utils.EmptyString {
usageRecord.ToR = utils.MetaVoice
}
if usageRecord.RequestType == utils.EmptyString {
usageRecord.RequestType = apierSv1.Config.GeneralCfg().DefaultReqType
}
if usageRecord.Tenant == utils.EmptyString {
usageRecord.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
}
if usageRecord.Category == utils.EmptyString {
usageRecord.Category = apierSv1.Config.GeneralCfg().DefaultCategory
}
if usageRecord.Subject == utils.EmptyString {
usageRecord.Subject = usageRecord.Account
}
if usageRecord.SetupTime == utils.EmptyString {
usageRecord.SetupTime = utils.MetaNow
}
if usageRecord.Usage == utils.EmptyString {
usageRecord.Usage = strconv.FormatFloat(
float64(apierSv1.Config.SessionSCfg().GetDefaultUsage(usageRecord.ToR)), 'f', -1, 64)
}
cd, err := usageRecord.AsCallDescriptor(apierSv1.Config.GeneralCfg().DefaultTimezone, false)
if err != nil {
return utils.NewErrServerError(err)
}
var maxDur time.Duration
if err := apierSv1.Responder.GetMaxSessionTime(&engine.CallDescriptorWithAPIOpts{
CallDescriptor: cd,
APIOpts: usageRecord.APIOpts,
}, &maxDur); err != nil {
return err
}
if maxDur == time.Duration(-1) {
*maxUsage = -1
return nil
}
*maxUsage = maxDur.Nanoseconds()
return nil
}

View File

@@ -1,114 +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 (
"time"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
type AttrGetCost struct {
Tenant string
Category string
Subject string
AnswerTime string
Destination string
Usage string
APIOpts map[string]interface{}
}
func (apierSv1 *APIerSv1) GetCost(attrs *AttrGetCost, ec *engine.EventCost) error {
if apierSv1.Responder == nil {
return utils.NewErrNotConnected(utils.RALService)
}
usage, err := utils.ParseDurationWithNanosecs(attrs.Usage)
if err != nil {
return err
}
aTime, err := utils.ParseTimeDetectLayout(attrs.AnswerTime,
apierSv1.Config.GeneralCfg().DefaultTimezone)
if err != nil {
return err
}
cd := &engine.CallDescriptor{
Category: attrs.Category,
Tenant: utils.FirstNonEmpty(attrs.Tenant, apierSv1.Config.GeneralCfg().DefaultTenant),
Subject: attrs.Subject,
Destination: attrs.Destination,
TimeStart: aTime,
TimeEnd: aTime.Add(usage),
DurationIndex: usage,
}
var cc engine.CallCost
if err := apierSv1.Responder.GetCost(
&engine.CallDescriptorWithAPIOpts{
CallDescriptor: cd,
APIOpts: attrs.APIOpts,
}, &cc); err != nil {
return utils.NewErrServerError(err)
}
*ec = *engine.NewEventCostFromCallCost(&cc, "", "")
ec.Compute()
return nil
}
type AttrGetDataCost struct {
Tenant string
Category string
Subject string
AnswerTime string
Usage time.Duration // the call duration so far (till TimeEnd)
Opts map[string]interface{}
}
func (apierSv1 *APIerSv1) GetDataCost(attrs *AttrGetDataCost, reply *engine.DataCost) error {
if apierSv1.Responder == nil {
return utils.NewErrNotConnected(utils.RALService)
}
aTime, err := utils.ParseTimeDetectLayout(attrs.AnswerTime,
apierSv1.Config.GeneralCfg().DefaultTimezone)
if err != nil {
return err
}
cd := &engine.CallDescriptor{
Category: attrs.Category,
Tenant: utils.FirstNonEmpty(attrs.Tenant, apierSv1.Config.GeneralCfg().DefaultTenant),
Subject: attrs.Subject,
TimeStart: aTime,
TimeEnd: aTime.Add(attrs.Usage),
DurationIndex: attrs.Usage,
ToR: utils.MetaData,
}
var cc engine.CallCost
if err := apierSv1.Responder.GetCost(&engine.CallDescriptorWithAPIOpts{
CallDescriptor: cd,
APIOpts: attrs.Opts,
}, &cc); err != nil {
return utils.NewErrServerError(err)
}
if dc, err := cc.ToDataCost(); err != nil {
return utils.NewErrServerError(err)
} else if dc != nil {
*reply = *dc
}
return nil
}

View File

@@ -1,133 +0,0 @@
// +build integration
/*
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"
"path"
"testing"
"time"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var (
costCfgPath string
costCfg *config.CGRConfig
costRPC *rpc.Client
costConfigDIR string //run tests for specific configuration
sTestsCost = []func(t *testing.T){
testCostInitCfg,
testCostInitDataDb,
testCostResetStorDb,
testCostStartEngine,
testCostRPCConn,
testCostLoadFromFolder,
testCostGetCost,
testCostKillEngine,
}
)
//Test start here
func TestCostIT(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
costConfigDIR = "tutinternal"
case utils.MetaMySQL:
costConfigDIR = "tutmysql"
case utils.MetaMongo:
costConfigDIR = "tutmongo"
case utils.MetaPostgres:
t.SkipNow()
default:
t.Fatal("Unknown Database type")
}
for _, stest := range sTestsCost {
t.Run(costConfigDIR, stest)
}
}
func testCostInitCfg(t *testing.T) {
var err error
costCfgPath = path.Join(*dataDir, "conf", "samples", costConfigDIR)
costCfg, err = config.NewCGRConfigFromPath(costCfgPath)
if err != nil {
t.Error(err)
}
}
func testCostInitDataDb(t *testing.T) {
if err := engine.InitDataDb(costCfg); err != nil {
t.Fatal(err)
}
}
// Wipe out the cdr database
func testCostResetStorDb(t *testing.T) {
if err := engine.InitStorDb(costCfg); err != nil {
t.Fatal(err)
}
}
// Start CGR Engine
func testCostStartEngine(t *testing.T) {
if _, err := engine.StopStartEngine(costCfgPath, *waitRater); err != nil {
t.Fatal(err)
}
}
// Connect rpc client to rater
func testCostRPCConn(t *testing.T) {
var err error
costRPC, err = newRPCClient(costCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
if err != nil {
t.Fatal(err)
}
}
func testCostLoadFromFolder(t *testing.T) {
var reply string
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}
if err := costRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
t.Error(err)
}
time.Sleep(100 * time.Millisecond)
}
func testCostGetCost(t *testing.T) {
attrs := AttrGetCost{Category: "call", Tenant: "cgrates.org",
Subject: "1001", AnswerTime: "*now", Destination: "1002", Usage: "120000000000"} //120s ( 2m)
var rply *engine.EventCost
if err := costRPC.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil {
t.Error("Unexpected nil error received: ", err.Error())
} else if *rply.Cost != 0.700200 { // expect to get 0.7 (0.4 connect fee 0.2 first minute 0.1 each minute after)
t.Errorf("Unexpected cost received: %f", *rply.Cost)
}
}
func testCostKillEngine(t *testing.T) {
if err := engine.KillEngine(*waitRater); err != nil {
t.Error(err)
}
}

View File

@@ -1,90 +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/engine"
"github.com/cgrates/cgrates/utils"
)
// DebitUsage will debit the balance for the usage cost, allowing the
// account to go negative if the cost calculated is greater than the balance
func (apierSv1 *APIerSv1) DebitUsage(usageRecord *engine.UsageRecordWithAPIOpts, reply *string) error {
return apierSv1.DebitUsageWithOptions(&AttrDebitUsageWithOptions{
UsageRecord: usageRecord,
AllowNegativeAccount: true,
}, reply)
}
// AttrDebitUsageWithOptions represents the DebitUsage request
type AttrDebitUsageWithOptions struct {
UsageRecord *engine.UsageRecordWithAPIOpts
AllowNegativeAccount bool // allow account to go negative during debit
}
// DebitUsageWithOptions will debit the account based on the usage cost with
// additional options to control if the balance can go negative
func (apierSv1 *APIerSv1) DebitUsageWithOptions(args *AttrDebitUsageWithOptions, reply *string) error {
if apierSv1.Responder == nil {
return utils.NewErrNotConnected(utils.RALService)
}
usageRecord := args.UsageRecord.UsageRecord
if missing := utils.MissingStructFields(usageRecord, []string{"Account", "Destination", "Usage"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
// Set values for optional parameters
if usageRecord.ToR == "" {
usageRecord.ToR = utils.MetaVoice
}
if usageRecord.RequestType == "" {
usageRecord.RequestType = apierSv1.Config.GeneralCfg().DefaultReqType
}
if usageRecord.Tenant == "" {
usageRecord.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
}
if usageRecord.Category == "" {
usageRecord.Category = apierSv1.Config.GeneralCfg().DefaultCategory
}
if usageRecord.Subject == "" {
usageRecord.Subject = usageRecord.Account
}
if usageRecord.AnswerTime == "" {
usageRecord.AnswerTime = utils.MetaNow
}
// Get the call descriptor from the usage record
cd, err := usageRecord.AsCallDescriptor(apierSv1.Config.GeneralCfg().DefaultTimezone,
!args.AllowNegativeAccount)
if err != nil {
return utils.NewErrServerError(err)
}
// Calculate the cost for usage and debit the account
var cc engine.CallCost
if err := apierSv1.Responder.Debit(&engine.CallDescriptorWithAPIOpts{
CallDescriptor: cd,
APIOpts: args.UsageRecord.APIOpts,
}, &cc); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}

View File

@@ -1,165 +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 (
"testing"
"time"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var (
apierDebit *APIerSv1
apierDebitStorage *engine.InternalDB
responder *engine.Responder
dm *engine.DataManager
)
func init() {
cfg := config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
apierDebitStorage = engine.NewInternalDB(nil, nil, true)
responder := &engine.Responder{MaxComputedUsage: cfg.RalsCfg().MaxComputedUsage}
dm = engine.NewDataManager(apierDebitStorage, config.CgrConfig().CacheCfg(), nil)
engine.SetDataStorage(dm)
apierDebit = &APIerSv1{
DataManager: dm,
Config: cfg,
Responder: responder,
}
}
func TestDebitUsageWithOptionsSetConfig(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
apierDebitStorage = engine.NewInternalDB(nil, nil, true)
responder := &engine.Responder{MaxComputedUsage: cfg.RalsCfg().MaxComputedUsage}
dm = engine.NewDataManager(apierDebitStorage, cfg.CacheCfg(), nil)
engine.SetDataStorage(dm)
apierDebit = &APIerSv1{
DataManager: dm,
Config: cfg,
Responder: responder,
}
}
func TestDebitUsageWithOptions(t *testing.T) {
cgrTenant := "cgrates.org"
b10 := &engine.Balance{Value: 10, Weight: 10}
cgrAcnt1 := &engine.Account{
ID: utils.ConcatenatedKey(cgrTenant, "account1"),
BalanceMap: map[string]engine.Balances{
utils.MetaMonetary: {b10},
},
}
if err := apierDebitStorage.SetAccountDrv(cgrAcnt1); err != nil {
t.Error(err)
}
dstDe := &engine.Destination{Id: "*any", Prefixes: []string{"*any"}}
if err := apierDebitStorage.SetDestinationDrv(dstDe, utils.NonTransactional); err != nil {
t.Error(err)
}
if err := apierDebitStorage.SetReverseDestinationDrv(dstDe.Id, dstDe.Prefixes, utils.NonTransactional); err != nil {
t.Error(err)
}
rp1 := &engine.RatingPlan{
Id: "RP1",
Timings: map[string]*engine.RITiming{
"30eab300": {
Years: utils.Years{},
Months: utils.Months{},
MonthDays: utils.MonthDays{},
WeekDays: utils.WeekDays{},
StartTime: "00:00:00",
},
},
Ratings: map[string]*engine.RIRate{
"b457f86d": {
ConnectFee: 0,
Rates: []*engine.RGRate{
{
GroupIntervalStart: 0,
Value: 0.03,
RateIncrement: time.Second,
RateUnit: time.Second,
},
},
RoundingMethod: utils.MetaRoundingMiddle,
RoundingDecimals: 4,
},
},
DestinationRates: map[string]engine.RPRateList{
dstDe.Id: []*engine.RPRate{
{
Timing: "30eab300",
Rating: "b457f86d",
Weight: 10,
},
},
},
}
if err := dm.SetRatingPlan(rp1, utils.NonTransactional); err != nil {
t.Error(err)
}
rpfl := &engine.RatingProfile{Id: "*out:cgrates.org:call:account1",
RatingPlanActivations: engine.RatingPlanActivations{&engine.RatingPlanActivation{
ActivationTime: time.Date(2001, 1, 1, 8, 0, 0, 0, time.UTC),
RatingPlanId: rp1.Id,
FallbackKeys: []string{},
}},
}
if err := dm.SetRatingProfile(rpfl, utils.NonTransactional); err != nil {
t.Error(err)
}
usageRecord := &engine.UsageRecord{
Tenant: cgrTenant,
Account: "account1",
Destination: "*any",
Usage: "1",
ToR: utils.MetaMonetary,
Category: "call",
SetupTime: time.Date(2013, 11, 7, 7, 42, 20, 0, time.UTC).String(),
AnswerTime: time.Date(2013, 11, 7, 7, 42, 20, 0, time.UTC).String(),
}
var reply string
if err := apierDebit.DebitUsageWithOptions(&AttrDebitUsageWithOptions{
UsageRecord: &engine.UsageRecordWithAPIOpts{UsageRecord: usageRecord},
AllowNegativeAccount: false}, &reply); err != nil {
t.Error(err)
}
// Reload the account and verify that the usage of $1 was removed from the monetary balance
resolvedAccount, err := apierDebitStorage.GetAccountDrv(cgrAcnt1.ID)
if err != nil {
t.Error(err)
}
eAcntVal := 9.0
if resolvedAccount.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal {
t.Errorf("Expected: %f, received: %f", eAcntVal,
resolvedAccount.BalanceMap[utils.MetaMonetary].GetTotalValue())
}
}

View File

@@ -539,48 +539,6 @@ func (dS *DispatcherSessionSv1) STIRIdentity(args *sessions.V1STIRIdentityArgs,
return dS.dS.SessionSv1STIRIdentity(args, reply)
}
func NewDispatcherResponder(dps *dispatchers.DispatcherService) *DispatcherResponder {
return &DispatcherResponder{dS: dps}
}
// Exports RPC from RLs
type DispatcherResponder struct {
dS *dispatchers.DispatcherService
}
func (dS *DispatcherResponder) GetCost(args *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) error {
return dS.dS.ResponderGetCost(args, reply)
}
func (dS *DispatcherResponder) Debit(args *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) error {
return dS.dS.ResponderDebit(args, reply)
}
func (dS *DispatcherResponder) MaxDebit(args *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) error {
return dS.dS.ResponderMaxDebit(args, reply)
}
func (dS *DispatcherResponder) RefundIncrements(args *engine.CallDescriptorWithAPIOpts, reply *engine.Account) error {
return dS.dS.ResponderRefundIncrements(args, reply)
}
func (dS *DispatcherResponder) RefundRounding(args *engine.CallDescriptorWithAPIOpts, reply *float64) error {
return dS.dS.ResponderRefundRounding(args, reply)
}
func (dS *DispatcherResponder) GetMaxSessionTime(args *engine.CallDescriptorWithAPIOpts, reply *time.Duration) error {
return dS.dS.ResponderGetMaxSessionTime(args, reply)
}
func (dS *DispatcherResponder) Shutdown(args *utils.TenantWithAPIOpts, reply *string) error {
return dS.dS.ResponderShutdown(args, reply)
}
// Ping used to detreminate if component is active
func (dS *DispatcherResponder) Ping(args *utils.CGREvent, reply *string) error {
return dS.dS.ResponderPing(args, reply)
}
func NewDispatcherCacheSv1(dps *dispatchers.DispatcherService) *DispatcherCacheSv1 {
return &DispatcherCacheSv1{dS: dps}
}
@@ -704,35 +662,6 @@ func (dS *DispatcherGuardianSv1) Ping(args *utils.CGREvent, reply *string) error
return dS.dS.GuardianSv1Ping(args, reply)
}
func NewDispatcherSchedulerSv1(dps *dispatchers.DispatcherService) *DispatcherSchedulerSv1 {
return &DispatcherSchedulerSv1{dS: dps}
}
// Exports RPC from SchedulerSv1
type DispatcherSchedulerSv1 struct {
dS *dispatchers.DispatcherService
}
// Reload reloads scheduler instructions
func (dS *DispatcherSchedulerSv1) Reload(attr *utils.CGREvent, reply *string) (err error) {
return dS.dS.SchedulerSv1Reload(attr, reply)
}
// Ping used to detreminate if component is active
func (dS *DispatcherSchedulerSv1) Ping(args *utils.CGREvent, reply *string) error {
return dS.dS.SchedulerSv1Ping(args, reply)
}
// ExecuteActions execute an actionPlan or multiple actionsPlans between a time interval
func (dS *DispatcherSchedulerSv1) ExecuteActions(args *utils.AttrsExecuteActions, reply *string) error {
return dS.dS.SchedulerSv1ExecuteActions(args, reply)
}
// ExecuteActionPlans execute multiple actionPlans one by one
func (dS *DispatcherSchedulerSv1) ExecuteActionPlans(args *utils.AttrsExecuteActionPlans, reply *string) (err error) {
return dS.dS.SchedulerSv1ExecuteActionPlans(args, reply)
}
func NewDispatcherSv1(dS *dispatchers.DispatcherService) *DispatcherSv1 {
return &DispatcherSv1{dS: dS}
}
@@ -873,24 +802,6 @@ func (dS *DispatcherCoreSv1) Sleep(arg *utils.DurationArgs, reply *string) error
return dS.dS.CoreSv1Sleep(arg, reply)
}
func NewDispatcherRALsV1(dps *dispatchers.DispatcherService) *DispatcherRALsV1 {
return &DispatcherRALsV1{dS: dps}
}
// Exports RPC from RLs
type DispatcherRALsV1 struct {
dS *dispatchers.DispatcherService
}
func (dS *DispatcherRALsV1) GetRatingPlansCost(args *utils.RatingPlanCostArg, reply *dispatchers.RatingPlanCost) error {
return dS.dS.RALsV1GetRatingPlansCost(args, reply)
}
// Ping used to detreminate if component is active
func (dS *DispatcherRALsV1) Ping(args *utils.CGREvent, reply *string) error {
return dS.dS.RALsV1Ping(args, reply)
}
type DispatcherReplicatorSv1 struct {
dS *dispatchers.DispatcherService
}
@@ -904,11 +815,6 @@ func (dS *DispatcherReplicatorSv1) Ping(args *utils.CGREvent, reply *string) err
return dS.dS.ReplicatorSv1Ping(args, reply)
}
// GetAccount
func (dS *DispatcherReplicatorSv1) GetAccount(args *utils.StringWithAPIOpts, reply *engine.Account) error {
return dS.dS.ReplicatorSv1GetAccount(args, reply)
}
// GetDestination
func (dS *DispatcherReplicatorSv1) GetDestination(key *utils.StringWithAPIOpts, reply *engine.Destination) error {
return dS.dS.ReplicatorSv1GetDestination(key, reply)
@@ -959,46 +865,6 @@ func (dS *DispatcherReplicatorSv1) GetResourceProfile(tntID *utils.TenantIDWithA
return dS.dS.ReplicatorSv1GetResourceProfile(tntID, reply)
}
// GetActionTriggers
func (dS *DispatcherReplicatorSv1) GetActionTriggers(id *utils.StringWithAPIOpts, reply *engine.ActionTriggers) error {
return dS.dS.ReplicatorSv1GetActionTriggers(id, reply)
}
// GetSharedGroup
func (dS *DispatcherReplicatorSv1) GetSharedGroup(id *utils.StringWithAPIOpts, reply *engine.SharedGroup) error {
return dS.dS.ReplicatorSv1GetSharedGroup(id, reply)
}
// GetActions
func (dS *DispatcherReplicatorSv1) GetActions(id *utils.StringWithAPIOpts, reply *engine.Actions) error {
return dS.dS.ReplicatorSv1GetActions(id, reply)
}
// GetActionPlan
func (dS *DispatcherReplicatorSv1) GetActionPlan(id *utils.StringWithAPIOpts, reply *engine.ActionPlan) error {
return dS.dS.ReplicatorSv1GetActionPlan(id, reply)
}
// GetAllActionPlans
func (dS *DispatcherReplicatorSv1) GetAllActionPlans(args *utils.StringWithAPIOpts, reply *map[string]*engine.ActionPlan) error {
return dS.dS.ReplicatorSv1GetAllActionPlans(args, reply)
}
// GetAccountActionPlans
func (dS *DispatcherReplicatorSv1) GetAccountActionPlans(id *utils.StringWithAPIOpts, reply *[]string) error {
return dS.dS.ReplicatorSv1GetAccountActionPlans(id, reply)
}
// GetRatingPlan
func (dS *DispatcherReplicatorSv1) GetRatingPlan(id *utils.StringWithAPIOpts, reply *engine.RatingPlan) error {
return dS.dS.ReplicatorSv1GetRatingPlan(id, reply)
}
// GetRatingProfile
func (dS *DispatcherReplicatorSv1) GetRatingProfile(id *utils.StringWithAPIOpts, reply *engine.RatingProfile) error {
return dS.dS.ReplicatorSv1GetRatingProfile(id, reply)
}
// GetRouteProfile
func (dS *DispatcherReplicatorSv1) GetRouteProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) error {
return dS.dS.ReplicatorSv1GetRouteProfile(tntID, reply)
@@ -1051,11 +917,6 @@ func (dS *DispatcherReplicatorSv1) SetDestination(args *engine.DestinationWithAP
return dS.dS.ReplicatorSv1SetDestination(args, reply)
}
// SetAccount
func (dS *DispatcherReplicatorSv1) SetAccount(args *engine.AccountWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1SetAccount(args, reply)
}
// SetReverseDestination
func (dS *DispatcherReplicatorSv1) SetReverseDestination(args *engine.DestinationWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1SetReverseDestination(args, reply)
@@ -1091,31 +952,11 @@ func (dS *DispatcherReplicatorSv1) SetResourceProfile(args *engine.ResourceProfi
return dS.dS.ReplicatorSv1SetResourceProfile(args, reply)
}
// SetActionTriggers
func (dS *DispatcherReplicatorSv1) SetActionTriggers(args *engine.SetActionTriggersArgWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1SetActionTriggers(args, reply)
}
// SetSharedGroup
func (dS *DispatcherReplicatorSv1) SetSharedGroup(args *engine.SharedGroupWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1SetSharedGroup(args, reply)
}
// SetActions
func (dS *DispatcherReplicatorSv1) SetActions(args *engine.SetActionsArgsWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1SetActions(args, reply)
}
// SetRatingPlan
func (dS *DispatcherReplicatorSv1) SetRatingPlan(args *engine.RatingPlanWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1SetRatingPlan(args, reply)
}
// SetRatingProfile
func (dS *DispatcherReplicatorSv1) SetRatingProfile(args *engine.RatingProfileWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1SetRatingProfile(args, reply)
}
// SetRouteProfile
func (dS *DispatcherReplicatorSv1) SetRouteProfile(args *engine.RouteProfileWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1SetRouteProfile(args, reply)
@@ -1141,16 +982,6 @@ func (dS *DispatcherReplicatorSv1) SetRateProfile(args *utils.RateProfileWithAPI
return dS.dS.ReplicatorSv1SetRateProfile(args, reply)
}
// SetActionPlan
func (dS *DispatcherReplicatorSv1) SetActionPlan(args *engine.SetActionPlanArgWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1SetActionPlan(args, reply)
}
// SetAccountActionPlans
func (dS *DispatcherReplicatorSv1) SetAccountActionPlans(args *engine.SetAccountActionPlansArgWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1SetAccountActionPlans(args, reply)
}
// SetDispatcherHost
func (dS *DispatcherReplicatorSv1) SetDispatcherHost(args *engine.DispatcherHostWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1SetDispatcherHost(args, reply)
@@ -1171,11 +1002,6 @@ func (dS *DispatcherReplicatorSv1) RemoveDestination(args *utils.StringWithAPIOp
return dS.dS.ReplicatorSv1RemoveDestination(args, reply)
}
// RemoveAccount
func (dS *DispatcherReplicatorSv1) RemoveAccount(args *utils.StringWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1RemoveAccount(args, reply)
}
// RemoveStatQueue
func (dS *DispatcherReplicatorSv1) RemoveStatQueue(args *utils.TenantIDWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1RemoveStatQueue(args, reply)
@@ -1211,41 +1037,6 @@ func (dS *DispatcherReplicatorSv1) RemoveResourceProfile(args *utils.TenantIDWit
return dS.dS.ReplicatorSv1RemoveResourceProfile(args, reply)
}
// RemoveActionTriggers
func (dS *DispatcherReplicatorSv1) RemoveActionTriggers(args *utils.StringWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1RemoveActionTriggers(args, reply)
}
// RemoveSharedGroup
func (dS *DispatcherReplicatorSv1) RemoveSharedGroup(args *utils.StringWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1RemoveSharedGroup(args, reply)
}
// RemoveActions
func (dS *DispatcherReplicatorSv1) RemoveActions(args *utils.StringWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1RemoveActions(args, reply)
}
// RemoveActionPlan
func (dS *DispatcherReplicatorSv1) RemoveActionPlan(args *utils.StringWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1RemoveActionPlan(args, reply)
}
// RemAccountActionPlans
func (dS *DispatcherReplicatorSv1) RemAccountActionPlans(args *engine.RemAccountActionPlansArgsWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1RemAccountActionPlans(args, reply)
}
// RemoveRatingPlan
func (dS *DispatcherReplicatorSv1) RemoveRatingPlan(args *utils.StringWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1RemoveRatingPlan(args, reply)
}
// RemoveRatingProfile
func (dS *DispatcherReplicatorSv1) RemoveRatingProfile(args *utils.StringWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1RemoveRatingProfile(args, reply)
}
// RemoveRouteProfile
func (dS *DispatcherReplicatorSv1) RemoveRouteProfile(args *utils.TenantIDWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1RemoveRouteProfile(args, reply)

View File

@@ -1,113 +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/config"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func NewRALsV1() *RALsV1 {
return &RALsV1{}
}
// Exports RPC from RALs
type RALsV1 struct {
}
// Call implements rpcclient.ClientConnector interface for internal RPC
func (rsv1 *RALsV1) Call(serviceMethod string, args interface{}, reply interface{}) error {
return utils.APIerRPCCall(rsv1, serviceMethod, args, reply)
}
// GetRatingPlansCost returns EventCosts matching RatingPlanIDs
func (rsv1 *RALsV1) GetRatingPlansCost(arg *utils.RatingPlanCostArg, reply *dispatchers.RatingPlanCost) error {
if missing := utils.MissingStructFields(arg, []string{utils.RatingPlanIDs,
utils.Destination, utils.SetupTime, utils.Usage}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
//parse SetupTime and Usage
setupTime, err := utils.ParseTimeDetectLayout(arg.SetupTime,
config.CgrConfig().GeneralCfg().DefaultTimezone)
if err != nil {
return err
}
usage, err := utils.ParseDurationWithNanosecs(arg.Usage)
if err != nil {
return err
}
tenant := utils.UUIDSha1Prefix()
category := utils.MetaRatingPlanCost
subject := utils.UUIDSha1Prefix()
cd := &engine.CallDescriptor{
Category: category,
Tenant: tenant,
Subject: subject,
Destination: arg.Destination,
TimeStart: setupTime,
TimeEnd: setupTime.Add(usage),
DurationIndex: usage,
}
for _, rp := range arg.RatingPlanIDs { // loop through RatingPlans until we find one without errors
rPrfl := &engine.RatingProfile{
Id: utils.ConcatenatedKey(utils.MetaOut,
tenant, category, subject),
RatingPlanActivations: engine.RatingPlanActivations{
&engine.RatingPlanActivation{
ActivationTime: setupTime,
RatingPlanId: rp,
},
},
}
// force cache set so it can be picked by calldescriptor for cost calculation
if err := engine.Cache.Set(utils.CacheRatingProfilesTmp, rPrfl.Id, rPrfl, nil,
true, utils.NonTransactional); err != nil {
return err
}
cc, err := cd.GetCost()
if err := engine.Cache.Remove(utils.CacheRatingProfilesTmp, rPrfl.Id, // Remove here so we don't overload memory
true, utils.NonTransactional); err != nil {
return err
}
if err != nil {
// in case we have UnauthorizedDestination
// or NotFound try next RatingPlan
if err != utils.ErrUnauthorizedDestination &&
err != utils.ErrNotFound {
return err
}
continue
}
ec := engine.NewEventCostFromCallCost(cc, utils.EmptyString, utils.EmptyString)
ec.Compute()
*reply = dispatchers.RatingPlanCost{
EventCost: ec,
RatingPlanID: rp,
}
break
}
return nil
}
func (rsv1 *RALsV1) Ping(ign *utils.CGREvent, reply *string) error {
*reply = utils.Pong
return nil
}

View File

@@ -42,17 +42,6 @@ func (rplSv1 *ReplicatorSv1) Call(serviceMethod string, args interface{}, reply
return utils.APIerRPCCall(rplSv1, serviceMethod, args, reply)
}
// GetAccount is the remote method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) GetAccount(args *utils.StringWithAPIOpts, reply *engine.Account) error {
engine.UpdateReplicationFilters(utils.AccountPrefix, args.Arg, utils.IfaceAsString(args.APIOpts[utils.RemoteHostOpt]))
rcv, err := rplSv1.dm.GetAccount(args.Arg)
if err != nil {
return err
}
*reply = *rcv
return nil
}
// GetDestination is the remote method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) GetDestination(key *utils.StringWithAPIOpts, reply *engine.Destination) error {
engine.UpdateReplicationFilters(utils.DestinationPrefix, key.Arg, utils.IfaceAsString(key.APIOpts[utils.RemoteHostOpt]))
@@ -165,96 +154,6 @@ func (rplSv1 *ReplicatorSv1) GetResourceProfile(tntID *utils.TenantIDWithAPIOpts
return nil
}
// GetActionTriggers is the remote method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) GetActionTriggers(id *utils.StringWithAPIOpts, reply *engine.ActionTriggers) error {
engine.UpdateReplicationFilters(utils.ActionTriggerPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt]))
rcv, err := rplSv1.dm.DataDB().GetActionTriggersDrv(id.Arg)
if err != nil {
return err
}
*reply = rcv
return nil
}
// GetSharedGroup is the remote method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) GetSharedGroup(id *utils.StringWithAPIOpts, reply *engine.SharedGroup) error {
engine.UpdateReplicationFilters(utils.SharedGroupPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt]))
rcv, err := rplSv1.dm.DataDB().GetSharedGroupDrv(id.Arg)
if err != nil {
return err
}
*reply = *rcv
return nil
}
// GetActions is the remote method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) GetActions(id *utils.StringWithAPIOpts, reply *engine.Actions) error {
engine.UpdateReplicationFilters(utils.ActionPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt]))
rcv, err := rplSv1.dm.DataDB().GetActionsDrv(id.Arg)
if err != nil {
return err
}
*reply = rcv
return nil
}
// GetActionPlan is the remote method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) GetActionPlan(id *utils.StringWithAPIOpts, reply *engine.ActionPlan) error {
engine.UpdateReplicationFilters(utils.ActionPlanPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt]))
rcv, err := rplSv1.dm.DataDB().GetActionPlanDrv(id.Arg, true, utils.NonTransactional)
if err != nil {
return err
}
*reply = *rcv
return nil
}
// GetAllActionPlans is the remote method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) GetAllActionPlans(id *utils.StringWithAPIOpts, reply *map[string]*engine.ActionPlan) error {
rcv, err := rplSv1.dm.DataDB().GetAllActionPlansDrv()
if err != nil {
return err
}
for _, ap := range rcv {
engine.UpdateReplicationFilters(utils.ActionPlanPrefix, ap.Id, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt]))
}
*reply = rcv
return nil
}
// GetAccountActionPlans is the remote method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) GetAccountActionPlans(id *utils.StringWithAPIOpts, reply *[]string) error {
engine.UpdateReplicationFilters(utils.AccountActionPlansPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt]))
rcv, err := rplSv1.dm.DataDB().GetAccountActionPlansDrv(id.Arg, false, utils.NonTransactional)
if err != nil {
return err
}
*reply = rcv
return nil
}
// GetRatingPlan is the remote method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) GetRatingPlan(id *utils.StringWithAPIOpts, reply *engine.RatingPlan) error {
engine.UpdateReplicationFilters(utils.RatingPlanPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt]))
rcv, err := rplSv1.dm.DataDB().GetRatingPlanDrv(id.Arg)
if err != nil {
return err
}
*reply = *rcv
return nil
}
// GetRatingProfile is the remote method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) GetRatingProfile(id *utils.StringWithAPIOpts, reply *engine.RatingProfile) error {
engine.UpdateReplicationFilters(utils.RatingProfilePrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt]))
rcv, err := rplSv1.dm.DataDB().GetRatingProfileDrv(id.Arg)
if err != nil {
return err
}
*reply = *rcv
return nil
}
// GetRouteProfile is the remote method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) GetRouteProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) error {
engine.UpdateReplicationFilters(utils.RouteProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
@@ -365,16 +264,6 @@ func (rplSv1 *ReplicatorSv1) GetIndexes(args *utils.GetIndexesArg, reply *map[st
return nil
}
// SetAccount is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) SetAccount(acc *engine.AccountWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().SetAccountDrv(acc.Account); err != nil {
return
}
// the account doesn't have cache
*reply = utils.OK
return
}
// SetDestination is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) SetDestination(dst *engine.DestinationWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().SetDestinationDrv(dst.Destination, utils.NonTransactional); err != nil {
@@ -505,71 +394,6 @@ func (rplSv1 *ReplicatorSv1) SetResource(rs *engine.ResourceWithAPIOpts, reply *
return
}
// SetActionTriggers is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) SetActionTriggers(args *engine.SetActionTriggersArgWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().SetActionTriggersDrv(args.Key, args.Attrs); err != nil {
return
}
if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
args.Tenant, utils.CacheActionTriggers, args.Key, nil, nil, args.APIOpts); err != nil {
return
}
*reply = utils.OK
return
}
// SetSharedGroup is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) SetSharedGroup(shg *engine.SharedGroupWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().SetSharedGroupDrv(shg.SharedGroup); err != nil {
return
}
if err = rplSv1.v1.CallCache(utils.IfaceAsString(shg.APIOpts[utils.CacheOpt]),
shg.Tenant, utils.CacheSharedGroups, shg.Id, nil, nil, shg.APIOpts); err != nil {
return
}
*reply = utils.OK
return
}
// SetActions is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) SetActions(args *engine.SetActionsArgsWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().SetActionsDrv(args.Key, args.Acs); err != nil {
return
}
if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
args.Tenant, utils.CacheActions, args.Key, nil, nil, args.APIOpts); err != nil {
return
}
*reply = utils.OK
return
}
// SetRatingPlan is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) SetRatingPlan(rp *engine.RatingPlanWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().SetRatingPlanDrv(rp.RatingPlan); err != nil {
return
}
if err = rplSv1.v1.CallCache(utils.IfaceAsString(rp.APIOpts[utils.CacheOpt]),
rp.Tenant, utils.CacheRatingPlans, rp.Id, nil, nil, rp.APIOpts); err != nil {
return
}
*reply = utils.OK
return
}
// SetRatingProfile is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) SetRatingProfile(rp *engine.RatingProfileWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().SetRatingProfileDrv(rp.RatingProfile); err != nil {
return
}
if err = rplSv1.v1.CallCache(utils.IfaceAsString(rp.APIOpts[utils.CacheOpt]),
rp.Tenant, utils.CacheRatingProfiles, rp.Id, nil, nil, rp.APIOpts); err != nil {
return
}
*reply = utils.OK
return
}
// SetRouteProfile is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) SetRouteProfile(sp *engine.RouteProfileWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().SetRouteProfileDrv(sp.RouteProfile); err != nil {
@@ -622,32 +446,6 @@ func (rplSv1 *ReplicatorSv1) SetDispatcherProfile(dpp *engine.DispatcherProfileW
return
}
// SetActionPlan is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) SetActionPlan(args *engine.SetActionPlanArgWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().SetActionPlanDrv(args.Key, args.Ats, args.Overwrite, utils.NonTransactional); err != nil {
return
}
if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
args.Tenant, utils.CacheActionPlans, args.Key, nil, nil, args.APIOpts); err != nil {
return
}
*reply = utils.OK
return
}
// SetAccountActionPlans is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) SetAccountActionPlans(args *engine.SetAccountActionPlansArgWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().SetAccountActionPlansDrv(args.AcntID, args.AplIDs, args.Overwrite); err != nil {
return
}
if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
args.Tenant, utils.CacheAccountActionPlans, args.AcntID, nil, nil, args.APIOpts); err != nil {
return
}
*reply = utils.OK
return
}
// SetDispatcherHost is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) SetDispatcherHost(dpp *engine.DispatcherHostWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().SetDispatcherHostDrv(dpp.DispatcherHost); err != nil {
@@ -760,16 +558,6 @@ func (rplSv1 *ReplicatorSv1) RemoveDestination(id *utils.StringWithAPIOpts, repl
return
}
// RemoveAccount is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) RemoveAccount(id *utils.StringWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().RemoveAccountDrv(id.Arg); err != nil {
return
}
// the account doesn't have cache
*reply = utils.OK
return
}
// RemoveStatQueue is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) RemoveStatQueue(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().RemStatQueueDrv(args.Tenant, args.ID); err != nil {
@@ -861,97 +649,6 @@ func (rplSv1 *ReplicatorSv1) RemoveResourceProfile(args *utils.TenantIDWithAPIOp
return
}
// RemoveActionTriggers is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) RemoveActionTriggers(id *utils.StringWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().RemoveActionTriggersDrv(id.Arg); err != nil {
return
}
if err = rplSv1.v1.CallCache(utils.IfaceAsString(id.APIOpts[utils.CacheOpt]),
id.Tenant, utils.CacheActionTriggers, id.Arg, nil, nil, id.APIOpts); err != nil {
return
}
*reply = utils.OK
return
}
// RemoveSharedGroup is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) RemoveSharedGroup(id *utils.StringWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().RemoveSharedGroupDrv(id.Arg); err != nil {
return
}
if err = rplSv1.v1.CallCache(utils.IfaceAsString(id.APIOpts[utils.CacheOpt]),
id.Tenant, utils.CacheSharedGroups, id.Arg, nil, nil, id.APIOpts); err != nil {
return
}
*reply = utils.OK
return
}
// RemoveActions is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) RemoveActions(id *utils.StringWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().RemoveActionsDrv(id.Arg); err != nil {
return
}
if err = rplSv1.v1.CallCache(utils.IfaceAsString(id.APIOpts[utils.CacheOpt]),
id.Tenant, utils.CacheActions, id.Arg, nil, nil, id.APIOpts); err != nil {
return
}
*reply = utils.OK
return
}
// RemoveActionPlan is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) RemoveActionPlan(id *utils.StringWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().RemoveActionPlanDrv(id.Arg, utils.NonTransactional); err != nil {
return
}
if err = rplSv1.v1.CallCache(utils.IfaceAsString(id.APIOpts[utils.CacheOpt]),
id.Tenant, utils.CacheActionPlans, id.Arg, nil, nil, id.APIOpts); err != nil {
return
}
*reply = utils.OK
return
}
// RemAccountActionPlans is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) RemAccountActionPlans(args *engine.RemAccountActionPlansArgsWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().RemAccountActionPlansDrv(args.AcntID, args.ApIDs); err != nil {
return
}
if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
args.Tenant, utils.CacheAccountActionPlans, args.AcntID, nil, nil, args.APIOpts); err != nil {
return
}
*reply = utils.OK
return
}
// RemoveRatingPlan is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) RemoveRatingPlan(id *utils.StringWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().RemoveRatingPlanDrv(id.Arg); err != nil {
return
}
if err = rplSv1.v1.CallCache(utils.IfaceAsString(id.APIOpts[utils.CacheOpt]),
id.Tenant, utils.CacheRatingPlans, id.Arg, nil, nil, id.APIOpts); err != nil {
return
}
*reply = utils.OK
return
}
// RemoveRatingProfile is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) RemoveRatingProfile(id *utils.StringWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().RemoveRatingProfileDrv(id.Arg); err != nil {
return
}
if err = rplSv1.v1.CallCache(utils.IfaceAsString(id.APIOpts[utils.CacheOpt]),
id.Tenant, utils.CacheRatingProfiles, id.Arg, nil, nil, id.APIOpts); err != nil {
return
}
*reply = utils.OK
return
}
// RemoveRouteProfile is the replication method coresponding to the dataDb driver method
func (rplSv1 *ReplicatorSv1) RemoveRouteProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
if err = rplSv1.dm.DataDB().RemoveRouteProfileDrv(args.Tenant, args.ID); err != nil {

View File

@@ -1,149 +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/engine"
"github.com/cgrates/cgrates/utils"
)
// SetTPAccountActions creates a new AccountActions profile within a tariff plan
func (apierSv1 *APIerSv1) SetTPAccountActions(attrs *utils.TPAccountActions, reply *string) error {
if missing := utils.MissingStructFields(attrs,
[]string{utils.TPid, utils.LoadId, utils.AccountField, utils.ActionPlanId}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if attrs.Tenant == utils.EmptyString {
attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
}
if err := apierSv1.StorDb.SetTPAccountActions([]*utils.TPAccountActions{attrs}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
type AttrGetTPAccountActionsByLoadId struct {
TPid string // Tariff plan id
LoadId string // AccountActions id
}
// GetTPAccountActionsByLoadId queries specific AccountActions profile on tariff plan
func (apierSv1 *APIerSv1) GetTPAccountActionsByLoadId(attrs *utils.TPAccountActions, reply *[]*utils.TPAccountActions) error {
mndtryFlds := []string{utils.TPid, utils.LoadId}
if len(attrs.Account) != 0 { // If account provided as filter, make all related fields mandatory
mndtryFlds = append(mndtryFlds, utils.AccountField)
}
if missing := utils.MissingStructFields(attrs, mndtryFlds); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if attrs.Tenant == utils.EmptyString {
attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
}
aas, err := apierSv1.StorDb.GetTPAccountActions(attrs)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = aas
return nil
}
type AttrGetTPAccountActions struct {
TPid string // Tariff plan id
AccountActionsId string // DerivedCharge id
}
// GetTPAccountActions queries specific DerivedCharge on tariff plan
func (apierSv1 *APIerSv1) GetTPAccountActions(attrs *AttrGetTPAccountActions, reply *utils.TPAccountActions) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.AccountActionsId}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
filter := &utils.TPAccountActions{TPid: attrs.TPid}
if err := filter.SetAccountActionsId(attrs.AccountActionsId); err != nil {
return err
}
aas, err := apierSv1.StorDb.GetTPAccountActions(filter)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = *aas[0]
return nil
}
type AttrGetTPAccountActionIds struct {
TPid string // Tariff plan id
utils.PaginatorWithSearch
}
// GetTPAccountActionLoadIds queries AccountActions identities on specific tariff plan.
func (apierSv1 *APIerSv1) GetTPAccountActionLoadIds(attrs *AttrGetTPAccountActionIds, reply *[]string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPAccountActions,
utils.TPDistinctIds{utils.Loadid}, nil, &attrs.PaginatorWithSearch)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = ids
return nil
}
// GetTPAccountActionIds queries DerivedCharges identities on specific tariff plan.
func (apierSv1 *APIerSv1) GetTPAccountActionIds(attrs *AttrGetTPAccountActionIds, reply *[]string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPAccountActions,
utils.TPDistinctIds{utils.Loadid, utils.TenantCfg, utils.AccountLowerCase}, nil, &attrs.PaginatorWithSearch)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = ids
return nil
}
// RemoveTPAccountActions removes specific AccountActions on Tariff plan
func (apierSv1 *APIerSv1) RemoveTPAccountActions(attrs *AttrGetTPAccountActions, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.AccountActionsId}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
aa := engine.AccountActionMdl{Tpid: attrs.TPid}
if err := aa.SetAccountActionId(attrs.AccountActionsId); err != nil {
return err
}
if err := apierSv1.StorDb.RemTpData(utils.TBLTPAccountActions, aa.Tpid,
map[string]string{utils.Loadid: aa.Loadid, utils.TenantCfg: aa.Tenant, utils.AccountLowerCase: aa.Account}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}

View File

@@ -1,231 +0,0 @@
// +build offline
/*
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 (
tpAccActionsCfgPath string
tpAccActionsCfg *config.CGRConfig
tpAccActionsRPC *rpc.Client
tpAccActions *utils.TPAccountActions
tpAccActionsDelay int
tpAccActionsConfigDIR string //run tests for specific configuration
tpAccActionID = "ID:cgrates.org:1001"
)
var sTestsTPAccActions = []func(t *testing.T){
testTPAccActionsInitCfg,
testTPAccActionsResetStorDb,
testTPAccActionsStartEngine,
testTPAccActionsRpcConn,
testTPAccActionsGetTPAccActionBeforeSet,
testTPAccActionsSetTPAccAction,
testTPAccActionsGetTPAccActionAfterSet,
testTPAccActionsGetTPAccountActionsByLoadId,
testTPAccActionsGetTPAccountActionLoadIds,
testTPAccActionsGetTPAccountActionIds,
testTPAccActionsUpdateTPAccAction,
testTPAccActionsGetTPAccActionAfterUpdate,
testTPAccActionsRemTPAccAction,
testTPAccActionsGetTPAccActionAfterRemove,
testTPAccActionsKillEngine,
}
//Test start here
func TestTPAccActionsIT(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
tpAccActionsConfigDIR = "tutinternal"
case utils.MetaMySQL:
tpAccActionsConfigDIR = "tutmysql"
case utils.MetaMongo:
tpAccActionsConfigDIR = "tutmongo"
case utils.MetaPostgres:
tpAccActionsConfigDIR = "tutpostgres"
default:
t.Fatal("Unknown Database type")
}
for _, stest := range sTestsTPAccActions {
t.Run(tpAccActionsConfigDIR, stest)
}
}
func testTPAccActionsInitCfg(t *testing.T) {
var err error
tpAccActionsCfgPath = path.Join(*dataDir, "conf", "samples", tpAccActionsConfigDIR)
tpAccActionsCfg, err = config.NewCGRConfigFromPath(tpAccActionsCfgPath)
if err != nil {
t.Error(err)
}
tpAccActionsDelay = 1000
}
// Wipe out the cdr database
func testTPAccActionsResetStorDb(t *testing.T) {
if err := engine.InitStorDb(tpAccActionsCfg); err != nil {
t.Fatal(err)
}
}
// Start CGR Engine
func testTPAccActionsStartEngine(t *testing.T) {
if _, err := engine.StopStartEngine(tpAccActionsCfgPath, tpAccActionsDelay); err != nil {
t.Fatal(err)
}
}
// Connect rpc client to rater
func testTPAccActionsRpcConn(t *testing.T) {
var err error
tpAccActionsRPC, err = jsonrpc.Dial(utils.TCP, tpAccActionsCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
if err != nil {
t.Fatal(err)
}
}
func testTPAccActionsGetTPAccActionBeforeSet(t *testing.T) {
var reply *utils.TPAccountActions
if err := tpAccActionsRPC.Call(utils.APIerSv1GetTPAccountActions,
&AttrGetTPAccountActions{TPid: "TPAcc", AccountActionsId: tpAccActionID}, &reply); err == nil ||
err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPAccActionsSetTPAccAction(t *testing.T) {
tpAccActions = &utils.TPAccountActions{
TPid: "TPAcc",
LoadId: "ID",
Tenant: "cgrates.org",
Account: "1001",
ActionPlanId: "PREPAID_10",
//ActionTriggersId: "STANDARD_TRIGGERS", // ActionTriggersId is optional
AllowNegative: true,
Disabled: false,
}
var result string
if err := tpAccActionsRPC.Call(utils.APIerSv1SetTPAccountActions, tpAccActions, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTPAccActionsGetTPAccActionAfterSet(t *testing.T) {
var reply *utils.TPAccountActions
if err := tpAccActionsRPC.Call(utils.APIerSv1GetTPAccountActions,
&AttrGetTPAccountActions{TPid: "TPAcc", AccountActionsId: tpAccActionID}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpAccActions, reply) {
t.Errorf("Expecting : %+v, received: %+v", tpAccActions, reply)
}
}
func testTPAccActionsGetTPAccountActionsByLoadId(t *testing.T) {
var reply *[]*utils.TPAccountActions
if err := tpAccActionsRPC.Call(utils.APIerSv1GetTPAccountActionsByLoadId,
&utils.TPAccountActions{TPid: "TPAcc", LoadId: "ID"}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpAccActions, (*reply)[0]) {
t.Errorf("Expecting : %+v, received: %+v", tpAccActions, (*reply)[0])
}
}
func testTPAccActionsGetTPAccountActionLoadIds(t *testing.T) {
var result []string
expectedTPID := []string{"ID"}
if err := tpAccActionsRPC.Call(utils.APIerSv1GetTPAccountActionLoadIds,
&AttrGetTPAccountActionIds{TPid: "TPAcc"}, &result); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expectedTPID, result) {
t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
}
}
func testTPAccActionsGetTPAccountActionIds(t *testing.T) {
var result []string
expectedTPID := []string{"ID:cgrates.org:1001"}
if err := tpAccActionsRPC.Call(utils.APIerSv1GetTPAccountActionIds,
&AttrGetTPAccountActionIds{TPid: "TPAcc"}, &result); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expectedTPID, result) {
t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
}
}
func testTPAccActionsUpdateTPAccAction(t *testing.T) {
tpAccActions.ActionPlanId = "PlanOne"
var result string
if err := tpAccActionsRPC.Call(utils.APIerSv1SetTPAccountActions, tpAccActions, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTPAccActionsGetTPAccActionAfterUpdate(t *testing.T) {
var reply *utils.TPAccountActions
if err := tpAccActionsRPC.Call(utils.APIerSv1GetTPAccountActions,
&AttrGetTPAccountActions{TPid: "TPAcc", AccountActionsId: tpAccActionID}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpAccActions, reply) {
t.Errorf("Expecting : %+v, received: %+v", tpAccActions, reply)
}
}
func testTPAccActionsRemTPAccAction(t *testing.T) {
var resp string
if err := tpAccActionsRPC.Call(utils.APIerSv1RemoveTPAccountActions,
&AttrGetTPAccountActions{TPid: "TPAcc", AccountActionsId: tpAccActionID}, &resp); err != nil {
t.Error(err)
} else if resp != utils.OK {
t.Error("Unexpected reply returned", resp)
}
}
func testTPAccActionsGetTPAccActionAfterRemove(t *testing.T) {
var reply *utils.TPAccountActions
if err := tpAccActionsRPC.Call(utils.APIerSv1GetTPAccountActions,
&AttrGetTPAccountActions{TPid: "TPAcc", AccountActionsId: tpAccActionID}, &reply); err == nil ||
err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPAccActionsKillEngine(t *testing.T) {
if err := engine.KillEngine(tpAccActionsDelay); err != nil {
t.Error(err)
}
}

View File

@@ -1,99 +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 (
"fmt"
"github.com/cgrates/cgrates/utils"
)
// SetTPActionPlan creates a new ActionTimings profile within a tariff plan
func (apierSv1 *APIerSv1) SetTPActionPlan(attrs *utils.TPActionPlan, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.ActionPlan}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
for _, at := range attrs.ActionPlan {
requiredFields := []string{utils.ActionsId, utils.TimingId, utils.Weight}
if missing := utils.MissingStructFields(at, requiredFields); len(missing) != 0 {
return fmt.Errorf("%s:Action:%s:%v", utils.ErrMandatoryIeMissing.Error(), at.ActionsId, missing)
}
}
if err := apierSv1.StorDb.SetTPActionPlans([]*utils.TPActionPlan{attrs}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
type AttrGetTPActionPlan struct {
TPid string // Tariff plan id
ID string // ActionPlans id
}
// GetTPActionPlan queries specific ActionPlan profile on tariff plan
func (apierSv1 *APIerSv1) GetTPActionPlan(attrs *AttrGetTPActionPlan, reply *utils.TPActionPlan) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
aps, err := apierSv1.StorDb.GetTPActionPlans(attrs.TPid, attrs.ID)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = *aps[0]
return nil
}
type AttrGetTPActionPlanIds struct {
TPid string // Tariff plan id
utils.PaginatorWithSearch
}
// GetTPActionPlanIds queries ActionPlan identities on specific tariff plan.
func (apierSv1 *APIerSv1) GetTPActionPlanIds(attrs *AttrGetTPActionPlanIds, reply *[]string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPActionPlans,
utils.TPDistinctIds{utils.TagCfg}, nil, &attrs.PaginatorWithSearch)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = ids
return nil
}
// RemoveTPActionPlan removes specific ActionPlan on Tariff plan
func (apierSv1 *APIerSv1) RemoveTPActionPlan(attrs *AttrGetTPActionPlan, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierSv1.StorDb.RemTpData(utils.TBLTPActionPlans,
attrs.TPid, map[string]string{utils.TagCfg: attrs.ID}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}

View File

@@ -1,242 +0,0 @@
// +build offline
/*
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 (
tpAccPlansCfgPath string
tpAccPlansCfg *config.CGRConfig
tpAccPlansRPC *rpc.Client
tpAccPlan *utils.TPActionPlan
tpAccPlansDelay int
tpAccPlansConfigDIR string //run tests for specific configuration
)
var sTestsTPAccPlans = []func(t *testing.T){
testTPAccPlansInitCfg,
testTPAccPlansResetStorDb,
testTPAccPlansStartEngine,
testTPAccPlansRpcConn,
testTPAccPlansGetTPAccPlanBeforeSet,
testTPAccPlansSetTPAccPlan,
testTPAccPlansGetTPAccPlanAfterSet,
testTPAccPlansGetTPAccPlanIds,
testTPAccPlansUpdateTPAccPlan,
testTPAccPlansGetTPAccPlanAfterUpdate,
testTPAccPlansRemTPAccPlan,
testTPAccPlansGetTPAccPlanAfterRemove,
testTPAccPlansKillEngine,
}
//Test start here
func TestTPAccPlansIT(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
tpAccPlansConfigDIR = "tutinternal"
case utils.MetaMySQL:
tpAccPlansConfigDIR = "tutmysql"
case utils.MetaMongo:
tpAccPlansConfigDIR = "tutmongo"
case utils.MetaPostgres:
tpAccPlansConfigDIR = "tutpostgres"
default:
t.Fatal("Unknown Database type")
}
for _, stest := range sTestsTPAccPlans {
t.Run(tpAccPlansConfigDIR, stest)
}
}
func testTPAccPlansInitCfg(t *testing.T) {
var err error
tpAccPlansCfgPath = path.Join(*dataDir, "conf", "samples", tpAccPlansConfigDIR)
tpAccPlansCfg, err = config.NewCGRConfigFromPath(tpAccPlansCfgPath)
if err != nil {
t.Error(err)
}
switch tpAccPlansConfigDIR {
case "tutmongo": // Mongo needs more time to reset db, need to investigate
tpAccPlansDelay = 2000
default:
tpAccPlansDelay = 1000
}
}
// Wipe out the cdr database
func testTPAccPlansResetStorDb(t *testing.T) {
if err := engine.InitStorDb(tpAccPlansCfg); err != nil {
t.Fatal(err)
}
}
// Start CGR Engine
func testTPAccPlansStartEngine(t *testing.T) {
if _, err := engine.StopStartEngine(tpAccPlansCfgPath, tpAccPlansDelay); err != nil {
t.Fatal(err)
}
}
// Connect rpc client to rater
func testTPAccPlansRpcConn(t *testing.T) {
var err error
tpAccPlansRPC, err = jsonrpc.Dial(utils.TCP, tpAccPlansCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
if err != nil {
t.Fatal(err)
}
}
func testTPAccPlansGetTPAccPlanBeforeSet(t *testing.T) {
var reply *utils.TPActionPlan
if err := tpAccPlansRPC.Call(utils.APIerSv1GetTPActionPlan,
&AttrGetTPActionPlan{TPid: "TPAcc", ID: "ID"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPAccPlansSetTPAccPlan(t *testing.T) {
tpAccPlan = &utils.TPActionPlan{
TPid: "TPAcc",
ID: "ID",
ActionPlan: []*utils.TPActionTiming{
{
ActionsId: "AccId",
TimingId: "TimingID",
Weight: 10,
},
{
ActionsId: "AccId2",
TimingId: "TimingID2",
Weight: 11,
},
},
}
var result string
if err := tpAccPlansRPC.Call(utils.APIerSv1SetTPActionPlan, tpAccPlan, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTPAccPlansGetTPAccPlanAfterSet(t *testing.T) {
var reply *utils.TPActionPlan
if err := tpAccPlansRPC.Call(utils.APIerSv1GetTPActionPlan,
&AttrGetTPActionPlan{TPid: "TPAcc", ID: "ID"}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpAccPlan.TPid, reply.TPid) {
t.Errorf("Expecting : %+v, received: %+v", tpAccPlan.TPid, reply.TPid)
} else if !reflect.DeepEqual(tpAccPlan.ID, reply.ID) {
t.Errorf("Expecting : %+v, received: %+v", tpAccPlan.ID, reply.ID)
} else if !reflect.DeepEqual(len(tpAccPlan.ActionPlan), len(reply.ActionPlan)) {
t.Errorf("Expecting : %+v, received: %+v", len(tpAccPlan.ActionPlan), len(reply.ActionPlan))
}
}
func testTPAccPlansGetTPAccPlanIds(t *testing.T) {
var result []string
expectedTPID := []string{"ID"}
if err := tpAccPlansRPC.Call(utils.APIerSv1GetTPActionPlanIds,
&AttrGetTPActionPlanIds{TPid: "TPAcc"}, &result); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expectedTPID, result) {
t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
}
}
func testTPAccPlansUpdateTPAccPlan(t *testing.T) {
tpAccPlan.ActionPlan = []*utils.TPActionTiming{
{
ActionsId: "AccId",
TimingId: "TimingID",
Weight: 10,
},
{
ActionsId: "AccId2",
TimingId: "TimingID2",
Weight: 11,
},
{
ActionsId: "AccId3",
TimingId: "TimingID3",
Weight: 12,
},
}
var result string
if err := tpAccPlansRPC.Call(utils.APIerSv1SetTPActionPlan, tpAccPlan, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTPAccPlansGetTPAccPlanAfterUpdate(t *testing.T) {
var reply *utils.TPActionPlan
if err := tpAccPlansRPC.Call(utils.APIerSv1GetTPActionPlan,
&AttrGetTPActionPlan{TPid: "TPAcc", ID: "ID"}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpAccPlan.TPid, reply.TPid) {
t.Errorf("Expecting : %+v, received: %+v", tpAccPlan.TPid, reply.TPid)
} else if !reflect.DeepEqual(tpAccPlan.ID, reply.ID) {
t.Errorf("Expecting : %+v, received: %+v", tpAccPlan.ID, reply.ID)
} else if !reflect.DeepEqual(len(tpAccPlan.ActionPlan), len(reply.ActionPlan)) {
t.Errorf("Expecting : %+v, received: %+v", len(tpAccPlan.ActionPlan), len(reply.ActionPlan))
}
}
func testTPAccPlansRemTPAccPlan(t *testing.T) {
var resp string
if err := tpAccPlansRPC.Call(utils.APIerSv1RemoveTPActionPlan,
&AttrGetTPActionPlan{TPid: "TPAcc", ID: "ID"}, &resp); err != nil {
t.Error(err)
} else if resp != utils.OK {
t.Error("Unexpected reply returned", resp)
}
}
func testTPAccPlansGetTPAccPlanAfterRemove(t *testing.T) {
var reply *utils.TPActionPlan
if err := tpAccPlansRPC.Call(utils.APIerSv1GetTPActionPlan,
&AttrGetTPActionPlan{TPid: "TPAcc", ID: "ID"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPAccPlansKillEngine(t *testing.T) {
if err := engine.KillEngine(tpAccPlansDelay); err != nil {
t.Error(err)
}
}

View File

@@ -1,94 +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"
)
// SetTPActionTriggers creates a new ActionTriggers profile within a tariff plan
func (apierSv1 *APIerSv1) SetTPActionTriggers(attrs *utils.TPActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierSv1.StorDb.SetTPActionTriggers([]*utils.TPActionTriggers{attrs}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
// AttrGetTPActionTriggers used as argument for GetTPActionTriggers
type AttrGetTPActionTriggers struct {
TPid string // Tariff plan id
ID string // ActionTrigger id
}
// GetTPActionTriggers queries specific ActionTriggers profile on tariff plan
func (apierSv1 *APIerSv1) GetTPActionTriggers(attrs *AttrGetTPActionTriggers, reply *utils.TPActionTriggers) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
ats, err := apierSv1.StorDb.GetTPActionTriggers(attrs.TPid, attrs.ID)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = *ats[0]
return nil
}
// AttrGetTPActionTriggerIds used as argument for GetTPActionTriggerIds and RemoveTPActionTriggers
type AttrGetTPActionTriggerIds struct {
TPid string // Tariff plan id
utils.PaginatorWithSearch
}
// GetTPActionTriggerIds queries ActionTriggers identities on specific tariff plan.
func (apierSv1 *APIerSv1) GetTPActionTriggerIds(attrs *AttrGetTPActionTriggerIds, reply *[]string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPActionTriggers,
utils.TPDistinctIds{utils.TagCfg}, nil, &attrs.PaginatorWithSearch)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = ids
return nil
}
// RemoveTPActionTriggers removes specific ActionTriggers on Tariff plan
func (apierSv1 *APIerSv1) RemoveTPActionTriggers(attrs *AttrGetTPActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
err := apierSv1.StorDb.RemTpData(utils.TBLTPActionTriggers,
attrs.TPid, map[string]string{utils.TagCfg: attrs.ID})
if err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}

View File

@@ -1,332 +0,0 @@
// +build offline
/*
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 (
tpActionTriggerCfgPath string
tpActionTriggerCfg *config.CGRConfig
tpActionTriggerRPC *rpc.Client
tpActionTriggers *utils.TPActionTriggers
tpActionTriggerDelay int
tpActionTriggerConfigDIR string //run tests for specific configuration
)
var sTestsTPActionTriggers = []func(t *testing.T){
testTPActionTriggersInitCfg,
testTPActionTriggersResetStorDb,
testTPActionTriggersStartEngine,
testTPActionTriggersRpcConn,
testTPActionTriggersGetTPActionTriggersBeforeSet,
testTPActionTriggersSetTPActionTriggers,
testTPActionTriggersGetTPActionTriggersAfterSet,
testTPActionTriggersGetTPActionTriggersIds,
testTPActionTriggersUpdateTPActionTriggers,
testTPActionTriggersGetTPActionTriggersAfterUpdate,
testTPActionTriggersRemoveTPActionTriggers,
testTPActionTriggersGetTPActionTriggersAfterRemove,
testTPActionTriggersKillEngine,
}
//Test start here
func TestTPActionTriggersIT(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
tpActionTriggerConfigDIR = "tutinternal"
case utils.MetaMySQL:
tpActionTriggerConfigDIR = "tutmysql"
case utils.MetaMongo:
tpActionTriggerConfigDIR = "tutmongo"
case utils.MetaPostgres:
tpActionTriggerConfigDIR = "tutpostgres"
default:
t.Fatal("Unknown Database type")
}
for _, stest := range sTestsTPActionTriggers {
t.Run(tpActionTriggerConfigDIR, stest)
}
}
func testTPActionTriggersInitCfg(t *testing.T) {
var err error
tpActionTriggerCfgPath = path.Join(*dataDir, "conf", "samples", tpActionTriggerConfigDIR)
tpActionTriggerCfg, err = config.NewCGRConfigFromPath(tpActionTriggerCfgPath)
if err != nil {
t.Error(err)
}
switch tpActionTriggerConfigDIR {
case "tutmongo": // Mongo needs more time to reset db, need to investigate
tpActionTriggerDelay = 2000
default:
tpActionTriggerDelay = 1000
}
}
// Wipe out the cdr database
func testTPActionTriggersResetStorDb(t *testing.T) {
if err := engine.InitStorDb(tpActionTriggerCfg); err != nil {
t.Fatal(err)
}
}
// Start CGR Engine
func testTPActionTriggersStartEngine(t *testing.T) {
if _, err := engine.StopStartEngine(tpActionTriggerCfgPath, tpActionTriggerDelay); err != nil {
t.Fatal(err)
}
}
// Connect rpc client to rater
func testTPActionTriggersRpcConn(t *testing.T) {
var err error
tpActionTriggerRPC, err = jsonrpc.Dial(utils.TCP, tpActionTriggerCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
if err != nil {
t.Fatal(err)
}
}
func testTPActionTriggersGetTPActionTriggersBeforeSet(t *testing.T) {
var reply *utils.TPActionTriggers
if err := tpActionTriggerRPC.Call(utils.APIerSv1GetTPActionTriggers,
&AttrGetTPActionTriggers{TPid: "TPAct", ID: "ID"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPActionTriggersSetTPActionTriggers(t *testing.T) {
tpActionTriggers = &utils.TPActionTriggers{
TPid: "TPAct",
ID: "ID",
ActionTriggers: []*utils.TPActionTrigger{
&utils.TPActionTrigger{
Id: "STANDARD_TRIGGERS",
UniqueID: "",
ThresholdType: "*min_balance",
ThresholdValue: 2,
Recurrent: false,
MinSleep: "0",
ExpirationDate: "",
ActivationDate: "",
BalanceId: "",
BalanceType: "*monetary",
BalanceDestinationIds: "FS_USERS",
BalanceWeight: "",
BalanceExpirationDate: "",
BalanceTimingTags: "",
BalanceRatingSubject: "",
BalanceCategories: "",
BalanceSharedGroups: "",
BalanceBlocker: "",
BalanceDisabled: "",
ActionsId: "LOG_WARNING",
Weight: 10,
},
&utils.TPActionTrigger{
Id: "STANDARD_TRIGGERS",
UniqueID: "",
ThresholdType: "*max_event_counter",
ThresholdValue: 5,
Recurrent: false,
MinSleep: "0",
ExpirationDate: "",
ActivationDate: "",
BalanceId: "",
BalanceType: "*monetary",
BalanceDestinationIds: "FS_USERS",
BalanceWeight: "",
BalanceExpirationDate: "",
BalanceTimingTags: "",
BalanceRatingSubject: "",
BalanceCategories: "",
BalanceSharedGroups: "",
BalanceBlocker: "",
BalanceDisabled: "",
ActionsId: "LOG_WARNING",
Weight: 10,
},
},
}
var result string
if err := tpActionTriggerRPC.Call(utils.APIerSv1SetTPActionTriggers, tpActionTriggers, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTPActionTriggersGetTPActionTriggersAfterSet(t *testing.T) {
var reply *utils.TPActionTriggers
if err := tpActionTriggerRPC.Call(utils.APIerSv1GetTPActionTriggers,
&AttrGetTPActionTriggers{TPid: "TPAct", ID: "ID"}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpActionTriggers.TPid, reply.TPid) {
t.Errorf("Expecting : %+v, received: %+v", tpActionTriggers.TPid, reply.TPid)
} else if !reflect.DeepEqual(tpActionTriggers.ID, reply.ID) {
t.Errorf("Expecting : %+v, received: %+v", tpActionTriggers.ID, reply.ID)
} else if !reflect.DeepEqual(len(tpActionTriggers.ActionTriggers), len(reply.ActionTriggers)) {
t.Errorf("Expecting : %+v, received: %+v", len(tpActionTriggers.ActionTriggers), len(reply.ActionTriggers))
}
}
func testTPActionTriggersGetTPActionTriggersIds(t *testing.T) {
var result []string
expectedTPID := []string{"ID"}
if err := tpActionTriggerRPC.Call(utils.APIerSv1GetTPActionTriggerIds,
&AttrGetTPActionTriggerIds{TPid: "TPAct"}, &result); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expectedTPID, result) {
t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
}
}
func testTPActionTriggersUpdateTPActionTriggers(t *testing.T) {
tpActionTriggers.ActionTriggers = []*utils.TPActionTrigger{
&utils.TPActionTrigger{
Id: "STANDARD_TRIGGERS",
UniqueID: "",
ThresholdType: "*min_balance",
ThresholdValue: 2,
Recurrent: false,
MinSleep: "0",
ExpirationDate: "",
ActivationDate: "",
BalanceId: "",
BalanceType: "*monetary",
BalanceDestinationIds: "FS_USERS",
BalanceWeight: "",
BalanceExpirationDate: "",
BalanceTimingTags: "",
BalanceRatingSubject: "",
BalanceCategories: "",
BalanceSharedGroups: "",
BalanceBlocker: "",
BalanceDisabled: "",
ActionsId: "LOG_WARNING",
Weight: 10,
},
&utils.TPActionTrigger{
Id: "STANDARD_TRIGGERS",
UniqueID: "",
ThresholdType: "*max_event_counter",
ThresholdValue: 5,
Recurrent: false,
MinSleep: "0",
ExpirationDate: "",
ActivationDate: "",
BalanceId: "",
BalanceType: "*monetary",
BalanceDestinationIds: "FS_USERS",
BalanceWeight: "",
BalanceExpirationDate: "",
BalanceTimingTags: "",
BalanceRatingSubject: "",
BalanceCategories: "",
BalanceSharedGroups: "",
BalanceBlocker: "",
BalanceDisabled: "",
ActionsId: "LOG_WARNING",
Weight: 10,
},
&utils.TPActionTrigger{
Id: "CDRST1_WARN",
UniqueID: "",
ThresholdType: "*min_asr",
ThresholdValue: 45,
Recurrent: true,
MinSleep: "1m",
ExpirationDate: "",
ActivationDate: "",
BalanceId: "",
BalanceType: "",
BalanceDestinationIds: "",
BalanceWeight: "",
BalanceExpirationDate: "",
BalanceTimingTags: "",
BalanceRatingSubject: "",
BalanceCategories: "",
BalanceSharedGroups: "",
BalanceBlocker: "",
BalanceDisabled: "",
ActionsId: "LOG_WARNING",
Weight: 10,
},
}
var result string
if err := tpActionTriggerRPC.Call(utils.APIerSv1SetTPActionTriggers, tpActionTriggers, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTPActionTriggersGetTPActionTriggersAfterUpdate(t *testing.T) {
var reply *utils.TPActionTriggers
if err := tpActionTriggerRPC.Call(utils.APIerSv1GetTPActionTriggers,
&AttrGetTPActionTriggers{TPid: "TPAct", ID: "ID"}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpActionTriggers.TPid, reply.TPid) {
t.Errorf("Expecting : %+v, received: %+v", tpActionTriggers.TPid, reply.TPid)
} else if !reflect.DeepEqual(tpActionTriggers.ID, reply.ID) {
t.Errorf("Expecting : %+v, received: %+v", tpActionTriggers.ID, reply.ID)
} else if !reflect.DeepEqual(len(tpActionTriggers.ActionTriggers), len(reply.ActionTriggers)) {
t.Errorf("Expecting : %+v, received: %+v", len(tpActionTriggers.ActionTriggers), len(reply.ActionTriggers))
}
}
func testTPActionTriggersRemoveTPActionTriggers(t *testing.T) {
var resp string
if err := tpActionTriggerRPC.Call(utils.APIerSv1RemoveTPActionTriggers,
&AttrGetTPActionTriggers{TPid: "TPAct", ID: "ID"}, &resp); err != nil {
t.Error(err)
} else if resp != utils.OK {
t.Error("Unexpected reply returned", resp)
}
}
func testTPActionTriggersGetTPActionTriggersAfterRemove(t *testing.T) {
var reply *utils.TPActionTriggers
if err := tpActionTriggerRPC.Call(utils.APIerSv1GetTPActionTriggers,
&AttrGetTPActionTriggers{TPid: "TPAct", ID: "ID"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPActionTriggersKillEngine(t *testing.T) {
if err := engine.KillEngine(tpActionTriggerDelay); err != nil {
t.Error(err)
}
}

View File

@@ -1,93 +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
// This file deals with tp_destination_rates management over APIs
import (
"github.com/cgrates/cgrates/utils"
)
// SetTPDestinationRate creates a new DestinationRate profile within a tariff plan
func (apierSv1 *APIerSv1) SetTPDestinationRate(attrs *utils.TPDestinationRate, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.DestinationRates}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierSv1.StorDb.SetTPDestinationRates([]*utils.TPDestinationRate{attrs}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
type AttrGetTPDestinationRate struct {
TPid string // Tariff plan id
ID string // Rate id
utils.Paginator
}
// GetTPDestinationRate queries specific DestinationRate profile on tariff plan
func (apierSv1 *APIerSv1) GetTPDestinationRate(attrs *AttrGetTPDestinationRate, reply *utils.TPDestinationRate) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
drs, err := apierSv1.StorDb.GetTPDestinationRates(attrs.TPid, attrs.ID, &attrs.Paginator)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = *drs[0]
return nil
}
type AttrTPDestinationRateIds struct {
TPid string // Tariff plan id
utils.PaginatorWithSearch
}
// GetTPDestinationRateIds queries DestinationRate identities on specific tariff plan.
func (apierSv1 *APIerSv1) GetTPDestinationRateIds(attrs *AttrGetTPRateIds, reply *[]string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDestinationRates,
utils.TPDistinctIds{utils.TagCfg}, nil, &attrs.PaginatorWithSearch)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = ids
return nil
}
// RemoveTPDestinationRate removes specific DestinationRate on Tariff plan
func (apierSv1 *APIerSv1) RemoveTPDestinationRate(attrs *AttrGetTPDestinationRate, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierSv1.StorDb.RemTpData(utils.TBLTPDestinationRates, attrs.TPid, map[string]string{utils.TagCfg: attrs.ID}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}

View File

@@ -1,202 +0,0 @@
// +build offline
/*
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 (
tpDstRateCfgPath string
tpDstRateCfg *config.CGRConfig
tpDstRateRPC *rpc.Client
tpDstRate *utils.TPDestinationRate
tpDstRateDelay int
tpDstRateConfigDIR string //run tests for specific configuration
)
var sTestsTPDstRates = []func(t *testing.T){
testTPDstRateInitCfg,
testTPDstRateResetStorDb,
testTPDstRateStartEngine,
testTPDstRateRpcConn,
testTPDstRateGetTPDstRateBeforeSet,
testTPDstRateSetTPDstRate,
testTPDstRateGetTPDstRateAfterSet,
testTPDstRateGetTPDstRateIds,
testTPDstRateUpdateTPDstRate,
testTPDstRateGetTPDstRateAfterUpdate,
testTPDstRateRemTPDstRate,
testTPDstRateGetTPDstRateAfterRemove,
testTPDstRateKillEngine,
}
//Test start here
func TestTPDstRateIT(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
tpDstRateConfigDIR = "tutinternal"
case utils.MetaMySQL:
tpDstRateConfigDIR = "tutmysql"
case utils.MetaMongo:
tpDstRateConfigDIR = "tutmongo"
case utils.MetaPostgres:
tpDstRateConfigDIR = "tutpostgres"
default:
t.Fatal("Unknown Database type")
}
for _, stest := range sTestsTPDstRates {
t.Run(tpDstRateConfigDIR, stest)
}
}
func testTPDstRateInitCfg(t *testing.T) {
var err error
tpDstRateCfgPath = path.Join(*dataDir, "conf", "samples", tpDstRateConfigDIR)
tpDstRateCfg, err = config.NewCGRConfigFromPath(tpDstRateCfgPath)
if err != nil {
t.Error(err)
}
tpDstRateDelay = 1000
}
// Wipe out the cdr database
func testTPDstRateResetStorDb(t *testing.T) {
if err := engine.InitStorDb(tpDstRateCfg); err != nil {
t.Fatal(err)
}
}
// Start CGR Engine
func testTPDstRateStartEngine(t *testing.T) {
if _, err := engine.StopStartEngine(tpDstRateCfgPath, tpDstRateDelay); err != nil {
t.Fatal(err)
}
}
// Connect rpc client to rater
func testTPDstRateRpcConn(t *testing.T) {
var err error
tpDstRateRPC, err = jsonrpc.Dial(utils.TCP, tpDstRateCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
if err != nil {
t.Fatal(err)
}
}
func testTPDstRateGetTPDstRateBeforeSet(t *testing.T) {
var reply *utils.TPDestinationRate
if err := tpDstRateRPC.Call(utils.APIerSv1GetTPDestinationRate,
&AttrGetTPDestinationRate{TPid: "TP1", ID: "DR_FREESWITCH_USERS"}, &reply); err == nil ||
err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPDstRateSetTPDstRate(t *testing.T) {
tpDstRate = &utils.TPDestinationRate{
TPid: "TP1",
ID: "DR_FREESWITCH_USERS",
DestinationRates: []*utils.DestinationRate{
&utils.DestinationRate{
DestinationId: "FS_USERS",
RateId: "RT_FS_USERS",
RoundingMethod: "*up",
RoundingDecimals: 2},
},
}
var result string
if err := tpDstRateRPC.Call(utils.APIerSv1SetTPDestinationRate, tpDstRate, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTPDstRateGetTPDstRateAfterSet(t *testing.T) {
var reply *utils.TPDestinationRate
if err := tpDstRateRPC.Call(utils.APIerSv1GetTPDestinationRate,
&AttrGetTPDestinationRate{TPid: "TP1", ID: "DR_FREESWITCH_USERS"}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpDstRate, reply) {
t.Errorf("Expecting : %+v, received: %+v", tpDstRate, reply)
}
}
func testTPDstRateGetTPDstRateIds(t *testing.T) {
var result []string
expectedTPID := []string{"DR_FREESWITCH_USERS"}
if err := tpDstRateRPC.Call(utils.APIerSv1GetTPDestinationRateIds,
&AttrTPDestinationRateIds{TPid: "TP1"}, &result); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expectedTPID, result) {
t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
}
}
func testTPDstRateUpdateTPDstRate(t *testing.T) {
}
func testTPDstRateGetTPDstRateAfterUpdate(t *testing.T) {
var reply *utils.TPDestinationRate
if err := tpDstRateRPC.Call(utils.APIerSv1GetTPDestinationRate,
&AttrGetTPDestinationRate{TPid: "TP1", ID: "DR_FREESWITCH_USERS"}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpDstRate, reply) {
t.Errorf("Expecting : %+v, received: %+v", tpDstRate, reply)
}
}
func testTPDstRateRemTPDstRate(t *testing.T) {
var resp string
if err := tpDstRateRPC.Call(utils.APIerSv1RemoveTPDestinationRate,
&AttrGetTPDestinationRate{TPid: "TP1", ID: "DR_FREESWITCH_USERS"}, &resp); err != nil {
t.Error(err)
} else if resp != utils.OK {
t.Error("Unexpected reply returned", resp)
}
}
func testTPDstRateGetTPDstRateAfterRemove(t *testing.T) {
var reply *utils.TPDestinationRate
if err := tpDstRateRPC.Call(utils.APIerSv1GetTPDestinationRate,
&AttrGetTPDestinationRate{TPid: "TP1", ID: "DR_FREESWITCH_USERS"}, &reply); err == nil ||
err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPDstRateKillEngine(t *testing.T) {
if err := engine.KillEngine(tpDstRateDelay); err != nil {
t.Error(err)
}
}

View File

@@ -1,92 +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
// This file deals with tp_rates management over APIs
import (
"github.com/cgrates/cgrates/utils"
)
// SetTPRate creates a new rate within a tariff plan
func (apierSv1 *APIerSv1) SetTPRate(attrs *utils.TPRateRALs, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.RateSlots}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierSv1.StorDb.SetTPRates([]*utils.TPRateRALs{attrs}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
type AttrGetTPRate struct {
TPid string // Tariff plan id
ID string // Rate id
}
// GetTPRate queries specific Rate on tariff plan
func (apierSv1 *APIerSv1) GetTPRate(attrs *AttrGetTPRate, reply *utils.TPRateRALs) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
rs, err := apierSv1.StorDb.GetTPRates(attrs.TPid, attrs.ID)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = *rs[0]
return nil
}
type AttrGetTPRateIds struct {
TPid string // Tariff plan id
utils.PaginatorWithSearch
}
// GetTPRateIds queries rate identities on specific tariff plan.
func (apierSv1 *APIerSv1) GetTPRateIds(attrs *AttrGetTPRateIds, reply *[]string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRates,
utils.TPDistinctIds{utils.TagCfg}, nil, &attrs.PaginatorWithSearch)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = ids
return nil
}
// RemoveTPRate removes specific Rate on Tariff plan
func (apierSv1 *APIerSv1) RemoveTPRate(attrs *AttrGetTPRate, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierSv1.StorDb.RemTpData(utils.TBLTPRates, attrs.TPid, map[string]string{utils.TagCfg: attrs.ID}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}

View File

@@ -1,238 +0,0 @@
// +build offline
/*
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 (
tpRateCfgPath string
tpRateCfg *config.CGRConfig
tpRateRPC *rpc.Client
tpRate *utils.TPRateRALs
tpRateDelay int
tpRateConfigDIR string //run tests for specific configuration
)
var sTestsTPRates = []func(t *testing.T){
testTPRatesInitCfg,
testTPRatesResetStorDb,
testTPRatesStartEngine,
testTPRatesRpcConn,
testTPRatesGetTPRateforeSet,
testTPRatesSetTPRate,
testTPRatesGetTPRateAfterSet,
testTPRatesGetTPRateIds,
testTPRatesUpdateTPRate,
testTPRatesGetTPRateAfterUpdate,
testTPRatesRemoveTPRate,
testTPRatesGetTPRateAfterRemove,
testTPRatesKillEngine,
}
//Test start here
func TestTPRatesIT(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
tpRateConfigDIR = "tutinternal"
case utils.MetaMySQL:
tpRateConfigDIR = "tutmysql"
case utils.MetaMongo:
tpRateConfigDIR = "tutmongo"
case utils.MetaPostgres:
tpRateConfigDIR = "tutpostgres"
default:
t.Fatal("Unknown Database type")
}
for _, stest := range sTestsTPRates {
t.Run(tpRateConfigDIR, stest)
}
}
func testTPRatesInitCfg(t *testing.T) {
var err error
tpRateCfgPath = path.Join(*dataDir, "conf", "samples", tpRateConfigDIR)
tpRateCfg, err = config.NewCGRConfigFromPath(tpRateCfgPath)
if err != nil {
t.Error(err)
}
switch tpRateConfigDIR {
case "tutmongo": // Mongo needs more time to reset db, need to investigate
tpRateDelay = 2000
default:
tpRateDelay = 1000
}
}
// Wipe out the cdr database
func testTPRatesResetStorDb(t *testing.T) {
if err := engine.InitStorDb(tpRateCfg); err != nil {
t.Fatal(err)
}
}
// Start CGR Engine
func testTPRatesStartEngine(t *testing.T) {
if _, err := engine.StopStartEngine(tpRateCfgPath, tpRateDelay); err != nil {
t.Fatal(err)
}
}
// Connect rpc client to rater
func testTPRatesRpcConn(t *testing.T) {
var err error
tpRateRPC, err = jsonrpc.Dial(utils.TCP, tpRateCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
if err != nil {
t.Fatal(err)
}
}
func testTPRatesGetTPRateforeSet(t *testing.T) {
var reply *utils.TPRateRALs
if err := tpRateRPC.Call(utils.APIerSv1GetTPRate,
&AttrGetTPRate{TPid: "TPidTpRate", ID: "RT_FS_USERS"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPRatesSetTPRate(t *testing.T) {
tpRate = &utils.TPRateRALs{
TPid: "TPidTpRate",
ID: "RT_FS_USERS",
RateSlots: []*utils.RateSlot{
&utils.RateSlot{
ConnectFee: 12,
Rate: 3,
RateUnit: "6s",
RateIncrement: "6s",
GroupIntervalStart: "0s",
},
&utils.RateSlot{
ConnectFee: 12,
Rate: 3,
RateUnit: "4s",
RateIncrement: "6s",
GroupIntervalStart: "1s",
},
},
}
var result string
if err := tpRateRPC.Call(utils.APIerSv1SetTPRate, tpRate, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTPRatesGetTPRateAfterSet(t *testing.T) {
var reply *utils.TPRateRALs
if err := tpRateRPC.Call(utils.APIerSv1GetTPRate, &AttrGetTPRate{TPid: "TPidTpRate", ID: tpRate.ID}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpRate, reply) {
t.Errorf("Expecting : %+v, received: %+v", tpRate, reply)
}
}
func testTPRatesGetTPRateIds(t *testing.T) {
var result []string
expectedTPID := []string{"RT_FS_USERS"}
if err := tpRateRPC.Call(utils.APIerSv1GetTPRateIds, &AttrGetTPRateIds{TPid: "TPidTpRate"}, &result); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expectedTPID, result) {
t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
}
}
func testTPRatesUpdateTPRate(t *testing.T) {
var result string
tpRate.RateSlots = []*utils.RateSlot{
&utils.RateSlot{
ConnectFee: 12,
Rate: 3,
RateUnit: "6s",
RateIncrement: "6s",
GroupIntervalStart: "0s",
},
&utils.RateSlot{
ConnectFee: 12,
Rate: 10,
RateUnit: "4s",
RateIncrement: "6s",
GroupIntervalStart: "1s",
},
&utils.RateSlot{
ConnectFee: 5,
Rate: 10,
RateUnit: "4s",
RateIncrement: "6s",
GroupIntervalStart: "3s",
},
}
if err := tpRateRPC.Call(utils.APIerSv1SetTPRate, tpRate, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTPRatesGetTPRateAfterUpdate(t *testing.T) {
var reply *utils.TPRateRALs
if err := tpRateRPC.Call(utils.APIerSv1GetTPRate,
&AttrGetTPRate{TPid: "TPidTpRate", ID: tpRate.ID}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpRate, reply) {
t.Errorf("Expecting : %+v, received: %+v", tpRate, reply)
}
}
func testTPRatesRemoveTPRate(t *testing.T) {
var resp string
if err := tpRateRPC.Call(utils.APIerSv1RemoveTPRate,
&AttrGetTPRate{TPid: "TPidTpRate", ID: "RT_FS_USERS"}, &resp); err != nil {
t.Error(err)
} else if resp != utils.OK {
t.Error("Unexpected reply returned", resp)
}
}
func testTPRatesGetTPRateAfterRemove(t *testing.T) {
var reply *utils.TPRateRALs
if err := tpRateRPC.Call(utils.APIerSv1GetTPRate,
&AttrGetTPRate{TPid: "TPidTpRate", ID: "RT_FS_USERS"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPRatesKillEngine(t *testing.T) {
if err := engine.KillEngine(tpRateDelay); err != nil {
t.Error(err)
}
}

View File

@@ -1,93 +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
// This file deals with tp_destrates_timing management over APIs
import (
"github.com/cgrates/cgrates/utils"
)
// SetTPRatingPlan creates a new DestinationRateTiming profile within a tariff plan
func (apierSv1 *APIerSv1) SetTPRatingPlan(attrs *utils.TPRatingPlan, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.RatingPlanBindings}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierSv1.StorDb.SetTPRatingPlans([]*utils.TPRatingPlan{attrs}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
type AttrGetTPRatingPlan struct {
TPid string // Tariff plan id
ID string // Rate id
utils.Paginator
}
// GetTPRatingPlan queries specific RatingPlan profile on tariff plan
func (apierSv1 *APIerSv1) GetTPRatingPlan(attrs *AttrGetTPRatingPlan, reply *utils.TPRatingPlan) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
rps, err := apierSv1.StorDb.GetTPRatingPlans(attrs.TPid, attrs.ID, &attrs.Paginator)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = *rps[0]
return nil
}
type AttrGetTPRatingPlanIds struct {
TPid string // Tariff plan id
utils.PaginatorWithSearch
}
// GetTPRatingPlanIds queries RatingPlan identities on specific tariff plan.
func (apierSv1 *APIerSv1) GetTPRatingPlanIds(attrs *AttrGetTPRatingPlanIds, reply *[]string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRatingPlans,
utils.TPDistinctIds{utils.TagCfg}, nil, &attrs.PaginatorWithSearch)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = ids
return nil
}
// RemoveTPRatingPlan removes specific RatingPlan on Tariff plan
func (apierSv1 *APIerSv1) RemoveTPRatingPlan(attrs *AttrGetTPRatingPlan, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierSv1.StorDb.RemTpData(utils.TBLTPRatingPlans, attrs.TPid, map[string]string{utils.TagCfg: attrs.ID}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}

View File

@@ -1,237 +0,0 @@
// +build offline
/*
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 (
tpRatingPlanCfgPath string
tpRatingPlanCfg *config.CGRConfig
tpRatingPlanRPC *rpc.Client
tpRatingPlan *utils.TPRatingPlan
tpRatingPlanDelay int
tpRatingPlanConfigDIR string //run tests for specific configuration
)
var sTestsTPRatingPlans = []func(t *testing.T){
testTPRatingPlansInitCfg,
testTPRatingPlansResetStorDb,
testTPRatingPlansStartEngine,
testTPRatingPlansRpcConn,
testTPRatingPlansGetTPRatingPlanBeforeSet,
testTPRatingPlansSetTPRatingPlan,
testTPRatingPlansGetTPRatingPlanAfterSet,
testTPRatingPlansGetTPRatingPlanIds,
testTPRatingPlansUpdateTPRatingPlan,
testTPRatingPlansGetTPRatingPlanAfterUpdate,
testTPRatingPlansRemoveTPRatingPlan,
testTPRatingPlansGetTPRatingPlanAfterRemove,
testTPRatingPlansKillEngine,
}
//Test start here
func TestTPRatingPlansIT(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
tpRatingPlanConfigDIR = "tutinternal"
case utils.MetaMySQL:
tpRatingPlanConfigDIR = "tutmysql"
case utils.MetaMongo:
tpRatingPlanConfigDIR = "tutmongo"
case utils.MetaPostgres:
tpRatingPlanConfigDIR = "tutpostgres"
default:
t.Fatal("Unknown Database type")
}
for _, stest := range sTestsTPRatingPlans {
t.Run(tpRatingPlanConfigDIR, stest)
}
}
func testTPRatingPlansInitCfg(t *testing.T) {
var err error
tpRatingPlanCfgPath = path.Join(*dataDir, "conf", "samples", tpRatingPlanConfigDIR)
tpRatingPlanCfg, err = config.NewCGRConfigFromPath(tpRatingPlanCfgPath)
if err != nil {
t.Error(err)
}
switch tpRatingPlanConfigDIR {
case "tutmongo": // Mongo needs more time to reset db, need to investigate
tpRatingPlanDelay = 2000
default:
tpRatingPlanDelay = 1000
}
}
// Wipe out the cdr database
func testTPRatingPlansResetStorDb(t *testing.T) {
if err := engine.InitStorDb(tpRatingPlanCfg); err != nil {
t.Fatal(err)
}
}
// Start CGR Engine
func testTPRatingPlansStartEngine(t *testing.T) {
if _, err := engine.StopStartEngine(tpRatingPlanCfgPath, tpRatingPlanDelay); err != nil {
t.Fatal(err)
}
}
// Connect rpc client to rater
func testTPRatingPlansRpcConn(t *testing.T) {
var err error
tpRatingPlanRPC, err = jsonrpc.Dial(utils.TCP, tpRatingPlanCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
if err != nil {
t.Fatal(err)
}
}
func testTPRatingPlansGetTPRatingPlanBeforeSet(t *testing.T) {
var reply *utils.TPRatingPlan
if err := tpRatingPlanRPC.Call(utils.APIerSv1GetTPRatingPlan,
&AttrGetTPRatingPlan{TPid: "TPRP1", ID: "Plan1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPRatingPlansSetTPRatingPlan(t *testing.T) {
tpRatingPlan = &utils.TPRatingPlan{
TPid: "TPRP1",
ID: "Plan1",
RatingPlanBindings: []*utils.TPRatingPlanBinding{
&utils.TPRatingPlanBinding{
DestinationRatesId: "RateId",
TimingId: "TimingID",
Weight: 12,
},
&utils.TPRatingPlanBinding{
DestinationRatesId: "DR_FREESWITCH_USERS",
TimingId: "ALWAYS",
Weight: 10,
},
},
}
var result string
if err := tpRatingPlanRPC.Call(utils.APIerSv1SetTPRatingPlan, tpRatingPlan, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTPRatingPlansGetTPRatingPlanAfterSet(t *testing.T) {
var respond *utils.TPRatingPlan
if err := tpRatingPlanRPC.Call(utils.APIerSv1GetTPRatingPlan,
&AttrGetTPRatingPlan{TPid: "TPRP1", ID: "Plan1"}, &respond); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpRatingPlan.TPid, respond.TPid) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingPlan.TPid, respond.TPid)
} else if !reflect.DeepEqual(tpRatingPlan.ID, respond.ID) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingPlan, respond)
} else if !reflect.DeepEqual(len(tpRatingPlan.RatingPlanBindings), len(respond.RatingPlanBindings)) {
t.Errorf("Expecting : %+v, received: %+v", len(tpRatingPlan.RatingPlanBindings), len(respond.RatingPlanBindings))
}
}
func testTPRatingPlansGetTPRatingPlanIds(t *testing.T) {
var result []string
expected := []string{"Plan1"}
if err := tpRatingPlanRPC.Call(utils.APIerSv1GetTPRatingPlanIds,
&AttrGetTPRatingPlanIds{TPid: tpRatingPlan.TPid}, &result); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, result) {
t.Errorf("Expecting: %+v, received: %+v", expected, result)
}
}
func testTPRatingPlansUpdateTPRatingPlan(t *testing.T) {
tpRatingPlan.RatingPlanBindings = []*utils.TPRatingPlanBinding{
&utils.TPRatingPlanBinding{
DestinationRatesId: "RateId",
TimingId: "TimingID",
Weight: 12,
},
&utils.TPRatingPlanBinding{
DestinationRatesId: "DR_FREESWITCH_USERS",
TimingId: "ALWAYS",
Weight: 10,
},
&utils.TPRatingPlanBinding{
DestinationRatesId: "RateID2",
TimingId: "ALWAYS",
Weight: 11,
},
}
var result string
if err := tpRatingPlanRPC.Call(utils.APIerSv1SetTPRatingPlan, tpRatingPlan, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTPRatingPlansGetTPRatingPlanAfterUpdate(t *testing.T) {
var respond *utils.TPRatingPlan
if err := tpRatingPlanRPC.Call(utils.APIerSv1GetTPRatingPlan,
&AttrGetTPRatingPlan{TPid: "TPRP1", ID: "Plan1"}, &respond); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpRatingPlan.TPid, respond.TPid) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingPlan.TPid, respond.TPid)
} else if !reflect.DeepEqual(tpRatingPlan.ID, respond.ID) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingPlan, respond)
} else if !reflect.DeepEqual(len(tpRatingPlan.RatingPlanBindings), len(respond.RatingPlanBindings)) {
t.Errorf("Expecting : %+v, received: %+v", len(tpRatingPlan.RatingPlanBindings), len(respond.RatingPlanBindings))
}
}
func testTPRatingPlansRemoveTPRatingPlan(t *testing.T) {
var resp string
if err := tpRatingPlanRPC.Call(utils.APIerSv1RemoveTPRatingPlan,
&AttrGetTPRatingPlan{TPid: "TPRP1", ID: "Plan1"}, &resp); err != nil {
t.Error(err)
} else if resp != utils.OK {
t.Error("Unexpected reply returned", resp)
}
}
func testTPRatingPlansGetTPRatingPlanAfterRemove(t *testing.T) {
var respond *utils.TPRatingPlan
if err := tpRatingPlanRPC.Call(utils.APIerSv1GetTPRatingPlan,
&AttrGetTPRatingPlan{TPid: "TPRP1", ID: "Plan1"}, &respond); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPRatingPlansKillEngine(t *testing.T) {
if err := engine.KillEngine(tpRatingPlanDelay); err != nil {
t.Error(err)
}
}

View File

@@ -1,161 +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
// This file deals with tp_rate_profiles management over APIs
import (
"github.com/cgrates/cgrates/utils"
)
// SetTPRatingProfile creates a new RatingProfile within a tariff plan
func (apierSv1 *APIerSv1) SetTPRatingProfile(attrs *utils.TPRatingProfile, reply *string) error {
if missing := utils.MissingStructFields(attrs,
[]string{utils.TPid, utils.LoadId, utils.Category, utils.Subject, utils.RatingPlanActivations}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if attrs.Tenant == utils.EmptyString {
attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
}
if err := apierSv1.StorDb.SetTPRatingProfiles([]*utils.TPRatingProfile{attrs}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
// GetTPRatingProfilesByLoadID queries specific RatingProfile on tariff plan
func (apierSv1 *APIerSv1) GetTPRatingProfilesByLoadID(attrs *utils.TPRatingProfile, reply *[]*utils.TPRatingProfile) error {
mndtryFlds := []string{utils.TPid, utils.LoadId}
if len(attrs.Subject) != 0 { // If Subject provided as filter, make all related fields mandatory
mndtryFlds = append(mndtryFlds, utils.Category, utils.Subject)
}
if missing := utils.MissingStructFields(attrs, mndtryFlds); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if attrs.Tenant == utils.EmptyString {
attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
}
rps, err := apierSv1.StorDb.GetTPRatingProfiles(attrs)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = rps
return nil
}
// GetTPRatingProfileLoadIds queries RatingProfile identities on specific tariff plan.
func (apierSv1 *APIerSv1) GetTPRatingProfileLoadIds(attrs *utils.AttrTPRatingProfileIds, reply *[]string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if attrs.Tenant == utils.EmptyString {
attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
}
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRatingProfiles,
utils.TPDistinctIds{utils.Loadid}, map[string]string{
utils.TenantCfg: attrs.Tenant,
utils.CategoryLowerCase: attrs.Category,
utils.SubjectLowerCase: attrs.Subject,
}, new(utils.PaginatorWithSearch))
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = ids
return nil
}
// AttrGetTPRatingProfile arguments used by GetTPRatingProfile and RemoveTPRatingProfile
type AttrGetTPRatingProfile struct {
TPid string // Tariff plan id
RatingProfileID string // RatingProfile id
}
// GetTPRatingProfile queries specific RatingProfile on tariff plan
func (apierSv1 *APIerSv1) GetTPRatingProfile(attrs *AttrGetTPRatingProfile, reply *utils.TPRatingProfile) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.RatingProfileID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
tmpRpf := &utils.TPRatingProfile{TPid: attrs.TPid}
if err := tmpRpf.SetRatingProfileID(attrs.RatingProfileID); err != nil {
return err
}
rpfs, err := apierSv1.StorDb.GetTPRatingProfiles(tmpRpf)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = *rpfs[0]
return nil
}
// AttrGetTPRatingProfileIds arguments used by GetTPRatingProfileIds
type AttrGetTPRatingProfileIds struct {
TPid string // Tariff plan id
utils.PaginatorWithSearch
}
// GetTPRatingProfileIds queries RatingProfiles identities on specific tariff plan.
func (apierSv1 *APIerSv1) GetTPRatingProfileIds(attrs *AttrGetTPRatingProfileIds, reply *[]string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRatingProfiles,
utils.TPDistinctIds{utils.Loadid, utils.TenantCfg, utils.CategoryLowerCase, utils.SubjectLowerCase},
nil, &attrs.PaginatorWithSearch)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = ids
return nil
}
// RemoveTPRatingProfile removes specific RatingProfiles on Tariff plan
func (apierSv1 *APIerSv1) RemoveTPRatingProfile(attrs *AttrGetTPRatingProfile, reply *string) (err error) {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.RatingProfileID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
tmpRpf := new(utils.TPRatingProfile)
if err = tmpRpf.SetRatingProfileID(attrs.RatingProfileID); err != nil {
return
}
err = apierSv1.StorDb.RemTpData(utils.TBLTPRatingProfiles,
attrs.TPid, map[string]string{
utils.Loadid: tmpRpf.LoadId,
utils.TenantCfg: tmpRpf.Tenant,
utils.CategoryLowerCase: tmpRpf.Category,
utils.SubjectLowerCase: tmpRpf.Subject,
})
if err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return
}

View File

@@ -1,287 +0,0 @@
// +build offline
/*
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 (
tpRatingProfileCfgPath string
tpRatingProfileCfg *config.CGRConfig
tpRatingProfileRPC *rpc.Client
tpRatingProfile *utils.TPRatingProfile
tpRatingProfileDelay int
tpRatingProfileConfigDIR string //run tests for specific configuration
tpRatingProfileID = "RPrf:Tenant1:Category:Subject"
)
var sTestsTPRatingProfiles = []func(t *testing.T){
testTPRatingProfilesInitCfg,
testTPRatingProfilesResetStorDb,
testTPRatingProfilesStartEngine,
testTPRatingProfilesRpcConn,
testTPRatingProfilesGetTPRatingProfileBeforeSet,
testTPRatingProfilesSetTPRatingProfile,
testTPRatingProfilesGetTPRatingProfileAfterSet,
testTPRatingProfilesGetTPRatingProfileLoadIds,
testTPRatingProfilesGetTPRatingProfilesByLoadID,
testTPRatingProfilesUpdateTPRatingProfile,
testTPRatingProfilesGetTPRatingProfileAfterUpdate,
testTPRatingProfilesGetTPRatingProfileIds,
testTPRatingProfilesRemoveTPRatingProfile,
testTPRatingProfilesGetTPRatingProfileAfterRemove,
testTPRatingProfilesKillEngine,
}
//Test start here
func TestTPRatingProfilesIT(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
tpRatingProfileConfigDIR = "tutinternal"
case utils.MetaMySQL:
tpRatingProfileConfigDIR = "tutmysql"
case utils.MetaMongo:
tpRatingProfileConfigDIR = "tutmongo"
case utils.MetaPostgres:
tpRatingProfileConfigDIR = "tutpostgres"
default:
t.Fatal("Unknown Database type")
}
for _, stest := range sTestsTPRatingProfiles {
t.Run(tpRatingProfileConfigDIR, stest)
}
}
func testTPRatingProfilesInitCfg(t *testing.T) {
var err error
tpRatingProfileCfgPath = path.Join(*dataDir, "conf", "samples", tpRatingProfileConfigDIR)
tpRatingProfileCfg, err = config.NewCGRConfigFromPath(tpRatingProfileCfgPath)
if err != nil {
t.Error(err)
}
switch tpRatingProfileConfigDIR {
case "tutmongo": // Mongo needs more time to reset db, need to investigate
tpRatingProfileDelay = 2000
default:
tpRatingProfileDelay = 1000
}
}
// Wipe out the cdr database
func testTPRatingProfilesResetStorDb(t *testing.T) {
if err := engine.InitStorDb(tpRatingProfileCfg); err != nil {
t.Fatal(err)
}
}
// Start CGR Engine
func testTPRatingProfilesStartEngine(t *testing.T) {
if _, err := engine.StopStartEngine(tpRatingProfileCfgPath, tpRatingProfileDelay); err != nil {
t.Fatal(err)
}
}
// Connect rpc client to rater
func testTPRatingProfilesRpcConn(t *testing.T) {
var err error
tpRatingProfileRPC, err = jsonrpc.Dial(utils.TCP, tpRatingProfileCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
if err != nil {
t.Fatal(err)
}
}
func testTPRatingProfilesGetTPRatingProfileBeforeSet(t *testing.T) {
var reply *utils.TPRatingProfile
if err := tpRatingProfileRPC.Call(utils.APIerSv1GetTPRatingProfile,
&AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileID: tpRatingProfileID}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPRatingProfilesSetTPRatingProfile(t *testing.T) {
tpRatingProfile = &utils.TPRatingProfile{
TPid: "TPRProf1",
LoadId: "RPrf",
Tenant: "Tenant1",
Category: "Category",
Subject: "Subject",
RatingPlanActivations: []*utils.TPRatingActivation{
&utils.TPRatingActivation{
ActivationTime: "2014-07-29T15:00:00Z",
RatingPlanId: "PlanOne",
FallbackSubjects: "FallBack",
},
&utils.TPRatingActivation{
ActivationTime: "2015-07-29T10:00:00Z",
RatingPlanId: "PlanTwo",
FallbackSubjects: "FallOut",
},
},
}
var result string
if err := tpRatingProfileRPC.Call(utils.APIerSv1SetTPRatingProfile, tpRatingProfile, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTPRatingProfilesGetTPRatingProfileAfterSet(t *testing.T) {
var respond *utils.TPRatingProfile
if err := tpRatingProfileRPC.Call(utils.APIerSv1GetTPRatingProfile,
&AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileID: tpRatingProfileID}, &respond); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpRatingProfile.TPid, respond.TPid) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.TPid, respond.TPid)
} else if !reflect.DeepEqual(tpRatingProfile.LoadId, respond.LoadId) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.LoadId, respond.LoadId)
} else if !reflect.DeepEqual(tpRatingProfile.Tenant, respond.Tenant) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Tenant, respond.Tenant)
} else if !reflect.DeepEqual(tpRatingProfile.Category, respond.Category) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Category, respond.Category)
} else if !reflect.DeepEqual(tpRatingProfile.Subject, respond.Subject) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Subject, respond.Subject)
} else if !reflect.DeepEqual(len(tpRatingProfile.RatingPlanActivations), len(respond.RatingPlanActivations)) {
t.Errorf("Expecting : %+v, received: %+v", len(tpRatingProfile.RatingPlanActivations), len(respond.RatingPlanActivations))
}
}
func testTPRatingProfilesGetTPRatingProfileLoadIds(t *testing.T) {
var result []string
expected := []string{"RPrf"}
if err := tpRatingProfileRPC.Call(utils.APIerSv1GetTPRatingProfileLoadIds,
&utils.AttrTPRatingProfileIds{TPid: tpRatingProfile.TPid, Tenant: tpRatingProfile.Tenant,
Category: tpRatingProfile.Category, Subject: tpRatingProfile.Subject}, &result); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, result) {
t.Errorf("Expecting: %+v, received: %+v", expected, result)
}
}
func testTPRatingProfilesGetTPRatingProfilesByLoadID(t *testing.T) {
var respond *[]*utils.TPRatingProfile
if err := tpRatingProfileRPC.Call(utils.APIerSv1GetTPRatingProfilesByLoadID,
&utils.TPRatingProfile{TPid: "TPRProf1", LoadId: "RPrf", Tenant: "Tenant1"}, &respond); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpRatingProfile.TPid, (*respond)[0].TPid) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.TPid, (*respond)[0].TPid)
} else if !reflect.DeepEqual(tpRatingProfile.LoadId, (*respond)[0].LoadId) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.LoadId, (*respond)[0].LoadId)
} else if !reflect.DeepEqual(tpRatingProfile.Tenant, (*respond)[0].Tenant) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Tenant, (*respond)[0].Tenant)
} else if !reflect.DeepEqual(tpRatingProfile.Category, (*respond)[0].Category) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Category, (*respond)[0].Category)
} else if !reflect.DeepEqual(tpRatingProfile.Subject, (*respond)[0].Subject) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Subject, (*respond)[0].Subject)
} else if !reflect.DeepEqual(len(tpRatingProfile.RatingPlanActivations), len((*respond)[0].RatingPlanActivations)) {
t.Errorf("Expecting : %+v, received: %+v", len(tpRatingProfile.RatingPlanActivations), len((*respond)[0].RatingPlanActivations))
}
}
func testTPRatingProfilesUpdateTPRatingProfile(t *testing.T) {
var result string
tpRatingProfile.RatingPlanActivations = []*utils.TPRatingActivation{
&utils.TPRatingActivation{
ActivationTime: "2014-07-29T15:00:00Z",
RatingPlanId: "PlanOne",
FallbackSubjects: "FallBack",
},
&utils.TPRatingActivation{
ActivationTime: "2015-07-29T10:00:00Z",
RatingPlanId: "PlanTwo",
FallbackSubjects: "FallOut",
},
&utils.TPRatingActivation{
ActivationTime: "2017-07-29T10:00:00Z",
RatingPlanId: "BackupPlan",
FallbackSubjects: "Retreat",
},
}
if err := tpRatingProfileRPC.Call(utils.APIerSv1SetTPRatingProfile, tpRatingProfile, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTPRatingProfilesGetTPRatingProfileAfterUpdate(t *testing.T) {
var respond *utils.TPRatingProfile
if err := tpRatingProfileRPC.Call(utils.APIerSv1GetTPRatingProfile,
&AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileID: tpRatingProfileID}, &respond); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpRatingProfile.TPid, respond.TPid) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.TPid, respond.TPid)
} else if !reflect.DeepEqual(tpRatingProfile.LoadId, respond.LoadId) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.LoadId, respond.LoadId)
} else if !reflect.DeepEqual(tpRatingProfile.Tenant, respond.Tenant) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Tenant, respond.Tenant)
} else if !reflect.DeepEqual(tpRatingProfile.Category, respond.Category) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Category, respond.Category)
} else if !reflect.DeepEqual(tpRatingProfile.Subject, respond.Subject) {
t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Subject, respond.Subject)
} else if !reflect.DeepEqual(len(tpRatingProfile.RatingPlanActivations), len(respond.RatingPlanActivations)) {
t.Errorf("Expecting : %+v, received: %+v", len(tpRatingProfile.RatingPlanActivations), len(respond.RatingPlanActivations))
}
}
func testTPRatingProfilesGetTPRatingProfileIds(t *testing.T) {
var respond []string
expected := []string{"RPrf:Tenant1:Category:Subject"}
if err := tpRatingProfileRPC.Call(utils.APIerSv1GetTPRatingProfileIds,
&AttrGetTPRatingProfileIds{TPid: "TPRProf1"}, &respond); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, respond) {
t.Errorf("Expecting : %+v, received: %+v", expected, respond)
}
}
func testTPRatingProfilesRemoveTPRatingProfile(t *testing.T) {
var resp string
if err := tpRatingProfileRPC.Call(utils.APIerSv1RemoveTPRatingProfile,
&AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileID: utils.ConcatenatedKey(tpRatingProfile.LoadId, tpRatingProfile.Tenant, tpRatingProfile.Category, tpRatingProfile.Subject)}, &resp); err != nil {
t.Error(err)
} else if resp != utils.OK {
t.Error("Unexpected reply returned", resp)
}
}
func testTPRatingProfilesGetTPRatingProfileAfterRemove(t *testing.T) {
var respond *utils.TPRatingProfile
if err := tpRatingProfileRPC.Call(utils.APIerSv1GetTPRatingProfile,
&AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileID: tpRatingProfileID}, &respond); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPRatingProfilesKillEngine(t *testing.T) {
if err := engine.KillEngine(tpRatingProfileDelay); err != nil {
t.Error(err)
}
}

View File

@@ -1,90 +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"
)
// SetTPSharedGroups creates a new SharedGroups profile within a tariff plan
func (apierSv1 *APIerSv1) SetTPSharedGroups(attrs *utils.TPSharedGroups, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.SharedGroups}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierSv1.StorDb.SetTPSharedGroups([]*utils.TPSharedGroups{attrs}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
type AttrGetTPSharedGroups struct {
TPid string // Tariff plan id
ID string // SharedGroup id
}
// GetTPSharedGroups queries specific SharedGroup on tariff plan
func (apierSv1 *APIerSv1) GetTPSharedGroups(attrs *AttrGetTPSharedGroups, reply *utils.TPSharedGroups) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
sgs, err := apierSv1.StorDb.GetTPSharedGroups(attrs.TPid, attrs.ID)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = *sgs[0]
return nil
}
type AttrGetTPSharedGroupIds struct {
TPid string // Tariff plan id
utils.PaginatorWithSearch
}
// GetTPSharedGroupIds queries SharedGroups identities on specific tariff plan.
func (apierSv1 *APIerSv1) GetTPSharedGroupIds(attrs *AttrGetTPSharedGroupIds, reply *[]string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPSharedGroups,
utils.TPDistinctIds{utils.TagCfg}, nil, &attrs.PaginatorWithSearch)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = ids
return nil
}
// RemoveTPSharedGroups removes specific SharedGroups on Tariff plan
func (apierSv1 *APIerSv1) RemoveTPSharedGroups(attrs *AttrGetTPSharedGroups, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierSv1.StorDb.RemTpData(utils.TBLTPSharedGroups, attrs.TPid, map[string]string{utils.TagCfg: attrs.ID}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}

View File

@@ -1,232 +0,0 @@
// +build offline
/*
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 (
tpSharedGroupCfgPath string
tpSharedGroupCfg *config.CGRConfig
tpSharedGroupRPC *rpc.Client
tpSharedGroups *utils.TPSharedGroups
tpSharedGroupDelay int
tpSharedGroupConfigDIR string //run tests for specific configuration
)
var sTestsTPSharedGroups = []func(t *testing.T){
testTPSharedGroupsInitCfg,
testTPSharedGroupsResetStorDb,
testTPSharedGroupsStartEngine,
testTPSharedGroupsRpcConn,
testTPSharedGroupsBeforeSet,
testTPSharedGroupsSetSharedGroups,
testTPSharedGroupsAfterSet,
testTPSharedGroupsGetTPSharedGroupIds,
testTPSharedGroupsUpdateTPShareGroups,
testTpSharedGroupsGetTPSharedGroupsAfterUpdate,
testTPSharedGroupsRemoveTPSharedGroups,
testTPSharedGroupsGetTPSharedGroupsAfterRemove,
testTPSharedGroupsKillEngine,
}
//Test start here
func TestTPSharedGroupsIT(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
tpSharedGroupConfigDIR = "tutinternal"
case utils.MetaMySQL:
tpSharedGroupConfigDIR = "tutmysql"
case utils.MetaMongo:
tpSharedGroupConfigDIR = "tutmongo"
case utils.MetaPostgres:
tpSharedGroupConfigDIR = "tutpostgres"
default:
t.Fatal("Unknown Database type")
}
for _, stest := range sTestsTPSharedGroups {
t.Run(tpSharedGroupConfigDIR, stest)
}
}
func testTPSharedGroupsInitCfg(t *testing.T) {
var err error
tpSharedGroupCfgPath = path.Join(*dataDir, "conf", "samples", tpSharedGroupConfigDIR)
tpSharedGroupCfg, err = config.NewCGRConfigFromPath(tpSharedGroupCfgPath)
if err != nil {
t.Error(err)
}
switch tpSharedGroupConfigDIR {
case "tutmongo": // Mongo needs more time to reset db
tpSharedGroupDelay = 2000
default:
tpSharedGroupDelay = 1000
}
}
// Wipe out the cdr database
func testTPSharedGroupsResetStorDb(t *testing.T) {
if err := engine.InitStorDb(tpSharedGroupCfg); err != nil {
t.Fatal(err)
}
}
// Start CGR Engine
func testTPSharedGroupsStartEngine(t *testing.T) {
if _, err := engine.StopStartEngine(tpSharedGroupCfgPath, tpSharedGroupDelay); err != nil {
t.Fatal(err)
}
}
// Connect rpc client to rater
func testTPSharedGroupsRpcConn(t *testing.T) {
var err error
tpSharedGroupRPC, err = jsonrpc.Dial(utils.TCP, tpSharedGroupCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
if err != nil {
t.Fatal(err)
}
}
func testTPSharedGroupsBeforeSet(t *testing.T) {
var reply *utils.TPSharedGroups
if err := tpSharedGroupRPC.Call(utils.APIerSv1GetTPSharedGroups, &AttrGetTPSharedGroups{TPid: "TPS1", ID: "Group1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPSharedGroupsSetSharedGroups(t *testing.T) {
tpSharedGroups = &utils.TPSharedGroups{
TPid: "TPS1",
ID: "Group1",
SharedGroups: []*utils.TPSharedGroup{
&utils.TPSharedGroup{
Account: "AccOne",
Strategy: "StrategyOne",
RatingSubject: "SubOne",
},
&utils.TPSharedGroup{
Account: "AccTow",
Strategy: "StrategyTwo",
RatingSubject: "SubTwo",
},
},
}
var result string
if err := tpSharedGroupRPC.Call(utils.APIerSv1SetTPSharedGroups, &tpSharedGroups, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTPSharedGroupsAfterSet(t *testing.T) {
var respond *utils.TPSharedGroups
if err := tpSharedGroupRPC.Call(utils.APIerSv1GetTPSharedGroups, &AttrGetTPSharedGroups{TPid: tpSharedGroups.TPid, ID: tpSharedGroups.ID}, &respond); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpSharedGroups.TPid, respond.TPid) {
t.Errorf("Expecting: %+v, received: %+v", tpSharedGroups.TPid, respond.TPid)
} else if !reflect.DeepEqual(tpSharedGroups.ID, respond.ID) {
t.Errorf("Expecting: %+v, received: %+v", tpSharedGroups.ID, respond.ID)
} else if !reflect.DeepEqual(len(tpSharedGroups.SharedGroups), len(respond.SharedGroups)) {
t.Errorf("Expecting: %+v, received: %+v", len(tpSharedGroups.SharedGroups), len(respond.SharedGroups))
}
}
func testTPSharedGroupsGetTPSharedGroupIds(t *testing.T) {
var result []string
expectedTPID := []string{"Group1"}
if err := tpSharedGroupRPC.Call(utils.APIerSv1GetTPSharedGroupIds,
&AttrGetTPSharedGroupIds{tpSharedGroups.TPid, utils.PaginatorWithSearch{}}, &result); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(result, expectedTPID) {
t.Errorf("Expecting: %+v, received: %+v", result, expectedTPID)
}
}
func testTPSharedGroupsUpdateTPShareGroups(t *testing.T) {
var result string
tpSharedGroups.SharedGroups = []*utils.TPSharedGroup{
&utils.TPSharedGroup{
Account: "AccOne",
Strategy: "StrategyOne",
RatingSubject: "SubOne",
},
&utils.TPSharedGroup{
Account: "AccTow",
Strategy: "StrategyTwo",
RatingSubject: "SubTwo",
},
&utils.TPSharedGroup{
Account: "AccPlus",
Strategy: "StrategyPlus",
RatingSubject: "SubPlus",
},
}
if err := tpSharedGroupRPC.Call(utils.APIerSv1SetTPSharedGroups, tpSharedGroups, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func testTpSharedGroupsGetTPSharedGroupsAfterUpdate(t *testing.T) {
var expectedTPS *utils.TPSharedGroups
if err := tpSharedGroupRPC.Call(utils.APIerSv1GetTPSharedGroups, &AttrGetTPSharedGroups{TPid: tpSharedGroups.TPid, ID: tpSharedGroups.ID}, &expectedTPS); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(tpSharedGroups.TPid, expectedTPS.TPid) {
t.Errorf("Expecting: %+v, received: %+v", tpSharedGroups.TPid, expectedTPS.TPid)
} else if !reflect.DeepEqual(tpSharedGroups.ID, expectedTPS.ID) {
t.Errorf("Expecting: %+v, received: %+v", tpSharedGroups.ID, expectedTPS.ID)
} else if !reflect.DeepEqual(len(tpSharedGroups.SharedGroups), len(expectedTPS.SharedGroups)) {
t.Errorf("Expecting: %+v, received: %+v", len(tpSharedGroups.SharedGroups), len(expectedTPS.SharedGroups))
}
}
func testTPSharedGroupsRemoveTPSharedGroups(t *testing.T) {
var resp string
if err := tpSharedGroupRPC.Call(utils.APIerSv1RemoveTPSharedGroups, &AttrGetTPSharedGroups{TPid: tpSharedGroups.TPid, ID: tpSharedGroups.ID}, &resp); err != nil {
t.Error(err)
} else if resp != utils.OK {
t.Error("Unexpected reply returned", resp)
}
}
func testTPSharedGroupsGetTPSharedGroupsAfterRemove(t *testing.T) {
var reply *utils.TPSharedGroups
if err := tpSharedGroupRPC.Call(utils.APIerSv1GetTPSharedGroups, &AttrGetTPSharedGroups{TPid: "TPS1", ID: "Group1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func testTPSharedGroupsKillEngine(t *testing.T) {
if err := engine.KillEngine(tpSharedGroupDelay); err != nil {
t.Error(err)
}
}

View File

@@ -1,604 +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 (
"errors"
"strings"
"time"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/guardian"
"github.com/cgrates/cgrates/utils"
)
// Returns a list of ActionTriggers on an account
func (apierSv1 *APIerSv1) GetAccountActionTriggers(attrs *utils.TenantAccount, reply *engine.ActionTriggers) error {
if missing := utils.MissingStructFields(attrs, []string{utils.AccountField}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
tnt := attrs.Tenant
if tnt == utils.EmptyString {
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
}
if account, err := apierSv1.DataManager.GetAccount(utils.ConcatenatedKey(tnt, attrs.Account)); err != nil {
return utils.NewErrServerError(err)
} else {
ats := account.ActionTriggers
if ats == nil {
ats = engine.ActionTriggers{}
}
*reply = ats
}
return nil
}
type AttrAddAccountActionTriggers struct {
Tenant string
Account string
ActionTriggerIDs []string
ActionTriggerOverwrite bool
ActivationDate string
Executed bool
}
func (apierSv1 *APIerSv1) AddAccountActionTriggers(attr *AttrAddAccountActionTriggers, reply *string) (err error) {
if missing := utils.MissingStructFields(attr, []string{utils.AccountField}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
tnt := attr.Tenant
if tnt == utils.EmptyString {
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
}
var actTime time.Time
if actTime, err = utils.ParseTimeDetectLayout(attr.ActivationDate,
apierSv1.Config.GeneralCfg().DefaultTimezone); err != nil {
return
}
accID := utils.ConcatenatedKey(tnt, attr.Account)
var account *engine.Account
_, err = guardian.Guardian.Guard(func() (interface{}, error) {
if account, err = apierSv1.DataManager.GetAccount(accID); err != nil {
return 0, err
}
if attr.ActionTriggerOverwrite {
account.ActionTriggers = make(engine.ActionTriggers, 0)
}
for _, actionTriggerID := range attr.ActionTriggerIDs {
atrs, err := apierSv1.DataManager.GetActionTriggers(actionTriggerID, false, utils.NonTransactional)
if err != nil {
return 0, err
}
for _, at := range atrs {
var found bool
for _, existingAt := range account.ActionTriggers {
if existingAt.Equals(at) {
found = true
break
}
}
at.ActivationDate = actTime
at.Executed = attr.Executed
if !found {
account.ActionTriggers = append(account.ActionTriggers, at)
}
}
}
account.InitCounters()
return 0, apierSv1.DataManager.SetAccount(account)
}, config.CgrConfig().GeneralCfg().LockingTimeout, utils.AccountPrefix+accID)
if err != nil {
return
}
*reply = utils.OK
return
}
type AttrRemoveAccountActionTriggers struct {
Tenant string
Account string
GroupID string
UniqueID string
}
func (apierSv1 *APIerSv1) RemoveAccountActionTriggers(attr *AttrRemoveAccountActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(attr, []string{utils.AccountField}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
tnt := attr.Tenant
if tnt == utils.EmptyString {
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
}
accID := utils.ConcatenatedKey(tnt, attr.Account)
_, err := guardian.Guardian.Guard(func() (interface{}, error) {
var account *engine.Account
if acc, err := apierSv1.DataManager.GetAccount(accID); err == nil {
account = acc
} else {
return 0, err
}
var newActionTriggers engine.ActionTriggers
for _, at := range account.ActionTriggers {
if (attr.UniqueID == "" || at.UniqueID == attr.UniqueID) &&
(attr.GroupID == "" || at.ID == attr.GroupID) {
// remove action trigger
continue
}
newActionTriggers = append(newActionTriggers, at)
}
account.ActionTriggers = newActionTriggers
account.InitCounters()
return 0, apierSv1.DataManager.SetAccount(account)
}, config.CgrConfig().GeneralCfg().LockingTimeout, accID)
if err != nil {
*reply = err.Error()
return err
}
*reply = utils.OK
return nil
}
type AttrResetAccountActionTriggers struct {
Tenant string
Account string
GroupID string
UniqueID string
Executed bool
}
func (apierSv1 *APIerSv1) ResetAccountActionTriggers(attr *AttrResetAccountActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(attr, []string{utils.AccountField}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
tnt := attr.Tenant
if tnt == utils.EmptyString {
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
}
accID := utils.ConcatenatedKey(tnt, attr.Account)
var account *engine.Account
_, err := guardian.Guardian.Guard(func() (interface{}, error) {
if acc, err := apierSv1.DataManager.GetAccount(accID); err == nil {
account = acc
} else {
return 0, err
}
for _, at := range account.ActionTriggers {
if (attr.UniqueID == "" || at.UniqueID == attr.UniqueID) &&
(attr.GroupID == "" || at.ID == attr.GroupID) {
// reset action trigger
at.Executed = attr.Executed
}
}
if attr.Executed == false {
account.ExecuteActionTriggers(nil)
}
return 0, apierSv1.DataManager.SetAccount(account)
}, config.CgrConfig().GeneralCfg().LockingTimeout, utils.AccountPrefix+accID)
if err != nil {
*reply = err.Error()
return err
}
*reply = utils.OK
return nil
}
type AttrSetAccountActionTriggers struct {
Tenant string
Account string
AttrSetActionTrigger
}
type AttrSetActionTrigger struct {
GroupID string
UniqueID string
ActionTrigger map[string]interface{}
}
// UpdateActionTrigger updates the ActionTrigger if is matching
func (attr *AttrSetActionTrigger) UpdateActionTrigger(at *engine.ActionTrigger, timezone string) (updated bool, err error) {
if at == nil {
return false, errors.New("Empty ActionTrigger")
}
if at.ID == utils.EmptyString { // New AT, update it's data
if attr.GroupID == utils.EmptyString {
return false, utils.NewErrMandatoryIeMissing(utils.GroupID)
}
if missing := utils.MissingMapFields(attr.ActionTrigger, []string{"ThresholdType", "ThresholdValue"}); len(missing) != 0 {
return false, utils.NewErrMandatoryIeMissing(missing...)
}
at.ID = attr.GroupID
if attr.UniqueID != utils.EmptyString {
at.UniqueID = attr.UniqueID
}
}
if attr.GroupID != utils.EmptyString && attr.GroupID != at.ID {
return
}
if attr.UniqueID != utils.EmptyString && attr.UniqueID != at.UniqueID {
return
}
// at matches
updated = true
if thr, has := attr.ActionTrigger[utils.ThresholdType]; has {
at.ThresholdType = utils.IfaceAsString(thr)
}
if thr, has := attr.ActionTrigger[utils.ThresholdValue]; has {
if at.ThresholdValue, err = utils.IfaceAsFloat64(thr); err != nil {
return
}
}
if rec, has := attr.ActionTrigger[utils.Recurrent]; has {
if at.Recurrent, err = utils.IfaceAsBool(rec); err != nil {
return
}
}
if exec, has := attr.ActionTrigger[utils.Executed]; has {
if at.Executed, err = utils.IfaceAsBool(exec); err != nil {
return
}
}
if minS, has := attr.ActionTrigger[utils.MinSleep]; has {
if at.MinSleep, err = utils.IfaceAsDuration(minS); err != nil {
return
}
}
if exp, has := attr.ActionTrigger[utils.ExpirationDate]; has {
if at.ExpirationDate, err = utils.IfaceAsTime(exp, timezone); err != nil {
return
}
}
if act, has := attr.ActionTrigger[utils.ActivationDate]; has {
if at.ActivationDate, err = utils.IfaceAsTime(act, timezone); err != nil {
return
}
}
if at.Balance == nil {
at.Balance = &engine.BalanceFilter{}
}
if bid, has := attr.ActionTrigger[utils.BalanceID]; has {
at.Balance.ID = utils.StringPointer(utils.IfaceAsString(bid))
}
if btype, has := attr.ActionTrigger[utils.BalanceType]; has {
at.Balance.Type = utils.StringPointer(utils.IfaceAsString(btype))
}
if bdest, has := attr.ActionTrigger[utils.BalanceDestinationIds]; has {
var bdIds []string
if bdIds, err = utils.IfaceAsSliceString(bdest); err != nil {
return
}
at.Balance.DestinationIDs = utils.StringMapPointer(utils.NewStringMap(bdIds...))
}
if bweight, has := attr.ActionTrigger[utils.BalanceWeight]; has {
var bw float64
if bw, err = utils.IfaceAsFloat64(bweight); err != nil {
return
}
at.Balance.Weight = utils.Float64Pointer(bw)
}
if exp, has := attr.ActionTrigger[utils.BalanceExpirationDate]; has {
var balanceExpTime time.Time
if balanceExpTime, err = utils.IfaceAsTime(exp, timezone); err != nil {
return
}
at.Balance.ExpirationDate = utils.TimePointer(balanceExpTime)
}
if bTimeTag, has := attr.ActionTrigger[utils.BalanceTimingTags]; has {
var timeTag []string
if timeTag, err = utils.IfaceAsSliceString(bTimeTag); err != nil {
return
}
at.Balance.TimingIDs = utils.StringMapPointer(utils.NewStringMap(timeTag...))
}
if brs, has := attr.ActionTrigger[utils.BalanceRatingSubject]; has {
at.Balance.RatingSubject = utils.StringPointer(utils.IfaceAsString(brs))
}
if bcat, has := attr.ActionTrigger[utils.BalanceCategories]; has {
var cat []string
if cat, err = utils.IfaceAsSliceString(bcat); err != nil {
return
}
at.Balance.Categories = utils.StringMapPointer(utils.NewStringMap(cat...))
}
if bsg, has := attr.ActionTrigger[utils.BalanceSharedGroups]; has {
var shrgrps []string
if shrgrps, err = utils.IfaceAsSliceString(bsg); err != nil {
return
}
at.Balance.SharedGroups = utils.StringMapPointer(utils.NewStringMap(shrgrps...))
}
if bb, has := attr.ActionTrigger[utils.BalanceBlocker]; has {
var bBlocker bool
if bBlocker, err = utils.IfaceAsBool(bb); err != nil {
return
}
at.Balance.Blocker = utils.BoolPointer(bBlocker)
}
if bd, has := attr.ActionTrigger[utils.BalanceDisabled]; has {
var bDis bool
if bDis, err = utils.IfaceAsBool(bd); err != nil {
return
}
at.Balance.Disabled = utils.BoolPointer(bDis)
}
if minQ, has := attr.ActionTrigger[utils.MinQueuedItems]; has {
var mQ int64
if mQ, err = utils.IfaceAsInt64(minQ); err != nil {
return
}
at.MinQueuedItems = int(mQ)
}
if accID, has := attr.ActionTrigger[utils.ActionsID]; has {
at.ActionsID = utils.IfaceAsString(accID)
}
return
}
// SetAccountActionTriggers updates or creates if not present the ActionTrigger for an Account
func (apierSv1 *APIerSv1) SetAccountActionTriggers(attr *AttrSetAccountActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(attr, []string{utils.AccountField}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
tnt := attr.Tenant
if tnt == utils.EmptyString {
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
}
accID := utils.ConcatenatedKey(tnt, attr.Account)
var account *engine.Account
_, err := guardian.Guardian.Guard(func() (interface{}, error) {
if acc, err := apierSv1.DataManager.GetAccount(accID); err == nil {
account = acc
} else {
return 0, err
}
var foundOne bool
for _, at := range account.ActionTriggers {
if updated, err := attr.UpdateActionTrigger(at,
apierSv1.Config.GeneralCfg().DefaultTimezone); err != nil {
return 0, err
} else if updated && !foundOne {
foundOne = true
}
}
if !foundOne { // Did not find one to update, create a new AT
at := new(engine.ActionTrigger)
if updated, err := attr.UpdateActionTrigger(at,
apierSv1.Config.GeneralCfg().DefaultTimezone); err != nil {
return 0, err
} else if updated { // Adding a new AT
account.ActionTriggers = append(account.ActionTriggers, at)
}
}
account.ExecuteActionTriggers(nil)
return 0, apierSv1.DataManager.SetAccount(account)
}, config.CgrConfig().GeneralCfg().LockingTimeout, utils.AccountPrefix+accID)
if err != nil {
*reply = err.Error()
return err
}
*reply = utils.OK
return nil
}
type AttrRemoveActionTrigger struct {
GroupID string
UniqueID string
}
func (apierSv1 *APIerSv1) RemoveActionTrigger(attr *AttrRemoveActionTrigger, reply *string) (err error) {
if missing := utils.MissingStructFields(attr, []string{"GroupID"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if attr.UniqueID == "" {
err = apierSv1.DataManager.RemoveActionTriggers(attr.GroupID, utils.NonTransactional)
if err != nil {
return
}
*reply = utils.OK
return
}
var atrs engine.ActionTriggers
if atrs, err = apierSv1.DataManager.GetActionTriggers(attr.GroupID, false, utils.NonTransactional); err != nil {
return
}
remainingAtrs := make(engine.ActionTriggers, 0, len(atrs))
for _, atr := range atrs {
if atr.UniqueID != attr.UniqueID {
remainingAtrs = append(remainingAtrs, atr)
}
}
// set the cleared list back
if err = apierSv1.DataManager.SetActionTriggers(attr.GroupID, remainingAtrs, utils.NonTransactional); err != nil {
return
}
// CacheReload
if err = apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil,
utils.CacheSv1ReloadCache, utils.AttrReloadCacheWithAPIOpts{
ArgsCache: map[string][]string{utils.ActionTriggerIDs: {attr.GroupID}},
}, reply); err != nil {
return
}
// generate a loadID for CacheActionTriggers and store it in database
if err = apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheActionTriggers: time.Now().UnixNano()}); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
return
}
// SetActionTrigger updates a ActionTrigger
func (apierSv1 *APIerSv1) SetActionTrigger(attr *AttrSetActionTrigger, reply *string) (err error) {
if missing := utils.MissingStructFields(attr, []string{"GroupID"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
atrs, _ := apierSv1.DataManager.GetActionTriggers(attr.GroupID, false, utils.NonTransactional)
var newAtr *engine.ActionTrigger
if attr.UniqueID != utils.EmptyString {
//search for exiting one
for _, atr := range atrs {
if atr.UniqueID == attr.UniqueID {
newAtr = atr
break
}
}
}
if newAtr == nil {
newAtr = &engine.ActionTrigger{}
atrs = append(atrs, newAtr)
}
if attr.UniqueID == utils.EmptyString {
attr.UniqueID = utils.GenUUID()
}
newAtr.ID = attr.GroupID
newAtr.UniqueID = attr.UniqueID
if _, err = attr.UpdateActionTrigger(newAtr,
apierSv1.Config.GeneralCfg().DefaultTimezone); err != nil {
return
}
if err = apierSv1.DataManager.SetActionTriggers(attr.GroupID, atrs, utils.NonTransactional); err != nil {
return
}
// CacheReload
if err = apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil,
utils.CacheSv1ReloadCache, utils.AttrReloadCacheWithAPIOpts{
ArgsCache: map[string][]string{utils.ActionTriggerIDs: {attr.GroupID}},
}, reply); err != nil {
return
}
// generate a loadID for CacheActionTriggers and store it in database
if err = apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheActionTriggers: time.Now().UnixNano()}); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
return
}
type AttrGetActionTriggers struct {
GroupIDs []string
}
func (apierSv1 *APIerSv1) GetActionTriggers(attr *AttrGetActionTriggers, atrs *engine.ActionTriggers) error {
var allAttrs engine.ActionTriggers
if len(attr.GroupIDs) > 0 {
for _, key := range attr.GroupIDs {
getAttrs, err := apierSv1.DataManager.GetActionTriggers(key, false, utils.NonTransactional)
if err != nil {
return err
}
allAttrs = append(allAttrs, getAttrs...)
}
} else {
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(utils.ActionTriggerPrefix)
if err != nil {
return err
}
if len(keys) == 0 {
return utils.ErrNotFound
}
for _, key := range keys {
getAttrs, err := apierSv1.DataManager.GetActionTriggers(key[len(utils.ActionTriggerPrefix):], false, utils.NonTransactional)
if err != nil {
return err
}
allAttrs = append(allAttrs, getAttrs...)
}
}
*atrs = allAttrs
return nil
}
type AttrAddActionTrigger struct {
ActionTriggersId string
Tenant string
Account string
ThresholdType string
ThresholdValue float64
BalanceId string
BalanceType string
BalanceDestinationIds string
BalanceRatingSubject string
BalanceWeight float64
BalanceExpiryTime string
BalanceSharedGroup string
Weight float64
ActionsId string
}
// Deprecated in rc8, replaced by AddAccountActionTriggers
func (apierSv1 *APIerSv1) AddTriggeredAction(attr AttrAddActionTrigger, reply *string) error {
if missing := utils.MissingStructFields(&attr, []string{utils.AccountField}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
tnt := attr.Tenant
if tnt == utils.EmptyString {
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
}
at := &engine.ActionTrigger{
ID: attr.ActionTriggersId,
ThresholdType: attr.ThresholdType,
ThresholdValue: attr.ThresholdValue,
Balance: new(engine.BalanceFilter),
Weight: attr.Weight,
ActionsID: attr.ActionsId,
}
if attr.BalanceId != "" {
at.Balance.ID = utils.StringPointer(attr.BalanceId)
}
if attr.BalanceType != "" {
at.Balance.Type = utils.StringPointer(attr.BalanceType)
}
if attr.BalanceDestinationIds != "" {
dstIDsMp := utils.StringMapFromSlice(strings.Split(attr.BalanceDestinationIds, utils.InfieldSep))
at.Balance.DestinationIDs = &dstIDsMp
}
if attr.BalanceRatingSubject != "" {
at.Balance.RatingSubject = utils.StringPointer(attr.BalanceRatingSubject)
}
if attr.BalanceWeight != 0.0 {
at.Balance.Weight = utils.Float64Pointer(attr.BalanceWeight)
}
if balExpiryTime, err := utils.ParseTimeDetectLayout(attr.BalanceExpiryTime,
apierSv1.Config.GeneralCfg().DefaultTimezone); err != nil {
return utils.NewErrServerError(err)
} else {
at.Balance.ExpirationDate = &balExpiryTime
}
if attr.BalanceSharedGroup != "" {
at.Balance.SharedGroups = &utils.StringMap{attr.BalanceSharedGroup: true}
}
acntID := utils.ConcatenatedKey(tnt, attr.Account)
_, err := guardian.Guardian.Guard(func() (interface{}, error) {
acnt, err := apierSv1.DataManager.GetAccount(acntID)
if err != nil {
return 0, err
}
acnt.ActionTriggers = append(acnt.ActionTriggers, at)
return 0, apierSv1.DataManager.SetAccount(acnt)
}, config.CgrConfig().GeneralCfg().LockingTimeout, utils.AccountPrefix+acntID)
if err != nil {
return err
}
*reply = utils.OK
return nil
}

View File

@@ -1,208 +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 (
"reflect"
"testing"
"time"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func TestAttrSetActionTriggerUpdateActionTrigger(t *testing.T) {
ast := AttrSetActionTrigger{}
if _, err := ast.UpdateActionTrigger(nil, ""); err == nil || err.Error() != "Empty ActionTrigger" {
t.Errorf("Expected error \"Empty ActionTrigger\", received: %v", err)
}
expErr := utils.NewErrMandatoryIeMissing(utils.GroupID)
args := &engine.ActionTrigger{}
if _, err := ast.UpdateActionTrigger(args, ""); err == nil || err.Error() != expErr.Error() {
t.Errorf("Expected error %s , received: %v", expErr, err)
}
ast.GroupID = "GroupID"
expErr = utils.NewErrMandatoryIeMissing("ThresholdType", "ThresholdValue")
if _, err := ast.UpdateActionTrigger(args, ""); err == nil || err.Error() != expErr.Error() {
t.Errorf("Expected error %s , received: %v", expErr, err)
}
tNow := time.Now()
ast = AttrSetActionTrigger{
GroupID: "GroupID",
UniqueID: "ID",
ActionTrigger: map[string]interface{}{
utils.ThresholdType: "THR",
utils.ThresholdValue: 10,
utils.Recurrent: false,
utils.Executed: false,
utils.MinSleep: time.Second,
utils.ExpirationDate: tNow,
utils.ActivationDate: tNow,
utils.BalanceID: "*default",
utils.BalanceType: "*call",
utils.BalanceDestinationIds: []interface{}{"DST1", "DST2"},
utils.BalanceWeight: 10,
utils.BalanceExpirationDate: tNow,
utils.BalanceTimingTags: []string{"*asap"},
utils.BalanceRatingSubject: "*zero",
utils.BalanceCategories: []string{utils.Call},
utils.BalanceSharedGroups: []string{"SHRGroup"},
utils.BalanceBlocker: true,
utils.BalanceDisabled: false,
utils.ActionsID: "ACT1",
utils.MinQueuedItems: 5,
},
}
exp := &engine.ActionTrigger{
ID: "GroupID",
UniqueID: "ID",
ThresholdType: "THR",
ThresholdValue: 10,
Recurrent: false,
MinSleep: time.Second,
ExpirationDate: tNow,
ActivationDate: tNow,
Balance: &engine.BalanceFilter{
ID: utils.StringPointer(utils.MetaDefault),
Type: utils.StringPointer("*call"),
ExpirationDate: utils.TimePointer(tNow),
Weight: utils.Float64Pointer(10),
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("DST1", "DST2")),
RatingSubject: utils.StringPointer("*zero"),
Categories: utils.StringMapPointer(utils.NewStringMap(utils.Call)),
SharedGroups: utils.StringMapPointer(utils.NewStringMap("SHRGroup")),
TimingIDs: utils.StringMapPointer(utils.NewStringMap("*asap")),
Disabled: utils.BoolPointer(false),
Blocker: utils.BoolPointer(true),
},
ActionsID: "ACT1",
MinQueuedItems: 5,
Executed: false,
}
if updated, err := ast.UpdateActionTrigger(args, ""); err != nil {
t.Error(err)
} else if !updated {
t.Errorf("Expected to be updated")
} else if !reflect.DeepEqual(exp, args) {
t.Errorf("Expected: %s ,received: %s", utils.ToJSON(exp), utils.ToJSON(args))
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.MinQueuedItems] = "NotInt"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.BalanceDisabled] = "NotBool"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.BalanceBlocker] = "NotBool"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.BalanceSharedGroups] = "notSlice"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.BalanceCategories] = "notSlice"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.BalanceTimingTags] = "notSlice"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.BalanceExpirationDate] = "notTime"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.BalanceWeight] = "notFloat"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.BalanceDestinationIds] = "notSlice"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.ActivationDate] = "notTime"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.ExpirationDate] = "notTime"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.MinSleep] = "notDuration"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.Executed] = "notBool"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.Recurrent] = "notBool"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{}
ast.ActionTrigger[utils.ThresholdValue] = "notFloat"
if _, err := ast.UpdateActionTrigger(args, ""); err == nil {
t.Errorf("Expected error received: %v", err)
}
args = &engine.ActionTrigger{
ID: "GroupID2",
UniqueID: "ID2",
}
ast = AttrSetActionTrigger{
GroupID: "GroupID",
UniqueID: "ID",
}
if updated, err := ast.UpdateActionTrigger(args, ""); err != nil {
t.Error(err)
} else if updated {
t.Errorf("Expected to not be updated")
}
args = &engine.ActionTrigger{
ID: "GroupID",
UniqueID: "ID2",
}
ast = AttrSetActionTrigger{
GroupID: "GroupID",
UniqueID: "ID",
}
if updated, err := ast.UpdateActionTrigger(args, ""); err != nil {
t.Error(err)
} else if updated {
t.Errorf("Expected to not be updated")
}
}

View File

@@ -19,13 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package v2
import (
"errors"
"fmt"
"math"
"os"
"strconv"
"strings"
"time"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
@@ -43,36 +39,6 @@ func (apiv2 *APIerSv2) Call(serviceMethod string,
return utils.APIerRPCCall(apiv2, serviceMethod, args, reply)
}
type AttrLoadRatingProfile struct {
TPid string
RatingProfileID string
}
// Process dependencies and load a specific rating profile from storDb into dataDb.
func (apiv2 *APIerSv2) LoadRatingProfile(attrs *AttrLoadRatingProfile, reply *string) error {
if len(attrs.TPid) == 0 {
return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader, err := engine.NewTpReader(apiv2.DataManager.DataDB(), apiv2.StorDb,
attrs.TPid, apiv2.Config.GeneralCfg().DefaultTimezone,
apiv2.Config.ApierCfg().CachesConns, apiv2.Config.ApierCfg().ActionConns,
apiv2.Config.DataDbCfg().Type == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
if err := dbReader.LoadRatingProfilesFiltered(&utils.TPRatingProfile{TPid: attrs.TPid}); err != nil {
return utils.NewErrServerError(err)
}
if err := apiv2.DataManager.SetLoadIDs(map[string]int64{utils.CacheRatingProfiles: time.Now().UnixNano()}); err != nil {
return utils.APIErrorHandler(err)
}
if err = dbReader.ReloadCache(config.CgrConfig().GeneralCfg().DefaultCaching, true, make(map[string]interface{})); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
type AttrLoadAccountActions struct {
TPid string
AccountActionsId string
@@ -105,12 +71,6 @@ func (apiv2 *APIerSv2) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFolde
return nil // Mission complete, no errors
}
if attrs.Validate {
if !loader.IsValid() {
return errors.New("invalid data")
}
}
if err := loader.WriteToDatabase(false, false); err != nil {
return utils.NewErrServerError(err)
}
@@ -142,61 +102,6 @@ func (apiv2 *APIerSv2) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFolde
return nil
}
type AttrGetActions struct {
ActionIDs []string
Offset int // Set the item offset
Limit int // Limit number of items retrieved
}
// Retrieves actions attached to specific ActionsId within cache
func (apiv2 *APIerSv2) GetActions(attr *AttrGetActions, reply *map[string]engine.Actions) error {
var actionKeys []string
var err error
if len(attr.ActionIDs) == 0 {
if actionKeys, err = apiv2.DataManager.DataDB().GetKeysForPrefix(utils.ActionPrefix); err != nil {
return err
}
} else {
for _, accID := range attr.ActionIDs {
if len(accID) == 0 { // Source of error returned from redis (key not found)
continue
}
actionKeys = append(actionKeys, utils.AccountPrefix+accID)
}
}
if len(actionKeys) == 0 {
return nil
}
if attr.Offset > len(actionKeys) {
attr.Offset = len(actionKeys)
}
if attr.Offset < 0 {
attr.Offset = 0
}
var limitedActions []string
if attr.Limit != 0 {
max := math.Min(float64(attr.Offset+attr.Limit), float64(len(actionKeys)))
limitedActions = actionKeys[attr.Offset:int(max)]
} else {
limitedActions = actionKeys[attr.Offset:]
}
retActions := make(map[string]engine.Actions)
for _, accKey := range limitedActions {
key := accKey[len(utils.ActionPrefix):]
acts, err := apiv2.DataManager.GetActions(key, false, utils.NonTransactional)
if err != nil {
return utils.NewErrServerError(err)
}
if len(acts) > 0 {
retActions[key] = acts
}
}
*reply = retActions
return nil
}
type AttrGetActionsCount struct{}
// GetActionsCount sets in reply var the total number of actions registered for the received tenant
@@ -238,108 +143,6 @@ func (apiv2 *APIerSv2) GetDestinations(attr *AttrGetDestinations, reply *[]*engi
return
}
func (apiv2 *APIerSv2) SetActions(attrs *utils.AttrSetActions, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{"ActionsId", "Actions"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
for _, action := range attrs.Actions {
requiredFields := []string{"Identifier", "Weight"}
if action.BalanceType != "" { // Add some inter-dependent parameters - if balanceType then we are not talking about simply calling actions
requiredFields = append(requiredFields, "Units")
}
if missing := utils.MissingStructFields(action, requiredFields); len(missing) != 0 {
return fmt.Errorf("%s:Action:%s:%v", utils.ErrMandatoryIeMissing.Error(), action.Identifier, missing)
}
}
if !attrs.Overwrite {
if exists, err := apiv2.DataManager.HasData(utils.ActionPrefix, attrs.ActionsId, ""); err != nil {
return utils.NewErrServerError(err)
} else if exists {
return utils.ErrExists
}
}
storeActions := make(engine.Actions, len(attrs.Actions))
for idx, apiAct := range attrs.Actions {
var vf *utils.ValueFormula
if apiAct.Units != "" {
x, err := utils.ParseBalanceFilterValue(apiAct.BalanceType, apiAct.Units)
if err != nil {
return err
}
vf = x
}
var weight *float64
if apiAct.BalanceWeight != "" {
x, err := strconv.ParseFloat(apiAct.BalanceWeight, 64)
if err != nil {
return err
}
weight = &x
}
var blocker *bool
if apiAct.BalanceBlocker != "" {
x, err := strconv.ParseBool(apiAct.BalanceBlocker)
if err != nil {
return err
}
blocker = &x
}
var disabled *bool
if apiAct.BalanceDisabled != "" {
x, err := strconv.ParseBool(apiAct.BalanceDisabled)
if err != nil {
return err
}
disabled = &x
}
a := &engine.Action{
Id: attrs.ActionsId,
ActionType: apiAct.Identifier,
Weight: apiAct.Weight,
ExpirationString: apiAct.ExpiryTime,
ExtraParameters: apiAct.ExtraParameters,
Filter: apiAct.Filter,
}
if apiAct.Identifier != utils.MetaResetTriggers { // add an exception for ResetTriggers
a.Balance = &engine.BalanceFilter{ // TODO: update this part
Uuid: utils.StringPointer(apiAct.BalanceUuid),
ID: utils.StringPointer(apiAct.BalanceId),
Type: utils.StringPointer(apiAct.BalanceType),
Value: vf,
Weight: weight,
DestinationIDs: utils.StringMapPointer(utils.ParseStringMap(apiAct.DestinationIds)),
RatingSubject: utils.StringPointer(apiAct.RatingSubject),
SharedGroups: utils.StringMapPointer(utils.ParseStringMap(apiAct.SharedGroups)),
Categories: utils.StringMapPointer(utils.ParseStringMap(apiAct.Categories)),
TimingIDs: utils.StringMapPointer(utils.ParseStringMap(apiAct.TimingTags)),
Blocker: blocker,
Disabled: disabled,
}
}
storeActions[idx] = a
}
if err := apiv2.DataManager.SetActions(attrs.ActionsId, storeActions, utils.NonTransactional); err != nil {
return utils.NewErrServerError(err)
}
//CacheReload
if err := apiv2.ConnMgr.Call(apiv2.Config.ApierCfg().CachesConns, nil,
utils.CacheSv1ReloadCache, utils.AttrReloadCacheWithAPIOpts{
ArgsCache: map[string][]string{utils.ActionIDs: {attrs.ActionsId}},
}, reply); err != nil {
return err
}
//generate a loadID for CacheActions and store it in database
if err := apiv2.DataManager.SetLoadIDs(map[string]int64{utils.CacheActions: time.Now().UnixNano()}); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
return nil
}
// Ping return pong if the service is active
func (apiv2 *APIerSv2) Ping(ign *utils.CGREvent, reply *string) error {
*reply = utils.Pong

View File

@@ -644,11 +644,7 @@ func main() {
routeS := services.NewRouteService(cfg, dmService, cacheS, filterSChan, server,
internalRouteSChan, connManager, anz, srvDep)
rals := services.NewRalService(cfg, cacheS, server,
internalRALsChan, internalResponderChan,
shdChan, connManager, anz, srvDep)
apiSv1 := services.NewAPIerSv1Service(cfg, dmService, storDBService, filterSChan, server, rals.GetResponder(),
apiSv1 := services.NewAPIerSv1Service(cfg, dmService, storDBService, filterSChan, server,
internalAPIerSv1Chan, connManager, anz, srvDep)
apiSv2 := services.NewAPIerSv2Service(apiSv1, cfg, server, internalAPIerSv2Chan, anz, srvDep)
@@ -661,7 +657,7 @@ func main() {
ldrs := services.NewLoaderService(cfg, dmService, filterSChan, server,
internalLoaderSChan, connManager, anz, srvDep)
srvManager.AddServices(gvService, attrS, chrS, tS, stS, reS, routeS, rals,
srvManager.AddServices(gvService, attrS, chrS, tS, stS, reS, routeS,
apiSv1, apiSv2, cdrS, smg, coreS,
services.NewEventReaderService(cfg, filterSChan, shdChan, connManager, srvDep),
services.NewDNSAgent(cfg, filterSChan, shdChan, connManager, srvDep),
@@ -700,8 +696,6 @@ func main() {
engine.IntRPC.AddInternalRPCClient(utils.GuardianSv1, internalGuardianSChan)
engine.IntRPC.AddInternalRPCClient(utils.LoaderSv1, internalLoaderSChan)
engine.IntRPC.AddInternalRPCClient(utils.ResourceSv1, internalResourceSChan)
engine.IntRPC.AddInternalRPCClient(utils.Responder, internalResponderChan)
engine.IntRPC.AddInternalRPCClient(utils.SchedulerSv1, internalSchedulerSChan)
engine.IntRPC.AddInternalRPCClient(utils.SessionSv1, internalSessionSChan)
engine.IntRPC.AddInternalRPCClient(utils.StatSv1, internalStatSChan)
engine.IntRPC.AddInternalRPCClient(utils.RouteSv1, internalRouteSChan)
@@ -709,7 +703,6 @@ func main() {
engine.IntRPC.AddInternalRPCClient(utils.ServiceManagerV1, internalServeManagerChan)
engine.IntRPC.AddInternalRPCClient(utils.ConfigSv1, internalConfigChan)
engine.IntRPC.AddInternalRPCClient(utils.CoreSv1, internalCoreSv1Chan)
engine.IntRPC.AddInternalRPCClient(utils.RALsV1, internalRALsChan)
engine.IntRPC.AddInternalRPCClient(utils.RateSv1, internalRateSChan)
engine.IntRPC.AddInternalRPCClient(utils.ActionSv1, internalActionSChan)
engine.IntRPC.AddInternalRPCClient(utils.EeSv1, internalEEsChan)

View File

@@ -1,64 +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 main
import (
"bytes"
"fmt"
"io"
"log"
"net/http"
"sync"
"github.com/cgrates/cgrates/utils"
)
func main() {
log.Print("Start!")
var wg sync.WaitGroup
for i := 1; i < 1002; i++ {
wg.Add(1)
go func(index int) {
resp, err := http.Post("http://localhost:2080/jsonrpc", "application/json", bytes.NewBuffer([]byte(fmt.Sprintf(`{"method": "APIerSv1.SetAccount","params": [{"Tenant":"reglo","Account":"100%d","ActionPlanId":"PACKAGE_NEW_FOR795", "ReloadScheduler":false}], "id":%d}`, index, index))))
if err != nil {
log.Print("Post error: ", err)
}
contents, err := io.ReadAll(resp.Body)
if err != nil {
log.Print("Body error: ", err)
}
log.Printf("SetAccount(%d): %s", index, string(contents))
wg.Done()
}(i)
}
wg.Wait()
for index := 1; index < 1002; index++ {
resp, err := http.Post("http://localhost:2080/jsonrpc", "application/json", bytes.NewBuffer([]byte(fmt.Sprintf(`{"method": "%s","params": [{"Tenant":"reglo","Account":"100%d"}], "id":%d}`, utils.APIerSv1GetAccountActionPlan, index, index))))
if err != nil {
log.Print("Post error: ", err)
}
contents, err := io.ReadAll(resp.Body)
if err != nil {
log.Print("Body error: ", err)
}
log.Printf("GetAccountActionPlan(%d): %s", index, string(contents))
}
log.Print("Done!")
}

View File

@@ -1,153 +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 main
import (
"flag"
"fmt"
"log"
"math/rand"
"net/rpc"
"net/rpc/jsonrpc"
"path"
"strconv"
"sync"
"time"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
var (
dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here")
requests = flag.Int("requests", 10000, "Number of requests")
gorutines = flag.Int("goroutines", 5, "Number of simultaneous goroutines")
)
// How to run:
// 1) Start the engine with the following configuration cgr-engine -config_path=/usr/share/cgrates/conf/samples/hundred_rates
// 2) Load the data with cgr-loader cgr-loader -config_path=/usr/share/cgrates/conf/samples/hundred_rates -verbose -path=/usr/share/cgrates/tariffplans/hundredrates
// 3) Run the program with go run proc_ev.go -requests=10000 -goroutines=5
func main() {
flag.Parse()
var err error
var rpc *rpc.Client
var cfgPath string
var cfg *config.CGRConfig
cfgPath = path.Join(*dataDir, "conf", "samples", "cdrsv1mysql")
if cfg, err = config.NewCGRConfigFromPath(cfgPath); err != nil {
log.Fatal("Got config error: ", err.Error())
}
if rpc, err = jsonrpc.Dial(utils.TCP, cfg.ListenCfg().RPCJSONListen); err != nil {
return
}
var sumApier float64
var sumRateS float64
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
//
var sls []string
for i := 100; i < 200; i++ {
sls = append(sls, strconv.Itoa(i))
}
var wgApier sync.WaitGroup
var wgRateS sync.WaitGroup
var apierTime time.Duration
var rateSTime time.Duration
for i := 0; i < *requests; i++ {
wgApier.Add(1)
wgRateS.Add(1)
destination := fmt.Sprintf("%+v%+v", sls[r1.Intn(100)], 1000000+rand.Intn(9999999-1000000))
usage := fmt.Sprintf("%+vm", r1.Intn(250))
go func() {
attrs := v1.AttrGetCost{
Category: "call",
Tenant: "cgrates.org",
Subject: "*any",
AnswerTime: utils.MetaNow,
Destination: destination,
Usage: usage,
}
var replyApier *engine.EventCost
tNow := time.Now()
if err := rpc.Call(utils.APIerSv1GetCost, &attrs, &replyApier); err != nil {
fmt.Println(err)
return
}
apierTime += time.Now().Sub(tNow)
sumApier += *replyApier.Cost
wgApier.Done()
}()
go func() {
argsRateS := &utils.ArgsCostForEvent{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Event: map[string]interface{}{
utils.Category: "call",
utils.Tenant: "cgrates.org",
utils.Subject: "*any",
utils.AnswerTime: utils.MetaNow,
utils.Destination: destination,
"PrefixDestination": destination[:3],
},
APIOpts: map[string]interface{}{
utils.OptsRatesUsage: usage,
},
},
}
var rplyRateS *utils.RateProfileCost
tNow := time.Now()
if err := rpc.Call(utils.RateSv1CostForEvent, argsRateS, &rplyRateS); err != nil {
fmt.Printf("Unexpected nil error received for RateSv1CostForEvent: %+v\n", err.Error())
return
}
rateSTime += time.Now().Sub(tNow)
sumRateS += rplyRateS.Cost
wgRateS.Done()
}()
if i%*gorutines == 0 {
wgApier.Wait()
wgRateS.Wait()
}
}
wgApier.Wait()
wgRateS.Wait()
fmt.Println("Cost for apier get cost : ")
fmt.Println(sumApier)
fmt.Println("Cost for RateS")
fmt.Println(sumRateS)
fmt.Println("Average ApierTime")
fmt.Println(apierTime / time.Duration(*requests))
fmt.Println("Average RateSTime")
fmt.Println(rateSTime / time.Duration(*requests))
fmt.Println("Total ApierTime")
fmt.Println(apierTime)
fmt.Println("Total RateSTime")
fmt.Println(rateSTime)
}

View File

@@ -130,14 +130,6 @@ func (cCfg CacheCfg) AsTransCacheConfig() (tcCfg map[string]*ltcache.CacheConfig
return
}
// AddTmpCaches adds all the temporary caches configuration needed
func (cCfg *CacheCfg) AddTmpCaches() {
cCfg.Partitions[utils.CacheRatingProfilesTmp] = &CacheParamCfg{
Limit: -1,
TTL: time.Minute,
}
}
// AsMapInterface returns the config as a map[string]interface{}
func (cCfg *CacheCfg) AsMapInterface() (initialMP map[string]interface{}) {
initialMP = make(map[string]interface{})

View File

@@ -1,66 +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 console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetAccountActionPlan{
name: "account_actionplan_get",
rpcMethod: utils.APIerSv1GetAccountActionPlan,
rpcParams: &utils.TenantAccount{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetAccountActionPlan struct {
name string
rpcMethod string
rpcParams *utils.TenantAccount
*CommandExecuter
}
func (self *CmdGetAccountActionPlan) Name() string {
return self.name
}
func (self *CmdGetAccountActionPlan) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetAccountActionPlan) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &utils.TenantAccount{}
}
return self.rpcParams
}
func (self *CmdGetAccountActionPlan) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetAccountActionPlan) RpcResult() interface{} {
s := make([]*v1.AccountActionTiming, 0)
return &s
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
"github.com/cgrates/cgrates/utils"
v1 "github.com/cgrates/cgrates/apier/v1"
)
func TestCmdGetAccountActionPlan(t *testing.T) {
// commands map is initiated in init function
command := commands["account_actionplan_get"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,62 +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 console
import "github.com/cgrates/cgrates/utils"
func init() {
c := &CmdRemoveAccount{
name: "account_remove",
rpcMethod: utils.APIerSv1RemoveAccount,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdRemoveAccount struct {
name string
rpcMethod string
rpcParams *utils.AttrRemoveAccount
*CommandExecuter
}
func (self *CmdRemoveAccount) Name() string {
return self.name
}
func (self *CmdRemoveAccount) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdRemoveAccount) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &utils.AttrRemoveAccount{}
}
return self.rpcParams
}
func (self *CmdRemoveAccount) PostprocessRpcParams() error {
return nil
}
func (self *CmdRemoveAccount) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
"github.com/cgrates/cgrates/utils"
v1 "github.com/cgrates/cgrates/apier/v1"
)
func TestCmdRemoveAccount(t *testing.T) {
// commands map is initiated in init function
command := commands["account_remove"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,65 +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 console
import (
v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdAddAccount{
name: "account_set",
rpcMethod: utils.APIerSv2SetAccount,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdAddAccount struct {
name string
rpcMethod string
rpcParams *v2.AttrSetAccount
*CommandExecuter
}
func (self *CmdAddAccount) Name() string {
return self.name
}
func (self *CmdAddAccount) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdAddAccount) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v2.AttrSetAccount{}
}
return self.rpcParams
}
func (self *CmdAddAccount) PostprocessRpcParams() error {
return nil
}
func (self *CmdAddAccount) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/utils"
)
func TestCmdSetAccount(t *testing.T) {
// commands map is initiated in init function
command := commands["account_set"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v2.APIerSv2)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,66 +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 console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdAccountAddTriggers{
name: "account_triggers_add",
rpcMethod: utils.APIerSv1AddAccountActionTriggers,
rpcParams: &v1.AttrAddAccountActionTriggers{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdAccountAddTriggers struct {
name string
rpcMethod string
rpcParams *v1.AttrAddAccountActionTriggers
*CommandExecuter
}
func (self *CmdAccountAddTriggers) Name() string {
return self.name
}
func (self *CmdAccountAddTriggers) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdAccountAddTriggers) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrAddAccountActionTriggers{}
}
return self.rpcParams
}
func (self *CmdAccountAddTriggers) PostprocessRpcParams() error {
return nil
}
func (self *CmdAccountAddTriggers) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,55 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdAccountTriggerAdd(t *testing.T) {
// commands map is initiated in init function
command := commands["account_triggers_add"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,66 +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 console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdAccountRemoveTriggers{
name: "account_triggers_remove",
rpcMethod: utils.APIerSv1RemoveAccountActionTriggers,
rpcParams: &v1.AttrRemoveAccountActionTriggers{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdAccountRemoveTriggers struct {
name string
rpcMethod string
rpcParams *v1.AttrRemoveAccountActionTriggers
*CommandExecuter
}
func (self *CmdAccountRemoveTriggers) Name() string {
return self.name
}
func (self *CmdAccountRemoveTriggers) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdAccountRemoveTriggers) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrRemoveAccountActionTriggers{}
}
return self.rpcParams
}
func (self *CmdAccountRemoveTriggers) PostprocessRpcParams() error {
return nil
}
func (self *CmdAccountRemoveTriggers) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,53 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdAccountTriggerRemove(t *testing.T) {
// commands map is initiated in init function
command := commands["account_triggers_remove"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,66 +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 console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdAccountResetTriggers{
name: "account_triggers_reset",
rpcMethod: utils.APIerSv1ResetAccountActionTriggers,
rpcParams: &v1.AttrResetAccountActionTriggers{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdAccountResetTriggers struct {
name string
rpcMethod string
rpcParams *v1.AttrResetAccountActionTriggers
*CommandExecuter
}
func (self *CmdAccountResetTriggers) Name() string {
return self.name
}
func (self *CmdAccountResetTriggers) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdAccountResetTriggers) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrResetAccountActionTriggers{}
}
return self.rpcParams
}
func (self *CmdAccountResetTriggers) PostprocessRpcParams() error {
return nil
}
func (self *CmdAccountResetTriggers) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,53 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdAccountTriggerReset(t *testing.T) {
// commands map is initiated in init function
command := commands["account_triggers_reset"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,66 +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 console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdAccountSetTriggers{
name: "account_triggers_set",
rpcMethod: utils.APIerSv1SetAccountActionTriggers,
rpcParams: &v1.AttrSetAccountActionTriggers{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdAccountSetTriggers struct {
name string
rpcMethod string
rpcParams *v1.AttrSetAccountActionTriggers
*CommandExecuter
}
func (self *CmdAccountSetTriggers) Name() string {
return self.name
}
func (self *CmdAccountSetTriggers) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdAccountSetTriggers) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrSetAccountActionTriggers{}
}
return self.rpcParams
}
func (self *CmdAccountSetTriggers) PostprocessRpcParams() error {
return nil
}
func (self *CmdAccountSetTriggers) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,53 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdAccountTriggerSet(t *testing.T) {
// commands map is initiated in init function
command := commands["account_triggers_set"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,72 +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 console
import (
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetAccounts{
name: "accounts",
rpcMethod: utils.APIerSv2GetAccounts,
rpcParams: &utils.AttrGetAccounts{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetAccounts struct {
name string
rpcMethod string
rpcParams *utils.AttrGetAccounts
*CommandExecuter
}
func (self *CmdGetAccounts) Name() string {
return self.name
}
func (self *CmdGetAccounts) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetAccounts) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &utils.AttrGetAccounts{}
}
return self.rpcParams
}
func (self *CmdGetAccounts) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetAccounts) RpcResult() interface{} {
a := make([]*engine.Account, 0)
return &a
}
func (self *CmdGetAccounts) GetFormatedResult(result interface{}) string {
return GetFormatedSliceResult(result, utils.StringSet{
utils.MinSleep: {},
})
}

View File

@@ -1,65 +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 console
import (
"reflect"
"strings"
"testing"
v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/utils"
)
func TestCmdAccounts(t *testing.T) {
// commands map is initiated in init function
command := commands["accounts"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v2.APIerSv2)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
// for coverage purpose
formatedResult := command.GetFormatedResult(command.RpcResult())
expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
utils.Usage: {},
utils.GroupIntervalStart: {},
utils.RateIncrement: {},
utils.RateUnit: {},
})
if !reflect.DeepEqual(formatedResult, expected) {
t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
}
}

View File

@@ -1,65 +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 console
import (
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdExecuteAction{
name: "action_execute",
rpcMethod: utils.APIerSv1ExecuteAction,
rpcParams: &utils.AttrExecuteAction{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdExecuteAction struct {
name string
rpcMethod string
rpcParams *utils.AttrExecuteAction
*CommandExecuter
}
func (self *CmdExecuteAction) Name() string {
return self.name
}
func (self *CmdExecuteAction) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdExecuteAction) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &utils.AttrExecuteAction{}
}
return self.rpcParams
}
func (self *CmdExecuteAction) PostprocessRpcParams() error {
return nil
}
func (self *CmdExecuteAction) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/utils"
)
func TestCmdActionExecute(t *testing.T) {
// commands map is initiated in init function
command := commands["action_execute"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v2.APIerSv2)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,67 +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 console
import (
"github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetActionPlan{
name: "actionplan_get",
rpcMethod: utils.APIerSv1GetActionPlan,
rpcParams: &v1.AttrGetActionPlan{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetActionPlan struct {
name string
rpcMethod string
rpcParams *v1.AttrGetActionPlan
*CommandExecuter
}
func (self *CmdGetActionPlan) Name() string {
return self.name
}
func (self *CmdGetActionPlan) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetActionPlan) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrGetActionPlan{}
}
return self.rpcParams
}
func (self *CmdGetActionPlan) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetActionPlan) RpcResult() interface{} {
s := make([]*engine.ActionPlan, 0)
return &s
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/utils"
)
func TestCmdActionPlanGet(t *testing.T) {
// commands map is initiated in init function
command := commands["actionplan_get"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v2.APIerSv2)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,66 +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 console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdRemoveActionPlan{
name: "actionplan_remove",
rpcMethod: utils.APIerSv1RemoveActionPlan,
rpcParams: &v1.AttrGetActionPlan{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdRemoveActionPlan struct {
name string
rpcMethod string
rpcParams *v1.AttrGetActionPlan
*CommandExecuter
}
func (self *CmdRemoveActionPlan) Name() string {
return self.name
}
func (self *CmdRemoveActionPlan) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdRemoveActionPlan) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrGetActionPlan{}
}
return self.rpcParams
}
func (self *CmdRemoveActionPlan) PostprocessRpcParams() error {
return nil
}
func (self *CmdRemoveActionPlan) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/utils"
)
func TestCmdActionPlanRemove(t *testing.T) {
// commands map is initiated in init function
command := commands["actionplan_remove"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v2.APIerSv2)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,66 +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 console
import (
"github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdSetActionPlan{
name: "actionplan_set",
rpcMethod: utils.APIerSv1SetActionPlan,
rpcParams: &v1.AttrSetActionPlan{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdSetActionPlan struct {
name string
rpcMethod string
rpcParams *v1.AttrSetActionPlan
*CommandExecuter
}
func (self *CmdSetActionPlan) Name() string {
return self.name
}
func (self *CmdSetActionPlan) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdSetActionPlan) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrSetActionPlan{}
}
return self.rpcParams
}
func (self *CmdSetActionPlan) PostprocessRpcParams() error {
return nil
}
func (self *CmdSetActionPlan) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/utils"
)
func TestCmdActionPlanSet(t *testing.T) {
// commands map is initiated in init function
command := commands["actionplan_set"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v2.APIerSv2)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,66 +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 console
import (
v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetActions{
name: "actions",
rpcMethod: utils.APIerSv2GetActions,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetActions struct {
name string
rpcMethod string
rpcParams *v2.AttrGetActions
*CommandExecuter
}
func (self *CmdGetActions) Name() string {
return self.name
}
func (self *CmdGetActions) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetActions) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v2.AttrGetActions{}
}
return self.rpcParams
}
func (self *CmdGetActions) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetActions) RpcResult() interface{} {
a := make(map[string]engine.Actions, 0)
return &a
}

View File

@@ -1,65 +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 console
import (
"github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdRemoveActions{
name: "actions_remove",
rpcMethod: utils.APIerSv1RemoveActions,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdRemoveActions struct {
name string
rpcMethod string
rpcParams *v1.AttrRemoveActions
*CommandExecuter
}
func (self *CmdRemoveActions) Name() string {
return self.name
}
func (self *CmdRemoveActions) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdRemoveActions) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrRemoveActions{}
}
return self.rpcParams
}
func (self *CmdRemoveActions) PostprocessRpcParams() error {
return nil
}
func (self *CmdRemoveActions) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/utils"
)
func TestCmdActionsRemove(t *testing.T) {
// commands map is initiated in init function
command := commands["actions_remove"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v2.APIerSv2)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/utils"
)
func TestCmdActions(t *testing.T) {
// commands map is initiated in init function
command := commands["actions"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v2.APIerSv2)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,65 +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 console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdAddBalance{
name: "balance_add",
rpcMethod: utils.APIerSv1AddBalance,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdAddBalance struct {
name string
rpcMethod string
rpcParams *v1.AttrAddBalance
*CommandExecuter
}
func (self *CmdAddBalance) Name() string {
return self.name
}
func (self *CmdAddBalance) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdAddBalance) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrAddBalance{BalanceType: utils.MetaMonetary, Overwrite: false}
}
return self.rpcParams
}
func (self *CmdAddBalance) PostprocessRpcParams() error {
return nil
}
func (self *CmdAddBalance) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdBalanceAdd(t *testing.T) {
// commands map is initiated in init function
command := commands["balance_add"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,66 +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 console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdBalanceDebit{
name: "balance_debit",
rpcMethod: utils.APIerSv1DebitBalance,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdBalanceDebit struct {
name string
rpcMethod string
rpcParams *v1.AttrAddBalance
clientArgs []string
*CommandExecuter
}
func (self *CmdBalanceDebit) Name() string {
return self.name
}
func (self *CmdBalanceDebit) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdBalanceDebit) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrAddBalance{}
}
return self.rpcParams
}
func (self *CmdBalanceDebit) PostprocessRpcParams() error {
return nil
}
func (self *CmdBalanceDebit) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdBalanceDebit(t *testing.T) {
// commands map is initiated in init function
command := commands["balance_debit"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,64 +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 console
import (
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdRemoveBalance{
name: "balance_remove",
rpcMethod: utils.APIerSv1RemoveBalances,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdRemoveBalance struct {
name string
rpcMethod string
rpcParams *utils.AttrSetBalance
*CommandExecuter
}
func (self *CmdRemoveBalance) Name() string {
return self.name
}
func (self *CmdRemoveBalance) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdRemoveBalance) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &utils.AttrSetBalance{BalanceType: utils.MetaMonetary}
}
return self.rpcParams
}
func (self *CmdRemoveBalance) PostprocessRpcParams() error {
return nil
}
func (self *CmdRemoveBalance) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,53 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdBalanceRemove(t *testing.T) {
// commands map is initiated in init function
command := commands["balance_remove"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,64 +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 console
import (
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdSetBalance{
name: "balance_set",
rpcMethod: utils.APIerSv1SetBalance,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdSetBalance struct {
name string
rpcMethod string
rpcParams *utils.AttrSetBalance
*CommandExecuter
}
func (self *CmdSetBalance) Name() string {
return self.name
}
func (self *CmdSetBalance) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdSetBalance) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &utils.AttrSetBalance{BalanceType: utils.MetaMonetary}
}
return self.rpcParams
}
func (self *CmdSetBalance) PostprocessRpcParams() error {
return nil
}
func (self *CmdSetBalance) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdBalanceSet(t *testing.T) {
// commands map is initiated in init function
command := commands["balance_set"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,65 +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 console
import (
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdComputeActionPlanIndexes{
name: "compute_actionplan_indexes",
rpcMethod: utils.APIerSv1ComputeActionPlanIndexes,
rpcParams: new(EmptyWrapper),
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdComputeActionPlanIndexes struct {
name string
rpcMethod string
rpcParams *EmptyWrapper
*CommandExecuter
}
func (self *CmdComputeActionPlanIndexes) Name() string {
return self.name
}
func (self *CmdComputeActionPlanIndexes) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdComputeActionPlanIndexes) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = new(EmptyWrapper)
}
return self.rpcParams
}
func (self *CmdComputeActionPlanIndexes) PostprocessRpcParams() error {
return nil
}
func (self *CmdComputeActionPlanIndexes) RpcResult() interface{} {
s := ""
return &s
}

View File

@@ -1,55 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdComputeActionPlanIndexes(t *testing.T) {
// commands map is initiated in init function
command := commands["compute_actionplan_indexes"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// for coverage purpose
result := command.RpcParams(true)
if !reflect.DeepEqual(result, new(EmptyWrapper)) {
t.Errorf("Expected <%T>, Received <%T>", new(EmptyWrapper), result)
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,81 +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 console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetCost{
name: "cost",
rpcMethod: utils.APIerSv1GetCost,
clientArgs: []string{utils.Tenant, utils.Category, utils.Subject, utils.AnswerTime, utils.Destination, utils.Usage},
rpcParams: &v1.AttrGetCost{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetCost struct {
name string
rpcMethod string
rpcParams *v1.AttrGetCost
clientArgs []string
*CommandExecuter
}
func (self *CmdGetCost) Name() string {
return self.name
}
func (self *CmdGetCost) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetCost) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrGetCost{APIOpts: make(map[string]interface{})}
}
return self.rpcParams
}
func (self *CmdGetCost) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetCost) RpcResult() interface{} {
return &engine.EventCost{}
}
func (self *CmdGetCost) ClientArgs() []string {
return self.clientArgs
}
func (self *CmdGetCost) GetFormatedResult(result interface{}) string {
return GetFormatedResult(result, utils.StringSet{
utils.Usage: {},
utils.GroupIntervalStart: {},
utils.RateIncrement: {},
utils.RateUnit: {},
})
}

View File

@@ -1,70 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdCost(t *testing.T) {
// commands map is initiated in init function
command := commands["cost"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
// for coverage purpose
formatedResult := command.GetFormatedResult(command.RpcResult())
expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
utils.Usage: {},
utils.GroupIntervalStart: {},
utils.RateIncrement: {},
utils.RateUnit: {},
})
if !reflect.DeepEqual(formatedResult, expected) {
t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
}
// for coverage purpose
result := command.ClientArgs()
expected2 := []string{utils.Tenant, utils.Category, utils.Subject, utils.AnswerTime, utils.Destination, utils.Usage}
if !reflect.DeepEqual(result, expected2) {
t.Errorf("Expected <%+v>, Received <%+v>", expected2, result)
}
}

View File

@@ -1,80 +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 console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetDataCost{
name: "datacost",
rpcMethod: utils.APIerSv1GetDataCost,
clientArgs: []string{utils.Category, utils.Tenant, utils.AccountField, utils.Subject, utils.StartTime, utils.Usage},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetDataCost struct {
name string
rpcMethod string
rpcParams *v1.AttrGetDataCost
clientArgs []string
*CommandExecuter
}
func (self *CmdGetDataCost) Name() string {
return self.name
}
func (self *CmdGetDataCost) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetDataCost) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrGetDataCost{Opts: make(map[string]interface{})}
}
return self.rpcParams
}
func (self *CmdGetDataCost) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetDataCost) RpcResult() interface{} {
return &engine.DataCost{}
}
func (self *CmdGetDataCost) ClientArgs() []string {
return self.clientArgs
}
func (self *CmdGetDataCost) GetFormatedResult(result interface{}) string {
return GetFormatedResult(result, utils.StringSet{
utils.Usage: {},
utils.GroupIntervalStart: {},
utils.RateIncrement: {},
utils.RateUnit: {},
})
}

View File

@@ -1,70 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdDatacost(t *testing.T) {
// commands map is initiated in init function
command := commands["datacost"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
// for coverage purpose
formatedResult := command.GetFormatedResult(command.RpcResult())
expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
utils.Usage: {},
utils.GroupIntervalStart: {},
utils.RateIncrement: {},
utils.RateUnit: {},
})
if !reflect.DeepEqual(formatedResult, expected) {
t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
}
// for coverage purpose
result := command.ClientArgs()
expected2 := []string{utils.Category, utils.Tenant, utils.AccountField, utils.Subject, utils.StartTime, utils.Usage}
if !reflect.DeepEqual(result, expected2) {
t.Errorf("Expected <%+v>, Received <%+v>", expected2, result)
}
}

View File

@@ -71,10 +71,6 @@ func (self *CmdApierPing) RpcMethod() string {
return utils.DispatcherSv1Ping
case utils.AnalyzerSLow:
return utils.AnalyzerSv1Ping
case utils.SchedulerSLow:
return utils.SchedulerSv1Ping
case utils.RALsLow:
return utils.RALsV1Ping
case utils.ReplicatorLow:
return utils.ReplicatorSv1Ping
case utils.ApierSLow:

View File

@@ -1,66 +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 console
import (
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetRatingPlanCost{
name: "ratingplan_cost",
rpcMethod: utils.RALsV1GetRatingPlansCost,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetRatingPlanCost struct {
name string
rpcMethod string
rpcParams *utils.RatingPlanCostArg
rpcResult string
*CommandExecuter
}
func (self *CmdGetRatingPlanCost) Name() string {
return self.name
}
func (self *CmdGetRatingPlanCost) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetRatingPlanCost) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = new(utils.RatingPlanCostArg)
}
return self.rpcParams
}
func (self *CmdGetRatingPlanCost) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetRatingPlanCost) RpcResult() interface{} {
var s dispatchers.RatingPlanCost
return &s
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdRatingPlanCost(t *testing.T) {
// commands map is initiated in init function
command := commands["ratingplan_cost"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.RALsV1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,66 +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 console
import (
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetRatingProfile{
name: "ratingprofile",
rpcMethod: utils.APIerSv1GetRatingProfile,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetRatingProfile struct {
name string
rpcMethod string
rpcParams *utils.AttrGetRatingProfile
rpcResult string
*CommandExecuter
}
func (self *CmdGetRatingProfile) Name() string {
return self.name
}
func (self *CmdGetRatingProfile) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetRatingProfile) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = new(utils.AttrGetRatingProfile)
}
return self.rpcParams
}
func (self *CmdGetRatingProfile) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetRatingProfile) RpcResult() interface{} {
var s engine.RatingProfile
return &s
}

View File

@@ -1,64 +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 console
import (
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetRatingProfileIDs{
name: "ratingprofile_ids",
rpcMethod: utils.APIerSv1GetRatingProfileIDs,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetRatingProfileIDs struct {
name string
rpcMethod string
rpcParams *utils.PaginatorWithTenant
*CommandExecuter
}
func (self *CmdGetRatingProfileIDs) Name() string {
return self.name
}
func (self *CmdGetRatingProfileIDs) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetRatingProfileIDs) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = new(utils.PaginatorWithTenant)
}
return self.rpcParams
}
func (self *CmdGetRatingProfileIDs) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetRatingProfileIDs) RpcResult() interface{} {
var s []string
return &s
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdRatingPlanIDs(t *testing.T) {
// commands map is initiated in init function
command := commands["ratingprofile_ids"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,71 +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 console
import (
"reflect"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdRemRatingProfile{
name: "ratingprofile_remove",
rpcMethod: utils.APIerSv1RemoveRatingProfile,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdRemRatingProfile struct {
name string
rpcMethod string
rpcParams *v1.AttrRemoveRatingProfile
rpcResult string
*CommandExecuter
}
func (self *CmdRemRatingProfile) Name() string {
return self.name
}
func (self *CmdRemRatingProfile) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdRemRatingProfile) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrRemoveRatingProfile{}
}
return self.rpcParams
}
func (self *CmdRemRatingProfile) PostprocessRpcParams() error {
if reflect.DeepEqual(self.rpcParams, &v1.AttrRemoveRatingProfile{}) {
return utils.ErrMandatoryIeMissing
}
return nil
}
func (self *CmdRemRatingProfile) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,81 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdRatingPlanRem(t *testing.T) {
// commands map is initiated in init function
command := commands["ratingprofile_remove"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
}
func TestCmdRatingPlanRemPostprocessRpcParams(t *testing.T) {
testStruct := CmdRemRatingProfile{
name: "",
rpcMethod: "",
rpcParams: nil,
rpcResult: "",
CommandExecuter: nil,
}
if err := testStruct.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}
func TestCmdRatingPlanRemPostprocessRpcParamsError(t *testing.T) {
testStruct := CmdRemRatingProfile{
name: "",
rpcMethod: "",
rpcParams: &v1.AttrRemoveRatingProfile{},
rpcResult: "",
CommandExecuter: nil,
}
err := testStruct.PostprocessRpcParams()
if err == nil || err != utils.ErrMandatoryIeMissing {
t.Fatal(err)
}
}

View File

@@ -1,65 +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 console
import (
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdSetRatingProfile{
name: "ratingprofile_set",
rpcMethod: utils.APIerSv1SetRatingProfile,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdSetRatingProfile struct {
name string
rpcMethod string
rpcParams *utils.AttrSetRatingProfile
rpcResult string
*CommandExecuter
}
func (self *CmdSetRatingProfile) Name() string {
return self.name
}
func (self *CmdSetRatingProfile) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdSetRatingProfile) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = new(utils.AttrSetRatingProfile)
}
return self.rpcParams
}
func (self *CmdSetRatingProfile) PostprocessRpcParams() error {
return nil
}
func (self *CmdSetRatingProfile) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdRatingPlanSet(t *testing.T) {
// commands map is initiated in init function
command := commands["ratingprofile_set"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdRatingPlan(t *testing.T) {
// commands map is initiated in init function
command := commands["ratingprofile"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,64 +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 console
import (
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetSharedGroup{
name: "sharedgroup",
rpcMethod: utils.APIerSv1GetSharedGroup,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetSharedGroup struct {
name string
rpcMethod string
rpcParams *StringWrapper
*CommandExecuter
}
func (self *CmdGetSharedGroup) Name() string {
return self.name
}
func (self *CmdGetSharedGroup) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetSharedGroup) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &StringWrapper{}
}
return self.rpcParams
}
func (self *CmdGetSharedGroup) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetSharedGroup) RpcResult() interface{} {
return &engine.SharedGroup{}
}

View File

@@ -1,54 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdSharedGroup(t *testing.T) {
// commands map is initiated in init function
command := commands["sharedgroup"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// for coverage purpose
result := command.RpcParams(false)
if !reflect.DeepEqual(result, new(StringWrapper)) {
t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,66 +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 console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdRemoveTriggers{
name: "triggers_remove",
rpcMethod: utils.APIerSv1RemoveActionTrigger,
rpcParams: &v1.AttrRemoveActionTrigger{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdRemoveTriggers struct {
name string
rpcMethod string
rpcParams *v1.AttrRemoveActionTrigger
*CommandExecuter
}
func (self *CmdRemoveTriggers) Name() string {
return self.name
}
func (self *CmdRemoveTriggers) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdRemoveTriggers) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrRemoveActionTrigger{}
}
return self.rpcParams
}
func (self *CmdRemoveTriggers) PostprocessRpcParams() error {
return nil
}
func (self *CmdRemoveTriggers) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,52 +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 console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
"reflect"
"strings"
"testing"
)
func TestCmdTriggerRemove(t *testing.T) {
// commands map is initiated in init function
command := commands["triggers_remove"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,66 +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 console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdSetTriggers{
name: "triggers_set",
rpcMethod: utils.APIerSv1SetActionTrigger,
rpcParams: &v1.AttrSetActionTrigger{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdSetTriggers struct {
name string
rpcMethod string
rpcParams *v1.AttrSetActionTrigger
*CommandExecuter
}
func (self *CmdSetTriggers) Name() string {
return self.name
}
func (self *CmdSetTriggers) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdSetTriggers) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrSetActionTrigger{}
}
return self.rpcParams
}
func (self *CmdSetTriggers) PostprocessRpcParams() error {
return nil
}
func (self *CmdSetTriggers) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,53 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdTriggerSet(t *testing.T) {
// commands map is initiated in init function
command := commands["triggers_set"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}

View File

@@ -1,73 +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 console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetTriggers{
name: "triggers",
rpcMethod: utils.APIerSv1GetActionTriggers,
rpcParams: &v1.AttrGetActionTriggers{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetTriggers struct {
name string
rpcMethod string
rpcParams *v1.AttrGetActionTriggers
*CommandExecuter
}
func (self *CmdGetTriggers) Name() string {
return self.name
}
func (self *CmdGetTriggers) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetTriggers) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrGetActionTriggers{}
}
return self.rpcParams
}
func (self *CmdGetTriggers) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetTriggers) RpcResult() interface{} {
var atr engine.ActionTriggers
return &atr
}
func (self *CmdGetTriggers) GetFormatedResult(result interface{}) string {
return GetFormatedSliceResult(result, utils.StringSet{
utils.MinSleep: {},
})
}

View File

@@ -1,61 +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 console
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdTriggers(t *testing.T) {
// commands map is initiated in init function
command := commands["triggers"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")
}
// verify the type of output parameter
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
// for coverage purpose
formatedResult := command.GetFormatedResult(command.RpcResult())
expected := GetFormatedSliceResult(command.RpcResult(), utils.StringSet{
utils.MinSleep: {},
})
if !reflect.DeepEqual(formatedResult, expected) {
t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
}
}

View File

@@ -1,53 +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 dispatchers
import (
"time"
"github.com/cgrates/cgrates/utils"
)
func (dS *DispatcherService) RALsV1Ping(args *utils.CGREvent, rpl *string) (err error) {
if args == nil {
args = new(utils.CGREvent)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.RALsV1Ping, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), args.Time); err != nil {
return
}
}
return dS.Dispatch(args, utils.MetaRALs, utils.RALsV1Ping, args, rpl)
}
func (dS *DispatcherService) RALsV1GetRatingPlansCost(args *utils.RatingPlanCostArg, rpl *RatingPlanCost) (err error) {
tenant := dS.cfg.GeneralCfg().DefaultTenant
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.RALsV1GetRatingPlansCost, tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: tenant,
APIOpts: args.APIOpts,
}, utils.MetaRALs, utils.RALsV1GetRatingPlansCost, args, rpl)
}

View File

@@ -1,102 +0,0 @@
// +build integration
/*
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 dispatchers
import (
"testing"
"time"
"github.com/cgrates/cgrates/utils"
)
var sTestsDspRALs = []func(t *testing.T){
testDspRALsPing,
testDspRALsGetRatingPlanCost,
}
//Test start here
func TestDspRALsIT(t *testing.T) {
var config1, config2, config3 string
switch *dbType {
case utils.MetaInternal:
t.SkipNow()
case utils.MetaMySQL:
config1 = "all_mysql"
config2 = "all2_mysql"
config3 = "dispatchers_mysql"
case utils.MetaMongo:
config1 = "all_mongo"
config2 = "all2_mongo"
config3 = "dispatchers_mongo"
case utils.MetaPostgres:
t.SkipNow()
default:
t.Fatal("Unknown Database type")
}
dispDIR := "dispatchers"
if *encoding == utils.MetaGOB {
dispDIR += "_gob"
}
testDsp(t, sTestsDspRALs, "TestDspRALsITMySQL", config1, config2, config3, "tutorial", "oldtutorial", dispDIR)
}
func testDspRALsPing(t *testing.T) {
var reply string
if err := allEngine.RPC.Call(utils.RALsV1Ping, new(utils.CGREvent), &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
if err := dispEngine.RPC.Call(utils.RALsV1Ping, &utils.CGREvent{
Tenant: "cgrates.org",
APIOpts: map[string]interface{}{
utils.OptsAPIKey: "rals12345",
},
}, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
}
func testDspRALsGetRatingPlanCost(t *testing.T) {
arg := &utils.RatingPlanCostArg{
Destination: "1002",
RatingPlanIDs: []string{"RP_1001", "RP_1002"},
SetupTime: utils.MetaNow,
Usage: "1h",
APIOpts: map[string]interface{}{
utils.OptsAPIKey: "rals12345",
},
}
var reply RatingPlanCost
if err := dispEngine.RPC.Call(utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil {
t.Error(err)
} else if reply.RatingPlanID != "RP_1001" {
t.Error("Unexpected RatingPlanID: ", reply.RatingPlanID)
} else if *reply.EventCost.Cost != 6.5118 {
t.Error("Unexpected Cost: ", *reply.EventCost.Cost)
} else if *reply.EventCost.Usage != time.Hour {
t.Error("Unexpected Usage: ", *reply.EventCost.Usage)
}
}

View File

@@ -39,23 +39,6 @@ func (dS *DispatcherService) ReplicatorSv1Ping(args *utils.CGREvent, rpl *string
return dS.Dispatch(args, utils.MetaReplicator, utils.ReplicatorSv1Ping, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1GetAccount(args *utils.StringWithAPIOpts, rpl *engine.Account) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1GetAccount, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1GetAccount, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1GetDestination(args *utils.StringWithAPIOpts, rpl *engine.Destination) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
@@ -233,142 +216,6 @@ func (dS *DispatcherService) ReplicatorSv1GetResourceProfile(args *utils.TenantI
}, utils.MetaReplicator, utils.ReplicatorSv1GetResourceProfile, args, reply)
}
func (dS *DispatcherService) ReplicatorSv1GetActionTriggers(args *utils.StringWithAPIOpts, rpl *engine.ActionTriggers) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1GetActionTriggers, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1GetActionTriggers, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1GetSharedGroup(args *utils.StringWithAPIOpts, rpl *engine.SharedGroup) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1GetSharedGroup, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1GetSharedGroup, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1GetActions(args *utils.StringWithAPIOpts, rpl *engine.Actions) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1GetActions, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1GetActions, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1GetActionPlan(args *utils.StringWithAPIOpts, rpl *engine.ActionPlan) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1GetActionPlan, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1GetActionPlan, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1GetAllActionPlans(args *utils.StringWithAPIOpts, rpl *map[string]*engine.ActionPlan) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1GetAllActionPlans, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1GetAllActionPlans, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1GetAccountActionPlans(args *utils.StringWithAPIOpts, rpl *[]string) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1GetAccountActionPlans, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1GetAccountActionPlans, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1GetRatingPlan(args *utils.StringWithAPIOpts, rpl *engine.RatingPlan) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1GetRatingPlan, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1GetRatingPlan, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1GetRatingProfile(args *utils.StringWithAPIOpts, rpl *engine.RatingProfile) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1GetRatingProfile, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1GetRatingProfile, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1GetRouteProfile(args *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) (err error) {
tnt := dS.cfg.GeneralCfg().DefaultTenant
if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString {
@@ -563,23 +410,6 @@ func (dS *DispatcherService) ReplicatorSv1SetDestination(args *engine.Destinatio
}, utils.MetaReplicator, utils.ReplicatorSv1SetDestination, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1SetAccount(args *engine.AccountWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &engine.AccountWithAPIOpts{}
}
tenant := utils.FirstNonEmpty(utils.SplitConcatenatedKey(args.ID)[0], dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1SetAccount, tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1SetAccount, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1SetReverseDestination(args *engine.DestinationWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &engine.DestinationWithAPIOpts{}
@@ -699,40 +529,6 @@ func (dS *DispatcherService) ReplicatorSv1SetResourceProfile(args *engine.Resour
}, utils.MetaReplicator, utils.ReplicatorSv1SetResourceProfile, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1SetActionTriggers(args *engine.SetActionTriggersArgWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &engine.SetActionTriggersArgWithAPIOpts{}
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1SetActionTriggers, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1SetActionTriggers, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1SetSharedGroup(args *engine.SharedGroupWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &engine.SharedGroupWithAPIOpts{}
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1SetSharedGroup, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1SetSharedGroup, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1SetActions(args *engine.SetActionsArgsWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &engine.SetActionsArgsWithAPIOpts{}
@@ -750,40 +546,6 @@ func (dS *DispatcherService) ReplicatorSv1SetActions(args *engine.SetActionsArgs
}, utils.MetaReplicator, utils.ReplicatorSv1SetActions, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1SetRatingPlan(args *engine.RatingPlanWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &engine.RatingPlanWithAPIOpts{}
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1SetRatingPlan, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1SetRatingPlan, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1SetRatingProfile(args *engine.RatingProfileWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &engine.RatingProfileWithAPIOpts{}
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1SetRatingProfile, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1SetRatingProfile, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1SetRouteProfile(args *engine.RouteProfileWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &engine.RouteProfileWithAPIOpts{}
@@ -886,40 +648,6 @@ func (dS *DispatcherService) ReplicatorSv1SetActionProfile(args *engine.ActionPr
}, utils.MetaReplicator, utils.ReplicatorSv1SetActionProfile, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1SetActionPlan(args *engine.SetActionPlanArgWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &engine.SetActionPlanArgWithAPIOpts{}
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1SetActionPlan, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1SetActionPlan, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1SetAccountActionPlans(args *engine.SetAccountActionPlansArgWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &engine.SetAccountActionPlansArgWithAPIOpts{}
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1SetAccountActionPlans, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1SetAccountActionPlans, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1SetDispatcherHost(args *engine.DispatcherHostWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &engine.DispatcherHostWithAPIOpts{}
@@ -988,23 +716,6 @@ func (dS *DispatcherService) ReplicatorSv1SetLoadIDs(args *utils.LoadIDsWithAPIO
}, utils.MetaReplicator, utils.ReplicatorSv1SetLoadIDs, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1RemoveAccount(args *utils.StringWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1RemoveAccount, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1RemoveAccount, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1RemoveStatQueue(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &utils.TenantIDWithAPIOpts{}
@@ -1124,40 +835,6 @@ func (dS *DispatcherService) ReplicatorSv1RemoveResourceProfile(args *utils.Tena
}, utils.MetaReplicator, utils.ReplicatorSv1RemoveResourceProfile, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1RemoveActionTriggers(args *utils.StringWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1RemoveActionTriggers, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1RemoveActionTriggers, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1RemoveSharedGroup(args *utils.StringWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1RemoveSharedGroup, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1RemoveSharedGroup, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1RemoveActions(args *utils.StringWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
@@ -1175,74 +852,6 @@ func (dS *DispatcherService) ReplicatorSv1RemoveActions(args *utils.StringWithAP
}, utils.MetaReplicator, utils.ReplicatorSv1RemoveActions, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1RemoveActionPlan(args *utils.StringWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1RemoveActionPlan, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1RemoveActionPlan, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1RemAccountActionPlans(args *engine.RemAccountActionPlansArgsWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &engine.RemAccountActionPlansArgsWithAPIOpts{}
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1RemAccountActionPlans, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1RemAccountActionPlans, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1RemoveRatingPlan(args *utils.StringWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1RemoveRatingPlan, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1RemoveRatingPlan, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1RemoveRatingProfile(args *utils.StringWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = new(utils.StringWithAPIOpts)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1RemoveRatingProfile, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1RemoveRatingProfile, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1RemoveRouteProfile(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &utils.TenantIDWithAPIOpts{}

View File

@@ -1,123 +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 dispatchers
import (
"time"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
// ResponderPing interogates Responder server responsible to process the event
func (dS *DispatcherService) ResponderPing(args *utils.CGREvent,
reply *string) (err error) {
if args == nil {
args = new(utils.CGREvent)
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ResponderPing, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), args.Time); err != nil {
return
}
}
return dS.Dispatch(args, utils.MetaResponder, utils.ResponderPing, args, reply)
}
func (dS *DispatcherService) ResponderGetCost(args *engine.CallDescriptorWithAPIOpts,
reply *engine.CallCost) (err error) {
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ResponderGetCost, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(args.AsCGREvent(args.APIOpts), utils.MetaResponder, utils.ResponderGetCost, args, reply)
}
func (dS *DispatcherService) ResponderDebit(args *engine.CallDescriptorWithAPIOpts,
reply *engine.CallCost) (err error) {
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ResponderDebit, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(args.AsCGREvent(args.APIOpts), utils.MetaResponder, utils.ResponderDebit, args, reply)
}
func (dS *DispatcherService) ResponderMaxDebit(args *engine.CallDescriptorWithAPIOpts,
reply *engine.CallCost) (err error) {
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ResponderMaxDebit, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(args.AsCGREvent(args.APIOpts), utils.MetaResponder, utils.ResponderMaxDebit, args, reply)
}
func (dS *DispatcherService) ResponderRefundIncrements(args *engine.CallDescriptorWithAPIOpts,
reply *engine.Account) (err error) {
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ResponderRefundIncrements, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(args.AsCGREvent(args.APIOpts), utils.MetaResponder, utils.ResponderRefundIncrements, args, reply)
}
func (dS *DispatcherService) ResponderRefundRounding(args *engine.CallDescriptorWithAPIOpts,
reply *float64) (err error) {
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ResponderRefundRounding, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(args.AsCGREvent(args.APIOpts), utils.MetaResponder, utils.ResponderRefundRounding, args, reply)
}
func (dS *DispatcherService) ResponderGetMaxSessionTime(args *engine.CallDescriptorWithAPIOpts,
reply *time.Duration) (err error) {
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ResponderGetMaxSessionTime, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(args.AsCGREvent(args.APIOpts), utils.MetaResponder, utils.ResponderGetMaxSessionTime, args, reply)
}
func (dS *DispatcherService) ResponderShutdown(args *utils.TenantWithAPIOpts,
reply *string) (err error) {
tnt := utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ResponderShutdown, tnt,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: tnt,
APIOpts: args.APIOpts,
}, utils.MetaResponder, utils.ResponderShutdown, args, reply)
}

Some files were not shown because too many files have changed in this diff Show More