Add max_reconnect_interval for dispatcherhost csv models

This commit is contained in:
ionutboangiu
2022-06-28 17:14:03 +03:00
committed by Dan Christian Bogos
parent a1f8bff851
commit 7299b09107
17 changed files with 205 additions and 184 deletions

View File

@@ -134,8 +134,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],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,,1m,2m,false,,,
`
RateProfileCSVContent = `
#Tenant,ID,FilterIDs,Weights,MinCost,MaxCost,MaxCostStrategy,RateID,RateFilterIDs,RateActivationStart,RateWeights,RateBlocker,RateIntervalStart,RateFixedFee,RateRecurrentFee,RateUnit,RateIncrement

View File

@@ -663,13 +663,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

@@ -1713,6 +1713,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
@@ -1736,19 +1741,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,
}
}
@@ -1759,17 +1765,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,
},
}
}
@@ -1779,16 +1786,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

@@ -1883,34 +1883,36 @@ func TestTPDispatcherHostsAsTPDispatcherHosts(t *testing.T) {
tps = &DispatcherHostMdls{
&DispatcherHostMdl{
ID: "ID1",
Tenant: "Tenant1",
Address: "localhost:6012",
Transport: "*json",
ConnectAttempts: 2,
Reconnects: 5,
ConnectTimeout: "2m",
ReplyTimeout: "1m",
TLS: true,
ClientKey: "client_key",
ClientCertificate: "client_certificate",
CaCertificate: "ca_certificate",
ID: "ID1",
Tenant: "Tenant1",
Address: "localhost:6012",
Transport: "*json",
ConnectAttempts: 2,
Reconnects: 5,
MaxReconnectInterval: "5m",
ConnectTimeout: "2m",
ReplyTimeout: "1m",
TLS: true,
ClientKey: "client_key",
ClientCertificate: "client_certificate",
CaCertificate: "ca_certificate",
}}
eOut := []*utils.TPDispatcherHost{
{
Tenant: "Tenant1",
ID: "ID1",
Conn: &utils.TPDispatcherHostConn{
Address: "localhost:6012",
Transport: "*json",
ConnectAttempts: 2,
Reconnects: 5,
ConnectTimeout: 2 * time.Minute,
ReplyTimeout: 1 * time.Minute,
TLS: true,
ClientKey: "client_key",
ClientCertificate: "client_certificate",
CaCertificate: "ca_certificate",
Address: "localhost:6012",
Transport: "*json",
ConnectAttempts: 2,
Reconnects: 5,
MaxReconnectInterval: 5 * time.Minute,
ConnectTimeout: 2 * time.Minute,
ReplyTimeout: 1 * time.Minute,
TLS: true,
ClientKey: "client_key",
ClientCertificate: "client_certificate",
CaCertificate: "ca_certificate",
},
},
}
@@ -2005,31 +2007,33 @@ func TestAPItoModelTPDispatcherHost(t *testing.T) {
Tenant: "Tenant",
ID: "ID",
Conn: &utils.TPDispatcherHostConn{
Address: "Address1",
Transport: "*json",
ConnectAttempts: 3,
Reconnects: 5,
ConnectTimeout: 1 * time.Minute,
ReplyTimeout: 2 * time.Minute,
TLS: true,
ClientKey: "client_key",
ClientCertificate: "client_certificate",
CaCertificate: "ca_certificate",
Address: "Address1",
Transport: "*json",
ConnectAttempts: 3,
Reconnects: 5,
MaxReconnectInterval: 5 * time.Minute,
ConnectTimeout: 1 * time.Minute,
ReplyTimeout: 2 * time.Minute,
TLS: true,
ClientKey: "client_key",
ClientCertificate: "client_certificate",
CaCertificate: "ca_certificate",
},
}
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: "5m0s",
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))
@@ -2047,33 +2051,35 @@ func TestAPItoDispatcherHost(t *testing.T) {
Tenant: "Tenant1",
ID: "ID1",
Conn: &utils.TPDispatcherHostConn{
Address: "localhost:6012",
Transport: "*json",
ConnectAttempts: 3,
Reconnects: 5,
ConnectTimeout: 1 * time.Minute,
ReplyTimeout: 2 * time.Minute,
TLS: true,
ClientKey: "client_key",
ClientCertificate: "client_certificate",
CaCertificate: "ca_certificate",
Address: "localhost:6012",
Transport: "*json",
ConnectAttempts: 3,
Reconnects: 5,
MaxReconnectInterval: 5 * time.Minute,
ConnectTimeout: 1 * time.Minute,
ReplyTimeout: 2 * time.Minute,
TLS: true,
ClientKey: "client_key",
ClientCertificate: "client_certificate",
CaCertificate: "ca_certificate",
},
}
eOut := &DispatcherHost{
Tenant: "Tenant1",
RemoteHost: &config.RemoteHost{
ID: "ID1",
Address: "localhost:6012",
Transport: "*json",
Reconnects: 5,
ConnectTimeout: 1 * time.Minute,
ReplyTimeout: 2 * time.Minute,
TLS: true,
ClientKey: "client_key",
ClientCertificate: "client_certificate",
CaCertificate: "ca_certificate",
ConnectAttempts: 3,
ID: "ID1",
Address: "localhost:6012",
Transport: "*json",
Reconnects: 5,
MaxReconnectInterval: 5 * time.Minute,
ConnectTimeout: 1 * time.Minute,
ReplyTimeout: 2 * time.Minute,
TLS: true,
ClientKey: "client_key",
ClientCertificate: "client_certificate",
CaCertificate: "ca_certificate",
ConnectAttempts: 3,
},
}
if rcv := APItoDispatcherHost(tpDPH); !reflect.DeepEqual(eOut, rcv) {
@@ -2107,31 +2113,33 @@ func TestDispatcherHostToAPI(t *testing.T) {
dph := &DispatcherHost{
Tenant: "Tenant1",
RemoteHost: &config.RemoteHost{
Address: "127.0.0.1:2012",
Transport: "*json",
ConnectAttempts: 0,
Reconnects: 0,
ConnectTimeout: 1 * time.Minute,
ReplyTimeout: 1 * time.Minute,
TLS: false,
ClientKey: "",
ClientCertificate: "",
CaCertificate: "",
Address: "127.0.0.1:2012",
Transport: "*json",
ConnectAttempts: 0,
Reconnects: 0,
MaxReconnectInterval: 5 * time.Minute,
ConnectTimeout: 1 * time.Minute,
ReplyTimeout: 1 * time.Minute,
TLS: false,
ClientKey: "",
ClientCertificate: "",
CaCertificate: "",
},
}
eOut := &utils.TPDispatcherHost{
Tenant: "Tenant1",
Conn: &utils.TPDispatcherHostConn{
Address: "127.0.0.1:2012",
Transport: "*json",
ConnectAttempts: 0,
Reconnects: 0,
ConnectTimeout: 1 * time.Minute,
ReplyTimeout: 1 * time.Minute,
TLS: false,
ClientKey: "",
ClientCertificate: "",
CaCertificate: "",
Address: "127.0.0.1:2012",
Transport: "*json",
ConnectAttempts: 0,
Reconnects: 0,
MaxReconnectInterval: 5 * time.Minute,
ConnectTimeout: 1 * time.Minute,
ReplyTimeout: 1 * time.Minute,
TLS: false,
ClientKey: "",
ClientCertificate: "",
CaCertificate: "",
},
}
if rcv := DispatcherHostToAPI(dph); !reflect.DeepEqual(eOut, rcv) {

View File

@@ -276,21 +276,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 {