Added cores package and tests for caps

This commit is contained in:
Trial97
2020-11-04 17:05:32 +02:00
committed by Dan Christian Bogos
parent eb57017632
commit 568df81745
101 changed files with 1527 additions and 926 deletions

View File

@@ -116,7 +116,7 @@ func (cdrS *CDRServer) ListenAndServe(stopChan chan struct{}) (err error) {
}
// RegisterHandlersToServer is called by cgr-engine to register HTTP URL handlers
func (cdrS *CDRServer) RegisterHandlersToServer(server *utils.Server) {
func (cdrS *CDRServer) RegisterHandlersToServer(server utils.Server) {
server.RegisterHttpFunc(cdrS.cgrCfg.HTTPCfg().HTTPCDRsURL, cdrS.cgrCdrHandler)
server.RegisterHttpFunc(cdrS.cgrCfg.HTTPCfg().HTTPFreeswitchCDRsURL, cdrS.fsCdrHandler)
}

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 engine
import (
"fmt"
"runtime"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
func NewCoreService() *CoreService {
return &CoreService{}
}
type CoreService struct{}
// ListenAndServe will initialize the service
func (cS *CoreService) ListenAndServe(exitChan chan bool) (err error) {
utils.Logger.Info("Starting Core service")
e := <-exitChan
exitChan <- e // put back for the others listening for shutdown request
return
}
// Shutdown is called to shutdown the service
func (cS *CoreService) Shutdown() (err error) {
utils.Logger.Info(fmt.Sprintf("<%s> shutdown initialized", utils.CoreS))
utils.Logger.Info(fmt.Sprintf("<%s> shutdown complete", utils.CoreS))
return
}
func (cS *CoreService) Status(arg *utils.TenantWithOpts, reply *map[string]interface{}) (err error) {
memstats := new(runtime.MemStats)
runtime.ReadMemStats(memstats)
response := make(map[string]interface{})
response[utils.NodeID] = config.CgrConfig().GeneralCfg().NodeID
response[utils.MemoryUsage] = utils.SizeFmt(float64(memstats.HeapAlloc), "")
response[utils.ActiveGoroutines] = runtime.NumGoroutine()
if response[utils.Version], err = utils.GetCGRVersion(); err != nil {
utils.Logger.Err(err.Error())
err = nil
}
response[utils.RunningSince] = utils.GetStartTime()
response[utils.GoVersion] = runtime.Version()
*reply = response
return
}

View File

@@ -521,6 +521,7 @@ func GetDefaultEmptyCacheStats() map[string]*ltcache.CacheStats {
utils.CacheEventCharges: {},
utils.CacheReverseFilterIndexes: {},
utils.MetaAPIBan: {},
utils.CacheCapsEvents: {},
utils.CacheAccounts: {},
utils.CacheVersions: {},

View File

@@ -604,14 +604,14 @@ func (attr *ArgsGetRoutes) Clone() *ArgsGetRoutes {
}
}
func (args *ArgsGetRoutes) asOptsGetRoutes() (opts *optsGetRoutes, err error) {
opts = &optsGetRoutes{ignoreErrors: args.IgnoreErrors}
if args.MaxCost == utils.MetaEventCost { // dynamic cost needs to be calculated from event
if err = args.CGREvent.CheckMandatoryFields([]string{utils.Account,
func (attr *ArgsGetRoutes) asOptsGetRoutes() (opts *optsGetRoutes, err error) {
opts = &optsGetRoutes{ignoreErrors: attr.IgnoreErrors}
if attr.MaxCost == utils.MetaEventCost { // dynamic cost needs to be calculated from event
if err = attr.CGREvent.CheckMandatoryFields([]string{utils.Account,
utils.Destination, utils.SetupTime, utils.Usage}); err != nil {
return
}
cd, err := NewCallDescriptorFromCGREvent(args.CGREvent,
cd, err := NewCallDescriptorFromCGREvent(attr.CGREvent,
config.CgrConfig().GeneralCfg().DefaultTimezone)
if err != nil {
return nil, err
@@ -621,8 +621,8 @@ func (args *ArgsGetRoutes) asOptsGetRoutes() (opts *optsGetRoutes, err error) {
return nil, err
}
opts.maxCost = cc.Cost
} else if args.MaxCost != "" {
if opts.maxCost, err = strconv.ParseFloat(args.MaxCost,
} else if attr.MaxCost != "" {
if opts.maxCost, err = strconv.ParseFloat(attr.MaxCost,
64); err != nil {
return nil, err
}

View File

@@ -119,7 +119,7 @@ func (se *SafEvent) GetString(fldName string) (out string, err error) {
return
}
func (se SafEvent) GetTInt64(fldName string) (out int64, err error) {
func (se *SafEvent) GetTInt64(fldName string) (out int64, err error) {
se.RLock()
out, err = se.Me.GetTInt64(fldName)
se.RUnlock()

View File

@@ -70,7 +70,7 @@ func (sg *SharedGroup) Clone() (sharedGroup *SharedGroup) {
if sg.MemberIds != nil {
sharedGroup.MemberIds = sg.MemberIds.Clone()
}
for id, _ := range sg.AccountParameters {
for id := range sg.AccountParameters {
sharedGroup.AccountParameters[id] = sg.AccountParameters[id].Clone()
}
return