From d8a803db0b75673d8017671772bf2d96718e251b Mon Sep 17 00:00:00 2001 From: nickolasdaniel Date: Tue, 13 Jul 2021 17:36:27 +0300 Subject: [PATCH] Added extra fields for DispatcherHost such as in RemoteHost in rpcconn.go --- engine/libtest.go | 4 +- engine/loader_csv_test.go | 19 +++++++--- engine/model_helpers.go | 77 ++++++++++++++++++++++++++++++--------- engine/models.go | 24 ++++++++---- utils/apitpdata.go | 14 +++++-- 5 files changed, 102 insertions(+), 36 deletions(-) diff --git a/engine/libtest.go b/engine/libtest.go index fbc53cb19..21790e362 100644 --- a/engine/libtest.go +++ b/engine/libtest.go @@ -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 diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 4ff519994..1a4ed1693 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -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)) } diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 3fac49a68..58b513fff 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -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, }, } } diff --git a/engine/models.go b/engine/models.go index b20bd3f1f..a8313c236 100644 --- a/engine/models.go +++ b/engine/models.go @@ -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 { diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 0b04f9425..5fbc5b4e9 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -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 {