Added extra fields for DispatcherHost such as in RemoteHost in rpcconn.go

This commit is contained in:
nickolasdaniel
2021-07-13 17:36:27 +03:00
committed by Dan Christian Bogos
parent 89f9a9bffd
commit d8a803db0b
5 changed files with 102 additions and 36 deletions

View File

@@ -135,8 +135,8 @@ cgrates.org,D1,*string:~*req.Account:1001,20,*first,,C1,*gt:~*req.Usage:10,10,fa
cgrates.org,D1,,,*first,,C2,*lt:~*req.Usage:10,10,false,192.168.56.204
`
DispatcherHostCSVContent = `
#Tenant[0],ID[1],Address[2],Transport[3],TLS[4]
cgrates.org,ALL1,127.0.0.1:2012,*json,true
#Tenant[0],ID[1],Address[2],Transport[3],Synchronous[4],ConnectAttempts[5],Reconnects[6],ConnectTimeout[7],ReplyTimeout[8],TLS[9],ClientKey[10],ClientCertificate[11],CaCertificate[12]
cgrates.org,ALL,127.0.0.1:6012,*json,false,1,3,1m,2m,true,key2,cert2,ca_cert2
`
RateProfileCSVContent = `
#Tenant,ID,FilterIDs,Weights,MinCost,MaxCost,MaxCostStrategy,RateID,RateFilterIDs,RateActivationStart,RateWeights,RateBlocker,RateIntervalStart,RateFixedFee,RateRecurrentFee,RateUnit,RateIncrement

View File

@@ -23,6 +23,7 @@ import (
"sort"
"strings"
"testing"
"time"
"github.com/cgrates/cgrates/utils"
)
@@ -659,15 +660,23 @@ func TestLoadDispatcherHosts(t *testing.T) {
eDispatcherHosts := &utils.TPDispatcherHost{
TPid: testTPID,
Tenant: "cgrates.org",
ID: "ALL1",
ID: "ALL",
Conn: &utils.TPDispatcherHostConn{
Address: "127.0.0.1:2012",
Transport: utils.MetaJSON,
TLS: true,
Address: "127.0.0.1:6012",
Transport: utils.MetaJSON,
Synchronous: false,
ConnectAttempts: 1,
Reconnects: 3,
ConnectTimeout: 2 * time.Minute,
ReplyTimeout: 2 * time.Minute,
TLS: true,
ClientKey: "key2",
ClientCertificate: "cert2",
CaCertificate: "ca_cert2",
},
}
dphKey := utils.TenantID{Tenant: "cgrates.org", ID: "ALL1"}
dphKey := utils.TenantID{Tenant: "cgrates.org", ID: "ALL"}
if len(csvr.dispatcherHosts) != 1 {
t.Fatalf("Failed to load DispatcherHosts: %v", len(csvr.dispatcherHosts))
}

View File

@@ -1595,7 +1595,7 @@ func (tps DispatcherHostMdls) CSVHeader() (result []string) {
return []string{"#" + utils.Tenant, utils.ID, utils.Address, utils.Transport, utils.TLS}
}
func (tps DispatcherHostMdls) AsTPDispatcherHosts() (result []*utils.TPDispatcherHost) {
func (tps DispatcherHostMdls) AsTPDispatcherHosts() (result []*utils.TPDispatcherHost, err error) {
hostsMap := make(map[string]*utils.TPDispatcherHost)
for _, tp := range tps {
if len(tp.Address) == 0 { // empty addres do not populate conns
@@ -1609,17 +1609,34 @@ func (tps DispatcherHostMdls) AsTPDispatcherHosts() (result []*utils.TPDispatche
Tenant: tp.Tenant,
ID: tp.ID,
Conn: &utils.TPDispatcherHostConn{
Address: tp.Address,
Transport: tp.Transport,
TLS: tp.TLS,
Address: tp.Address,
Transport: tp.Transport,
Synchronous: tp.Synchronous,
TLS: tp.TLS,
ConnectAttempts: tp.ConnAttempts,
// ConnectTimeout: tp.ConnectTimeout,
// ReplyTimeout: tp.ReplyTimeout,
ClientKey: tp.KeyPath,
ClientCertificate: tp.CertPath,
CaCertificate: tp.CaPath,
},
}
if tp.ConnectTimeout != utils.EmptyString {
if hostsMap[utils.ConcatenatedKey(tp.Tenant, tp.ID)].Conn.ConnectTimeout, err = utils.ParseDurationWithNanosecs(tp.ConnectTimeout); err != nil {
return nil, err
}
}
if tp.ReplyTimeout != utils.EmptyString {
if hostsMap[utils.ConcatenatedKey(tp.Tenant, tp.ID)].Conn.ReplyTimeout, err = utils.ParseDurationWithNanosecs(tp.ReplyTimeout); err != nil {
return nil, err
}
}
continue
}
for _, host := range hostsMap {
result = append(result, host)
}
return
return result, nil
}
func APItoModelTPDispatcherHost(tpDPH *utils.TPDispatcherHost) (mdls *DispatcherHostMdl) {
@@ -1627,12 +1644,20 @@ func APItoModelTPDispatcherHost(tpDPH *utils.TPDispatcherHost) (mdls *Dispatcher
return
}
return &DispatcherHostMdl{
Tpid: tpDPH.TPid,
Tenant: tpDPH.Tenant,
ID: tpDPH.ID,
Address: tpDPH.Conn.Address,
Transport: tpDPH.Conn.Transport,
TLS: tpDPH.Conn.TLS,
Tpid: tpDPH.TPid,
Tenant: tpDPH.Tenant,
ID: tpDPH.ID,
Address: tpDPH.Conn.Address,
Transport: tpDPH.Conn.Transport,
Synchronous: tpDPH.Conn.Synchronous,
ConnAttempts: tpDPH.Conn.ConnectAttempts,
Reconnects: tpDPH.Conn.Reconnects,
ConnectTimeout: tpDPH.Conn.ConnectTimeout,
ReplyTimeout: tpDPH.Conn.ReplyTimeout,
TLS: tpDPH.Conn.TLS,
KeyPath: tpDPH.Conn.ClientKey,
CertPath: tpDPH.Conn.ClientCertificate,
CaPath: tpDPH.Conn.CaCertificate,
}
}
@@ -1643,10 +1668,18 @@ func APItoDispatcherHost(tpDPH *utils.TPDispatcherHost) (dpp *DispatcherHost) {
return &DispatcherHost{
Tenant: tpDPH.Tenant,
RemoteHost: &config.RemoteHost{
ID: tpDPH.ID,
Address: tpDPH.Conn.Address,
Transport: tpDPH.Conn.Transport,
TLS: tpDPH.Conn.TLS,
ID: tpDPH.ID,
Address: tpDPH.Conn.Address,
Transport: tpDPH.Conn.Transport,
Synchronous: tpDPH.Conn.Synchronous,
ConnAttempts: tpDPH.Conn.ConnectAttempts,
Reconnects: tpDPH.Conn.Reconnects,
ConnectTimeout: tpDPH.Conn.ConnectTimeout,
ReplyTimeout: tpDPH.Conn.ReplyTimeout,
TLS: tpDPH.Conn.TLS,
KeyPath: tpDPH.Conn.ClientKey,
CertPath: tpDPH.Conn.ClientCertificate,
CaPath: tpDPH.Conn.CaCertificate,
},
}
}
@@ -1656,9 +1689,17 @@ func DispatcherHostToAPI(dph *DispatcherHost) (tpDPH *utils.TPDispatcherHost) {
Tenant: dph.Tenant,
ID: dph.ID,
Conn: &utils.TPDispatcherHostConn{
Address: dph.Address,
Transport: dph.Transport,
TLS: dph.TLS,
Address: dph.Address,
Transport: dph.Transport,
Synchronous: dph.Synchronous,
ConnectAttempts: dph.ConnAttempts,
Reconnects: dph.Reconnects,
ConnectTimeout: dph.ConnectTimeout,
ReplyTimeout: dph.ReplyTimeout,
TLS: dph.TLS,
ClientKey: dph.KeyPath,
ClientCertificate: dph.CertPath,
CaCertificate: dph.CaPath,
},
}
}

View File

@@ -274,14 +274,22 @@ func (DispatcherProfileMdl) TableName() string {
}
type DispatcherHostMdl struct {
PK uint `gorm:"primary_key"`
Tpid string //
Tenant string `index:"0" re:""`
ID string `index:"1" re:""`
Address string `index:"2" re:""`
Transport string `index:"3" re:""`
TLS bool `index:"4" re:""`
CreatedAt time.Time
PK uint `gorm:"primary_key"`
Tpid string //
Tenant string `index:"0" re:""`
ID string `index:"1" re:""`
Address string `index:"2" re:""`
Transport string `index:"3" re:""`
Synchronous bool `index:"4" re:""`
ConnAttempts int `index:"5" re:""`
Reconnects int `index:"6" re:""`
ConnectTimeout string `index:"7" re:""`
ReplyTimeout string `index:"8" re:""`
TLS bool `index:"9" re:""`
KeyPath string `index:"10" re:""`
CertPath string `index:"11" re:""`
CaPath string `index:"12" re:""`
CreatedAt time.Time
}
func (DispatcherHostMdl) TableName() string {

View File

@@ -704,9 +704,17 @@ type TPDispatcherHost struct {
// TPDispatcherHostConn is used in TPDispatcherHost
type TPDispatcherHostConn struct {
Address string
Transport string
TLS bool
Address string
Transport string
Synchronous bool
ConnectAttempts int
Reconnects int
ConnectTimeout time.Duration
ReplyTimeout time.Duration
TLS bool
ClientKey string
ClientCertificate string
CaCertificate string
}
type AttrRemoteLock struct {