From 7299b091073bb651775d7b64758dff8a2578720a Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Tue, 28 Jun 2022 17:14:03 +0300 Subject: [PATCH] Add max_reconnect_interval for dispatcherhost csv models --- apis/loaders_it_test.go | 8 +- .../mysql/create_tariffplan_tables.sql | 1 + .../postgres/create_tariffplan_tables.sql | 1 + .../dispatcher_engine/DispatcherHosts.csv | 4 +- .../dispatcher_engine2/DispatcherHosts.csv | 6 +- .../dispatcher_engine/DispatcherHosts.csv | 6 +- .../dispatcher_engine2/DispatcherHosts.csv | 6 +- .../dispatchers/DispatcherHosts.csv | 10 +- .../dispatchers_gob/DispatcherHosts.csv | 10 +- .../gocs/dsp_site/DispatcherHosts.csv | 8 +- data/tariffplans/precache/DispatcherHosts.csv | 4 +- engine/libtest.go | 4 +- engine/loader_csv_test.go | 15 +- engine/model_helpers.go | 76 ++++---- engine/model_helpers_test.go | 178 +++++++++--------- engine/models.go | 31 +-- utils/apitpdata.go | 21 ++- 17 files changed, 205 insertions(+), 184 deletions(-) diff --git a/apis/loaders_it_test.go b/apis/loaders_it_test.go index 87b3dab33..84e2fcab8 100644 --- a/apis/loaders_it_test.go +++ b/apis/loaders_it_test.go @@ -250,10 +250,10 @@ cgrates.org,D2,*string:~*req.Account:1002,20,,,C2,fltr3,10,,param3:value3 // Create and populate DispatcherHosts.csv if err := writeFile(utils.DispatcherHostsCsv, ` -#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,,,,,,,,,, -cgrates.org,ALL,127.0.0.1:6012,,1,3,1m,2m,true,,, -cgrates.org,ALL,,*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,,,,,,,,,,, +cgrates.org,ALL,127.0.0.1:6012,,1,3,,1m,2m,true,,, +cgrates.org,ALL,,*json,1,3,,1m,2m,false,,, `); err != nil { t.Fatal(err) } diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 4fe77d7a8..99bf8eb90 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -217,6 +217,7 @@ CREATE TABLE tp_dispatcher_hosts ( `transport` varchar(64) NOT NULL, `connect_attempts` int(11) NOT NULL, `reconnects` int(11) NOT NULL, + `max_reconnect_interval` varchar(64) NOT NULL, `connect_timeout` varchar(64) NOT NULL, `reply_timeout` varchar(64) NOT NULL, `tls` BOOLEAN NOT NULL, diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index ac41e4715..218760e34 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -209,6 +209,7 @@ CREATE INDEX tp_routes_unique ON tp_routes ("tpid", "tenant", "id", "transport" varchar(64) NOT NULL, "connect_attempts" INTEGER NOT NULL, "reconnects" INTEGER NOT NULL, + "max_reconnect_interval" varchar(64) NOT NULL, "connect_timeout" varchar(64) NOT NULL, "reply_timeout" varchar(64) NOT NULL, "tls" BOOLEAN NOT NULL, diff --git a/data/tariffplans/cache_replications/dispatcher_engine/DispatcherHosts.csv b/data/tariffplans/cache_replications/dispatcher_engine/DispatcherHosts.csv index 18ae171bc..c2bfc8d2f 100644 --- a/data/tariffplans/cache_replications/dispatcher_engine/DispatcherHosts.csv +++ b/data/tariffplans/cache_replications/dispatcher_engine/DispatcherHosts.csv @@ -1,2 +1,2 @@ -#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,Engine1,127.0.0.1:6012,*json,1,3,"1m","2m",false,,, \ No newline at end of file +#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,Engine1,127.0.0.1:6012,*json,1,3,,"1m","2m",false,,, \ No newline at end of file diff --git a/data/tariffplans/cache_replications/dispatcher_engine2/DispatcherHosts.csv b/data/tariffplans/cache_replications/dispatcher_engine2/DispatcherHosts.csv index ab80c356c..a237ab4b6 100644 --- a/data/tariffplans/cache_replications/dispatcher_engine2/DispatcherHosts.csv +++ b/data/tariffplans/cache_replications/dispatcher_engine2/DispatcherHosts.csv @@ -1,3 +1,3 @@ -#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,Self,*internal,,1,3,"1m","2m",false,,, -cgrates.org,Engine1,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,Self,*internal,,1,3,,"1m","2m",false,,, +cgrates.org,Engine1,127.0.0.1:6012,*json,1,3,,"1m","2m",false,,, diff --git a/data/tariffplans/cache_rpl_active_active/dispatcher_engine/DispatcherHosts.csv b/data/tariffplans/cache_rpl_active_active/dispatcher_engine/DispatcherHosts.csv index ab80c356c..a237ab4b6 100644 --- a/data/tariffplans/cache_rpl_active_active/dispatcher_engine/DispatcherHosts.csv +++ b/data/tariffplans/cache_rpl_active_active/dispatcher_engine/DispatcherHosts.csv @@ -1,3 +1,3 @@ -#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,Self,*internal,,1,3,"1m","2m",false,,, -cgrates.org,Engine1,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,Self,*internal,,1,3,,"1m","2m",false,,, +cgrates.org,Engine1,127.0.0.1:6012,*json,1,3,,"1m","2m",false,,, diff --git a/data/tariffplans/cache_rpl_active_active/dispatcher_engine2/DispatcherHosts.csv b/data/tariffplans/cache_rpl_active_active/dispatcher_engine2/DispatcherHosts.csv index 14b35598a..368049bd3 100644 --- a/data/tariffplans/cache_rpl_active_active/dispatcher_engine2/DispatcherHosts.csv +++ b/data/tariffplans/cache_rpl_active_active/dispatcher_engine2/DispatcherHosts.csv @@ -1,3 +1,3 @@ -#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,Self,*internal,,1,3,"1m","2m",false,,, -cgrates.org,Engine1,127.0.0.1:6012,*json,1,3,"1m","2m",false,,, \ No newline at end of file +#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,Self,*internal,,1,3,,"1m","2m",false,,, +cgrates.org,Engine1,127.0.0.1:6012,*json,1,3,,"1m","2m",false,,, \ No newline at end of file diff --git a/data/tariffplans/dispatchers/DispatcherHosts.csv b/data/tariffplans/dispatchers/DispatcherHosts.csv index 94924cee0..f61624ed2 100644 --- a/data/tariffplans/dispatchers/DispatcherHosts.csv +++ b/data/tariffplans/dispatchers/DispatcherHosts.csv @@ -1,5 +1,5 @@ -#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,SELF,*internal,,1,3,"1m","2m",false,,, -cgrates.org,ALL,127.0.0.1:6012,*json,1,3,"1m","2m",false,,, -cgrates.org,ALL2,127.0.0.1:7012,*json,1,3,"1m","2m",false,,, -cgrates.org,NonexistingHost,127.0.0.1:10012,*json,1,3,"1m","2m",false,,, \ No newline at end of file +#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,SELF,*internal,,1,3,,"1m","2m",false,,, +cgrates.org,ALL,127.0.0.1:6012,*json,1,3,,"1m","2m",false,,, +cgrates.org,ALL2,127.0.0.1:7012,*json,1,3,,"1m","2m",false,,, +cgrates.org,NonexistingHost,127.0.0.1:10012,*json,1,3,,"1m","2m",false,,, \ No newline at end of file diff --git a/data/tariffplans/dispatchers_gob/DispatcherHosts.csv b/data/tariffplans/dispatchers_gob/DispatcherHosts.csv index 7476906b7..fc24a9a96 100644 --- a/data/tariffplans/dispatchers_gob/DispatcherHosts.csv +++ b/data/tariffplans/dispatchers_gob/DispatcherHosts.csv @@ -1,5 +1,5 @@ -#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,SELF,*internal,,1,3,"1m","2m",false,,, -cgrates.org,ALL,127.0.0.1:6013,*gob,1,3,"1m","2m",false,,, -cgrates.org,ALL2,127.0.0.1:7013,*gob,1,3,"1m","2m",false,,, -cgrates.org,NonexistingHost,127.0.0.1:10012,*json,1,3,"1m","2m",false,,, \ No newline at end of file +#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,SELF,*internal,,1,3,,"1m","2m",false,,, +cgrates.org,ALL,127.0.0.1:6013,*gob,1,3,,"1m","2m",false,,, +cgrates.org,ALL2,127.0.0.1:7013,*gob,1,3,,"1m","2m",false,,, +cgrates.org,NonexistingHost,127.0.0.1:10012,*json,1,3,,"1m","2m",false,,, \ No newline at end of file diff --git a/data/tariffplans/gocs/dsp_site/DispatcherHosts.csv b/data/tariffplans/gocs/dsp_site/DispatcherHosts.csv index ca46a1ccf..75a0e0bc2 100644 --- a/data/tariffplans/gocs/dsp_site/DispatcherHosts.csv +++ b/data/tariffplans/gocs/dsp_site/DispatcherHosts.csv @@ -1,4 +1,4 @@ -#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,AU_SITE,127.0.0.1:3012,*json,1,3,"1m","2m",false,,, -cgrates.org,US_SITE,127.0.0.1:4012,*json,1,3,"1m","2m",false,,, -cgrates.org,SELF,*internal,,1,3,"1m","2m",false,,, \ No newline at end of file +#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,AU_SITE,127.0.0.1:3012,*json,1,3,,"1m","2m",false,,, +cgrates.org,US_SITE,127.0.0.1:4012,*json,1,3,,"1m","2m",false,,, +cgrates.org,SELF,*internal,,1,3,,"1m","2m",false,,, \ No newline at end of file diff --git a/data/tariffplans/precache/DispatcherHosts.csv b/data/tariffplans/precache/DispatcherHosts.csv index f3bd855e4..15275cb62 100644 --- a/data/tariffplans/precache/DispatcherHosts.csv +++ b/data/tariffplans/precache/DispatcherHosts.csv @@ -1,2 +1,2 @@ -#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,SELF,*internal,,1,3,"1m","2m",false,,, \ No newline at end of file +#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,SELF,*internal,,1,3,,"1m","2m",false,,, \ No newline at end of file diff --git a/engine/libtest.go b/engine/libtest.go index 1a59387c8..0d5946045 100644 --- a/engine/libtest.go +++ b/engine/libtest.go @@ -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 diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index db7d13fe8..38fed288b 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -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, }, } diff --git a/engine/model_helpers.go b/engine/model_helpers.go index b2e9f3700..d4dad1166 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -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, }, } } diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index 38045899e..58d6225b2 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -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) { diff --git a/engine/models.go b/engine/models.go index b518ac33e..02a83be1a 100644 --- a/engine/models.go +++ b/engine/models.go @@ -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 { diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 080541ebb..e67ab669b 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -375,16 +375,17 @@ type TPDispatcherHost struct { // TPDispatcherHostConn is used in TPDispatcherHost type TPDispatcherHostConn struct { - Address string - Transport string - ConnectAttempts int - Reconnects int - ConnectTimeout time.Duration - ReplyTimeout time.Duration - TLS bool - ClientKey string - ClientCertificate string - CaCertificate string + Address string + Transport string + ConnectAttempts int + Reconnects int + MaxReconnectInterval time.Duration + ConnectTimeout time.Duration + ReplyTimeout time.Duration + TLS bool + ClientKey string + ClientCertificate string + CaCertificate string } type AttrRemoteLock struct {