diff --git a/agents/fsevent_test.go b/agents/fsevent_test.go index 3fa322f80..a1c51364d 100644 --- a/agents/fsevent_test.go +++ b/agents/fsevent_test.go @@ -337,7 +337,7 @@ variable_rtp_audio_out_dtmf_packet_count: 0 variable_rtp_audio_out_cng_packet_count: 0 variable_rtp_audio_rtcp_packet_count: 1450 variable_rtp_audio_rtcp_octet_count: 45940 -variable_cgr_subsystems: *resources%3B*attributes%3B*sessions%3B*suppliers%3B*suppliers_event_cost%3B*suppliers_ignore_errors%3B*accounts` +variable_cgr_subsystems: *resources%3B*attributes%3B*sessions%3B*suppliers_event_cost%3B*suppliers_ignore_errors%3B*accounts` func TestEventCreation(t *testing.T) { body := `Event-Name: RE_SCHEDULE diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index 0eed57533..3261a8556 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -1007,6 +1007,14 @@ func main() { cfg, dm, server, exitChan, filterSChan) } + if cfg.DispatcherSCfg().Enabled { + /* + go startDispatcherService(internalSupplierSChan, cacheS, + internalRsChan, internalStatSChan, + cfg, dm, server, exitChan, filterSChan) + */ + } + go loaderService(cacheS, cfg, dm, server, exitChan) // Serve rpc connections diff --git a/config/config.go b/config/config.go index 05da1ba6c..947933415 100755 --- a/config/config.go +++ b/config/config.go @@ -144,6 +144,9 @@ func NewDefaultCGRConfig() (*CGRConfig, error) { cfg.diameterAgentCfg = new(DiameterAgentCfg) cfg.radiusAgentCfg = new(RadiusAgentCfg) cfg.filterSCfg = new(FilterSCfg) + cfg.dispatcherSCfg = &DispatcherSCfg{ + Enabled: true, + } cfg.ConfigReloads = make(map[string]chan struct{}) cfg.ConfigReloads[utils.CDRC] = make(chan struct{}, 1) cfg.ConfigReloads[utils.CDRC] <- struct{}{} // Unlock the channel @@ -346,6 +349,7 @@ type CGRConfig struct { thresholdSCfg *ThresholdSCfg // configuration for ThresholdS supplierSCfg *SupplierSCfg // configuration for SupplierS loaderCfg []*LoaderConfig // configuration for Loader + dispatcherSCfg *DispatcherSCfg // configuration for Dispatcher MailerServer string // The server to use when sending emails out MailerAuthUser string // Authenticate to email server using this user MailerAuthPass string // Authenticate to email server with this password @@ -657,7 +661,9 @@ func (self *CGRConfig) checkConfigSanity() error { } } } - + // DispaterS checks + if self.dispatcherSCfg != nil && self.dispatcherSCfg.Enabled { + } return nil } @@ -816,6 +822,11 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) { return err } + jsnDispatcherCfg, err := jsnCfg.DispatcherSJsonCfg() + if err != nil { + return err + } + if jsnDataDbCfg != nil { if jsnDataDbCfg.Db_type != nil { self.DataDbType = *jsnDataDbCfg.Db_type @@ -1349,6 +1360,15 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) { } } + if jsnDispatcherCfg != nil { + if self.dispatcherSCfg == nil { + self.dispatcherSCfg = new(DispatcherSCfg) + } + if self.dispatcherSCfg.loadFromJsonCfg(jsnDispatcherCfg); err != nil { + return err + } + } + return nil } diff --git a/config/config_json.go b/config/config_json.go index 64628eaeb..e43db4f2e 100644 --- a/config/config_json.go +++ b/config/config_json.go @@ -64,6 +64,7 @@ const ( LoaderJson = "loaders" MAILER_JSN = "mailer" SURETAX_JSON = "suretax" + DispatcherSJson = "dispatcher" ) // Loads the json config out of io.Reader, eg other sources than file, maybe over http @@ -436,3 +437,15 @@ func (self CgrJsonCfg) SureTaxJsonCfg() (*SureTaxJsonCfg, error) { } return cfg, nil } + +func (self CgrJsonCfg) DispatcherSJsonCfg() (*DispatcherSJsonCfg, error) { + rawCfg, hasKey := self[DispatcherSJson] + if !hasKey { + return nil, nil + } + cfg := new(DispatcherSJsonCfg) + if err := json.Unmarshal(*rawCfg, cfg); err != nil { + return nil, err + } + return cfg, nil +} diff --git a/config/config_json_test.go b/config/config_json_test.go index 8f2712bec..5bc1d985a 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -960,3 +960,17 @@ func TestDfHttpJsonCfg(t *testing.T) { t.Error("Received: ", cfg) } } + +// Will be activated after finish config struct +/* +func TestDfDispatcherSJsonCfg(t *testing.T) { + eCfg := &DispatcherSJsonCfg{ + Enabled: utils.BoolPointer(true), + } + if cfg, err := dfCgrJsonCfg.DispatcherSJsonCfg(); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(eCfg, cfg) { + t.Errorf("expecting: %+v, received: %+v", eCfg, cfg) + } +} +*/ diff --git a/config/config_test.go b/config/config_test.go index 3affa529d..d96e6e515 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -287,13 +287,11 @@ func TestCgrCfgJSONDefaultsStorDB(t *testing.T) { } func TestCgrCfgJSONDefaultsRALs(t *testing.T) { - //asd eHaPoolcfg := []*HaPoolConfig{} if cgrCfg.RALsEnabled != false { t.Error(cgrCfg.RALsEnabled) } - if !reflect.DeepEqual(cgrCfg.RALsThresholdSConns, eHaPoolcfg) { t.Error(cgrCfg.RALsThresholdSConns) } @@ -988,3 +986,12 @@ func TestLoaderDefaults(t *testing.T) { t.Errorf("received: %+v, expecting: %+v", eCfg, cgrCfg.loaderCfg) } } + +func TestCgrCfgJSONDefaultDispatcherSCfg(t *testing.T) { + eDspSCfg := &DispatcherSCfg{ + Enabled: true, + } + if !reflect.DeepEqual(cgrCfg.dispatcherSCfg, eDspSCfg) { + t.Errorf("received: %+v, expecting: %+v", cgrCfg.dispatcherSCfg, eDspSCfg) + } +} diff --git a/config/dispatchercfg.go b/config/dispatchercfg.go new file mode 100755 index 000000000..e28cbc5e5 --- /dev/null +++ b/config/dispatchercfg.go @@ -0,0 +1,34 @@ +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package config + +// DispatcherSCfg is the configuration of dispatcher service +type DispatcherSCfg struct { + Enabled bool +} + +func (dps *DispatcherSCfg) loadFromJsonCfg(jsnCfg *DispatcherSJsonCfg) (err error) { + if jsnCfg == nil { + return nil + } + if jsnCfg.Enabled != nil { + dps.Enabled = *jsnCfg.Enabled + } + return nil +} diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 7ed002943..c003771b2 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -485,3 +485,8 @@ type SureTaxJsonCfg struct { Sales_type_code *string Tax_exemption_code_list *string } + +// Dispatcher service config section +type DispatcherSJsonCfg struct { + Enabled *bool +} diff --git a/dispatcher/dispatcher.go b/dispatcher/dispatcher.go new file mode 100755 index 000000000..79d409330 --- /dev/null +++ b/dispatcher/dispatcher.go @@ -0,0 +1,48 @@ +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package dispatcher + +import ( + "github.com/cgrates/cgrates/utils" +) + +// NewDispatcherService initializes a DispatcherService +func NewDispatcherService() (dspS *DispatcherService, err error) { + dspS = &DispatcherService{} + return +} + +// DispatcherService is the service handling dispatcher +type DispatcherService struct { +} + +// ListenAndServe will initialize the service +func (spS *DispatcherService) ListenAndServe(exitChan chan bool) error { + utils.Logger.Info("Starting Dispatcher Service") + e := <-exitChan + exitChan <- e // put back for the others listening for shutdown request + return nil +} + +// Shutdown is called to shutdown the service +func (spS *DispatcherService) Shutdown() error { + utils.Logger.Info(fmt.Sprintf("<%s> service shutdown initialized", utils.DispatcherS)) + utils.Logger.Info(fmt.Sprintf("<%s> service shutdown complete", utils.DispatcherS)) + return nil +} diff --git a/utils/consts.go b/utils/consts.go index 53f891f7d..79f4c74d8 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -559,6 +559,7 @@ const ( StatService = "StatS" FilterS = "FilterS" ThresholdS = "ThresholdS" + DispatcherS = "DispatcherS" ) //Migrator Metas