mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 14:48:43 +05:00
ThresholdSV1 APIer instance with initial methods, centralized APIerRPCCall for stats, resources and thresholds
This commit is contained in:
@@ -19,12 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package v1
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
func NewResourceSV1(rls *engine.ResourceService) *ResourceSV1 {
|
||||
@@ -38,27 +34,7 @@ type ResourceSV1 struct {
|
||||
|
||||
// Call implements rpcclient.RpcClientConnection interface for internal RPC
|
||||
func (rsv1 *ResourceSV1) Call(serviceMethod string, args interface{}, reply interface{}) error {
|
||||
methodSplit := strings.Split(serviceMethod, ".")
|
||||
if len(methodSplit) != 2 {
|
||||
return rpcclient.ErrUnsupporteServiceMethod
|
||||
}
|
||||
method := reflect.ValueOf(rsv1).MethodByName(methodSplit[1])
|
||||
if !method.IsValid() {
|
||||
return rpcclient.ErrUnsupporteServiceMethod
|
||||
}
|
||||
params := []reflect.Value{reflect.ValueOf(args), reflect.ValueOf(reply)}
|
||||
ret := method.Call(params)
|
||||
if len(ret) != 1 {
|
||||
return utils.ErrServerError
|
||||
}
|
||||
if ret[0].Interface() == nil {
|
||||
return nil
|
||||
}
|
||||
err, ok := ret[0].Interface().(error)
|
||||
if !ok {
|
||||
return utils.ErrServerError
|
||||
}
|
||||
return err
|
||||
return utils.APIerRPCCall(rsv1, serviceMethod, args, reply)
|
||||
}
|
||||
|
||||
// GetResourcesForEvent returns Resources matching a specific event
|
||||
|
||||
@@ -19,13 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package v1
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/cache"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
// GetStatQueueProfile returns a StatQueue profile
|
||||
@@ -80,27 +76,7 @@ type StatSV1 struct {
|
||||
|
||||
// Call implements rpcclient.RpcClientConnection interface for internal RPC
|
||||
func (stsv1 *StatSV1) Call(serviceMethod string, args interface{}, reply interface{}) error {
|
||||
methodSplit := strings.Split(serviceMethod, ".")
|
||||
if len(methodSplit) != 2 {
|
||||
return rpcclient.ErrUnsupporteServiceMethod
|
||||
}
|
||||
method := reflect.ValueOf(stsv1).MethodByName(methodSplit[1])
|
||||
if !method.IsValid() {
|
||||
return rpcclient.ErrUnsupporteServiceMethod
|
||||
}
|
||||
params := []reflect.Value{reflect.ValueOf(args), reflect.ValueOf(reply)}
|
||||
ret := method.Call(params)
|
||||
if len(ret) != 1 {
|
||||
return utils.ErrServerError
|
||||
}
|
||||
if ret[0].Interface() == nil {
|
||||
return nil
|
||||
}
|
||||
err, ok := ret[0].Interface().(error)
|
||||
if !ok {
|
||||
return utils.ErrServerError
|
||||
}
|
||||
return err
|
||||
return utils.APIerRPCCall(stsv1, serviceMethod, args, reply)
|
||||
}
|
||||
|
||||
// GetQueueIDs returns list of queueIDs registered for a tenant
|
||||
|
||||
54
apier/v1/thresholds.go
Normal file
54
apier/v1/thresholds.go
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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 FITNEtS 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"
|
||||
)
|
||||
|
||||
// NewThresholdSV1 initializes ThresholdSV1
|
||||
func NewThresholdSV1(tS *engine.ThresholdService) *ThresholdSV1 {
|
||||
return &ThresholdSV1{tS: tS}
|
||||
}
|
||||
|
||||
// Exports RPC from RLs
|
||||
type ThresholdSV1 struct {
|
||||
tS *engine.ThresholdService
|
||||
}
|
||||
|
||||
// Call implements rpcclient.RpcClientConnection interface for internal RPC
|
||||
func (tSv1 *ThresholdSV1) Call(serviceMethod string, args interface{}, reply interface{}) error {
|
||||
return utils.APIerRPCCall(tSv1, serviceMethod, args, reply)
|
||||
}
|
||||
|
||||
// GetThresholdIDs returns list of threshold IDs registered for a tenant
|
||||
func (tSv1 *ThresholdSV1) GetThresholdIDs(tenant string, tIDs *[]string) error {
|
||||
return tSv1.tS.V1GetThresholdIDs(tenant, tIDs)
|
||||
}
|
||||
|
||||
// GetThresholdsForEvent returns a list of thresholds matching an event
|
||||
func (tSv1 *ThresholdSV1) GetThresholdsForEvent(ev *engine.ThresholdEvent, reply *engine.Thresholds) error {
|
||||
return tSv1.tS.V1GetThresholdsForEvent(ev, reply)
|
||||
}
|
||||
|
||||
// ProcessEvent will process an Event
|
||||
func (tSv1 *ThresholdSV1) ProcessEvent(ev *engine.ThresholdEvent, reply *string) error {
|
||||
return tSv1.tS.V1ProcessEvent(ev, reply)
|
||||
}
|
||||
@@ -808,3 +808,28 @@ func RPCCall(inst interface{}, serviceMethod string, args interface{}, reply int
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// ApierRPCCall implements generic RPCCall for APIer instances
|
||||
func APIerRPCCall(inst interface{}, serviceMethod string, args interface{}, reply interface{}) error {
|
||||
methodSplit := strings.Split(serviceMethod, ".")
|
||||
if len(methodSplit) != 2 {
|
||||
return rpcclient.ErrUnsupporteServiceMethod
|
||||
}
|
||||
method := reflect.ValueOf(inst).MethodByName(methodSplit[1])
|
||||
if !method.IsValid() {
|
||||
return rpcclient.ErrUnsupporteServiceMethod
|
||||
}
|
||||
params := []reflect.Value{reflect.ValueOf(args), reflect.ValueOf(reply)}
|
||||
ret := method.Call(params)
|
||||
if len(ret) != 1 {
|
||||
return ErrServerError
|
||||
}
|
||||
if ret[0].Interface() == nil {
|
||||
return nil
|
||||
}
|
||||
err, ok := ret[0].Interface().(error)
|
||||
if !ok {
|
||||
return ErrServerError
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user