From 17b16a415aafda81d5a17223e2b33723ddfc434b Mon Sep 17 00:00:00 2001 From: edwardro22 Date: Thu, 4 Jan 2018 11:46:25 +0200 Subject: [PATCH] Removed history service --- apier/v1/apier_it_test.go | 2 +- apier/v1/resourcesv1_it_test.go | 4 +- cmd/cgr-engine/cgr-engine.go | 26 +-- cmd/cgr-engine/rater.go | 20 +- cmd/cgr-loader/cgr-loader.go | 16 -- config/config.go | 35 --- config/config_defaults.go | 8 - config/config_json.go | 13 -- config/config_json_test.go | 14 -- config/config_test.go | 15 -- config/libconfig_json.go | 1 - data/conf/cgrates/cgrates.json | 8 - data/conf/samples/tutmongo/cgrates.json | 5 - data/conf/samples/tutmysql/cgrates.json | 5 - .../cgrates/etc/cgrates/cgrates.json | 9 - .../asterisk_ari/cgrates/etc/init.d/cgrates | 6 - data/tutorials/fs_evsock/README.md | 1 - .../cgrates/etc/cgrates/cgrates.json | 9 - .../etc/init.d/.fuse_hidden0000001700000001 | 6 - .../fs_evsock/cgrates/etc/init.d/cgrates | 6 - .../kamevapi/cgrates/etc/cgrates/cgrates.json | 9 - .../kamevapi/cgrates/etc/init.d/cgrates | 6 - .../cgrates/etc/cgrates/cgrates.json | 9 - .../etc/init.d/.fuse_hidden0000001700000001 | 6 - .../osips_async/cgrates/etc/init.d/cgrates | 6 - .../cgrates/etc/cgrates/cgrates.json | 9 - .../etc/init.d/.fuse_hidden0000001700000001 | 6 - .../osips_native/cgrates/etc/init.d/cgrates | 6 - docs/advanced.rst | 1 - docs/architecture.rst | 33 +-- docs/history.rst | 20 -- engine/calldesc.go | 6 - engine/calldesc_test.go | 2 - engine/destinations.go | 14 -- engine/history_test.go | 56 ----- engine/ratingplan.go | 13 -- engine/ratingprofile.go | 12 -- engine/storage_map.go | 22 -- engine/storage_mongo_datadb.go | 21 -- engine/storage_redis.go | 22 -- history/file_scribe.go | 204 ------------------ history/mock_scribe.go | 98 --------- history/scribe.go | 94 -------- history/scribe_test.go | 59 ----- 44 files changed, 15 insertions(+), 928 deletions(-) delete mode 100644 engine/history_test.go delete mode 100644 history/file_scribe.go delete mode 100644 history/mock_scribe.go delete mode 100644 history/scribe.go delete mode 100644 history/scribe_test.go diff --git a/apier/v1/apier_it_test.go b/apier/v1/apier_it_test.go index 3d6073179..520883157 100644 --- a/apier/v1/apier_it_test.go +++ b/apier/v1/apier_it_test.go @@ -77,7 +77,7 @@ func TestApierLoadConfig(t *testing.T) { } func TestApierCreateDirs(t *testing.T) { - for _, pathDir := range []string{cfg.CdreProfiles[utils.META_DEFAULT].ExportPath, "/var/log/cgrates/cdrc/in", "/var/log/cgrates/cdrc/out", cfg.HistoryDir} { + for _, pathDir := range []string{cfg.CdreProfiles[utils.META_DEFAULT].ExportPath, "/var/log/cgrates/cdrc/in", "/var/log/cgrates/cdrc/out"} { if err := os.RemoveAll(pathDir); err != nil { t.Fatal("Error removing folder: ", pathDir, err) } diff --git a/apier/v1/resourcesv1_it_test.go b/apier/v1/resourcesv1_it_test.go index bc120da02..9092d1ad7 100644 --- a/apier/v1/resourcesv1_it_test.go +++ b/apier/v1/resourcesv1_it_test.go @@ -45,7 +45,7 @@ var sTestsRLSV1 = []func(t *testing.T){ testV1RsLoadConfig, testV1RsInitDataDb, testV1RsResetStorDb, - // testV1RsStartEngine, + testV1RsStartEngine, testV1RsRpcConn, testV1RsFromFolder, testV1RsGetResourcesForEvent, @@ -61,7 +61,7 @@ var sTestsRLSV1 = []func(t *testing.T){ testV1RsGetResourceProfileAfterUpdate, testV1RsRemResourceProfile, testV1RsGetResourceProfileAfterDelete, - // testV1RsStopEngine, + testV1RsStopEngine, } //Test start here diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index 6ce19d155..2de6076e3 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -35,7 +35,6 @@ import ( "github.com/cgrates/cgrates/cdrc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" - "github.com/cgrates/cgrates/history" "github.com/cgrates/cgrates/scheduler" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/sessionmanager" @@ -496,17 +495,6 @@ func startCdrStats(internalCdrStatSChan chan rpcclient.RpcClientConnection, dm * internalCdrStatSChan <- cdrStats } -func startHistoryServer(internalHistorySChan chan rpcclient.RpcClientConnection, server *utils.Server, exitChan chan bool) { - scribeServer, err := history.NewFileScribe(cfg.HistoryDir, cfg.HistorySaveInterval) - if err != nil { - utils.Logger.Crit(fmt.Sprintf(" Could not start, error: %s", err.Error())) - exitChan <- true - return - } - server.RpcRegisterName("HistoryV1", scribeServer) - internalHistorySChan <- scribeServer -} - func startPubSubServer(internalPubSubSChan chan rpcclient.RpcClientConnection, dm *engine.DataManager, server *utils.Server, exitChan chan bool) { pubSubServer, err := engine.NewPubSub(dm, cfg.HttpSkipTlsVerify) if err != nil { @@ -729,7 +717,7 @@ func startFilterService(filterSChan chan *engine.FilterS, } func startRpc(server *utils.Server, internalRaterChan, - internalCdrSChan, internalCdrStatSChan, internalHistorySChan, internalPubSubSChan, internalUserSChan, + internalCdrSChan, internalCdrStatSChan, internalPubSubSChan, internalUserSChan, internalAliaseSChan, internalRsChan, internalStatSChan, internalSMGChan chan rpcclient.RpcClientConnection) { select { // Any of the rpc methods will unlock listening to rpc requests case resp := <-internalRaterChan: @@ -738,8 +726,6 @@ func startRpc(server *utils.Server, internalRaterChan, internalCdrSChan <- cdrs case cdrstats := <-internalCdrStatSChan: internalCdrStatSChan <- cdrstats - case hist := <-internalHistorySChan: - internalHistorySChan <- hist case pubsubs := <-internalPubSubSChan: internalPubSubSChan <- pubsubs case users := <-internalUserSChan: @@ -896,7 +882,6 @@ func main() { cacheDoneChan := make(chan struct{}, 1) internalCdrSChan := make(chan rpcclient.RpcClientConnection, 1) internalCdrStatSChan := make(chan rpcclient.RpcClientConnection, 1) - internalHistorySChan := make(chan rpcclient.RpcClientConnection, 1) internalPubSubSChan := make(chan rpcclient.RpcClientConnection, 1) internalUserSChan := make(chan rpcclient.RpcClientConnection, 1) internalAliaseSChan := make(chan rpcclient.RpcClientConnection, 1) @@ -914,7 +899,7 @@ func main() { // Start rater service if cfg.RALsEnabled { go startRater(internalRaterChan, cacheDoneChan, internalThresholdSChan, - internalCdrStatSChan, internalStatSChan, internalHistorySChan, + internalCdrStatSChan, internalStatSChan, internalPubSubSChan, internalAttributeSChan, internalUserSChan, internalAliaseSChan, srvManager, server, dm, loadDb, cdrDb, &stopHandled, exitChan) @@ -980,11 +965,6 @@ func main() { go startRadiusAgent(internalSMGChan, exitChan) } - // Start HistoryS service - if cfg.HistoryServerEnabled { - go startHistoryServer(internalHistorySChan, server, exitChan) - } - // Start PubSubS service if cfg.PubSubServerEnabled { go startPubSubServer(internalPubSubSChan, dm, server, exitChan) @@ -1026,7 +1006,7 @@ func main() { } // Serve rpc connections - go startRpc(server, internalRaterChan, internalCdrSChan, internalCdrStatSChan, internalHistorySChan, + go startRpc(server, internalRaterChan, internalCdrSChan, internalCdrStatSChan, internalPubSubSChan, internalUserSChan, internalAliaseSChan, internalRsChan, internalStatSChan, internalSMGChan) <-exitChan diff --git a/cmd/cgr-engine/rater.go b/cmd/cgr-engine/rater.go index 8b3286499..efdc02504 100755 --- a/cmd/cgr-engine/rater.go +++ b/cmd/cgr-engine/rater.go @@ -24,7 +24,6 @@ import ( "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/apier/v2" "github.com/cgrates/cgrates/engine" - "github.com/cgrates/cgrates/history" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" "github.com/cgrates/rpcclient" @@ -32,7 +31,7 @@ import ( // Starts rater and reports on chan func startRater(internalRaterChan chan rpcclient.RpcClientConnection, cacheDoneChan chan struct{}, - internalThdSChan, internalCdrStatSChan, internalStatSChan, internalHistorySChan, internalPubSubSChan, + internalThdSChan, internalCdrStatSChan, internalStatSChan, internalPubSubSChan, internalAttributeSChan, internalUserSChan, internalAliaseSChan chan rpcclient.RpcClientConnection, serviceManager *servmanager.ServiceManager, server *utils.Server, dm *engine.DataManager, loadDb engine.LoadStorage, cdrDb engine.CdrStorage, stopHandled *bool, exitChan chan bool) { @@ -173,22 +172,6 @@ func startRater(internalRaterChan chan rpcclient.RpcClientConnection, cacheDoneC }() } - if len(cfg.RALsHistorySConns) != 0 { // Connection to HistoryS, - histTaskChan := make(chan struct{}) - waitTasks = append(waitTasks, histTaskChan) - go func() { - defer close(histTaskChan) - if historySConns, err := engine.NewRPCPool(rpcclient.POOL_FIRST, cfg.ConnectAttempts, cfg.Reconnects, cfg.ConnectTimeout, cfg.ReplyTimeout, - cfg.RALsHistorySConns, internalHistorySChan, cfg.InternalTtl); err != nil { - utils.Logger.Crit(fmt.Sprintf(" Could not connect HistoryS, error: %s", err.Error())) - exitChan <- true - return - } else { - engine.SetHistoryScribe(historySConns) - } - }() - } - if len(cfg.RALsPubSubSConns) != 0 { // Connection to pubsubs pubsubTaskChan := make(chan struct{}) waitTasks = append(waitTasks, pubsubTaskChan) @@ -291,7 +274,6 @@ func startRater(internalRaterChan chan rpcclient.RpcClientConnection, cacheDoneC utils.RegisterRpcParams("", &engine.Stats{}) utils.RegisterRpcParams("", &v1.CDRStatsV1{}) - utils.RegisterRpcParams("ScribeV1", &history.FileScribe{}) utils.RegisterRpcParams("PubSubV1", &engine.PubSub{}) utils.RegisterRpcParams("AliasesV1", &engine.AliasHandler{}) utils.RegisterRpcParams("UsersV1", &engine.UserMap{}) diff --git a/cmd/cgr-loader/cgr-loader.go b/cmd/cgr-loader/cgr-loader.go index 21091df75..fe5efddea 100755 --- a/cmd/cgr-loader/cgr-loader.go +++ b/cmd/cgr-loader/cgr-loader.go @@ -59,7 +59,6 @@ var ( fromStorDb = flag.Bool("from_stordb", false, "Load the tariff plan from storDb to dataDb") toStorDb = flag.Bool("to_stordb", false, "Import the tariff plan from files to storDb") rpcEncoding = flag.String("rpc_encoding", "json", "RPC encoding used ") - historyServer = flag.String("historys", config.CgrConfig().RPCJSONListen, "The history server address:port, empty to disable automatic history archiving") ralsAddress = flag.String("rals", config.CgrConfig().RPCJSONListen, "Rater service to contact for cache reloads, empty to disable automatic cache reloads") cdrstatsAddress = flag.String("cdrstats", config.CgrConfig().RPCJSONListen, "CDRStats service to contact for data reloads, empty to disable automatic data reloads") usersAddress = flag.String("users", config.CgrConfig().RPCJSONListen, "Users service to contact for data reloads, empty to disable automatic data reloads") @@ -171,18 +170,6 @@ func main() { if *dryRun { // We were just asked to parse the data, not saving it return } - if *historyServer != "" { // Init scribeAgent so we can store the differences - if scribeAgent, err := rpcclient.NewRpcClient("tcp", *historyServer, 3, 3, - time.Duration(1*time.Second), time.Duration(5*time.Minute), *rpcEncoding, nil, false); err != nil { - log.Fatalf("Could not connect to history server, error: %s. Make sure you have properly configured it via -history_server flag.", err.Error()) - return - } else { - engine.SetHistoryScribe(scribeAgent) - //defer scribeAgent.Client.Close() - } - } else { - log.Print("WARNING: Rates history archiving is disabled!") - } if *ralsAddress != "" { // Init connection to rater so we can reload it's data if rater, err = rpcclient.NewRpcClient("tcp", *ralsAddress, 3, 3, time.Duration(1*time.Second), time.Duration(5*time.Minute), *rpcEncoding, nil, false); err != nil { @@ -223,9 +210,6 @@ func main() { if err := tpReader.WriteToDatabase(*flush, *verbose, *disable_reverse); err != nil { log.Fatal("Could not write to database: ", err) } - if len(*historyServer) != 0 && *verbose { - log.Print("Wrote history.") - } var dstIds, revDstIDs, rplIds, rpfIds, actIds, aapIDs, shgIds, alsIds, lcrIds, dcsIds, rspIDs, resIDs, aatIDs, ralsIDs []string if rater != nil { dstIds, _ = tpReader.GetLoadedIds(utils.DESTINATION_PREFIX) diff --git a/config/config.go b/config/config.go index 655c6f716..7efedb06c 100755 --- a/config/config.go +++ b/config/config.go @@ -233,7 +233,6 @@ type CGRConfig struct { RALsThresholdSConns []*HaPoolConfig // address where to reach ThresholdS config RALsCDRStatSConns []*HaPoolConfig // address where to reach the cdrstats service. Empty to disable stats gathering <""|internal|x.y.z.y:1234> RALsStatSConns []*HaPoolConfig - RALsHistorySConns []*HaPoolConfig RALsPubSubSConns []*HaPoolConfig RALsAttributeSConns []*HaPoolConfig RALsUserSConns []*HaPoolConfig @@ -268,9 +267,6 @@ type CGRConfig struct { diameterAgentCfg *DiameterAgentCfg // DiameterAgent configuration radiusAgentCfg *RadiusAgentCfg // RadiusAgent configuration filterSCfg *FilterSCfg // FilterS configuration - HistoryServerEnabled bool // Starts History as server: . - HistoryDir string // Location on disk where to store history files. - HistorySaveInterval time.Duration // The timout duration between pubsub writes PubSubServerEnabled bool // Starts PubSub as server: . AliasesServerEnabled bool // Starts PubSub as server: . UserServerEnabled bool // Starts User as server: @@ -305,11 +301,6 @@ func (self *CGRConfig) checkConfigSanity() error { return errors.New("StatS not enabled but requested by RALs component.") } } - for _, connCfg := range self.RALsHistorySConns { - if connCfg.Address == utils.MetaInternal && !self.HistoryServerEnabled { - return errors.New("History server not enabled but requested by RALs component.") - } - } for _, connCfg := range self.RALsPubSubSConns { if connCfg.Address == utils.MetaInternal && !self.PubSubServerEnabled { return errors.New("PubSub server not enabled but requested by RALs component.") @@ -681,11 +672,6 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) { return err } - jsnHistServCfg, err := jsnCfg.HistServJsonCfg() - if err != nil { - return err - } - jsnPubSubServCfg, err := jsnCfg.PubSubServJsonCfg() if err != nil { return err @@ -931,13 +917,6 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) { self.RALsStatSConns[idx].loadFromJsonCfg(jsnHaCfg) } } - if jsnRALsCfg.Historys_conns != nil { - self.RALsHistorySConns = make([]*HaPoolConfig, len(*jsnRALsCfg.Historys_conns)) - for idx, jsnHaCfg := range *jsnRALsCfg.Historys_conns { - self.RALsHistorySConns[idx] = NewDfltHaPoolConfig() - self.RALsHistorySConns[idx].loadFromJsonCfg(jsnHaCfg) - } - } if jsnRALsCfg.Pubsubs_conns != nil { self.RALsPubSubSConns = make([]*HaPoolConfig, len(*jsnRALsCfg.Pubsubs_conns)) for idx, jsnHaCfg := range *jsnRALsCfg.Pubsubs_conns { @@ -1175,20 +1154,6 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) { } } - if jsnHistServCfg != nil { - if jsnHistServCfg.Enabled != nil { - self.HistoryServerEnabled = *jsnHistServCfg.Enabled - } - if jsnHistServCfg.History_dir != nil { - self.HistoryDir = *jsnHistServCfg.History_dir - } - if jsnHistServCfg.Save_interval != nil { - if self.HistorySaveInterval, err = utils.ParseDurationWithNanosecs(*jsnHistServCfg.Save_interval); err != nil { - return err - } - } - } - if jsnPubSubServCfg != nil { if jsnPubSubServCfg.Enabled != nil { self.PubSubServerEnabled = *jsnPubSubServCfg.Enabled diff --git a/config/config_defaults.go b/config/config_defaults.go index 3083afaf9..03a3f4615 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -135,7 +135,6 @@ const CGRATES_CFG_JSON = ` "thresholds_conns": [], // address where to reach the thresholds service, empty to disable thresholds functionality: <""|*internal|x.y.z.y:1234> "cdrstats_conns": [], // address where to reach the cdrstats service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234> "stats_conns": [], // address where to reach the stat service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234> - "historys_conns": [], // address where to reach the history service, empty to disable history functionality: <""|*internal|x.y.z.y:1234> "pubsubs_conns": [], // address where to reach the pubusb service, empty to disable pubsub functionality: <""|*internal|x.y.z.y:1234> "attributes_conns": [], // address where to reach the attribute service, empty to disable attributes functionality: <""|*internal|x.y.z.y:1234> "users_conns": [], // address where to reach the user service, empty to disable user profile functionality: <""|*internal|x.y.z.y:1234> @@ -403,13 +402,6 @@ const CGRATES_CFG_JSON = ` }, -"historys": { - "enabled": false, // starts History service: . - "history_dir": "/var/lib/cgrates/history", // location on disk where to store history files. - "save_interval": "1s", // interval to save changed cache into .git archive -}, - - "pubsubs": { "enabled": false, // starts PubSub service: . }, diff --git a/config/config_json.go b/config/config_json.go index 77c4e12c8..b73ff9881 100644 --- a/config/config_json.go +++ b/config/config_json.go @@ -53,7 +53,6 @@ const ( OSIPS_JSN = "opensips" DA_JSN = "diameter_agent" RA_JSN = "radius_agent" - HISTSERV_JSN = "historys" PUBSUBSERV_JSN = "pubsubs" ALIASESSERV_JSN = "aliases" USERSERV_JSN = "users" @@ -318,18 +317,6 @@ func (self CgrJsonCfg) RadiusAgentJsonCfg() (*RadiusAgentJsonCfg, error) { return cfg, nil } -func (self CgrJsonCfg) HistServJsonCfg() (*HistServJsonCfg, error) { - rawCfg, hasKey := self[HISTSERV_JSN] - if !hasKey { - return nil, nil - } - cfg := new(HistServJsonCfg) - if err := json.Unmarshal(*rawCfg, cfg); err != nil { - return nil, err - } - return cfg, nil -} - func (self CgrJsonCfg) PubSubServJsonCfg() (*PubSubServJsonCfg, error) { rawCfg, hasKey := self[PUBSUBSERV_JSN] if !hasKey { diff --git a/config/config_json_test.go b/config/config_json_test.go index 5dd400e30..61c5a66a0 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -206,7 +206,6 @@ func TestDfRalsJsonCfg(t *testing.T) { Thresholds_conns: &[]*HaPoolJsonCfg{}, Cdrstats_conns: &[]*HaPoolJsonCfg{}, Stats_conns: &[]*HaPoolJsonCfg{}, - Historys_conns: &[]*HaPoolJsonCfg{}, Pubsubs_conns: &[]*HaPoolJsonCfg{}, Attributes_conns: &[]*HaPoolJsonCfg{}, Users_conns: &[]*HaPoolJsonCfg{}, @@ -652,19 +651,6 @@ func TestRadiusAgentJsonCfg(t *testing.T) { } } -func TestDfHistServJsonCfg(t *testing.T) { - eCfg := &HistServJsonCfg{ - Enabled: utils.BoolPointer(false), - History_dir: utils.StringPointer("/var/lib/cgrates/history"), - Save_interval: utils.StringPointer("1s"), - } - if cfg, err := dfCgrJsonCfg.HistServJsonCfg(); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(eCfg, cfg) { - t.Error("Received: ", cfg) - } -} - func TestDfPubSubServJsonCfg(t *testing.T) { eCfg := &PubSubServJsonCfg{ Enabled: utils.BoolPointer(false), diff --git a/config/config_test.go b/config/config_test.go index 987176628..ef6c6930e 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -300,9 +300,6 @@ func TestCgrCfgJSONDefaultsRALs(t *testing.T) { if !reflect.DeepEqual(cgrCfg.RALsCDRStatSConns, eHaPoolcfg) { t.Error(cgrCfg.RALsCDRStatSConns) } - if !reflect.DeepEqual(cgrCfg.RALsHistorySConns, eHaPoolcfg) { - t.Error(cgrCfg.RALsHistorySConns) - } if !reflect.DeepEqual(cgrCfg.RALsPubSubSConns, eHaPoolcfg) { t.Error(cgrCfg.RALsPubSubSConns) } @@ -599,18 +596,6 @@ func TestCgrCfgJSONDefaultsSMAsteriskCfg(t *testing.T) { } } -func TestCgrCfgJSONDefaultsHistoryS(t *testing.T) { - if cgrCfg.HistoryServerEnabled != false { - t.Error(cgrCfg.HistoryServerEnabled) - } - if cgrCfg.HistoryDir != "/var/lib/cgrates/history" { - t.Error(cgrCfg.HistoryDir) - } - if cgrCfg.HistorySaveInterval != 1*time.Second { - t.Error(cgrCfg.HistorySaveInterval) - } -} - func TestCgrCfgJSONDefaultsPubSubS(t *testing.T) { if cgrCfg.PubSubServerEnabled != false { t.Error(cgrCfg.PubSubServerEnabled) diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 521c40924..2786d44a5 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -83,7 +83,6 @@ type RalsJsonCfg struct { Thresholds_conns *[]*HaPoolJsonCfg Cdrstats_conns *[]*HaPoolJsonCfg Stats_conns *[]*HaPoolJsonCfg - Historys_conns *[]*HaPoolJsonCfg Pubsubs_conns *[]*HaPoolJsonCfg Attributes_conns *[]*HaPoolJsonCfg Aliases_conns *[]*HaPoolJsonCfg diff --git a/data/conf/cgrates/cgrates.json b/data/conf/cgrates/cgrates.json index ad81d3f5b..e3b07c210 100644 --- a/data/conf/cgrates/cgrates.json +++ b/data/conf/cgrates/cgrates.json @@ -94,7 +94,6 @@ // "rals": { // "enabled": false, // enable Rater service: // "cdrstats_conns": [], // address where to reach the cdrstats service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234> -// "historys_conns": [], // address where to reach the history service, empty to disable history functionality: <""|*internal|x.y.z.y:1234> // "pubsubs_conns": [], // address where to reach the pubusb service, empty to disable pubsub functionality: <""|*internal|x.y.z.y:1234> // "users_conns": [], // address where to reach the user service, empty to disable user profile functionality: <""|*internal|x.y.z.y:1234> // "aliases_conns": [], // address where to reach the aliases service, empty to disable aliases functionality: <""|*internal|x.y.z.y:1234> @@ -360,13 +359,6 @@ // }, -// "historys": { -// "enabled": false, // starts History service: . -// "history_dir": "/var/lib/cgrates/history", // location on disk where to store history files. -// "save_interval": "1s", // interval to save changed cache into .git archive -// }, - - // "pubsubs": { // "enabled": false, // starts PubSub service: . // }, diff --git a/data/conf/samples/tutmongo/cgrates.json b/data/conf/samples/tutmongo/cgrates.json index 9e94988f4..f9b5a854b 100644 --- a/data/conf/samples/tutmongo/cgrates.json +++ b/data/conf/samples/tutmongo/cgrates.json @@ -158,11 +158,6 @@ }, -"historys": { - "enabled": true, -}, - - "aliases": { "enabled": true, }, diff --git a/data/conf/samples/tutmysql/cgrates.json b/data/conf/samples/tutmysql/cgrates.json index 60cdd6e27..f424dac56 100644 --- a/data/conf/samples/tutmysql/cgrates.json +++ b/data/conf/samples/tutmysql/cgrates.json @@ -150,11 +150,6 @@ }, -"historys": { - "enabled": true, -}, - - "aliases": { "enabled": true, }, diff --git a/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json b/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json index e6880d9d6..7608d36e0 100644 --- a/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json @@ -29,9 +29,6 @@ "cdrstats_conns": [ {"address": "*internal"} ], - "historys_conns": [ - {"address": "*internal"} - ], "pubsubs_conns": [ {"address": "*internal"} ], @@ -142,12 +139,6 @@ }, -"historys": { - "enabled": true, // starts History service: . - "history_dir": "/tmp/cgr_osipsasync/cgrates/history", // location on disk where to store history files. -}, - - "pubsubs": { "enabled": true, // starts PubSub service: . }, diff --git a/data/tutorials/asterisk_ari/cgrates/etc/init.d/cgrates b/data/tutorials/asterisk_ari/cgrates/etc/init.d/cgrates index 2d8543976..9bafa0608 100755 --- a/data/tutorials/asterisk_ari/cgrates/etc/init.d/cgrates +++ b/data/tutorials/asterisk_ari/cgrates/etc/init.d/cgrates @@ -29,7 +29,6 @@ PIDFILE=$RUNDIR/cgr-engine.pid STACKTRACE=$RUNDIR/$NAME.strace ENABLE=true DAEMON_OPTS="-config_dir=$TUTFOLDER/etc/cgrates" -HISTDIR=$TMP_DIR/history CDREDIR=$TMP_DIR/cdre CDRCINDIR=$TMP_DIR/cdrc/in CDRCOUTDIR=$TMP_DIR/cdrc/out @@ -68,11 +67,6 @@ if [ ! -d $CDREDIR ]; then mkdir -p $CDREDIR chown $USER:$GROUP $CDREDIR fi -# Install the history folder -if [ ! -d $HISTDIR ]; then - mkdir -p $HISTDIR - chown $USER:$GROUP $HISTDIR -fi # # Function that starts the daemon/service diff --git a/data/tutorials/fs_evsock/README.md b/data/tutorials/fs_evsock/README.md index 46467eb65..15a9598f5 100644 --- a/data/tutorials/fs_evsock/README.md +++ b/data/tutorials/fs_evsock/README.md @@ -15,4 +15,3 @@ Scenario: - CGR-Mediator component attaching costs to the raw CDRs from FreeSWITCH_ inside CGR StorDB. - CGR-CDRE exporting mediated CDRs from CGR StorDB (export path: */tmp*). - CGR-CDRStats component building up stats in 5 different queues. - - CGR-History component keeping the archive of the rates modifications (path browsable with git client at */tmp/cgr_history*). diff --git a/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json b/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json index 78ad83432..a6b570600 100644 --- a/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json @@ -12,9 +12,6 @@ "cdrstats_conns": [ {"address": "*internal"} ], - "historys_conns": [ - {"address": "*internal"} - ], "pubsubs_conns": [ {"address": "*internal"} ], @@ -132,12 +129,6 @@ }, -"historys": { - "enabled": true, // starts History service: . - "history_dir": "/tmp/cgr_fsevsock/cgrates/history", // location on disk where to store history files. -}, - - "pubsubs": { "enabled": true, // starts PubSub service: . }, diff --git a/data/tutorials/fs_evsock/cgrates/etc/init.d/.fuse_hidden0000001700000001 b/data/tutorials/fs_evsock/cgrates/etc/init.d/.fuse_hidden0000001700000001 index 8011a04a5..bf03c9e1c 100755 --- a/data/tutorials/fs_evsock/cgrates/etc/init.d/.fuse_hidden0000001700000001 +++ b/data/tutorials/fs_evsock/cgrates/etc/init.d/.fuse_hidden0000001700000001 @@ -29,7 +29,6 @@ PIDFILE=$RUNDIR/cgr-engine.pid STACKTRACE=$RUNDIR/$NAME.strace ENABLE=true DAEMON_OPTS="-config_dir=/usr/share/cgrates/tutorials/fs_evsock/cgrates/etc/cgrates" -HISTDIR=$TMP_DIR/history CDREDIR=$TMP_DIR/cdre # Exit if the package is not installed @@ -59,11 +58,6 @@ if [ ! -d $CDREDIR ]; then mkdir -p $CDREDIR chown $USER:$GROUP $CDREDIR fi -# Install the history folder -if [ ! -d $HISTDIR ]; then - mkdir -p $HISTDIR - chown $USER:$GROUP $HISTDIR -fi # # Function that starts the daemon/service diff --git a/data/tutorials/fs_evsock/cgrates/etc/init.d/cgrates b/data/tutorials/fs_evsock/cgrates/etc/init.d/cgrates index 9e4230c92..66e50a990 100755 --- a/data/tutorials/fs_evsock/cgrates/etc/init.d/cgrates +++ b/data/tutorials/fs_evsock/cgrates/etc/init.d/cgrates @@ -29,7 +29,6 @@ PIDFILE=$RUNDIR/cgr-engine.pid STACKTRACE=$RUNDIR/$NAME.strace ENABLE=true DAEMON_OPTS="-config_dir=$TUTFOLDER/etc/cgrates" -HISTDIR=$TMP_DIR/history CDREDIR=$TMP_DIR/cdre CDRCINDIR=$TMP_DIR/cdrc/in CDRCOUTDIR=$TMP_DIR/cdrc/out @@ -68,11 +67,6 @@ if [ ! -d $CDREDIR ]; then mkdir -p $CDREDIR chown $USER:$GROUP $CDREDIR fi -# Install the history folder -if [ ! -d $HISTDIR ]; then - mkdir -p $HISTDIR - chown $USER:$GROUP $HISTDIR -fi # # Function that starts the daemon/service diff --git a/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json b/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json index 8cea3520e..a6d86e587 100644 --- a/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json @@ -19,9 +19,6 @@ "cdrstats_conns": [ {"address": "*internal"} ], - "historys_conns": [ - {"address": "*internal"} - ], "pubsubs_conns": [ {"address": "*internal"} ], @@ -121,12 +118,6 @@ }, -"historys": { - "enabled": true, - "history_dir": "/tmp/cgr_kamevapi/cgrates/history", -}, - - "pubsubs": { "enabled": true, }, diff --git a/data/tutorials/kamevapi/cgrates/etc/init.d/cgrates b/data/tutorials/kamevapi/cgrates/etc/init.d/cgrates index f3595026a..dc969b416 100755 --- a/data/tutorials/kamevapi/cgrates/etc/init.d/cgrates +++ b/data/tutorials/kamevapi/cgrates/etc/init.d/cgrates @@ -29,7 +29,6 @@ PIDFILE=$RUNDIR/cgr-engine.pid STACKTRACE=$RUNDIR/$NAME.strace ENABLE=true DAEMON_OPTS="-config_dir=$TUTFOLDER/etc/cgrates" -HISTDIR=$TMP_DIR/history CDREDIR=$TMP_DIR/cdre # Exit if the package is not installed @@ -59,11 +58,6 @@ if [ ! -d $CDREDIR ]; then mkdir -p $CDREDIR chown $USER:$GROUP $CDREDIR fi -# Install the history folder -if [ ! -d $HISTDIR ]; then - mkdir -p $HISTDIR - chown $USER:$GROUP $HISTDIR -fi # # Function that starts the daemon/service diff --git a/data/tutorials/osips_async/cgrates/etc/cgrates/cgrates.json b/data/tutorials/osips_async/cgrates/etc/cgrates/cgrates.json index 577da4fe0..866000c5e 100644 --- a/data/tutorials/osips_async/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/osips_async/cgrates/etc/cgrates/cgrates.json @@ -10,9 +10,6 @@ "cdrstats_conns": [ {"address": "*internal"} ], - "historys_conns": [ - {"address": "*internal"} - ], "pubsubs_conns": [ {"address": "*internal"} ], @@ -109,12 +106,6 @@ }, -"historys": { - "enabled": true, // starts History service: . - "history_dir": "/tmp/cgr_osipsasync/cgrates/history", // location on disk where to store history files. -}, - - "pubsubs": { "enabled": true, // starts PubSub service: . }, diff --git a/data/tutorials/osips_async/cgrates/etc/init.d/.fuse_hidden0000001700000001 b/data/tutorials/osips_async/cgrates/etc/init.d/.fuse_hidden0000001700000001 index 8011a04a5..bf03c9e1c 100755 --- a/data/tutorials/osips_async/cgrates/etc/init.d/.fuse_hidden0000001700000001 +++ b/data/tutorials/osips_async/cgrates/etc/init.d/.fuse_hidden0000001700000001 @@ -29,7 +29,6 @@ PIDFILE=$RUNDIR/cgr-engine.pid STACKTRACE=$RUNDIR/$NAME.strace ENABLE=true DAEMON_OPTS="-config_dir=/usr/share/cgrates/tutorials/fs_evsock/cgrates/etc/cgrates" -HISTDIR=$TMP_DIR/history CDREDIR=$TMP_DIR/cdre # Exit if the package is not installed @@ -59,11 +58,6 @@ if [ ! -d $CDREDIR ]; then mkdir -p $CDREDIR chown $USER:$GROUP $CDREDIR fi -# Install the history folder -if [ ! -d $HISTDIR ]; then - mkdir -p $HISTDIR - chown $USER:$GROUP $HISTDIR -fi # # Function that starts the daemon/service diff --git a/data/tutorials/osips_async/cgrates/etc/init.d/cgrates b/data/tutorials/osips_async/cgrates/etc/init.d/cgrates index 9539c65cc..aaf141440 100755 --- a/data/tutorials/osips_async/cgrates/etc/init.d/cgrates +++ b/data/tutorials/osips_async/cgrates/etc/init.d/cgrates @@ -29,7 +29,6 @@ PIDFILE=$RUNDIR/cgr-engine.pid STACKTRACE=$RUNDIR/$NAME.strace ENABLE=true DAEMON_OPTS="-config_dir=$TUTFOLDER/etc/cgrates" -HISTDIR=$TMP_DIR/history CDREDIR=$TMP_DIR/cdre # Exit if the package is not installed @@ -59,11 +58,6 @@ if [ ! -d $CDREDIR ]; then mkdir -p $CDREDIR chown $USER:$GROUP $CDREDIR fi -# Install the history folder -if [ ! -d $HISTDIR ]; then - mkdir -p $HISTDIR - chown $USER:$GROUP $HISTDIR -fi # # Function that starts the daemon/service diff --git a/data/tutorials/osips_native/cgrates/etc/cgrates/cgrates.json b/data/tutorials/osips_native/cgrates/etc/cgrates/cgrates.json index b9d2d62bd..3539bb321 100644 --- a/data/tutorials/osips_native/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/osips_native/cgrates/etc/cgrates/cgrates.json @@ -17,9 +17,6 @@ "cdrstats_conns": [ {"address": "*internal"} ], - "historys_conns": [ - {"address": "*internal"} - ], "pubsubs_conns": [ {"address": "*internal"} ], @@ -113,12 +110,6 @@ }, -"historys": { - "enabled": true, // starts History service: . - "history_dir": "/tmp/cgr_osipsnative/cgrates/history", // location on disk where to store history files. -}, - - "pubsubs": { "enabled": true, // starts PubSub service: . }, diff --git a/data/tutorials/osips_native/cgrates/etc/init.d/.fuse_hidden0000001700000001 b/data/tutorials/osips_native/cgrates/etc/init.d/.fuse_hidden0000001700000001 index 8011a04a5..bf03c9e1c 100755 --- a/data/tutorials/osips_native/cgrates/etc/init.d/.fuse_hidden0000001700000001 +++ b/data/tutorials/osips_native/cgrates/etc/init.d/.fuse_hidden0000001700000001 @@ -29,7 +29,6 @@ PIDFILE=$RUNDIR/cgr-engine.pid STACKTRACE=$RUNDIR/$NAME.strace ENABLE=true DAEMON_OPTS="-config_dir=/usr/share/cgrates/tutorials/fs_evsock/cgrates/etc/cgrates" -HISTDIR=$TMP_DIR/history CDREDIR=$TMP_DIR/cdre # Exit if the package is not installed @@ -59,11 +58,6 @@ if [ ! -d $CDREDIR ]; then mkdir -p $CDREDIR chown $USER:$GROUP $CDREDIR fi -# Install the history folder -if [ ! -d $HISTDIR ]; then - mkdir -p $HISTDIR - chown $USER:$GROUP $HISTDIR -fi # # Function that starts the daemon/service diff --git a/data/tutorials/osips_native/cgrates/etc/init.d/cgrates b/data/tutorials/osips_native/cgrates/etc/init.d/cgrates index bac8e4a99..cdbe2a758 100755 --- a/data/tutorials/osips_native/cgrates/etc/init.d/cgrates +++ b/data/tutorials/osips_native/cgrates/etc/init.d/cgrates @@ -29,7 +29,6 @@ PIDFILE=$RUNDIR/cgr-engine.pid STACKTRACE=$RUNDIR/$NAME.strace ENABLE=true DAEMON_OPTS="-config_dir=$TUTFOLDER/etc/cgrates" -HISTDIR=$TMP_DIR/history CDREDIR=$TMP_DIR/cdre # Exit if the package is not installed @@ -59,11 +58,6 @@ if [ ! -d $CDREDIR ]; then mkdir -p $CDREDIR chown $USER:$GROUP $CDREDIR fi -# Install the history folder -if [ ! -d $HISTDIR ]; then - mkdir -p $HISTDIR - chown $USER:$GROUP $HISTDIR -fi # # Function that starts the daemon/service diff --git a/docs/advanced.rst b/docs/advanced.rst index 0a6fe3558..7a6eebae4 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -11,7 +11,6 @@ cdrstats lcr derived_charging - history ratinglogic diff --git a/docs/architecture.rst b/docs/architecture.rst index 4597bd317..42937c665 100644 --- a/docs/architecture.rst +++ b/docs/architecture.rst @@ -211,22 +211,7 @@ Gathers offline CDRs and post them to CDR Server - (CDRS component) - Config section in the CGRateS configuration file: - ``"cdrc": {...}`` -2.1.8. History service -~~~~~~~~~~~~~~~~~~~~~~ -Archives rate changes in human readable JSON format using **GIT**. - -- Communicates via: - - RPC - - internal/in-process *within the same running* **cgr-engine** process. - -- Operates with the following CGRateS database(s): :: - - - none - -- Config section in the CGRateS configuration file: - - ``"historys": {...}`` - -2.1.9. Aliases service +2.1.8. Aliases service ~~~~~~~~~~~~~~~~~~~~~~~ Generic purpose **aliasing** system. @@ -246,7 +231,7 @@ Possible applications: - Config section in the CGRateS configuration file: - ``"aliases": {...}`` -2.1.10. User service +2.1.9. User service ~~~~~~~~~~~~~~~~~~~~ Generic purpose **user** system to maintain user profiles (LDAP similarity). @@ -261,7 +246,7 @@ Generic purpose **user** system to maintain user profiles (LDAP similarity). - Config section in the CGRateS configuration file: - ``"users": {...}`` -2.1.11. PubSub service +2.1.10. PubSub service ~~~~~~~~~~~~~~~~~~~~~~ PubSub service used to expose internal events to interested external components (eg: balance ops) @@ -277,7 +262,7 @@ PubSub service used to expose internal events to interested external components - ``"pubsubs": {...}`` -2.1.12. Resource Limiter service +2.1.11. Resource Limiter service ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Resource Limiter service used to limit resources during authorization (eg: maximum calls per destination for an account) @@ -292,7 +277,7 @@ Resource Limiter service used to limit resources during authorization (eg: maxim - Config section in the CGRateS configuration file: - ``"rls": {...}`` -2.1.13. APIER RPC service +2.1.12. APIER RPC service ~~~~~~~~~~~~~~~~~~~~~~~~~ RPC service used to expose external access towards internal components. @@ -301,7 +286,7 @@ RPC service used to expose external access towards internal components. - JSON over HTTP - JSON over WebSocket -2.1.14. Cdre +2.1.13. Cdre ~~~~~~~~~~~~ Component to retrieve rated CDRs from internal CDRs database. @@ -314,7 +299,7 @@ Component to retrieve rated CDRs from internal CDRs database. - Config section in the CGRateS configuration file: - ``"cdre": {...}`` -2.1.15. Mailer +2.1.14. Mailer ~~~~~~~~~~~~~~ TBD @@ -325,7 +310,7 @@ TBD - Config section in the CGRateS configuration file: - ``"mailer": {...}`` -2.1.16. Suretax +2.1.15. Suretax ~~~~~~~~~~~~~~~ TBD @@ -386,8 +371,6 @@ Can be used to: Flush the database before importing -from_stordb Load the tariff plan from storDb to dataDb - -history_server string - The history server address:port, empty to disable automatic history archiving (default "127.0.0.1:2013") -load_history_size int Limit the number of records in the load history (default 10) -migrate_rc8 string diff --git a/docs/history.rst b/docs/history.rst index 4c51f2666..63209b91d 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -6,26 +6,6 @@ Enhances CGRateS with ability to archive rates modifications. Large scaling posibility using server-agents approach. In a distributed environment, there will be a single server (which can be backed up using technologies such as Linux-HA) and more agents sending the modifications to be archived. -History-Server --------------- - -Part of the *cgr-engine*. - -Controlled within *history_server* section of the configuration file. - -Stores rating archive in a .git folder, hence making the changes available for analysis via any git browser tool (eg: gitg in linux). - -Functionality: - -- On startup reads the rating archive out of .git folder and caches the data. -- When receiving rating information from the agents it will recompile the cache. -- Based on configured save interval it will dump the rating cache (if changed) into the .git archive. -- Archives the following rating data: - - - Destinations inside *destinations.json* file. - - Rating plans inside *rating_plans.json* file. - - Rating profiles inside *rating_profiles.json* file. - History-Agent ------------- diff --git a/engine/calldesc.go b/engine/calldesc.go index dd5d46ded..543399169 100755 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -72,7 +72,6 @@ var ( debitPeriod = 10 * time.Second globalRoundingDecimals = 6 thresholdS rpcclient.RpcClientConnection // used by RALs to communicate with ThresholdS - historyScribe rpcclient.RpcClientConnection pubSubServer rpcclient.RpcClientConnection userService rpcclient.RpcClientConnection aliasService rpcclient.RpcClientConnection @@ -109,11 +108,6 @@ func SetCdrStorage(cStorage CdrStorage) { cdrStorage = cStorage } -// Exported method to set the history scribe. -func SetHistoryScribe(scribe rpcclient.RpcClientConnection) { - historyScribe = scribe -} - func SetPubSub(ps rpcclient.RpcClientConnection) { pubSubServer = ps } diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go index 2211108cb..992d874a7 100644 --- a/engine/calldesc_test.go +++ b/engine/calldesc_test.go @@ -18,7 +18,6 @@ along with this program. If not, see package engine import ( - "github.com/cgrates/cgrates/history" "github.com/cgrates/cgrates/utils" "log" "reflect" @@ -32,7 +31,6 @@ var ( ) func init() { - historyScribe, _ = history.NewMockScribe() dm.DataDB().Flush("") populateDB() } diff --git a/engine/destinations.go b/engine/destinations.go index 77af7df00..f50e48443 100644 --- a/engine/destinations.go +++ b/engine/destinations.go @@ -19,12 +19,9 @@ along with this program. If not, see package engine import ( - "encoding/json" "strings" "github.com/cgrates/cgrates/utils" - - "github.com/cgrates/cgrates/history" ) func NewDestinationFromTPDestination(tpDst *utils.TPDestination) *Destination { @@ -66,17 +63,6 @@ func (d *Destination) AddPrefix(pfx string) { d.Prefixes = append(d.Prefixes, pfx) } -// history record method -func (d *Destination) GetHistoryRecord(deleted bool) history.Record { - js, _ := json.Marshal(d) - return history.Record{ - Id: d.Id, - Filename: history.DESTINATIONS_FN, - Payload: js, - Deleted: deleted, - } -} - // Reverse search in cache to see if prefix belongs to destination id func CachedDestHasPrefix(destId, prefix string) bool { if cached, err := dm.DataDB().GetReverseDestination(prefix, false, utils.NonTransactional); err == nil { diff --git a/engine/history_test.go b/engine/history_test.go deleted file mode 100644 index c834ac609..000000000 --- a/engine/history_test.go +++ /dev/null @@ -1,56 +0,0 @@ -/* -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 engine - -import ( - "strings" - "testing" - - "github.com/cgrates/cgrates/history" -) - -func TestHistoryRatinPlans(t *testing.T) { - scribe := historyScribe.(*history.MockScribe) - buf := scribe.GetBuffer(history.RATING_PROFILES_FN) - if !strings.Contains(buf.String(), `{"Id":"*out:vdf:0:minu","RatingPlanActivations":[{"ActivationTime":"2012-01-01T00:00:00Z","RatingPlanId":"EVENING","FallbackKeys":null,"CdrStatQueueIds":[""]}]}`) { - t.Error("Error in destination history content:", buf.String()) - } -} - -func TestHistoryDestinations(t *testing.T) { - scribe := historyScribe.(*history.MockScribe) - buf := scribe.GetBuffer(history.DESTINATIONS_FN) - expected := `{"Id":"ALL","Prefixes":["49","41","43"]}, -{"Id":"DST_TCDDBSWF","Prefixes":["1716"]}, -{"Id":"DST_UK_Mobile_BIG5","Prefixes":["447956"]}, -{"Id":"EU_LANDLINE","Prefixes":["444"]}, -{"Id":"EXOTIC","Prefixes":["999"]}, -{"Id":"GERMANY","Prefixes":["49"]}, -{"Id":"GERMANY_O2","Prefixes":["41"]}, -{"Id":"GERMANY_PREMIUM","Prefixes":["43"]}, -{"Id":"NAT","Prefixes":["0256","0257","0723","+49"]}, -{"Id":"PSTN_70","Prefixes":["+4970"]}, -{"Id":"PSTN_71","Prefixes":["+4971"]}, -{"Id":"PSTN_72","Prefixes":["+4972"]}, -{"Id":"RET","Prefixes":["0723","0724"]}, -{"Id":"SPEC","Prefixes":["0723045"]}, -{"Id":"URG","Prefixes":["112"]}` - if !strings.Contains(buf.String(), expected) { - t.Errorf("Expecting:\n%s\nReceived:\n%s", expected, buf.String()) - } -} diff --git a/engine/ratingplan.go b/engine/ratingplan.go index 46a93084f..ee8efc798 100644 --- a/engine/ratingplan.go +++ b/engine/ratingplan.go @@ -19,10 +19,7 @@ along with this program. If not, see package engine import ( - "encoding/json" "math" - - "github.com/cgrates/cgrates/history" ) /* @@ -99,16 +96,6 @@ func (rp *RatingPlan) Equal(o *RatingPlan) bool { return rp.Id == o.Id } -// history record method -func (rp *RatingPlan) GetHistoryRecord() history.Record { - js, _ := json.Marshal(rp) - return history.Record{ - Id: rp.Id, - Filename: history.RATING_PLANS_FN, - Payload: js, - } -} - // IsValid determines if the rating plan covers a continous period of time func (rp *RatingPlan) isContinous() bool { weekdays := make([]int, 7) diff --git a/engine/ratingprofile.go b/engine/ratingprofile.go index 6dc0af651..58f9bff3d 100644 --- a/engine/ratingprofile.go +++ b/engine/ratingprofile.go @@ -25,7 +25,6 @@ import ( "strings" "time" - "github.com/cgrates/cgrates/history" "github.com/cgrates/cgrates/utils" ) @@ -240,17 +239,6 @@ func (rpf *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error return utils.ErrNotFound } -// history record method -func (rpf *RatingProfile) GetHistoryRecord(deleted bool) history.Record { - js, _ := json.Marshal(rpf) - return history.Record{ - Id: rpf.Id, - Filename: history.RATING_PROFILES_FN, - Payload: js, - Deleted: deleted, - } -} - type TenantRatingSubject struct { Tenant, Subject string } diff --git a/engine/storage_map.go b/engine/storage_map.go index 8584db724..441bf4da7 100755 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -258,10 +258,6 @@ func (ms *MapStorage) SetRatingPlanDrv(rp *RatingPlan) (err error) { w.Write(result) w.Close() ms.dict[utils.RATING_PLAN_PREFIX+rp.Id] = b.Bytes() - response := 0 - if historyScribe != nil { - go historyScribe.Call("HistoryV1.Record", rp.GetHistoryRecord(), &response) - } return } @@ -271,11 +267,6 @@ func (ms *MapStorage) RemoveRatingPlanDrv(key string) (err error) { for k := range ms.dict { if strings.HasPrefix(k, key) { delete(ms.dict, key) - response := 0 - rpf := &RatingPlan{Id: key} - if historyScribe != nil { - go historyScribe.Call("HistoryV1.Record", rpf.GetHistoryRecord(), &response) - } } } return @@ -300,10 +291,6 @@ func (ms *MapStorage) SetRatingProfileDrv(rpf *RatingProfile) (err error) { defer ms.mu.Unlock() result, err := ms.ms.Marshal(rpf) ms.dict[utils.RATING_PROFILE_PREFIX+rpf.Id] = result - response := 0 - if historyScribe != nil { - go historyScribe.Call("HistoryV1.Record", rpf.GetHistoryRecord(false), &response) - } return } @@ -313,11 +300,6 @@ func (ms *MapStorage) RemoveRatingProfileDrv(key string) (err error) { for k := range ms.dict { if strings.HasPrefix(k, key) { delete(ms.dict, key) - response := 0 - rpf := &RatingProfile{Id: key} - if historyScribe != nil { - go historyScribe.Call("HistoryV1.Record", rpf.GetHistoryRecord(true), &response) - } } } return @@ -400,10 +382,6 @@ func (ms *MapStorage) SetDestination(dest *Destination, transactionID string) (e w.Close() key := utils.DESTINATION_PREFIX + dest.Id ms.dict[key] = b.Bytes() - response := 0 - if historyScribe != nil { - go historyScribe.Call("HistoryV1.Record", dest.GetHistoryRecord(false), &response) - } cache.RemKey(key, cacheCommit(transactionID), transactionID) return } diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index b2dfa6a39..16ab10fba 100755 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -756,10 +756,6 @@ func (ms *MongoStorage) SetRatingPlanDrv(rp *RatingPlan) error { Key string Value []byte }{Key: rp.Id, Value: b.Bytes()}) - if err == nil && historyScribe != nil { - var response int - historyScribe.Call("HistoryV1.Record", rp.GetHistoryRecord(), &response) - } return err } @@ -788,10 +784,6 @@ func (ms *MongoStorage) RemoveRatingPlanDrv(key string) error { if err = ms.ms.Unmarshal(out, &rp); err != nil { return err } - if err == nil && historyScribe != nil { - var response int - go historyScribe.Call("HistoryV1.Record", rp.GetHistoryRecord(), &response) - } } return iter.Close() } @@ -814,10 +806,6 @@ func (ms *MongoStorage) SetRatingProfileDrv(rp *RatingProfile) (err error) { if _, err = col.Upsert(bson.M{"id": rp.Id}, rp); err != nil { return } - if historyScribe != nil { - var response int - historyScribe.Call("HistoryV1.Record", rp.GetHistoryRecord(false), &response) - } return } @@ -830,11 +818,6 @@ func (ms *MongoStorage) RemoveRatingProfileDrv(key string) error { if err := col.Remove(bson.M{"id": result.Id}); err != nil { return err } - rpf := &RatingProfile{Id: result.Id} - if historyScribe != nil { - var response int - go historyScribe.Call("HistoryV1.Record", rpf.GetHistoryRecord(true), &response) - } } return iter.Close() } @@ -934,10 +917,6 @@ func (ms *MongoStorage) SetDestination(dest *Destination, transactionID string) }{Key: dest.Id, Value: b.Bytes()}); err != nil { return } - if historyScribe != nil { - var response int - historyScribe.Call("HistoryV1.Record", dest.GetHistoryRecord(false), &response) - } return } diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 9bac915b3..cc4020f0a 100755 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -309,10 +309,6 @@ func (rs *RedisStorage) SetRatingPlanDrv(rp *RatingPlan) (err error) { w.Write(result) w.Close() err = rs.Cmd("SET", utils.RATING_PLAN_PREFIX+rp.Id, b.Bytes()).Err - if err == nil && historyScribe != nil { - response := 0 - go historyScribe.Call("HistoryV1.Record", rp.GetHistoryRecord(), &response) - } return } @@ -325,11 +321,6 @@ func (rs *RedisStorage) RemoveRatingPlanDrv(key string) error { if err = rs.Cmd("DEL", key).Err; err != nil { return err } - rpf := &RatingProfile{Id: key} - if historyScribe != nil { - response := 0 - go historyScribe.Call("HistoryV1.Record", rpf.GetHistoryRecord(true), &response) - } } return nil } @@ -358,10 +349,6 @@ func (rs *RedisStorage) SetRatingProfileDrv(rpf *RatingProfile) (err error) { if err = rs.Cmd("SET", key, result).Err; err != nil { return } - if historyScribe != nil { - response := 0 - go historyScribe.Call("HistoryV1.Record", rpf.GetHistoryRecord(false), &response) - } return } @@ -374,11 +361,6 @@ func (rs *RedisStorage) RemoveRatingProfileDrv(key string) error { if err = rs.Cmd("DEL", key).Err; err != nil { return err } - rpf := &RatingProfile{Id: key} - if historyScribe != nil { - response := 0 - go historyScribe.Call("HistoryV1.Record", rpf.GetHistoryRecord(true), &response) - } } return nil } @@ -466,10 +448,6 @@ func (rs *RedisStorage) SetDestination(dest *Destination, transactionID string) if err = rs.Cmd("SET", key, b.Bytes()).Err; err != nil { return err } - if historyScribe != nil { - response := 0 - go historyScribe.Call("HistoryV1.Record", dest.GetHistoryRecord(false), &response) - } return } diff --git a/history/file_scribe.go b/history/file_scribe.go deleted file mode 100644 index 8d7bf9f6b..000000000 --- a/history/file_scribe.go +++ /dev/null @@ -1,204 +0,0 @@ -/* -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 history - -import ( - "bufio" - "encoding/json" - "errors" - "fmt" - "io" - "log" - "os" - "os/exec" - "path/filepath" - "reflect" - "strings" - "sync" - "time" - - "github.com/cgrates/cgrates/utils" -) - -type FileScribe struct { - mu sync.Mutex - fileRoot string - gitCommand string - loopChecker chan int - waitingFile string - savePeriod time.Duration -} - -func NewFileScribe(fileRoot string, saveInterval time.Duration) (*FileScribe, error) { - // looking for git - gitCommand, err := exec.LookPath("git") - if err != nil { - return nil, errors.New("Please install git: " + err.Error()) - } - s := &FileScribe{fileRoot: fileRoot, gitCommand: gitCommand, savePeriod: saveInterval} - s.loopChecker = make(chan int) - files := []string{DESTINATIONS_FN, RATING_PLANS_FN, RATING_PROFILES_FN} - s.gitInit(files) - - for _, fn := range files { - if err := s.load(fn); err != nil { - return nil, err - } - } - return s, nil -} - -func (s *FileScribe) Record(rec Record, out *int) error { - s.mu.Lock() - fileToSave := rec.Filename - recordsMap[fileToSave] = recordsMap[fileToSave].Modify(&rec) - - // flood protection for save method (do not save on every loop iteration) - if s.waitingFile == fileToSave { - s.loopChecker <- 1 - } - s.waitingFile = fileToSave - defer s.mu.Unlock() - go func() { - t := time.NewTicker(s.savePeriod) - select { - case <-s.loopChecker: - t.Stop() - // cancel saving - case <-t.C: - if fileToSave != "" { - s.save(fileToSave) - } - t.Stop() - s.waitingFile = "" - } - }() - // no protection variant - /*if fileToSave != "" { - s.save(fileToSave) - }*/ - *out = 0 - return nil -} - -func (s *FileScribe) gitInit(files []string) error { - s.mu.Lock() - defer s.mu.Unlock() - if _, err := os.Stat(s.fileRoot); os.IsNotExist(err) { - if err := os.MkdirAll(s.fileRoot, os.ModeDir|0755); err != nil { - return errors.New(" Error creating history folder: " + err.Error()) - } - } - if _, err := os.Stat(filepath.Join(s.fileRoot, ".git")); os.IsNotExist(err) { - cmd := exec.Command(s.gitCommand, "init") - cmd.Dir = s.fileRoot - if out, err := cmd.Output(); err != nil { - return errors.New(string(out) + " " + err.Error()) - } - log.Print("CREATING FILES") - for _, fn := range files { - log.Print("FILE: ", fn) - if f, err := os.Create(filepath.Join(s.fileRoot, fn)); err != nil { - return fmt.Errorf(" Error writing %s file: %s", fn, err.Error()) - } else { - f.Close() - } - } - - cmd = exec.Command(s.gitCommand, "add", ".") - cmd.Dir = s.fileRoot - if out, err := cmd.Output(); err != nil { - return errors.New(string(out) + " " + err.Error()) - } - } - return nil -} - -func (s *FileScribe) gitCommit() error { - cmd := exec.Command(s.gitCommand, "commit", "-a", "-m", "'historic commit'") - cmd.Dir = s.fileRoot - if out, err := cmd.Output(); err != nil { - return errors.New(string(out) + " " + err.Error()) - } - return nil -} - -func (s *FileScribe) load(filename string) error { - s.mu.Lock() - defer s.mu.Unlock() - f, err := os.Open(filepath.Join(s.fileRoot, filename)) - if err != nil { - return err - } - defer f.Close() - d := json.NewDecoder(f) - - records := recordsMap[filename] - if err := d.Decode(&records); err != nil && err != io.EOF { - return fmt.Errorf(" Error loading %s: %s", filename, err.Error()) - } - records.Sort() - return nil -} - -func (s *FileScribe) save(filename string) error { - s.mu.Lock() - defer s.mu.Unlock() - f, err := os.Create(filepath.Join(s.fileRoot, filename)) - if err != nil { - return err - } - - b := bufio.NewWriter(f) - records := recordsMap[filename] - if err := format(b, records); err != nil { - return err - } - b.Flush() - f.Close() - return s.gitCommit() -} - -func (s *FileScribe) Call(serviceMethod string, args interface{}, reply interface{}) error { - parts := strings.Split(serviceMethod, ".") - if len(parts) != 2 { - return utils.ErrNotImplemented - } - // get method - method := reflect.ValueOf(s).MethodByName(parts[1]) - if !method.IsValid() { - return utils.ErrNotImplemented - } - - // construct the params - params := []reflect.Value{reflect.ValueOf(args), reflect.ValueOf(reply)} - - ret := method.Call(params) - if len(ret) != 1 { - return utils.ErrServerError - } - if ret[0].Interface() == nil { - return nil - } - err, ok := ret[0].Interface().(error) - if !ok { - return utils.ErrServerError - } - return err -} diff --git a/history/mock_scribe.go b/history/mock_scribe.go deleted file mode 100644 index 0ffd175de..000000000 --- a/history/mock_scribe.go +++ /dev/null @@ -1,98 +0,0 @@ -/* -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 history - -import ( - "bufio" - "bytes" - "reflect" - "strings" - "sync" - - "github.com/cgrates/cgrates/utils" -) - -type MockScribe struct { - mu sync.Mutex - BufMap map[string]*bytes.Buffer -} - -func NewMockScribe() (*MockScribe, error) { - return &MockScribe{BufMap: map[string]*bytes.Buffer{ - DESTINATIONS_FN: bytes.NewBuffer(nil), - RATING_PLANS_FN: bytes.NewBuffer(nil), - RATING_PROFILES_FN: bytes.NewBuffer(nil), - }}, nil -} - -func (s *MockScribe) Record(rec Record, out *int) error { - s.mu.Lock() - fn := rec.Filename - recordsMap[fn] = recordsMap[fn].Modify(&rec) - s.mu.Unlock() - s.save(fn) - return nil -} - -func (s *MockScribe) save(filename string) error { - s.mu.Lock() - defer s.mu.Unlock() - records := recordsMap[filename] - s.BufMap[filename].Reset() - b := bufio.NewWriter(s.BufMap[filename]) - defer b.Flush() - if err := format(b, records); err != nil { - return err - } - return nil -} - -func (s *MockScribe) GetBuffer(fn string) *bytes.Buffer { - s.mu.Lock() - defer s.mu.Unlock() - return s.BufMap[fn] -} - -func (s *MockScribe) Call(serviceMethod string, args interface{}, reply interface{}) error { - parts := strings.Split(serviceMethod, ".") - if len(parts) != 2 { - return utils.ErrNotImplemented - } - // get method - method := reflect.ValueOf(s).MethodByName(parts[1]) - if !method.IsValid() { - return utils.ErrNotImplemented - } - - // construct the params - params := []reflect.Value{reflect.ValueOf(args), reflect.ValueOf(reply)} - - ret := method.Call(params) - if len(ret) != 1 { - return utils.ErrServerError - } - if ret[0].Interface() == nil { - return nil - } - err, ok := ret[0].Interface().(error) - if !ok { - return utils.ErrServerError - } - return err -} diff --git a/history/scribe.go b/history/scribe.go deleted file mode 100644 index 8c034a64d..000000000 --- a/history/scribe.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -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 history - -import ( - "io" - "reflect" - "sort" -) - -const ( - DESTINATIONS_FN = "destinations.json" - RATING_PLANS_FN = "rating_plans.json" - RATING_PROFILES_FN = "rating_profiles.json" -) - -type Record struct { - Id string - Filename string - Payload []byte - Deleted bool -} - -type records []*Record - -var ( - recordsMap = make(map[string]records) - filenameMap = make(map[reflect.Type]string) -) - -func (rs records) Len() int { - return len(rs) -} - -func (rs records) Swap(i, j int) { - rs[i], rs[j] = rs[j], rs[i] -} - -func (rs records) Less(i, j int) bool { - return rs[i].Id < rs[j].Id -} - -func (rs records) Sort() { - sort.Sort(rs) -} - -func (rs records) Modify(rec *Record) records { - //rs.Sort() - n := len(rs) - i := sort.Search(n, func(i int) bool { return rs[i].Id >= rec.Id }) - if i < n && rs[i].Id == rec.Id { - if rec.Deleted { - // delete - rs = append(rs[:i], rs[i+1:]...) - } else { - rs[i] = rec - } - } else { - // i is the index where it would be inserted. - rs = append(rs, nil) - copy(rs[i+1:], rs[i:]) - rs[i] = rec - } - return rs -} - -func format(b io.Writer, recs records) error { - recs.Sort() - b.Write([]byte("[")) - for i, r := range recs { - b.Write(r.Payload) - if i < len(recs)-1 { - b.Write([]byte(",\n")) - } - } - b.Write([]byte("]")) - return nil -} diff --git a/history/scribe_test.go b/history/scribe_test.go deleted file mode 100644 index b16c983f2..000000000 --- a/history/scribe_test.go +++ /dev/null @@ -1,59 +0,0 @@ -/* -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 history - -import ( - "strconv" - "testing" -) - -func TestHistorySet(t *testing.T) { - rs := records{&Record{Id: "first"}} - second := &Record{Id: "first"} - rs.Modify(second) - if len(rs) != 1 || rs[0] != second { - t.Error("error setting new value: ", rs[0]) - } -} - -func TestHistoryAdd(t *testing.T) { - rs := records{&Record{Id: "first"}} - second := &Record{Id: "second"} - rs = rs.Modify(second) - if len(rs) != 2 || rs[1] != second { - t.Error("error setting new value: ", rs) - } -} - -func TestHistoryRemove(t *testing.T) { - rs := records{&Record{Id: "first"}, &Record{Id: "second"}} - rs = rs.Modify(&Record{Id: "first", Deleted: true}) - if len(rs) != 1 || rs[0].Id != "second" { - t.Error("error deleting record: ", rs) - } -} - -func BenchmarkModify(b *testing.B) { - var rs records - for i := 0; i < 1000; i++ { - rs = rs.Modify(&Record{Id: strconv.Itoa(i)}) - } - for i := 0; i < b.N; i++ { - rs.Modify(&Record{Id: "400"}) - } -}