mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 05:09:54 +05:00
New type ResourceWithConfig + Available method
This commit is contained in:
committed by
Dan Christian Bogos
parent
f74608dedc
commit
2ccf3f7fa5
@@ -101,8 +101,8 @@ func (dDP *dynamicDP) fieldAsInterface(fldPath []string) (val interface{}, err e
|
||||
return dp.FieldAsInterface(fldPath[2:])
|
||||
case utils.MetaResources:
|
||||
// sample of fieldName : ~*resources.ResourceID.Field
|
||||
var reply *Resource
|
||||
if err := connMgr.Call(dDP.resConns, nil, utils.ResourceSv1GetResource,
|
||||
var reply *ResourceWithConfig
|
||||
if err := connMgr.Call(dDP.resConns, nil, utils.ResourceSv1GetResourceWithConfig,
|
||||
&utils.TenantID{Tenant: dDP.tenant, ID: fldPath[1]}, &reply); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -162,8 +162,8 @@ func (r *Resource) TotalUsage() (tU float64) {
|
||||
|
||||
// Available returns the available number of units
|
||||
// Exported method to be used by filterS
|
||||
func (r *Resource) Available() float64 {
|
||||
return r.rPrf.Limit - r.totalUsage()
|
||||
func (r *ResourceWithConfig) Available() float64 {
|
||||
return r.Config.Limit - r.totalUsage()
|
||||
}
|
||||
|
||||
// recordUsage records a new usage
|
||||
@@ -815,6 +815,39 @@ func (rS *ResourceService) V1GetResource(arg *utils.TenantIDWithOpts, reply *Res
|
||||
return nil
|
||||
}
|
||||
|
||||
type ResourceWithConfig struct {
|
||||
*Resource
|
||||
Config *ResourceProfile
|
||||
}
|
||||
|
||||
func (rS *ResourceService) V1GetResourceWithConfig(arg *utils.TenantIDWithOpts, reply *ResourceWithConfig) (err 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 = rS.cgrcfg.GeneralCfg().DefaultTenant
|
||||
}
|
||||
var res *Resource
|
||||
res, err = rS.dm.GetResource(tnt, arg.ID, true, true, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if res.rPrf == nil {
|
||||
var cfg *ResourceProfile
|
||||
cfg, err = rS.dm.GetResourceProfile(tnt, arg.ID, true, true, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res.rPrf = cfg
|
||||
}
|
||||
*reply = ResourceWithConfig{
|
||||
Resource: res,
|
||||
Config: res.rPrf,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Reload stops the backupLoop and restarts it
|
||||
func (rS *ResourceService) Reload() {
|
||||
close(rS.stopBackup)
|
||||
|
||||
Reference in New Issue
Block a user