mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added extra configurable fields for DispatcherHost related structs, corresponding tests and redesigned methods where needed
This commit is contained in:
committed by
Dan Christian Bogos
parent
bf78386bf2
commit
016e913190
@@ -1,5 +1,5 @@
|
||||
#Tenant[0],ID[1],Address[2],Transport[3],TLS[4]
|
||||
cgrates.org,SELF,*internal,,
|
||||
cgrates.org,ALL,127.0.0.1:6012,*json,false
|
||||
cgrates.org,ALL2,127.0.0.1:7012,*json,false
|
||||
cgrates.org,NonexistingHost,127.0.0.1:10012,*json,false
|
||||
#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,SELF,*internal,,false,1,3,"1m","2m",true,"key1","cert1","ca_cert1"
|
||||
cgrates.org,ALL,127.0.0.1:6012,*json,false,1,3,"1m","2m",true,"key2","cert2","ca_cert2"
|
||||
cgrates.org,ALL2,127.0.0.1:7012,*json,false,1,3,"1m","2m",true,"key3","cert3","ca_cert3",
|
||||
cgrates.org,NonexistingHost,127.0.0.1:10012,*json,false,1,3,"1m","2m",true,"key4","cert4","ca_cert4"
|
||||
|
@@ -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],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
|
||||
`
|
||||
)
|
||||
|
||||
|
||||
@@ -1396,15 +1396,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: 1 * 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))
|
||||
}
|
||||
|
||||
@@ -2796,10 +2796,10 @@ 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.TLS}
|
||||
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}
|
||||
}
|
||||
|
||||
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
|
||||
@@ -2808,16 +2808,33 @@ func (tps DispatcherHostMdls) AsTPDispatcherHosts() (result []*utils.TPDispatche
|
||||
if len(tp.Transport) == 0 {
|
||||
tp.Transport = utils.MetaJSON
|
||||
}
|
||||
hostsMap[utils.ConcatenatedKey(tp.Tenant, tp.ID)] = &utils.TPDispatcherHost{
|
||||
tntId := utils.ConcatenatedKey(tp.Tenant, tp.ID)
|
||||
hostsMap[tntId] = &utils.TPDispatcherHost{
|
||||
TPid: tp.Tpid,
|
||||
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,
|
||||
ConnectAttempts: tp.ConnectAttempts,
|
||||
Reconnects: tp.Reconnects,
|
||||
TLS: tp.TLS,
|
||||
ClientKey: tp.ClientKey,
|
||||
ClientCertificate: tp.ClientCertificate,
|
||||
CaCertificate: tp.CaCertificate,
|
||||
},
|
||||
}
|
||||
if tp.ConnectTimeout != utils.EmptyString {
|
||||
if hostsMap[tntId].Conn.ConnectTimeout, err = utils.ParseDurationWithNanosecs(tp.ConnectTimeout); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if tp.ReplyTimeout != utils.EmptyString {
|
||||
if hostsMap[tntId].Conn.ReplyTimeout, err = utils.ParseDurationWithNanosecs(tp.ReplyTimeout); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
for _, host := range hostsMap {
|
||||
@@ -2831,12 +2848,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,
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2847,10 +2872,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,
|
||||
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,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -2860,9 +2893,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.ConnectAttempts,
|
||||
Reconnects: dph.Reconnects,
|
||||
ConnectTimeout: dph.ConnectTimeout,
|
||||
ReplyTimeout: dph.ReplyTimeout,
|
||||
TLS: dph.TLS,
|
||||
ClientKey: dph.ClientKey,
|
||||
ClientCertificate: dph.ClientCertificate,
|
||||
CaCertificate: dph.CaCertificate,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3764,7 +3764,7 @@ func TestAPItoModelTPDispatcher(t *testing.T) {
|
||||
|
||||
func TestTPDispatcherHostsCSVHeader(t *testing.T) {
|
||||
tps := &DispatcherHostMdls{}
|
||||
eOut := []string{"#" + utils.Tenant, utils.ID, utils.Address, utils.Transport, utils.TLS}
|
||||
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}
|
||||
if rcv := tps.CSVHeader(); !reflect.DeepEqual(rcv, eOut) {
|
||||
t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv))
|
||||
}
|
||||
@@ -3772,7 +3772,9 @@ func TestTPDispatcherHostsCSVHeader(t *testing.T) {
|
||||
|
||||
func TestTPDispatcherHostsAsTPDispatcherHosts(t *testing.T) {
|
||||
tps := &DispatcherHostMdls{}
|
||||
if rcv := tps.AsTPDispatcherHosts(); rcv != nil {
|
||||
if rcv, err := tps.AsTPDispatcherHosts(); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv != nil {
|
||||
t.Errorf("Expecting: nil,\nReceived: %+v", utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
@@ -3781,28 +3783,50 @@ func TestTPDispatcherHostsAsTPDispatcherHosts(t *testing.T) {
|
||||
ID: "ID1",
|
||||
Tenant: "Tenant1",
|
||||
}}
|
||||
if rcv := tps.AsTPDispatcherHosts(); rcv != nil {
|
||||
if rcv, err := tps.AsTPDispatcherHosts(); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv != nil {
|
||||
t.Errorf("Expecting: nil,\nReceived: %+v", utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
tps = &DispatcherHostMdls{
|
||||
&DispatcherHostMdl{
|
||||
Address: "Address1",
|
||||
ID: "ID1",
|
||||
Tenant: "Tenant1",
|
||||
Transport: utils.EmptyString,
|
||||
ID: "ID1",
|
||||
Tenant: "Tenant1",
|
||||
Address: "localhost:6012",
|
||||
Transport: "*json",
|
||||
Synchronous: true,
|
||||
ConnectAttempts: 2,
|
||||
Reconnects: 5,
|
||||
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: "Address1",
|
||||
Transport: "*json",
|
||||
Address: "localhost:6012",
|
||||
Transport: "*json",
|
||||
Synchronous: true,
|
||||
ConnectAttempts: 2,
|
||||
Reconnects: 5,
|
||||
ConnectTimeout: 2 * time.Minute,
|
||||
ReplyTimeout: 1 * time.Minute,
|
||||
TLS: true,
|
||||
ClientKey: "client_key",
|
||||
ClientCertificate: "client_certificate",
|
||||
CaCertificate: "ca_certificate",
|
||||
},
|
||||
},
|
||||
}
|
||||
if rcv := tps.AsTPDispatcherHosts(); !reflect.DeepEqual(rcv, eOut) {
|
||||
if rcv, err := tps.AsTPDispatcherHosts(); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rcv, eOut) {
|
||||
t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
@@ -3823,7 +3847,9 @@ func TestTPDispatcherHostsAsTPDispatcherHosts(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if rcv := tps.AsTPDispatcherHosts(); !reflect.DeepEqual(rcv, eOut) {
|
||||
if rcv, err := tps.AsTPDispatcherHosts(); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rcv, eOut) {
|
||||
t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
@@ -3845,7 +3871,9 @@ func TestTPDispatcherHostsAsTPDispatcherHosts(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if rcv := tps.AsTPDispatcherHosts(); !reflect.DeepEqual(rcv, eOut) {
|
||||
if rcv, err := tps.AsTPDispatcherHosts(); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rcv, eOut) {
|
||||
t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
@@ -3867,7 +3895,10 @@ func TestTPDispatcherHostsAsTPDispatcherHosts(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
rcv := tps.AsTPDispatcherHosts()
|
||||
rcv, err := tps.AsTPDispatcherHosts()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
sort.Slice(rcv, func(i, j int) bool { return strings.Compare(rcv[i].ID, rcv[j].ID) < 0 })
|
||||
if !reflect.DeepEqual(rcv, eOut) {
|
||||
t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv))
|
||||
@@ -3884,15 +3915,33 @@ func TestAPItoModelTPDispatcherHost(t *testing.T) {
|
||||
Tenant: "Tenant",
|
||||
ID: "ID",
|
||||
Conn: &utils.TPDispatcherHostConn{
|
||||
Address: "Address1",
|
||||
Transport: "*json",
|
||||
Address: "Address1",
|
||||
Transport: "*json",
|
||||
Synchronous: true,
|
||||
ConnectAttempts: 3,
|
||||
Reconnects: 5,
|
||||
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",
|
||||
Address: "Address1",
|
||||
Transport: "*json",
|
||||
Tenant: "Tenant",
|
||||
ID: "ID",
|
||||
Synchronous: true,
|
||||
ConnectAttempts: 3,
|
||||
Reconnects: 5,
|
||||
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))
|
||||
@@ -3910,17 +3959,35 @@ func TestAPItoDispatcherHost(t *testing.T) {
|
||||
Tenant: "Tenant1",
|
||||
ID: "ID1",
|
||||
Conn: &utils.TPDispatcherHostConn{
|
||||
Address: "Address1",
|
||||
Transport: "*json",
|
||||
Address: "localhost:6012",
|
||||
Transport: "*json",
|
||||
Synchronous: true,
|
||||
ConnectAttempts: 3,
|
||||
Reconnects: 5,
|
||||
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: "Address1",
|
||||
Transport: "*json",
|
||||
ID: "ID1",
|
||||
Address: "localhost:6012",
|
||||
Transport: "*json",
|
||||
Synchronous: true,
|
||||
Reconnects: 5,
|
||||
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) {
|
||||
@@ -3954,19 +4021,33 @@ func TestDispatcherHostToAPI(t *testing.T) {
|
||||
dph := &DispatcherHost{
|
||||
Tenant: "Tenant1",
|
||||
RemoteHost: &config.RemoteHost{
|
||||
ID: "ID1",
|
||||
Address: "Address1",
|
||||
Transport: "*json",
|
||||
TLS: true,
|
||||
Address: "127.0.0.1:2012",
|
||||
Transport: "*json",
|
||||
Synchronous: false,
|
||||
ConnectAttempts: 0,
|
||||
Reconnects: 0,
|
||||
ConnectTimeout: 1 * time.Minute,
|
||||
ReplyTimeout: 1 * time.Minute,
|
||||
TLS: false,
|
||||
ClientKey: "",
|
||||
ClientCertificate: "",
|
||||
CaCertificate: "",
|
||||
},
|
||||
}
|
||||
eOut := &utils.TPDispatcherHost{
|
||||
Tenant: "Tenant1",
|
||||
ID: "ID1",
|
||||
Conn: &utils.TPDispatcherHostConn{
|
||||
Address: "Address1",
|
||||
Transport: "*json",
|
||||
TLS: true,
|
||||
Address: "127.0.0.1:2012",
|
||||
Transport: "*json",
|
||||
Synchronous: false,
|
||||
ConnectAttempts: 0,
|
||||
Reconnects: 0,
|
||||
ConnectTimeout: 1 * time.Minute,
|
||||
ReplyTimeout: 1 * time.Minute,
|
||||
TLS: false,
|
||||
ClientKey: "",
|
||||
ClientCertificate: "",
|
||||
CaCertificate: "",
|
||||
},
|
||||
}
|
||||
if rcv := DispatcherHostToAPI(dph); !reflect.DeepEqual(eOut, rcv) {
|
||||
|
||||
@@ -496,14 +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:""`
|
||||
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:""`
|
||||
ConnectAttempts int `index:"5" re:""`
|
||||
Reconnects int `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 {
|
||||
|
||||
@@ -637,7 +637,11 @@ func (csvs *CSVStorage) GetTPDispatcherHosts(tpid, tenant, id string) ([]*utils.
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tpDDHs.AsTPDispatcherHosts(), nil
|
||||
result, err := tpDDHs.AsTPDispatcherHosts()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (csvs *CSVStorage) GetTpIds(colName string) ([]string, error) {
|
||||
|
||||
@@ -1544,7 +1544,10 @@ func (sqls *SQLStorage) GetTPDispatcherHosts(tpid, tenant, id string) ([]*utils.
|
||||
if err := q.Find(&dpps).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
arls := dpps.AsTPDispatcherHosts()
|
||||
arls, err := dpps.AsTPDispatcherHosts()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(arls) == 0 {
|
||||
return arls, utils.ErrNotFound
|
||||
}
|
||||
|
||||
@@ -521,7 +521,11 @@ func (ldr *Loader) storeLoadedData(loaderType string,
|
||||
return
|
||||
}
|
||||
}
|
||||
for _, tpDsp := range dispModels.AsTPDispatcherHosts() {
|
||||
tpDsps, err := dispModels.AsTPDispatcherHosts()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, tpDsp := range tpDsps {
|
||||
dsp := engine.APItoDispatcherHost(tpDsp)
|
||||
if ldr.dryRun {
|
||||
utils.Logger.Info(
|
||||
|
||||
@@ -1285,11 +1285,67 @@ func TestLoaderProcessDispatcheHosts(t *testing.T) {
|
||||
Value: config.NewRSRParsersMustCompile("~*req.3", utils.InfieldSep),
|
||||
},
|
||||
{
|
||||
Tag: "TLS",
|
||||
Path: "TLS",
|
||||
Tag: "Synchronous",
|
||||
Path: "Synchronous",
|
||||
Type: utils.MetaComposed,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.4", utils.InfieldSep),
|
||||
},
|
||||
{
|
||||
Tag: "ConnectAttempts",
|
||||
Path: "ConnectAttempts",
|
||||
Type: utils.MetaComposed,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.5", utils.InfieldSep),
|
||||
Mandatory: true,
|
||||
},
|
||||
{
|
||||
Tag: "Reconnects",
|
||||
Path: "Reconnects",
|
||||
Type: utils.MetaComposed,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.6", utils.InfieldSep),
|
||||
Mandatory: true,
|
||||
},
|
||||
{
|
||||
Tag: "ConnectTimeout",
|
||||
Path: "ConnectTimeout",
|
||||
Type: utils.MetaComposed,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.7", utils.InfieldSep),
|
||||
Mandatory: true,
|
||||
},
|
||||
{
|
||||
Tag: "ReplyTimeout",
|
||||
Path: "ReplyTimeout",
|
||||
Type: utils.MetaComposed,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.8", utils.InfieldSep),
|
||||
Mandatory: true,
|
||||
},
|
||||
{
|
||||
Tag: "TLS",
|
||||
Path: "TLS",
|
||||
Type: utils.MetaComposed,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.9", utils.InfieldSep),
|
||||
Mandatory: true,
|
||||
},
|
||||
{
|
||||
Tag: "ClientKey",
|
||||
Path: "ClientKey",
|
||||
Type: utils.MetaComposed,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.10", utils.InfieldSep),
|
||||
Mandatory: true,
|
||||
},
|
||||
{
|
||||
Tag: "ClientCertificate",
|
||||
Path: "ClientCertificate",
|
||||
Type: utils.MetaComposed,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.11", utils.InfieldSep),
|
||||
Mandatory: true,
|
||||
},
|
||||
{
|
||||
Tag: "CaCertificate",
|
||||
Path: "CaCertificate",
|
||||
Type: utils.MetaComposed,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.12", utils.InfieldSep),
|
||||
Mandatory: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
rdr := io.NopCloser(strings.NewReader(engine.DispatcherHostCSVContent))
|
||||
@@ -1313,14 +1369,22 @@ func TestLoaderProcessDispatcheHosts(t *testing.T) {
|
||||
eDispHost := &engine.DispatcherHost{
|
||||
Tenant: "cgrates.org",
|
||||
RemoteHost: &config.RemoteHost{
|
||||
ID: "ALL1",
|
||||
Address: "127.0.0.1:2012",
|
||||
Transport: utils.MetaJSON,
|
||||
TLS: true,
|
||||
ID: "ALL",
|
||||
Address: "127.0.0.1:6012",
|
||||
Transport: utils.MetaJSON,
|
||||
Synchronous: false,
|
||||
ConnectAttempts: 1,
|
||||
Reconnects: 3,
|
||||
ConnectTimeout: 1 * time.Minute,
|
||||
ReplyTimeout: 2 * time.Minute,
|
||||
TLS: true,
|
||||
ClientKey: "key2",
|
||||
ClientCertificate: "cert2",
|
||||
CaCertificate: "ca_cert2",
|
||||
},
|
||||
}
|
||||
|
||||
rcv, err := ldr.dm.GetDispatcherHost("cgrates.org", "ALL1",
|
||||
rcv, err := ldr.dm.GetDispatcherHost("cgrates.org", "ALL",
|
||||
true, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -1144,9 +1144,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 UsageInterval struct {
|
||||
|
||||
Reference in New Issue
Block a user