Add maxReconnectInterval for DispatcherHost csv models

This commit is contained in:
ionutboangiu
2022-05-25 18:26:56 +03:00
committed by Dan Christian Bogos
parent ec7d1d3ebc
commit 77430ee80a
14 changed files with 121 additions and 109 deletions

View File

@@ -278,8 +278,8 @@ cgrates.org,D1,*any,*string:~*req.Account:1001,2014-07-29T15:00:00Z,*first,,C1,*
cgrates.org,D1,,,,*first,,C2,*lt:~*req.Usage:10,10,false,192.168.56.204,
`
DispatcherHostCSVContent = `
#Tenant[0],ID[1],Address[2],Transport[3],ConnectAttempts[4],Reconnects[5],ConnectTimeout[6],ReplyTimeout[7],Tls[8],ClientKey[9],ClientCertificate[10],CaCertificate[11]
cgrates.org,ALL,127.0.0.1:6012,*json,1,3,1m,2m,false,,,
#Tenant[0],ID[1],Address[2],Transport[3],ConnectAttempts[4],Reconnects[5],MaxReconnectInterval[6],ConnectTimeout[7],ReplyTimeout[8],Tls[9],ClientKey[10],ClientCertificate[11],CaCertificate[12]
cgrates.org,ALL,127.0.0.1:6012,*json,1,3,5m,1m,2m,false,,,
`
)

View File

@@ -1398,13 +1398,14 @@ func TestLoadDispatcherHosts(t *testing.T) {
Tenant: "cgrates.org",
ID: "ALL",
Conn: &utils.TPDispatcherHostConn{
Address: "127.0.0.1:6012",
Transport: utils.MetaJSON,
ConnectAttempts: 1,
Reconnects: 3,
ConnectTimeout: 1 * time.Minute,
ReplyTimeout: 2 * time.Minute,
TLS: false,
Address: "127.0.0.1:6012",
Transport: utils.MetaJSON,
ConnectAttempts: 1,
Reconnects: 3,
MaxReconnectInterval: 5 * time.Minute,
ConnectTimeout: 1 * time.Minute,
ReplyTimeout: 2 * time.Minute,
TLS: false,
},
}

View File

@@ -2804,7 +2804,7 @@ type DispatcherHostMdls []*DispatcherHostMdl
// CSVHeader return the header for csv fields as a slice of string
func (tps DispatcherHostMdls) CSVHeader() (result []string) {
return []string{"#" + utils.Tenant, utils.ID, utils.Address, utils.Transport, utils.SynchronousCfg, utils.ConnectAttemptsCfg, utils.ReconnectsCfg, utils.ConnectTimeoutCfg, utils.ReplyTimeoutCfg, utils.TLS, utils.ClientKeyCfg, utils.ClientCerificateCfg, utils.CaCertificateCfg}
return []string{"#" + utils.Tenant, utils.ID, utils.Address, utils.Transport, utils.SynchronousCfg, utils.ConnectAttemptsCfg, utils.ReconnectsCfg, utils.MaxReconnectIntervalCfg, utils.ConnectTimeoutCfg, utils.ReplyTimeoutCfg, utils.TLS, utils.ClientKeyCfg, utils.ClientCerificateCfg, utils.CaCertificateCfg}
}
func (tps DispatcherHostMdls) AsTPDispatcherHosts() (result []*utils.TPDispatcherHost, err error) {
@@ -2832,6 +2832,11 @@ func (tps DispatcherHostMdls) AsTPDispatcherHosts() (result []*utils.TPDispatche
CaCertificate: tp.CaCertificate,
},
}
if tp.MaxReconnectInterval != utils.EmptyString {
if hostsMap[tntId].Conn.MaxReconnectInterval, err = utils.ParseDurationWithNanosecs(tp.MaxReconnectInterval); err != nil {
return nil, err
}
}
if tp.ConnectTimeout != utils.EmptyString {
if hostsMap[tntId].Conn.ConnectTimeout, err = utils.ParseDurationWithNanosecs(tp.ConnectTimeout); err != nil {
return nil, err
@@ -2855,19 +2860,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,
ConnectAttempts: tpDPH.Conn.ConnectAttempts,
Reconnects: tpDPH.Conn.Reconnects,
ConnectTimeout: tpDPH.Conn.ConnectTimeout.String(),
ReplyTimeout: tpDPH.Conn.ReplyTimeout.String(),
TLS: tpDPH.Conn.TLS,
ClientKey: tpDPH.Conn.ClientKey,
ClientCertificate: tpDPH.Conn.ClientCertificate,
CaCertificate: tpDPH.Conn.CaCertificate,
Tpid: tpDPH.TPid,
Tenant: tpDPH.Tenant,
ID: tpDPH.ID,
Address: tpDPH.Conn.Address,
Transport: tpDPH.Conn.Transport,
ConnectAttempts: tpDPH.Conn.ConnectAttempts,
Reconnects: tpDPH.Conn.Reconnects,
MaxReconnectInterval: tpDPH.Conn.MaxReconnectInterval.String(),
ConnectTimeout: tpDPH.Conn.ConnectTimeout.String(),
ReplyTimeout: tpDPH.Conn.ReplyTimeout.String(),
TLS: tpDPH.Conn.TLS,
ClientKey: tpDPH.Conn.ClientKey,
ClientCertificate: tpDPH.Conn.ClientCertificate,
CaCertificate: tpDPH.Conn.CaCertificate,
}
}
@@ -2878,17 +2884,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,
ConnectAttempts: tpDPH.Conn.ConnectAttempts,
Reconnects: tpDPH.Conn.Reconnects,
ConnectTimeout: tpDPH.Conn.ConnectTimeout,
ReplyTimeout: tpDPH.Conn.ReplyTimeout,
TLS: tpDPH.Conn.TLS,
ClientKey: tpDPH.Conn.ClientKey,
ClientCertificate: tpDPH.Conn.ClientCertificate,
CaCertificate: tpDPH.Conn.CaCertificate,
ID: tpDPH.ID,
Address: tpDPH.Conn.Address,
Transport: tpDPH.Conn.Transport,
ConnectAttempts: tpDPH.Conn.ConnectAttempts,
Reconnects: tpDPH.Conn.Reconnects,
MaxReconnectInterval: tpDPH.Conn.MaxReconnectInterval,
ConnectTimeout: tpDPH.Conn.ConnectTimeout,
ReplyTimeout: tpDPH.Conn.ReplyTimeout,
TLS: tpDPH.Conn.TLS,
ClientKey: tpDPH.Conn.ClientKey,
ClientCertificate: tpDPH.Conn.ClientCertificate,
CaCertificate: tpDPH.Conn.CaCertificate,
},
}
}
@@ -2898,16 +2905,17 @@ func DispatcherHostToAPI(dph *DispatcherHost) (tpDPH *utils.TPDispatcherHost) {
Tenant: dph.Tenant,
ID: dph.ID,
Conn: &utils.TPDispatcherHostConn{
Address: dph.Address,
Transport: dph.Transport,
ConnectAttempts: dph.ConnectAttempts,
Reconnects: dph.Reconnects,
ConnectTimeout: dph.ConnectTimeout,
ReplyTimeout: dph.ReplyTimeout,
TLS: dph.TLS,
ClientKey: dph.ClientKey,
ClientCertificate: dph.ClientCertificate,
CaCertificate: dph.CaCertificate,
Address: dph.Address,
Transport: dph.Transport,
ConnectAttempts: dph.ConnectAttempts,
Reconnects: dph.Reconnects,
MaxReconnectInterval: dph.MaxReconnectInterval,
ConnectTimeout: dph.ConnectTimeout,
ReplyTimeout: dph.ReplyTimeout,
TLS: dph.TLS,
ClientKey: dph.ClientKey,
ClientCertificate: dph.ClientCertificate,
CaCertificate: dph.CaCertificate,
},
}
}

View File

@@ -3825,7 +3825,7 @@ func TestAPItoModelTPDispatcher(t *testing.T) {
func TestTPDispatcherHostsCSVHeader(t *testing.T) {
tps := &DispatcherHostMdls{}
eOut := []string{"#" + utils.Tenant, utils.ID, utils.Address, utils.Transport, utils.SynchronousCfg, utils.ConnectAttemptsCfg, utils.ReconnectsCfg, utils.ConnectTimeoutCfg, utils.ReplyTimeoutCfg, utils.TLS, utils.ClientKeyCfg, utils.ClientCerificateCfg, utils.CaCertificateCfg}
eOut := []string{"#" + utils.Tenant, utils.ID, utils.Address, utils.Transport, utils.SynchronousCfg, utils.ConnectAttemptsCfg, utils.ReconnectsCfg, utils.MaxReconnectIntervalCfg, utils.ConnectTimeoutCfg, utils.ReplyTimeoutCfg, utils.TLS, utils.ClientKeyCfg, utils.ClientCerificateCfg, utils.CaCertificateCfg}
if rcv := tps.CSVHeader(); !reflect.DeepEqual(rcv, eOut) {
t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv))
}
@@ -3987,18 +3987,19 @@ func TestAPItoModelTPDispatcherHost(t *testing.T) {
},
}
eOut := &DispatcherHostMdl{
Address: "Address1",
Transport: "*json",
Tenant: "Tenant",
ID: "ID",
ConnectAttempts: 3,
Reconnects: 5,
ConnectTimeout: "1m0s",
ReplyTimeout: "2m0s",
TLS: true,
ClientKey: "client_key",
ClientCertificate: "client_certificate",
CaCertificate: "ca_certificate",
Address: "Address1",
Transport: "*json",
Tenant: "Tenant",
ID: "ID",
ConnectAttempts: 3,
Reconnects: 5,
MaxReconnectInterval: "0s",
ConnectTimeout: "1m0s",
ReplyTimeout: "2m0s",
TLS: true,
ClientKey: "client_key",
ClientCertificate: "client_certificate",
CaCertificate: "ca_certificate",
}
if rcv := APItoModelTPDispatcherHost(tpDPH); !reflect.DeepEqual(eOut, rcv) {
t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv))

View File

@@ -496,21 +496,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:""`
ConnectAttempts int `index:"4" re:""`
Reconnects int `index:"5" re:""`
ConnectTimeout string `index:"6" re:""`
ReplyTimeout string `index:"7" re:""`
TLS bool `index:"8" re:""`
ClientKey string `index:"9" re:""`
ClientCertificate string `index:"10" re:""`
CaCertificate string `index:"11" 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:""`
ConnectAttempts int `index:"4" re:""`
Reconnects int `index:"5" re:""`
MaxReconnectInterval string `index:"6" re:""`
ConnectTimeout string `index:"7" re:""`
ReplyTimeout string `index:"8" re:""`
TLS bool `index:"9" re:""`
ClientKey string `index:"10" re:""`
ClientCertificate string `index:"11" re:""`
CaCertificate string `index:"12" re:""`
CreatedAt time.Time
}
func (DispatcherHostMdl) TableName() string {