diff --git a/apier/v1/resourcesv1.go b/apier/v1/resourcesv1.go
index 14d21f27f..d56f5cce7 100644
--- a/apier/v1/resourcesv1.go
+++ b/apier/v1/resourcesv1.go
@@ -19,12 +19,8 @@ along with this program. If not, see
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
diff --git a/apier/v1/stats.go b/apier/v1/stats.go
index 1a3dfa436..dea86d4f2 100644
--- a/apier/v1/stats.go
+++ b/apier/v1/stats.go
@@ -19,13 +19,9 @@ along with this program. If not, see
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
diff --git a/apier/v1/thresholds.go b/apier/v1/thresholds.go
new file mode 100644
index 000000000..be58775ba
--- /dev/null
+++ b/apier/v1/thresholds.go
@@ -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
+*/
+
+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)
+}
diff --git a/utils/coreutils.go b/utils/coreutils.go
index 94d95a43b..070e157d3 100644
--- a/utils/coreutils.go
+++ b/utils/coreutils.go
@@ -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
+}