mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
add implementation for new ips module
This commit is contained in:
committed by
Dan Christian Bogos
parent
d6676866d5
commit
43cdd396ba
@@ -55,6 +55,14 @@ type ResourceSv1Interface interface {
|
||||
GetResourceWithConfig(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.ResourceWithConfig) error
|
||||
}
|
||||
|
||||
type IPsV1Interface interface {
|
||||
GetIPsForEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.IPs) error
|
||||
AuthorizeIPs(ctx *context.Context, args *utils.CGREvent, reply *string) error
|
||||
AllocateIPs(ctx *context.Context, args *utils.CGREvent, reply *string) error
|
||||
ReleaseIPs(ctx *context.Context, args *utils.CGREvent, reply *string) error
|
||||
GetIP(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.IP) error
|
||||
}
|
||||
|
||||
type RouteSv1Interface interface {
|
||||
GetRoutes(ctx *context.Context, args *utils.CGREvent, reply *engine.SortedRoutesList) error
|
||||
GetRouteProfilesForEvent(ctx *context.Context, args *utils.CGREvent, reply *[]*engine.RouteProfile) error
|
||||
@@ -189,6 +197,8 @@ type ReplicatorSv1Interface interface {
|
||||
GetTiming(ctx *context.Context, id *utils.StringWithAPIOpts, reply *utils.TPTiming) error
|
||||
GetResource(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.Resource) error
|
||||
GetResourceProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.ResourceProfile) error
|
||||
GetIP(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.IP) error
|
||||
GetIPProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.IPProfile) error
|
||||
GetActionTriggers(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.ActionTriggers) error
|
||||
GetSharedGroup(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.SharedGroup) error
|
||||
GetActions(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.Actions) error
|
||||
@@ -214,6 +224,8 @@ type ReplicatorSv1Interface interface {
|
||||
SetTiming(ctx *context.Context, tm *utils.TPTimingWithAPIOpts, reply *string) error
|
||||
SetResource(ctx *context.Context, rs *engine.ResourceWithAPIOpts, reply *string) error
|
||||
SetResourceProfile(ctx *context.Context, rs *engine.ResourceProfileWithAPIOpts, reply *string) error
|
||||
SetIP(ctx *context.Context, rs *engine.IPWithAPIOpts, reply *string) error
|
||||
SetIPProfile(ctx *context.Context, rs *engine.IPProfileWithAPIOpts, reply *string) error
|
||||
SetActionTriggers(ctx *context.Context, args *engine.SetActionTriggersArgWithAPIOpts, reply *string) error
|
||||
SetSharedGroup(ctx *context.Context, shg *engine.SharedGroupWithAPIOpts, reply *string) error
|
||||
SetActions(ctx *context.Context, args *engine.SetActionsArgsWithAPIOpts, reply *string) error
|
||||
@@ -237,6 +249,8 @@ type ReplicatorSv1Interface interface {
|
||||
RemoveTiming(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) error
|
||||
RemoveResource(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error
|
||||
RemoveResourceProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error
|
||||
RemoveIP(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error
|
||||
RemoveIPProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error
|
||||
RemoveActionTriggers(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) error
|
||||
RemoveSharedGroup(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) error
|
||||
RemoveActions(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) error
|
||||
|
||||
@@ -39,6 +39,11 @@ func TestResourceSv1Interface(t *testing.T) {
|
||||
_ = ResourceSv1Interface(NewResourceSv1(nil))
|
||||
}
|
||||
|
||||
func TestIPsV1Interface(t *testing.T) {
|
||||
_ = IPsV1Interface(NewDispatcherIPsV1(nil))
|
||||
_ = IPsV1Interface(NewIPsV1(nil))
|
||||
}
|
||||
|
||||
func TestRouteSv1Interface(t *testing.T) {
|
||||
_ = RouteSv1Interface(NewDispatcherRouteSv1(nil))
|
||||
_ = RouteSv1Interface(NewRouteSv1(nil))
|
||||
|
||||
@@ -1717,6 +1717,44 @@ func (apierSv1 *APIerSv1) ExportToFolder(ctx *context.Context, arg *utils.ArgExp
|
||||
}
|
||||
}
|
||||
csvWriter.Flush()
|
||||
case utils.MetaIPs:
|
||||
prfx := utils.IPProfilesPrefix
|
||||
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(keys) == 0 { // if we don't find items we skip
|
||||
continue
|
||||
}
|
||||
f, err := os.Create(path.Join(arg.Path, utils.IPsCsv))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
csvWriter := csv.NewWriter(f)
|
||||
csvWriter.Comma = utils.CSVSep
|
||||
//write the header of the file
|
||||
if err := csvWriter.Write(engine.IPMdls{}.CSVHeader()); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, key := range keys {
|
||||
tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2)
|
||||
ipPrf, err := apierSv1.DataManager.GetIPProfile(tntID[0], tntID[1],
|
||||
true, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, model := range engine.APItoModelIP(
|
||||
engine.IPProfileToAPI(ipPrf)) {
|
||||
if record, err := engine.CsvDump(model); err != nil {
|
||||
return err
|
||||
} else if err := csvWriter.Write(record); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
csvWriter.Flush()
|
||||
case utils.MetaStats:
|
||||
prfx := utils.StatQueueProfilePrefix
|
||||
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx)
|
||||
|
||||
@@ -1701,7 +1701,7 @@ func testApierResetDataAfterLoadFromFolder(t *testing.T) {
|
||||
expStats[utils.CacheRouteProfiles].Items = 2
|
||||
expStats[utils.CacheThresholdProfiles].Items = 1
|
||||
expStats[utils.CacheThresholds].Items = 1
|
||||
expStats[utils.CacheLoadIDs].Items = 35
|
||||
expStats[utils.CacheLoadIDs].Items = 38
|
||||
expStats[utils.CacheTimings].Items = 12
|
||||
expStats[utils.CacheThresholdFilterIndexes].Items = 5
|
||||
expStats[utils.CacheThresholdFilterIndexes].Groups = 1
|
||||
|
||||
@@ -163,7 +163,7 @@ func testCacheSAfterLoadFromFolder(t *testing.T) {
|
||||
expStats[utils.CacheRouteProfiles].Items = 2
|
||||
expStats[utils.CacheThresholdProfiles].Items = 1
|
||||
expStats[utils.CacheThresholds].Items = 1
|
||||
expStats[utils.CacheLoadIDs].Items = 35
|
||||
expStats[utils.CacheLoadIDs].Items = 38
|
||||
expStats[utils.CacheTimings].Items = 12
|
||||
expStats[utils.CacheThresholdFilterIndexes].Items = 5
|
||||
expStats[utils.CacheThresholdFilterIndexes].Groups = 1
|
||||
@@ -235,7 +235,7 @@ func testCacheSReload(t *testing.T) {
|
||||
expStats[utils.CacheRouteProfiles].Items = 2
|
||||
expStats[utils.CacheThresholdProfiles].Items = 1
|
||||
expStats[utils.CacheThresholds].Items = 1
|
||||
expStats[utils.CacheLoadIDs].Items = 35
|
||||
expStats[utils.CacheLoadIDs].Items = 38
|
||||
expStats[utils.CacheTimings].Items = 12
|
||||
expStats[utils.CacheThresholdFilterIndexes].Items = 5
|
||||
expStats[utils.CacheThresholdFilterIndexes].Groups = 1
|
||||
|
||||
@@ -415,6 +415,45 @@ func (dRs *DispatcherResourceSv1) ReleaseResources(ctx *context.Context, args *u
|
||||
return dRs.dRs.ResourceSv1ReleaseResources(ctx, args, reply)
|
||||
}
|
||||
|
||||
func NewDispatcherIPsV1(dps *dispatchers.DispatcherService) *DispatcherIPsV1 {
|
||||
return &DispatcherIPsV1{dRs: dps}
|
||||
}
|
||||
|
||||
// Exports RPC from RLs
|
||||
type DispatcherIPsV1 struct {
|
||||
dRs *dispatchers.DispatcherService
|
||||
}
|
||||
|
||||
// Ping implements IPsV1Ping
|
||||
func (dRs *DispatcherIPsV1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error {
|
||||
return dRs.dRs.IPsV1Ping(ctx, args, reply)
|
||||
}
|
||||
|
||||
// GetIPsForEvent implements IPsV1GetIPsForEvent
|
||||
func (dRs *DispatcherIPsV1) GetIPsForEvent(ctx *context.Context, args *utils.CGREvent,
|
||||
reply *engine.IPs) error {
|
||||
return dRs.dRs.IPsV1GetIPsForEvent(ctx, args, reply)
|
||||
}
|
||||
|
||||
func (dRs *DispatcherIPsV1) GetIP(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.IP) error {
|
||||
return dRs.dRs.IPsV1GetIP(ctx, args, reply)
|
||||
}
|
||||
|
||||
func (dRs *DispatcherIPsV1) AuthorizeIPs(ctx *context.Context, args *utils.CGREvent,
|
||||
reply *string) error {
|
||||
return dRs.dRs.IPsV1AuthorizeIPs(ctx, args, reply)
|
||||
}
|
||||
|
||||
func (dRs *DispatcherIPsV1) AllocateIPs(ctx *context.Context, args *utils.CGREvent,
|
||||
reply *string) error {
|
||||
return dRs.dRs.IPsV1AllocateIPs(ctx, args, reply)
|
||||
}
|
||||
|
||||
func (dRs *DispatcherIPsV1) ReleaseIPs(ctx *context.Context, args *utils.CGREvent,
|
||||
reply *string) error {
|
||||
return dRs.dRs.IPsV1ReleaseIPs(ctx, args, reply)
|
||||
}
|
||||
|
||||
func NewDispatcherRouteSv1(dps *dispatchers.DispatcherService) *DispatcherRouteSv1 {
|
||||
return &DispatcherRouteSv1{dRoute: dps}
|
||||
}
|
||||
@@ -1132,6 +1171,16 @@ func (dS *DispatcherReplicatorSv1) GetResourceProfile(ctx *context.Context, tntI
|
||||
return dS.dS.ReplicatorSv1GetResourceProfile(ctx, tntID, reply)
|
||||
}
|
||||
|
||||
// GetIP
|
||||
func (dS *DispatcherReplicatorSv1) GetIP(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.IP) error {
|
||||
return dS.dS.ReplicatorSv1GetIP(ctx, tntID, reply)
|
||||
}
|
||||
|
||||
// GetIPProfile
|
||||
func (dS *DispatcherReplicatorSv1) GetIPProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.IPProfile) error {
|
||||
return dS.dS.ReplicatorSv1GetIPProfile(ctx, tntID, reply)
|
||||
}
|
||||
|
||||
// GetActionTriggers
|
||||
func (dS *DispatcherReplicatorSv1) GetActionTriggers(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.ActionTriggers) error {
|
||||
return dS.dS.ReplicatorSv1GetActionTriggers(ctx, id, reply)
|
||||
@@ -1259,6 +1308,16 @@ func (dS *DispatcherReplicatorSv1) SetResourceProfile(ctx *context.Context, args
|
||||
return dS.dS.ReplicatorSv1SetResourceProfile(ctx, args, reply)
|
||||
}
|
||||
|
||||
// SetIP
|
||||
func (dS *DispatcherReplicatorSv1) SetIP(ctx *context.Context, args *engine.IPWithAPIOpts, reply *string) error {
|
||||
return dS.dS.ReplicatorSv1SetIP(ctx, args, reply)
|
||||
}
|
||||
|
||||
// SetIPProfile
|
||||
func (dS *DispatcherReplicatorSv1) SetIPProfile(ctx *context.Context, args *engine.IPProfileWithAPIOpts, reply *string) error {
|
||||
return dS.dS.ReplicatorSv1SetIPProfile(ctx, args, reply)
|
||||
}
|
||||
|
||||
// SetActionTriggers
|
||||
func (dS *DispatcherReplicatorSv1) SetActionTriggers(ctx *context.Context, args *engine.SetActionTriggersArgWithAPIOpts, reply *string) error {
|
||||
return dS.dS.ReplicatorSv1SetActionTriggers(ctx, args, reply)
|
||||
@@ -1374,6 +1433,16 @@ func (dS *DispatcherReplicatorSv1) RemoveResourceProfile(ctx *context.Context, a
|
||||
return dS.dS.ReplicatorSv1RemoveResourceProfile(ctx, args, reply)
|
||||
}
|
||||
|
||||
// RemoveIP
|
||||
func (dS *DispatcherReplicatorSv1) RemoveIP(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error {
|
||||
return dS.dS.ReplicatorSv1RemoveIP(ctx, args, reply)
|
||||
}
|
||||
|
||||
// RemoveIPProfile
|
||||
func (dS *DispatcherReplicatorSv1) RemoveIPProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error {
|
||||
return dS.dS.ReplicatorSv1RemoveIPProfile(ctx, args, reply)
|
||||
}
|
||||
|
||||
// RemoveActionTriggers
|
||||
func (dS *DispatcherReplicatorSv1) RemoveActionTriggers(ctx *context.Context, args *utils.StringWithAPIOpts, reply *string) error {
|
||||
return dS.dS.ReplicatorSv1RemoveActionTriggers(ctx, args, reply)
|
||||
|
||||
165
apier/v1/ips.go
Normal file
165
apier/v1/ips.go
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
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"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func NewIPsV1(rls *engine.IPService) *IPsV1 {
|
||||
return &IPsV1{rls: rls}
|
||||
}
|
||||
|
||||
type IPsV1 struct {
|
||||
rls *engine.IPService
|
||||
}
|
||||
|
||||
// GetIPsForEvent returns IPs matching a specific event.
|
||||
func (ip *IPsV1) GetIPsForEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.IPs) error {
|
||||
return ip.rls.V1GetIPsForEvent(ctx, args, reply)
|
||||
}
|
||||
|
||||
// AuthorizeIPs checks if there are limits imposed for event.
|
||||
func (ip *IPsV1) AuthorizeIPs(ctx *context.Context, args *utils.CGREvent, reply *string) error {
|
||||
return ip.rls.V1AuthorizeIPs(ctx, args, reply)
|
||||
}
|
||||
|
||||
// AllocateIPs records usage for an event.
|
||||
func (ip *IPsV1) AllocateIPs(ctx *context.Context, args *utils.CGREvent, reply *string) error {
|
||||
return ip.rls.V1AllocateIPs(ctx, args, reply)
|
||||
}
|
||||
|
||||
// V1TerminateIPUsage releases usage for an event
|
||||
func (ip *IPsV1) ReleaseIPs(ctx *context.Context, args *utils.CGREvent, reply *string) error {
|
||||
return ip.rls.V1ReleaseIPs(ctx, args, reply)
|
||||
}
|
||||
|
||||
// GetIP retrieves the specified IP from data_db.
|
||||
func (ip *IPsV1) GetIP(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.IP) error {
|
||||
return ip.rls.V1GetIP(ctx, args, reply)
|
||||
}
|
||||
|
||||
// GetIPProfile retrieves the specificed IPProfile from data_db.
|
||||
func (a *APIerSv1) GetIPProfile(ctx *context.Context, arg *utils.TenantID, reply *engine.IPProfile) error {
|
||||
if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := arg.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = a.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if rcfg, err := a.DataManager.GetIPProfile(tnt, arg.ID, true, true, utils.NonTransactional); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
} else {
|
||||
*reply = *rcfg
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetIPProfileIDs returns list of IPProfile IDs registered for a tenant.
|
||||
func (a *APIerSv1) GetIPProfileIDs(ctx *context.Context, args *utils.PaginatorWithTenant, rsPrfIDs *[]string) error {
|
||||
tnt := args.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = a.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
prfx := utils.IPProfilesPrefix + tnt + utils.ConcatenatedKeySep
|
||||
keys, err := a.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
|
||||
}
|
||||
|
||||
// SetIPProfile persists the passed IPProfile to data_db.
|
||||
func (a *APIerSv1) SetIPProfile(ctx *context.Context, arg *engine.IPProfileWithAPIOpts, reply *string) (err error) {
|
||||
if missing := utils.MissingStructFields(arg.IPProfile, []string{utils.ID}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if arg.Tenant == utils.EmptyString {
|
||||
arg.Tenant = a.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err = a.DataManager.SetIPProfile(arg.IPProfile, true); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
//generate a loadID for CacheIPProfiles and CacheIPs and store it in database
|
||||
//make 1 insert for both IPProfile and IPs instead of 2
|
||||
loadID := time.Now().UnixNano()
|
||||
if err = a.DataManager.SetLoadIDs(
|
||||
map[string]int64{utils.CacheIPProfiles: loadID,
|
||||
utils.CacheIPs: loadID}); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
// delay if needed before cache call
|
||||
if a.Config.GeneralCfg().CachingDelay != 0 {
|
||||
utils.Logger.Info(fmt.Sprintf("<SetIPProfile> Delaying cache call for %v", a.Config.GeneralCfg().CachingDelay))
|
||||
time.Sleep(a.Config.GeneralCfg().CachingDelay)
|
||||
}
|
||||
//handle caching for IPProfile
|
||||
if err = a.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), arg.Tenant, utils.CacheIPProfiles,
|
||||
arg.TenantID(), utils.EmptyString, &arg.FilterIDs, nil, arg.APIOpts); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveIPProfile removes the specified IPProfile from data_db.
|
||||
func (a *APIerSv1) RemoveIPProfile(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *string) error {
|
||||
if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := arg.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = a.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := a.DataManager.RemoveIPProfile(tnt, arg.ID, true); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
// delay if needed before cache call
|
||||
if a.Config.GeneralCfg().CachingDelay != 0 {
|
||||
utils.Logger.Info(fmt.Sprintf("<RemoveIPProfile> Delaying cache call for %v", a.Config.GeneralCfg().CachingDelay))
|
||||
time.Sleep(a.Config.GeneralCfg().CachingDelay)
|
||||
}
|
||||
//handle caching for IPProfile
|
||||
if err := a.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), tnt, utils.CacheIPProfiles,
|
||||
utils.ConcatenatedKey(tnt, arg.ID), utils.EmptyString, nil, nil, arg.APIOpts); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
//generate a loadID for CacheIPProfiles and CacheIPs and store it in database
|
||||
//make 1 insert for both IPProfile and IPs instead of 2
|
||||
loadID := time.Now().UnixNano()
|
||||
if err := a.DataManager.SetLoadIDs(map[string]int64{utils.CacheIPProfiles: loadID, utils.CacheIPs: loadID}); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
@@ -80,6 +80,8 @@ func (apierSv1 *APIerSv1) CallCache(cacheopt string, tnt, cacheID, itemID, group
|
||||
cacheIDs = append(cacheIDs, utils.CacheThresholds)
|
||||
case utils.CacheResourceProfiles:
|
||||
cacheIDs = append(cacheIDs, utils.CacheResources)
|
||||
case utils.CacheIPProfiles:
|
||||
cacheIDs = append(cacheIDs, utils.CacheIPs)
|
||||
case utils.CacheStatQueueProfiles:
|
||||
cacheIDs = append(cacheIDs, utils.CacheStatQueues)
|
||||
}
|
||||
@@ -104,6 +106,8 @@ func (apierSv1 *APIerSv1) composeArgsReload(tnt, cacheID, itemID string, filterI
|
||||
argCache[utils.CacheThresholds] = []string{itemID}
|
||||
case utils.CacheResourceProfiles:
|
||||
argCache[utils.CacheResources] = []string{itemID}
|
||||
case utils.CacheIPProfiles:
|
||||
argCache[utils.CacheIPs] = []string{itemID}
|
||||
case utils.CacheStatQueueProfiles:
|
||||
argCache[utils.CacheStatQueues] = []string{itemID}
|
||||
}
|
||||
|
||||
@@ -183,6 +183,7 @@ func testPrecacheGetCacheStatsAfterRestart(t *testing.T) {
|
||||
utils.CacheDestinations: {Items: 5},
|
||||
utils.CacheDispatchers: {},
|
||||
utils.CacheEventResources: {},
|
||||
utils.CacheEventIPs: {},
|
||||
utils.CacheFilters: {Items: 15},
|
||||
utils.CacheRatingPlans: {Items: 4},
|
||||
utils.CacheRatingProfiles: {Items: 5},
|
||||
@@ -190,8 +191,11 @@ func testPrecacheGetCacheStatsAfterRestart(t *testing.T) {
|
||||
Items: 6,
|
||||
Groups: 1,
|
||||
},
|
||||
utils.CacheIPFilterIndexes: {},
|
||||
utils.CacheResourceProfiles: {Items: 3},
|
||||
utils.CacheResources: {Items: 3},
|
||||
utils.CacheIPProfiles: {},
|
||||
utils.CacheIPs: {},
|
||||
utils.CacheReverseDestinations: {Items: 7},
|
||||
utils.CacheRPCResponses: {},
|
||||
utils.MetaSentryPeer: {},
|
||||
|
||||
@@ -218,6 +218,28 @@ func (rplSv1 *ReplicatorSv1) GetResourceProfile(ctx *context.Context, tntID *uti
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetIP is the remote method coresponding to the dataDb driver method
|
||||
func (rplSv1 *ReplicatorSv1) GetIP(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.IP) error {
|
||||
engine.UpdateReplicationFilters(utils.IPsPrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
|
||||
rcv, err := rplSv1.dm.DataDB().GetIPDrv(tntID.Tenant, tntID.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*reply = *rcv
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetIPProfile is the remote method coresponding to the dataDb driver method
|
||||
func (rplSv1 *ReplicatorSv1) GetIPProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.IPProfile) error {
|
||||
engine.UpdateReplicationFilters(utils.IPProfilesPrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
|
||||
rcv, err := rplSv1.dm.DataDB().GetIPProfileDrv(tntID.Tenant, tntID.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*reply = *rcv
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetActionTriggers is the remote method coresponding to the dataDb driver method
|
||||
func (rplSv1 *ReplicatorSv1) GetActionTriggers(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.ActionTriggers) error {
|
||||
engine.UpdateReplicationFilters(utils.ActionTriggerPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt]))
|
||||
@@ -588,6 +610,37 @@ func (rplSv1 *ReplicatorSv1) SetResource(ctx *context.Context, rs *engine.Resour
|
||||
return
|
||||
}
|
||||
|
||||
// SetIPProfile is the replication method coresponding to the dataDb driver method
|
||||
func (rplSv1 *ReplicatorSv1) SetIPProfile(ctx *context.Context, ipp *engine.IPProfileWithAPIOpts, reply *string) (err error) {
|
||||
if err = rplSv1.dm.DataDB().SetIPProfileDrv(ipp.IPProfile); err != nil {
|
||||
return
|
||||
}
|
||||
// delay if needed before cache call
|
||||
if rplSv1.v1.Config.GeneralCfg().CachingDelay != 0 {
|
||||
utils.Logger.Info(fmt.Sprintf("<ReplicatorSv1SetIPProfile> Delaying cache call for %v", rplSv1.v1.Config.GeneralCfg().CachingDelay))
|
||||
time.Sleep(rplSv1.v1.Config.GeneralCfg().CachingDelay)
|
||||
}
|
||||
if err = rplSv1.v1.CallCache(utils.IfaceAsString(ipp.APIOpts[utils.CacheOpt]),
|
||||
ipp.Tenant, utils.CacheIPProfiles, ipp.TenantID(), utils.EmptyString, &ipp.FilterIDs, nil, ipp.APIOpts); err != nil {
|
||||
return
|
||||
}
|
||||
*reply = utils.OK
|
||||
return
|
||||
}
|
||||
|
||||
// SetIP is the replication method coresponding to the dataDb driver method
|
||||
func (rplSv1 *ReplicatorSv1) SetIP(ctx *context.Context, ip *engine.IPWithAPIOpts, reply *string) (err error) {
|
||||
if err = rplSv1.dm.DataDB().SetIPDrv(ip.IP); err != nil {
|
||||
return
|
||||
}
|
||||
if err = rplSv1.v1.CallCache(utils.IfaceAsString(ip.APIOpts[utils.CacheOpt]),
|
||||
ip.Tenant, utils.CacheIPs, ip.TenantID(), utils.EmptyString, nil, nil, ip.APIOpts); err != nil {
|
||||
return
|
||||
}
|
||||
*reply = utils.OK
|
||||
return
|
||||
}
|
||||
|
||||
// SetActionTriggers is the replication method coresponding to the dataDb driver method
|
||||
func (rplSv1 *ReplicatorSv1) SetActionTriggers(ctx *context.Context, args *engine.SetActionTriggersArgWithAPIOpts, reply *string) (err error) {
|
||||
if err = rplSv1.dm.DataDB().SetActionTriggersDrv(args.Key, args.Attrs); err != nil {
|
||||
@@ -1013,6 +1066,37 @@ func (rplSv1 *ReplicatorSv1) RemoveResourceProfile(ctx *context.Context, args *u
|
||||
return
|
||||
}
|
||||
|
||||
// RemoveIP is the replication method coresponding to the dataDb driver method
|
||||
func (rplSv1 *ReplicatorSv1) RemoveIP(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
|
||||
if err = rplSv1.dm.DataDB().RemoveIPDrv(args.Tenant, args.ID); err != nil {
|
||||
return
|
||||
}
|
||||
if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
|
||||
args.Tenant, utils.CacheIPs, args.TenantID.TenantID(), utils.EmptyString, nil, nil, args.APIOpts); err != nil {
|
||||
return
|
||||
}
|
||||
*reply = utils.OK
|
||||
return
|
||||
}
|
||||
|
||||
// RemoveIPProfile is the replication method coresponding to the dataDb driver method
|
||||
func (rplSv1 *ReplicatorSv1) RemoveIPProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
|
||||
if err = rplSv1.dm.DataDB().RemoveIPProfileDrv(args.Tenant, args.ID); err != nil {
|
||||
return
|
||||
}
|
||||
// delay if needed before cache call
|
||||
if rplSv1.v1.Config.GeneralCfg().CachingDelay != 0 {
|
||||
utils.Logger.Info(fmt.Sprintf("<ReplicatorSv1RemoveIPProfile> Delaying cache call for %v", rplSv1.v1.Config.GeneralCfg().CachingDelay))
|
||||
time.Sleep(rplSv1.v1.Config.GeneralCfg().CachingDelay)
|
||||
}
|
||||
if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
|
||||
args.Tenant, utils.CacheIPProfiles, args.TenantID.TenantID(), utils.EmptyString, nil, nil, args.APIOpts); err != nil {
|
||||
return
|
||||
}
|
||||
*reply = utils.OK
|
||||
return
|
||||
}
|
||||
|
||||
// RemoveActionTriggers is the replication method coresponding to the dataDb driver method
|
||||
func (rplSv1 *ReplicatorSv1) RemoveActionTriggers(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) (err error) {
|
||||
if err = rplSv1.dm.DataDB().RemoveActionTriggersDrv(id.Arg); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user