mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added DispatcherHosts to LoaderS
This commit is contained in:
committed by
Dan Christian Bogos
parent
2ff69dc8b5
commit
472c68c897
@@ -660,7 +660,7 @@ const CGRATES_CFG_JSON = `
|
||||
},
|
||||
{
|
||||
"type": "*dispatchers", // data source type
|
||||
"file_name": "DispatcherProfiles.csv", // file name in the tp_in_dir
|
||||
"file_name": "DispatcherProfiles.csv", // file name in the tp_in_dir
|
||||
"fields": [
|
||||
{"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true},
|
||||
{"tag": "ID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true},
|
||||
@@ -677,6 +677,17 @@ const CGRATES_CFG_JSON = `
|
||||
{"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "~12"},
|
||||
],
|
||||
},
|
||||
{
|
||||
"type": "*dispatcher_hosts", // data source type
|
||||
"file_name": "DispatcherHosts.csv", // file name in the tp_in_dir
|
||||
"fields": [
|
||||
{"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true},
|
||||
{"tag": "ID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true},
|
||||
{"tag": "Address", "field_id": "Address", "type": "*composed", "value": "~2"},
|
||||
{"tag": "Transport", "field_id": "Transport", "type": "*composed", "value": "~3"},
|
||||
{"tag": "TLS", "field_id": "TLS", "type": "*composed", "value": "~4"},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -1293,6 +1293,34 @@ func TestDfLoaderJsonCfg(t *testing.T) {
|
||||
Value: utils.StringPointer("~12")},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: utils.StringPointer(utils.MetaDispatcherHosts),
|
||||
File_name: utils.StringPointer(utils.DispatcherHostsCsv),
|
||||
Fields: &[]*FcTemplateJsonCfg{
|
||||
{Tag: utils.StringPointer(utils.Tenant),
|
||||
Field_id: utils.StringPointer(utils.Tenant),
|
||||
Type: utils.StringPointer(utils.META_COMPOSED),
|
||||
Value: utils.StringPointer("~0"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{Tag: utils.StringPointer(utils.ID),
|
||||
Field_id: utils.StringPointer(utils.ID),
|
||||
Type: utils.StringPointer(utils.META_COMPOSED),
|
||||
Value: utils.StringPointer("~1"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{Tag: utils.StringPointer("Address"),
|
||||
Field_id: utils.StringPointer("Address"),
|
||||
Type: utils.StringPointer(utils.META_COMPOSED),
|
||||
Value: utils.StringPointer("~2")},
|
||||
{Tag: utils.StringPointer("Transport"),
|
||||
Field_id: utils.StringPointer("Transport"),
|
||||
Type: utils.StringPointer(utils.META_COMPOSED),
|
||||
Value: utils.StringPointer("~3")},
|
||||
{Tag: utils.StringPointer("TLS"),
|
||||
Field_id: utils.StringPointer("TLS"),
|
||||
Type: utils.StringPointer(utils.META_COMPOSED),
|
||||
Value: utils.StringPointer("~4")},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1464,6 +1464,37 @@ func TestCgrLoaderCfgITDefaults(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: utils.MetaDispatcherHosts,
|
||||
Filename: utils.DispatcherHostsCsv,
|
||||
Fields: []*FCTemplate{
|
||||
{Tag: "Tenant",
|
||||
FieldId: "Tenant",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: NewRSRParsersMustCompile("~0", true, utils.INFIELD_SEP),
|
||||
Mandatory: true},
|
||||
{Tag: "ID",
|
||||
FieldId: "ID",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: NewRSRParsersMustCompile("~1", true, utils.INFIELD_SEP),
|
||||
Mandatory: true},
|
||||
{Tag: "Address",
|
||||
FieldId: "Address",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: NewRSRParsersMustCompile("~2", true, utils.INFIELD_SEP),
|
||||
},
|
||||
{Tag: "Transport",
|
||||
FieldId: "Transport",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: NewRSRParsersMustCompile("~3", true, utils.INFIELD_SEP),
|
||||
},
|
||||
{Tag: "TLS",
|
||||
FieldId: "TLS",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: NewRSRParsersMustCompile("~4", true, utils.INFIELD_SEP),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1186,3 +1186,91 @@ cgrates.org,EVENT1,,,,,,ALL,,10,,,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestLoaderProcessDispatcheHosts(t *testing.T) {
|
||||
dipatcherHostCSV := `
|
||||
#Tenant[0],ID[1],Address[2],Transport[3],TLS[4]
|
||||
cgrates.org,ALL,127.0.0.1:6012,*json,false
|
||||
`
|
||||
data, _ := engine.NewMapStorage()
|
||||
ldr := &Loader{
|
||||
ldrID: "TestLoaderProcessContent",
|
||||
bufLoaderData: make(map[string][]LoaderData),
|
||||
dm: engine.NewDataManager(data),
|
||||
timezone: "UTC",
|
||||
}
|
||||
ldr.dataTpls = map[string][]*config.FCTemplate{
|
||||
utils.MetaDispatcherHosts: []*config.FCTemplate{
|
||||
&config.FCTemplate{
|
||||
Tag: "Tenant",
|
||||
FieldId: "Tenant",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~0", true, utils.INFIELD_SEP),
|
||||
Mandatory: true,
|
||||
},
|
||||
&config.FCTemplate{
|
||||
Tag: "ID",
|
||||
FieldId: "ID",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~1", true, utils.INFIELD_SEP),
|
||||
Mandatory: true,
|
||||
},
|
||||
&config.FCTemplate{
|
||||
Tag: "Address",
|
||||
FieldId: "Address",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~2", true, utils.INFIELD_SEP),
|
||||
},
|
||||
&config.FCTemplate{
|
||||
Tag: "Transport",
|
||||
FieldId: "Transport",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~3", true, utils.INFIELD_SEP),
|
||||
},
|
||||
&config.FCTemplate{
|
||||
Tag: "TLS",
|
||||
FieldId: "TLS",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~4", true, utils.INFIELD_SEP),
|
||||
},
|
||||
},
|
||||
}
|
||||
rdr := ioutil.NopCloser(strings.NewReader(dipatcherHostCSV))
|
||||
csvRdr := csv.NewReader(rdr)
|
||||
csvRdr.Comment = '#'
|
||||
ldr.rdrs = map[string]map[string]*openedCSVFile{
|
||||
utils.MetaDispatcherHosts: map[string]*openedCSVFile{
|
||||
utils.DispatcherProfilesCsv: &openedCSVFile{
|
||||
fileName: utils.DispatcherProfilesCsv,
|
||||
rdr: rdr,
|
||||
csvRdr: csvRdr,
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := ldr.processContent(utils.MetaDispatcherHosts); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if len(ldr.bufLoaderData) != 0 {
|
||||
t.Errorf("wrong buffer content: %+v", ldr.bufLoaderData)
|
||||
}
|
||||
eDispHost := &engine.DispatcherHost{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ALL",
|
||||
Conns: []*config.RemoteHost{
|
||||
&config.RemoteHost{
|
||||
Address: "127.0.0.1:6012",
|
||||
Transport: utils.MetaJSONrpc,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
rcv, err := ldr.dm.GetDispatcherHost("cgrates.org", "ALL",
|
||||
true, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(eDispHost, rcv) {
|
||||
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eDispHost), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user