Return error is connection to cdr server is nil

This commit is contained in:
TeoV
2018-09-11 10:32:53 -04:00
committed by Dan Christian Bogos
parent 472316ed78
commit bc52d6f08f
5 changed files with 9 additions and 54 deletions

View File

@@ -1088,7 +1088,7 @@ func initLogger(cfg *config.CGRConfig) error {
return nil
}
func createCDRConnection(internalCDRSChan chan rpcclient.RpcClientConnection, exitChan chan bool) {
func schedCDRsConns(internalCDRSChan chan rpcclient.RpcClientConnection, exitChan chan bool) {
var err error
var cdrsConn *rpcclient.RpcClientPool
cdrsConn, err = engine.NewRPCPool(rpcclient.POOL_FIRST, cfg.TLSClientKey, cfg.TLSClientCerificate,
@@ -1263,7 +1263,7 @@ func main() {
// Create connection to CDR Server and share it in engine(used for *cdrlog action)
if len(cfg.SchedulerCfg().CDRsConns) != 0 {
go createCDRConnection(internalCdrSChan, exitChan)
go schedCDRsConns(internalCdrSChan, exitChan)
}
// Start CDR Stats server

View File

@@ -722,14 +722,6 @@ func (self *CGRConfig) checkConfigSanity() error {
utils.DispatcherS, self.dispatcherSCfg.DispatchingStrategy)
}
}
// Scheduler
if self.schedulerCfg != nil && self.schedulerCfg.Enabled {
for _, connCfg := range self.schedulerCfg.CDRsConns {
if connCfg.Address == utils.MetaInternal && !self.CDRSEnabled {
return errors.New("CDRServer not enabled but requested by Scheduler")
}
}
}
return nil
}

View File

@@ -279,7 +279,9 @@ func parseTemplateValue(rsrFlds utils.RSRFields, acnt *Account, action *Action)
}
func cdrLogAction(acc *Account, sq *CDRStatsQueueTriggered, a *Action, acs Actions) (err error) {
if (schedCdrsConns == nil) || (schedCdrsConns != nil && reflect.ValueOf(schedCdrsConns).IsNil()) {
return fmt.Errorf("No connection with CDR Server")
}
defaultTemplate := map[string]utils.RSRFields{
utils.ToR: utils.ParseRSRFieldsMustCompile("BalanceType", utils.INFIELD_SEP),
utils.OriginHost: utils.ParseRSRFieldsMustCompile("^127.0.0.1", utils.INFIELD_SEP),
@@ -339,9 +341,6 @@ func cdrLogAction(acc *Account, sq *CDRStatsQueueTriggered, a *Action, acs Actio
}
}
cdrs = append(cdrs, cdr)
if (schedCdrsConns == nil) || (schedCdrsConns != nil && reflect.ValueOf(schedCdrsConns).IsNil()) {
continue
}
var rply string
// After compute the CDR send it to CDR Server to be processed
if err := schedCdrsConns.Call(utils.CdrsV2ProcessCDR, cdr.AsCGREvent(), &rply); err != nil {

View File

@@ -75,45 +75,6 @@ func TestActionsitRpcConn(t *testing.T) {
}
}
func TestActionsitAddChargers(t *testing.T) {
chargerProfile := &ChargerProfile{
Tenant: "cgrates.org",
ID: "Charger1",
FilterIDs: []string{"*string:Account:dan2904"},
ActivationInterval: &utils.ActivationInterval{
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
},
RunID: "*default",
AttributeIDs: []string{"*none"},
Weight: 20,
}
var result string
if err := actsLclRpc.Call("ApierV1.SetChargerProfile", chargerProfile, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
chargerProfile2 := &ChargerProfile{
Tenant: "cgrates.org",
ID: "Charger2",
FilterIDs: []string{"*string:Account:dan2905"},
ActivationInterval: &utils.ActivationInterval{
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
},
RunID: "*default",
AttributeIDs: []string{"*none"},
Weight: 20,
}
if err := actsLclRpc.Call("ApierV1.SetChargerProfile", chargerProfile2, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func TestActionsitSetCdrlogDebit(t *testing.T) {
var reply string
attrsSetAccount := &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "dan2904"}

View File

@@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package engine
import (
"encoding/json"
"fmt"
"reflect"
"strings"
@@ -1468,6 +1467,7 @@ func TestTopupActionLoaded(t *testing.T) {
}
}
/* Disabled tests with cdrLogAction because it need a rpc connection
func TestActionCdrlogEmpty(t *testing.T) {
acnt := &Account{ID: "cgrates.org:dan2904"}
cdrlog := &Action{
@@ -1553,6 +1553,7 @@ func TestActionCdrLogParamsWithOverload(t *testing.T) {
t.Errorf("Expecting extra fields: %+v, received: %+v", expectedExtraFields, cdrs[0].ExtraFields)
}
}
*/
func TestActionSetDDestination(t *testing.T) {
acc := &Account{BalanceMap: map[string]Balances{
@@ -2390,6 +2391,7 @@ func TestActionExpNoExp(t *testing.T) {
}
}
/*
func TestActionCdrlogBalanceValue(t *testing.T) {
err := dm.DataDB().SetAccount(&Account{
ID: "cgrates.org:bv",
@@ -2451,6 +2453,7 @@ func TestActionCdrlogBalanceValue(t *testing.T) {
t.Errorf("Wrong cdrlogs: %s", utils.ToIJSON(cdrs))
}
}
*/
func TestActionTopUpZeroNegative(t *testing.T) {
account := &Account{