Renaming config conecto_agent into http_agent

This commit is contained in:
DanB
2018-06-05 14:10:48 +02:00
parent 62ee6bde6a
commit 225935d600
8 changed files with 96 additions and 80 deletions

View File

@@ -143,7 +143,6 @@ func NewDefaultCGRConfig() (*CGRConfig, error) {
cfg.asteriskAgentCfg = new(AsteriskAgentCfg)
cfg.diameterAgentCfg = new(DiameterAgentCfg)
cfg.radiusAgentCfg = new(RadiusAgentCfg)
cfg.conectoAgentCfg = new(ConectoAgentCfg)
cfg.filterSCfg = new(FilterSCfg)
cfg.dispatcherSCfg = new(DispatcherSCfg)
cfg.ConfigReloads = make(map[string]chan struct{})
@@ -347,7 +346,7 @@ type CGRConfig struct {
asteriskAgentCfg *AsteriskAgentCfg // SMAsterisk Configuration
diameterAgentCfg *DiameterAgentCfg // DiameterAgent configuration
radiusAgentCfg *RadiusAgentCfg // RadiusAgent configuration
conectoAgentCfg *ConectoAgentCfg // ConectoAgent configuration
httpAgentCfg []*HttpAgentCfg // HttpAgent configuration
filterSCfg *FilterSCfg // FilterS configuration
PubSubServerEnabled bool // Starts PubSub as server: <true|false>.
AliasesServerEnabled bool // Starts PubSub as server: <true|false>.
@@ -637,12 +636,12 @@ func (self *CGRConfig) checkConfigSanity() error {
}
}
}
// conectoAgent checks
if self.conectoAgentCfg.Enabled {
for _, sSConn := range self.conectoAgentCfg.SessionSConns {
for _, httpAgentCfg := range self.httpAgentCfg {
// httpAgent checks
for _, sSConn := range httpAgentCfg.SessionSConns {
if sSConn.Address == utils.MetaInternal &&
!self.sessionSCfg.Enabled {
return errors.New("SessionS not enabled but referenced by ConectoAgent component")
return errors.New("SessionS not enabled but referenced by HttpAgent component")
}
}
}
@@ -793,7 +792,7 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) {
return err
}
jsnCncAgntCfg, err := jsnCfg.ConectoAgentJsonCfg()
jsnHttpAgntCfg, err := jsnCfg.HttpAgentJsonCfg()
if err != nil {
return err
}
@@ -1345,9 +1344,13 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) {
}
}
if jsnCncAgntCfg != nil {
if err := self.conectoAgentCfg.loadFromJsonCfg(jsnCncAgntCfg); err != nil {
return err
if jsnHttpAgntCfg != nil {
self.httpAgentCfg = make([]*HttpAgentCfg, len(*jsnHttpAgntCfg))
for i, jsnCfg := range *jsnHttpAgntCfg {
self.httpAgentCfg[i] = new(HttpAgentCfg)
if err := self.httpAgentCfg[i].loadFromJsonCfg(jsnCfg); err != nil {
return err
}
}
}
@@ -1527,8 +1530,8 @@ func (self *CGRConfig) AsteriskAgentCfg() *AsteriskAgentCfg {
return self.asteriskAgentCfg
}
func (self *CGRConfig) ConectoAgentCfg() *ConectoAgentCfg {
return self.conectoAgentCfg
func (self *CGRConfig) HttpAgentCfg() []*HttpAgentCfg {
return self.httpAgentCfg
}
func (cfg *CGRConfig) FilterSCfg() *FilterSCfg {

View File

@@ -401,15 +401,8 @@ const CGRATES_CFG_JSON = `
},
"conecto_agent": { // agent for cnc.to MVNE platform
"enabled": false, // enables the conecto agent: <true|false>
"http_url": "/conecto", // relative URL for requests coming in from Conecto platform
"sessions_conns": [
{"address": "*internal"} // connection towards SessionService
],
"timezone": "", // timezone for timestamps where not specified, empty for general defaults <""|UTC|Local|$IANA_TZ_DB>
"request_processors": [],
},
"http_agent": [ // HTTP Agents, ie towards cnc.to MVNE platform
],
"pubsubs": {

View File

@@ -50,7 +50,7 @@ const (
OSIPS_JSN = "opensips"
DA_JSN = "diameter_agent"
RA_JSN = "radius_agent"
CncAgentJson = "conecto_agent"
HttpAgentJson = "http_agent"
HISTSERV_JSN = "historys"
PUBSUBSERV_JSN = "pubsubs"
ALIASESSERV_JSN = "aliases"
@@ -308,16 +308,16 @@ func (self CgrJsonCfg) RadiusAgentJsonCfg() (*RadiusAgentJsonCfg, error) {
return cfg, nil
}
func (self CgrJsonCfg) ConectoAgentJsonCfg() (*ConectoAgentJsonCfg, error) {
rawCfg, hasKey := self[CncAgentJson]
func (self CgrJsonCfg) HttpAgentJsonCfg() (*[]*HttpAgentJsonCfg, error) {
rawCfg, hasKey := self[HttpAgentJson]
if !hasKey {
return nil, nil
}
cfg := new(ConectoAgentJsonCfg)
if err := json.Unmarshal(*rawCfg, cfg); err != nil {
httpAgnt := make([]*HttpAgentJsonCfg, 0)
if err := json.Unmarshal(*rawCfg, &httpAgnt); err != nil {
return nil, err
}
return cfg, nil
return &httpAgnt, nil
}
func (self CgrJsonCfg) PubSubServJsonCfg() (*PubSubServJsonCfg, error) {

View File

@@ -648,22 +648,12 @@ func TestRadiusAgentJsonCfg(t *testing.T) {
}
}
func TestConectoAgentJsonCfg(t *testing.T) {
eCfg := &ConectoAgentJsonCfg{
Enabled: utils.BoolPointer(false),
Http_url: utils.StringPointer("/conecto"),
Sessions_conns: &[]*HaPoolJsonCfg{
&HaPoolJsonCfg{
Address: utils.StringPointer(utils.MetaInternal),
}},
Timezone: utils.StringPointer(""),
Request_processors: &[]*CncProcessorJsnCfg{},
}
if cfg, err := dfCgrJsonCfg.ConectoAgentJsonCfg(); err != nil {
func TestHttpAgentJsonCfg(t *testing.T) {
eCfg := &[]*HttpAgentJsonCfg{}
if cfg, err := dfCgrJsonCfg.HttpAgentJsonCfg(); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eCfg, cfg) {
rcv := *cfg.Request_processors
t.Errorf("Received: %+v", rcv)
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eCfg), utils.ToJSON(cfg))
}
}

View File

@@ -241,6 +241,43 @@ func TestCgrCfgCDRC(t *testing.T) {
}
}
func TestHttpAgentCfg(t *testing.T) {
JSN_RAW_CFG := `
{
"http_agent": [
{
"url": "/conecto", // relative URL for requests coming in
"sessions_conns": [
{"address": "*internal"} // connection towards SessionService
],
"timezone": "", // timezone for timestamps where not specified, empty for general defaults <""|UTC|Local|$IANA_TZ_DB>
"request_payload": "*url", // source of input data <*url>
"reply_payload": "*xml", // type of output data <*xml>
"request_processors": [],
}
],
}
`
eCgrCfg, _ := NewDefaultCGRConfig()
eCgrCfg.httpAgentCfg = []*HttpAgentCfg{
&HttpAgentCfg{
Url: "/conecto",
Timezone: "",
RequestPayload: utils.MetaUrl,
ReplyPayload: utils.MetaXml,
SessionSConns: []*HaPoolConfig{
&HaPoolConfig{Address: utils.MetaInternal}},
RequestProcessors: nil,
},
}
if cgrCfg, err := NewCGRConfigFromJsonStringWithDefaults(JSN_RAW_CFG); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eCgrCfg.HttpAgentCfg(), cgrCfg.HttpAgentCfg()) {
t.Errorf("Expected: %s, received: %s",
utils.ToJSON(eCgrCfg.httpAgentCfg), utils.ToJSON(cgrCfg.httpAgentCfg))
}
}
func TestCgrCfgLoadJSONDefaults(t *testing.T) {
cgrCfg, err = NewDefaultCGRConfig()
if err != nil {
@@ -996,20 +1033,6 @@ func TestRadiusAgentCfg(t *testing.T) {
}
}
func TestConectoAgentCfg(t *testing.T) {
expct := &ConectoAgentCfg{
Enabled: false,
HttpUrl: "/conecto",
Timezone: "",
SessionSConns: []*HaPoolConfig{
&HaPoolConfig{Address: utils.MetaInternal}},
RequestProcessors: nil,
}
if !reflect.DeepEqual(expct, cgrCfg.conectoAgentCfg) {
t.Errorf("expecting: %s, received: %s", utils.ToJSON(expct), utils.ToJSON(cgrCfg.conectoAgentCfg))
}
}
func TestDbDefaults(t *testing.T) {
dbdf := NewDbDefaults()
flagInput := utils.MetaDynamic

View File

@@ -22,23 +22,21 @@ import (
"github.com/cgrates/cgrates/utils"
)
type ConectoAgentCfg struct {
Enabled bool
HttpUrl string
type HttpAgentCfg struct {
Url string
SessionSConns []*HaPoolConfig
Timezone string
RequestProcessors []*CncProcessorCfg
RequestPayload string
ReplyPayload string
RequestProcessors []*HttpAgntProcCfg
}
func (ca *ConectoAgentCfg) loadFromJsonCfg(jsnCfg *ConectoAgentJsonCfg) error {
func (ca *HttpAgentCfg) loadFromJsonCfg(jsnCfg *HttpAgentJsonCfg) error {
if jsnCfg == nil {
return nil
}
if jsnCfg.Enabled != nil {
ca.Enabled = *jsnCfg.Enabled
}
if jsnCfg.Http_url != nil {
ca.HttpUrl = *jsnCfg.Http_url
if jsnCfg.Url != nil {
ca.Url = *jsnCfg.Url
}
if jsnCfg.Sessions_conns != nil {
ca.SessionSConns = make([]*HaPoolConfig, len(*jsnCfg.Sessions_conns))
@@ -50,9 +48,15 @@ func (ca *ConectoAgentCfg) loadFromJsonCfg(jsnCfg *ConectoAgentJsonCfg) error {
if jsnCfg.Timezone != nil {
ca.Timezone = *jsnCfg.Timezone
}
if jsnCfg.Request_payload != nil {
ca.RequestPayload = *jsnCfg.Request_payload
}
if jsnCfg.Reply_payload != nil {
ca.ReplyPayload = *jsnCfg.Reply_payload
}
if jsnCfg.Request_processors != nil {
for _, reqProcJsn := range *jsnCfg.Request_processors {
rp := new(CncProcessorCfg)
rp := new(HttpAgntProcCfg)
var haveID bool
for _, rpSet := range ca.RequestProcessors {
if reqProcJsn.Id != nil && rpSet.Id == *reqProcJsn.Id {
@@ -72,7 +76,7 @@ func (ca *ConectoAgentCfg) loadFromJsonCfg(jsnCfg *ConectoAgentJsonCfg) error {
return nil
}
type CncProcessorCfg struct {
type HttpAgntProcCfg struct {
Id string
DryRun bool
Filters []string
@@ -81,32 +85,32 @@ type CncProcessorCfg struct {
ReplyFields []*CfgCdrField
}
func (cp *CncProcessorCfg) loadFromJsonCfg(jsnCfg *CncProcessorJsnCfg) (err error) {
func (ha *HttpAgntProcCfg) loadFromJsonCfg(jsnCfg *HttpAgentProcessorJsnCfg) (err error) {
if jsnCfg == nil {
return nil
}
if jsnCfg.Id != nil {
cp.Id = *jsnCfg.Id
ha.Id = *jsnCfg.Id
}
if jsnCfg.Dry_run != nil {
cp.DryRun = *jsnCfg.Dry_run
ha.DryRun = *jsnCfg.Dry_run
}
if jsnCfg.Filters != nil {
cp.Filters = make([]string, len(*jsnCfg.Filters))
ha.Filters = make([]string, len(*jsnCfg.Filters))
for i, fltr := range *jsnCfg.Filters {
cp.Filters[i] = fltr
ha.Filters[i] = fltr
}
}
if jsnCfg.Flags != nil {
cp.Flags = utils.StringMapFromSlice(*jsnCfg.Flags)
ha.Flags = utils.StringMapFromSlice(*jsnCfg.Flags)
}
if jsnCfg.Request_fields != nil {
if cp.RequestFields, err = CfgCdrFieldsFromCdrFieldsJsonCfg(*jsnCfg.Request_fields); err != nil {
if ha.RequestFields, err = CfgCdrFieldsFromCdrFieldsJsonCfg(*jsnCfg.Request_fields); err != nil {
return
}
}
if jsnCfg.Reply_fields != nil {
if cp.ReplyFields, err = CfgCdrFieldsFromCdrFieldsJsonCfg(*jsnCfg.Reply_fields); err != nil {
if ha.ReplyFields, err = CfgCdrFieldsFromCdrFieldsJsonCfg(*jsnCfg.Reply_fields); err != nil {
return
}
}

View File

@@ -373,15 +373,16 @@ type RAReqProcessorJsnCfg struct {
}
// Conecto Agent configuration section
type ConectoAgentJsonCfg struct {
Enabled *bool
Http_url *string
type HttpAgentJsonCfg struct {
Url *string
Sessions_conns *[]*HaPoolJsonCfg
Timezone *string
Request_processors *[]*CncProcessorJsnCfg
Request_payload *string
Reply_payload *string
Request_processors *[]*HttpAgentProcessorJsnCfg
}
type CncProcessorJsnCfg struct {
type HttpAgentProcessorJsnCfg struct {
Id *string
Dry_run *bool
Filters *[]string

View File

@@ -539,6 +539,8 @@ const (
SchedulerS = "SchedulerS"
MetaMultiply = "*multiply"
MetaDivide = "*divide"
MetaUrl = "*url"
MetaXml = "*xml"
)
// Migrator Action