From f79a173aa6901e79c97dde8cc0384f33224089c2 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 18 Sep 2014 19:58:50 +0300 Subject: [PATCH] refactor for v1 and v2 api added Load api for multiple id resources --- apier/{ => v1}/accounts.go | 2 +- apier/{ => v1}/aliases.go | 2 +- apier/{ => v1}/apier.go | 2 +- apier/{ => v1}/apier_local_test.go | 2 +- apier/{ => v1}/cdre.go | 2 +- apier/{ => v1}/cdrs.go | 2 +- apier/{ => v1}/cdrstatsv1.go | 2 +- apier/{ => v1}/cdrstatsv1_local_test.go | 2 +- apier/{ => v1}/cdrsv1.go | 2 +- apier/{ => v1}/costs.go | 2 +- apier/{ => v1}/derivedcharging.go | 2 +- apier/{ => v1}/derivedcharging_test.go | 2 +- apier/{ => v1}/mediator.go | 2 +- apier/{ => v1}/scheduler.go | 2 +- apier/{ => v1}/tp.go | 2 +- apier/{ => v1}/tpaccountactions.go | 2 +- apier/{ => v1}/tpactions.go | 2 +- apier/{ => v1}/tpactiontimings.go | 2 +- apier/{ => v1}/tpactiontriggers.go | 2 +- apier/{ => v1}/tpcdrstats.go | 2 +- apier/{ => v1}/tpderivedcharges.go | 2 +- apier/{ => v1}/tpdestinationrates.go | 2 +- apier/{ => v1}/tpdestinations.go | 2 +- apier/{ => v1}/tplcrrules.go | 2 +- apier/{ => v1}/tprates.go | 2 +- apier/{ => v1}/tpratingplans.go | 2 +- apier/{ => v1}/tpratingprofiles.go | 2 +- apier/{ => v1}/tpsharedgroups.go | 2 +- apier/{ => v1}/tptimings.go | 2 +- apier/{ => v1}/tutfsjson_local_test | 0 apier/v2/apier.go | 135 ++++++++++++++++++++++++ cmd/cgr-engine/cgr-engine.go | 21 ++-- console/account_add.go | 6 +- console/action_execute.go | 8 +- console/balance_set.go | 6 +- console/callcost.go | 6 +- console/cdrstats_metrics.go | 6 +- console/datacost.go | 6 +- console/triggeredaction_add.go | 6 +- local_test.sh | 8 +- 40 files changed, 204 insertions(+), 62 deletions(-) rename apier/{ => v1}/accounts.go (99%) rename apier/{ => v1}/aliases.go (99%) rename apier/{ => v1}/apier.go (99%) rename apier/{ => v1}/apier_local_test.go (99%) rename apier/{ => v1}/cdre.go (99%) rename apier/{ => v1}/cdrs.go (99%) rename apier/{ => v1}/cdrstatsv1.go (99%) rename apier/{ => v1}/cdrstatsv1_local_test.go (99%) rename apier/{ => v1}/cdrsv1.go (98%) rename apier/{ => v1}/costs.go (99%) rename apier/{ => v1}/derivedcharging.go (99%) rename apier/{ => v1}/derivedcharging_test.go (99%) rename apier/{ => v1}/mediator.go (99%) rename apier/{ => v1}/scheduler.go (99%) rename apier/{ => v1}/tp.go (99%) rename apier/{ => v1}/tpaccountactions.go (99%) rename apier/{ => v1}/tpactions.go (99%) rename apier/{ => v1}/tpactiontimings.go (99%) rename apier/{ => v1}/tpactiontriggers.go (99%) rename apier/{ => v1}/tpcdrstats.go (99%) rename apier/{ => v1}/tpderivedcharges.go (99%) rename apier/{ => v1}/tpdestinationrates.go (99%) rename apier/{ => v1}/tpdestinations.go (99%) rename apier/{ => v1}/tplcrrules.go (99%) rename apier/{ => v1}/tprates.go (99%) rename apier/{ => v1}/tpratingplans.go (99%) rename apier/{ => v1}/tpratingprofiles.go (99%) rename apier/{ => v1}/tpsharedgroups.go (99%) rename apier/{ => v1}/tptimings.go (99%) rename apier/{ => v1}/tutfsjson_local_test (100%) create mode 100644 apier/v2/apier.go diff --git a/apier/accounts.go b/apier/v1/accounts.go similarity index 99% rename from apier/accounts.go rename to apier/v1/accounts.go index 592f11b68..a574e61af 100644 --- a/apier/accounts.go +++ b/apier/v1/accounts.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "errors" diff --git a/apier/aliases.go b/apier/v1/aliases.go similarity index 99% rename from apier/aliases.go rename to apier/v1/aliases.go index 8ba284993..3fd474bd0 100644 --- a/apier/aliases.go +++ b/apier/v1/aliases.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "errors" diff --git a/apier/apier.go b/apier/v1/apier.go similarity index 99% rename from apier/apier.go rename to apier/v1/apier.go index a2b51cfff..0a04b5f08 100644 --- a/apier/apier.go +++ b/apier/v1/apier.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "encoding/json" diff --git a/apier/apier_local_test.go b/apier/v1/apier_local_test.go similarity index 99% rename from apier/apier_local_test.go rename to apier/v1/apier_local_test.go index 7056f776a..76a376b94 100644 --- a/apier/apier_local_test.go +++ b/apier/v1/apier_local_test.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "encoding/json" diff --git a/apier/cdre.go b/apier/v1/cdre.go similarity index 99% rename from apier/cdre.go rename to apier/v1/cdre.go index 73bce39b5..0b8a00cec 100644 --- a/apier/cdre.go +++ b/apier/v1/cdre.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "archive/zip" diff --git a/apier/cdrs.go b/apier/v1/cdrs.go similarity index 99% rename from apier/cdrs.go rename to apier/v1/cdrs.go index 7aadaab9d..3873199da 100644 --- a/apier/cdrs.go +++ b/apier/v1/cdrs.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "fmt" diff --git a/apier/cdrstatsv1.go b/apier/v1/cdrstatsv1.go similarity index 99% rename from apier/cdrstatsv1.go rename to apier/v1/cdrstatsv1.go index a952e7194..9676d758a 100644 --- a/apier/cdrstatsv1.go +++ b/apier/v1/cdrstatsv1.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "fmt" diff --git a/apier/cdrstatsv1_local_test.go b/apier/v1/cdrstatsv1_local_test.go similarity index 99% rename from apier/cdrstatsv1_local_test.go rename to apier/v1/cdrstatsv1_local_test.go index a8c4d0836..6723684ee 100644 --- a/apier/cdrstatsv1_local_test.go +++ b/apier/v1/cdrstatsv1_local_test.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "fmt" diff --git a/apier/cdrsv1.go b/apier/v1/cdrsv1.go similarity index 98% rename from apier/cdrsv1.go rename to apier/v1/cdrsv1.go index 3b638ddfd..0a5a46f78 100644 --- a/apier/cdrsv1.go +++ b/apier/v1/cdrsv1.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "fmt" diff --git a/apier/costs.go b/apier/v1/costs.go similarity index 99% rename from apier/costs.go rename to apier/v1/costs.go index 93669b524..c2a252477 100644 --- a/apier/costs.go +++ b/apier/v1/costs.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "fmt" diff --git a/apier/derivedcharging.go b/apier/v1/derivedcharging.go similarity index 99% rename from apier/derivedcharging.go rename to apier/v1/derivedcharging.go index fb3766e1d..f54d80400 100644 --- a/apier/derivedcharging.go +++ b/apier/v1/derivedcharging.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "fmt" diff --git a/apier/derivedcharging_test.go b/apier/v1/derivedcharging_test.go similarity index 99% rename from apier/derivedcharging_test.go rename to apier/v1/derivedcharging_test.go index 9e70e4c35..4ffd0112b 100644 --- a/apier/derivedcharging_test.go +++ b/apier/v1/derivedcharging_test.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "fmt" diff --git a/apier/mediator.go b/apier/v1/mediator.go similarity index 99% rename from apier/mediator.go rename to apier/v1/mediator.go index e5cc8c0a7..8abb4332c 100644 --- a/apier/mediator.go +++ b/apier/v1/mediator.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "fmt" diff --git a/apier/scheduler.go b/apier/v1/scheduler.go similarity index 99% rename from apier/scheduler.go rename to apier/v1/scheduler.go index 7fe55ab29..688702256 100644 --- a/apier/scheduler.go +++ b/apier/v1/scheduler.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "errors" diff --git a/apier/tp.go b/apier/v1/tp.go similarity index 99% rename from apier/tp.go rename to apier/v1/tp.go index 0b81526af..896c1df81 100644 --- a/apier/tp.go +++ b/apier/v1/tp.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 // Tariff plan related APIs diff --git a/apier/tpaccountactions.go b/apier/v1/tpaccountactions.go similarity index 99% rename from apier/tpaccountactions.go rename to apier/v1/tpaccountactions.go index 29849809d..9e1f3a08b 100644 --- a/apier/tpaccountactions.go +++ b/apier/v1/tpaccountactions.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "errors" diff --git a/apier/tpactions.go b/apier/v1/tpactions.go similarity index 99% rename from apier/tpactions.go rename to apier/v1/tpactions.go index f51a1848f..c31d16d46 100644 --- a/apier/tpactions.go +++ b/apier/v1/tpactions.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "errors" diff --git a/apier/tpactiontimings.go b/apier/v1/tpactiontimings.go similarity index 99% rename from apier/tpactiontimings.go rename to apier/v1/tpactiontimings.go index 276514c85..98affe60f 100644 --- a/apier/tpactiontimings.go +++ b/apier/v1/tpactiontimings.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "errors" diff --git a/apier/tpactiontriggers.go b/apier/v1/tpactiontriggers.go similarity index 99% rename from apier/tpactiontriggers.go rename to apier/v1/tpactiontriggers.go index c79d7d83c..6a3f20d8f 100644 --- a/apier/tpactiontriggers.go +++ b/apier/v1/tpactiontriggers.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "errors" diff --git a/apier/tpcdrstats.go b/apier/v1/tpcdrstats.go similarity index 99% rename from apier/tpcdrstats.go rename to apier/v1/tpcdrstats.go index 318436819..98d62d152 100644 --- a/apier/tpcdrstats.go +++ b/apier/v1/tpcdrstats.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "errors" diff --git a/apier/tpderivedcharges.go b/apier/v1/tpderivedcharges.go similarity index 99% rename from apier/tpderivedcharges.go rename to apier/v1/tpderivedcharges.go index aa7258a0a..471a8fe15 100644 --- a/apier/tpderivedcharges.go +++ b/apier/v1/tpderivedcharges.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "errors" diff --git a/apier/tpdestinationrates.go b/apier/v1/tpdestinationrates.go similarity index 99% rename from apier/tpdestinationrates.go rename to apier/v1/tpdestinationrates.go index f74e1a60b..436c501ba 100644 --- a/apier/tpdestinationrates.go +++ b/apier/v1/tpdestinationrates.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 // This file deals with tp_destination_rates management over APIs diff --git a/apier/tpdestinations.go b/apier/v1/tpdestinations.go similarity index 99% rename from apier/tpdestinations.go rename to apier/v1/tpdestinations.go index 144791a87..8cc0465c5 100644 --- a/apier/tpdestinations.go +++ b/apier/v1/tpdestinations.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "errors" diff --git a/apier/tplcrrules.go b/apier/v1/tplcrrules.go similarity index 99% rename from apier/tplcrrules.go rename to apier/v1/tplcrrules.go index c13ea4ece..9344f47aa 100644 --- a/apier/tplcrrules.go +++ b/apier/v1/tplcrrules.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 /* // Creates a new LcrRules profile within a tariff plan diff --git a/apier/tprates.go b/apier/v1/tprates.go similarity index 99% rename from apier/tprates.go rename to apier/v1/tprates.go index 883e95c35..da8f13630 100644 --- a/apier/tprates.go +++ b/apier/v1/tprates.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 // This file deals with tp_rates management over APIs diff --git a/apier/tpratingplans.go b/apier/v1/tpratingplans.go similarity index 99% rename from apier/tpratingplans.go rename to apier/v1/tpratingplans.go index 4b0998be9..1fa1ecf25 100644 --- a/apier/tpratingplans.go +++ b/apier/v1/tpratingplans.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 // This file deals with tp_destrates_timing management over APIs diff --git a/apier/tpratingprofiles.go b/apier/v1/tpratingprofiles.go similarity index 99% rename from apier/tpratingprofiles.go rename to apier/v1/tpratingprofiles.go index e26268350..91cc8e879 100644 --- a/apier/tpratingprofiles.go +++ b/apier/v1/tpratingprofiles.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 // This file deals with tp_rate_profiles management over APIs diff --git a/apier/tpsharedgroups.go b/apier/v1/tpsharedgroups.go similarity index 99% rename from apier/tpsharedgroups.go rename to apier/v1/tpsharedgroups.go index 6288e59d7..e87607571 100644 --- a/apier/tpsharedgroups.go +++ b/apier/v1/tpsharedgroups.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "errors" diff --git a/apier/tptimings.go b/apier/v1/tptimings.go similarity index 99% rename from apier/tptimings.go rename to apier/v1/tptimings.go index ddc1f7e1a..530b65fd0 100644 --- a/apier/tptimings.go +++ b/apier/v1/tptimings.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package v1 import ( "errors" diff --git a/apier/tutfsjson_local_test b/apier/v1/tutfsjson_local_test similarity index 100% rename from apier/tutfsjson_local_test rename to apier/v1/tutfsjson_local_test diff --git a/apier/v2/apier.go b/apier/v2/apier.go new file mode 100644 index 000000000..2fd10b424 --- /dev/null +++ b/apier/v2/apier.go @@ -0,0 +1,135 @@ +/* +Real-time Charging System 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 v2 + +import ( + "fmt" + "log" + + "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +type ApierV2 struct { + v1.ApierV1 +} + +type AttrLoadRatingProfile struct { + TPid string + RatingProfileId string +} + +// Process dependencies and load a specific rating profile from storDb into dataDb. +func (self *ApierV2) LoadRatingProfile(attrs AttrLoadRatingProfile, reply *string) error { + if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RatingProfileId"}); len(missing) != 0 { + return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing) + } + + if attrs.RatingProfileId == utils.EMPTY { + attrs.RatingProfileId = "" + } + tpRpf := &utils.TPRatingProfile{TPid: attrs.TPid} + tpRpf.SetRatingProfilesId(attrs.RatingProfileId) + dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid) + if err := dbReader.LoadRatingProfileFiltered(tpRpf); err != nil { + return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) + } + //Automatic cache of the newly inserted rating profile + didNotChange := []string{} + var ratingProfile []string + if tpRpf.KeyId() != ":::" { // if has some filters + ratingProfile = []string{engine.RATING_PROFILE_PREFIX + tpRpf.KeyId()} + } + if err := self.RatingDb.CacheRating(didNotChange, didNotChange, ratingProfile, didNotChange, didNotChange); err != nil { + return err + } + *reply = v1.OK + return nil +} + +type AttrLoadAccountActions struct { + TPid string + AccountActionsId string +} + +// Process dependencies and load a specific AccountActions profile from storDb into dataDb. +func (self *ApierV2) LoadAccountActions(attrs AttrLoadAccountActions, reply *string) error { + if missing := utils.MissingStructFields(&attrs, []string{"TPid", "AccountActionsId"}); len(missing) != 0 { + return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing) + } + dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid) + + if attrs.AccountActionsId == utils.EMPTY { + attrs.AccountActionsId = "" + } + + tpAa := &utils.TPAccountActions{TPid: attrs.TPid} + tpAa.SetAccountActionsId(attrs.AccountActionsId) + + if _, err := engine.AccLock.Guard(attrs.AccountActionsId, func() (float64, error) { + if err := dbReader.LoadAccountActionsFiltered(tpAa); err != nil { + return 0, err + } + return 0, nil + }); err != nil { + return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) + } + // ToDo: Get the action keys loaded by dbReader so we reload only these in cache + // Need to do it before scheduler otherwise actions to run will be unknown + if err := self.AccountDb.CacheAccounting(nil, nil, nil, []string{}); err != nil { + return err + } + if self.Sched != nil { + self.Sched.LoadActionTimings(self.AccountDb) + self.Sched.Restart() + } + *reply = v1.OK + return nil +} + +type AttrLoadDerivedChargers struct { + TPid string + DerivedChargersId string +} + +// Load derived chargers from storDb into dataDb. +func (self *ApierV2) LoadDerivedChargers(attrs AttrLoadDerivedChargers, reply *string) error { + if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DerivedChargersId"}); len(missing) != 0 { + log.Printf("ATTR: %+v", attrs) + return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing) + } + if attrs.DerivedChargersId == utils.EMPTY { + attrs.DerivedChargersId = "" + } + tpDc := &utils.TPDerivedChargers{TPid: attrs.TPid} + tpDc.SetDerivedChargersId(attrs.DerivedChargersId) + + dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid) + if err := dbReader.LoadDerivedChargersFiltered(tpDc); err != nil { + return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) + } + //Automatic cache of the newly inserted rating plan + didNotChange := []string{} + if err := self.AccountDb.CacheAccounting(didNotChange, didNotChange, didNotChange, nil); err != nil { + return err + } + *reply = v1.OK + return nil +} diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index b3782cb07..0579481e4 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -28,7 +28,8 @@ import ( "strconv" "time" - "github.com/cgrates/cgrates/apier" + "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/apier/v2" "github.com/cgrates/cgrates/balancer2go" "github.com/cgrates/cgrates/cdrc" "github.com/cgrates/cgrates/config" @@ -118,7 +119,7 @@ func startMediator(responder *engine.Responder, loggerDb engine.LogStorage, cdrD return } engine.Logger.Info("Registering Mediator RPC service.") - server.RpcRegister(&apier.MediatorV1{Medi: medi}) + server.RpcRegister(&v1.MediatorV1{Medi: medi}) close(chanDone) } @@ -208,7 +209,7 @@ func startCDRS(responder *engine.Responder, cdrDb engine.CdrStorage, mediChan, d cdrServer = engine.NewCdrS(cdrDb, medi, cdrStats, cfg) cdrServer.RegisterHanlersToServer(server) engine.Logger.Info("Registering CDRS RPC service.") - server.RpcRegister(&apier.CDRSV1{CdrSrv: cdrServer}) + server.RpcRegister(&v1.CDRSV1{CdrSrv: cdrServer}) responder.CdrSrv = cdrServer // Make the cdrserver available for internal communication close(doneChan) } @@ -412,16 +413,18 @@ func main() { cdrStats.AddQueue(engine.NewCdrStatsFromCdrStatsCfg(cfg.CDRStatConfig), nil) } server.RpcRegister(cdrStats) - server.RpcRegister(&apier.CDRStatsV1{cdrStats}) // Public APIs + server.RpcRegister(&v1.CDRStatsV1{cdrStats}) // Public APIs } responder := &engine.Responder{ExitChan: exitChan} - apierRpc := &apier.ApierV1{StorDb: loadDb, RatingDb: ratingDb, AccountDb: accountDb, CdrDb: cdrDb, LogDb: logDb, Config: cfg, Responder: responder, CdrStatsSrv: cdrStats} + apierRpcV1 := &v1.ApierV1{StorDb: loadDb, RatingDb: ratingDb, AccountDb: accountDb, CdrDb: cdrDb, LogDb: logDb, Config: cfg, Responder: responder, CdrStatsSrv: cdrStats} + apierRpcV2 := &v2.ApierV2{ApierV1: v1.ApierV1{StorDb: loadDb, RatingDb: ratingDb, AccountDb: accountDb, CdrDb: cdrDb, LogDb: logDb, Config: cfg, Responder: responder, CdrStatsSrv: cdrStats}} if cfg.RaterEnabled && !cfg.BalancerEnabled && cfg.RaterBalancer != utils.INTERNAL { engine.Logger.Info("Registering Rater service") server.RpcRegister(responder) - server.RpcRegister(apierRpc) + server.RpcRegister(apierRpcV1) + server.RpcRegister(apierRpcV2) } if cfg.BalancerEnabled { @@ -430,7 +433,8 @@ func main() { stopHandled = true responder.Bal = bal server.RpcRegister(responder) - server.RpcRegister(apierRpc) + server.RpcRegister(apierRpcV1) + server.RpcRegister(apierRpcV2) if cfg.RaterEnabled { engine.Logger.Info(" Registering internal rater") bal.AddClient("local", new(engine.ResponderWorker)) @@ -446,7 +450,8 @@ func main() { go func() { sched := scheduler.NewScheduler() go reloadSchedulerSingnalHandler(sched, accountDb) - apierRpc.Sched = sched + apierRpcV1.Sched = sched + apierRpcV2.Sched = sched sched.LoadActionTimings(accountDb) sched.Loop() }() diff --git a/console/account_add.go b/console/account_add.go index 12815b188..9d152327e 100644 --- a/console/account_add.go +++ b/console/account_add.go @@ -18,7 +18,7 @@ along with this program. If not, see package console -import "github.com/cgrates/cgrates/apier" +import "github.com/cgrates/cgrates/apier/v1" func init() { c := &CmdAddAccount{ @@ -33,7 +33,7 @@ func init() { type CmdAddAccount struct { name string rpcMethod string - rpcParams *apier.AttrSetAccount + rpcParams *v1.AttrSetAccount *CommandExecuter } @@ -47,7 +47,7 @@ func (self *CmdAddAccount) RpcMethod() string { func (self *CmdAddAccount) RpcParams() interface{} { if self.rpcParams == nil { - self.rpcParams = &apier.AttrSetAccount{Direction: "*out"} + self.rpcParams = &v1.AttrSetAccount{Direction: "*out"} } return self.rpcParams } diff --git a/console/action_execute.go b/console/action_execute.go index 46a83ab65..889bf7670 100644 --- a/console/action_execute.go +++ b/console/action_execute.go @@ -18,13 +18,13 @@ along with this program. If not, see package console -import "github.com/cgrates/cgrates/apier" +import "github.com/cgrates/cgrates/apier/v1" func init() { c := &CmdExecuteAction{ name: "action_execute", rpcMethod: "ApierV1.ExecuteAction", - rpcParams: &apier.AttrExecuteAction{Direction: "*out"}, + rpcParams: &v1.AttrExecuteAction{Direction: "*out"}, } commands[c.Name()] = c c.CommandExecuter = &CommandExecuter{c} @@ -34,7 +34,7 @@ func init() { type CmdExecuteAction struct { name string rpcMethod string - rpcParams *apier.AttrExecuteAction + rpcParams *v1.AttrExecuteAction *CommandExecuter } @@ -48,7 +48,7 @@ func (self *CmdExecuteAction) RpcMethod() string { func (self *CmdExecuteAction) RpcParams() interface{} { if self.rpcParams == nil { - self.rpcParams = &apier.AttrExecuteAction{Direction: "*out"} + self.rpcParams = &v1.AttrExecuteAction{Direction: "*out"} } return self.rpcParams } diff --git a/console/balance_set.go b/console/balance_set.go index bc971f587..22e3eda1f 100644 --- a/console/balance_set.go +++ b/console/balance_set.go @@ -19,7 +19,7 @@ along with this program. If not, see package console import ( - "github.com/cgrates/cgrates/apier" + "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/engine" ) @@ -36,7 +36,7 @@ func init() { type CmdAddBalance struct { name string rpcMethod string - rpcParams *apier.AttrAddBalance + rpcParams *v1.AttrAddBalance *CommandExecuter } @@ -50,7 +50,7 @@ func (self *CmdAddBalance) RpcMethod() string { func (self *CmdAddBalance) RpcParams() interface{} { if self.rpcParams == nil { - self.rpcParams = &apier.AttrAddBalance{BalanceType: engine.CREDIT, Overwrite: false} + self.rpcParams = &v1.AttrAddBalance{BalanceType: engine.CREDIT, Overwrite: false} } return self.rpcParams } diff --git a/console/callcost.go b/console/callcost.go index 2a3804344..4e1b6ccdf 100644 --- a/console/callcost.go +++ b/console/callcost.go @@ -19,7 +19,7 @@ along with this program. If not, see package console import ( - "github.com/cgrates/cgrates/apier" + "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -37,7 +37,7 @@ func init() { type CmdGetCostDetails struct { name string rpcMethod string - rpcParams *apier.AttrGetCallCost + rpcParams *v1.AttrGetCallCost rpcResult string *CommandExecuter } @@ -52,7 +52,7 @@ func (self *CmdGetCostDetails) RpcMethod() string { func (self *CmdGetCostDetails) RpcParams() interface{} { if self.rpcParams == nil { - self.rpcParams = &apier.AttrGetCallCost{RunId: utils.DEFAULT_RUNID} + self.rpcParams = &v1.AttrGetCallCost{RunId: utils.DEFAULT_RUNID} } return self.rpcParams } diff --git a/console/cdrstats_metrics.go b/console/cdrstats_metrics.go index 07f39d190..b77eec707 100644 --- a/console/cdrstats_metrics.go +++ b/console/cdrstats_metrics.go @@ -18,7 +18,7 @@ along with this program. If not, see package console -import "github.com/cgrates/cgrates/apier" +import "github.com/cgrates/cgrates/apier/v1" func init() { c := &CmdCdrStatsMetrics{ @@ -33,7 +33,7 @@ func init() { type CmdCdrStatsMetrics struct { name string rpcMethod string - rpcParams *apier.AttrGetMetrics + rpcParams *v1.AttrGetMetrics *CommandExecuter } @@ -47,7 +47,7 @@ func (self *CmdCdrStatsMetrics) RpcMethod() string { func (self *CmdCdrStatsMetrics) RpcParams() interface{} { if self.rpcParams == nil { - self.rpcParams = &apier.AttrGetMetrics{} + self.rpcParams = &v1.AttrGetMetrics{} } return self.rpcParams } diff --git a/console/datacost.go b/console/datacost.go index 70e14b3ed..0176c5170 100644 --- a/console/datacost.go +++ b/console/datacost.go @@ -19,7 +19,7 @@ along with this program. If not, see package console import ( - "github.com/cgrates/cgrates/apier" + "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -38,7 +38,7 @@ func init() { type CmdGetDataCost struct { name string rpcMethod string - rpcParams *apier.AttrGetDataCost + rpcParams *v1.AttrGetDataCost clientArgs []string *CommandExecuter } @@ -53,7 +53,7 @@ func (self *CmdGetDataCost) RpcMethod() string { func (self *CmdGetDataCost) RpcParams() interface{} { if self.rpcParams == nil { - self.rpcParams = &apier.AttrGetDataCost{Direction: utils.OUT} + self.rpcParams = &v1.AttrGetDataCost{Direction: utils.OUT} } return self.rpcParams } diff --git a/console/triggeredaction_add.go b/console/triggeredaction_add.go index cd5f4703a..8c806ea44 100644 --- a/console/triggeredaction_add.go +++ b/console/triggeredaction_add.go @@ -18,7 +18,7 @@ along with this program. If not, see package console -import "github.com/cgrates/cgrates/apier" +import "github.com/cgrates/cgrates/apier/v1" func init() { c := &CmdAddTriggeredAction{ @@ -33,7 +33,7 @@ func init() { type CmdAddTriggeredAction struct { name string rpcMethod string - rpcParams *apier.AttrAddActionTrigger + rpcParams *v1.AttrAddActionTrigger *CommandExecuter } @@ -47,7 +47,7 @@ func (self *CmdAddTriggeredAction) RpcMethod() string { func (self *CmdAddTriggeredAction) RpcParams() interface{} { if self.rpcParams == nil { - self.rpcParams = &apier.AttrAddActionTrigger{Direction: "*out"} + self.rpcParams = &v1.AttrAddActionTrigger{Direction: "*out"} } return self.rpcParams } diff --git a/local_test.sh b/local_test.sh index b34696cb6..50ca97816 100755 --- a/local_test.sh +++ b/local_test.sh @@ -2,8 +2,10 @@ ./test.sh gen=$? -go test github.com/cgrates/cgrates/apier -local -ap=$? +go test github.com/cgrates/cgrates/apier/v1 -local +ap1=$? +go test github.com/cgrates/cgrates/apier/v2 -local +ap2=$? go test github.com/cgrates/cgrates/engine -local en=$? go test github.com/cgrates/cgrates/cdrc -local @@ -18,5 +20,5 @@ utl=$? -exit $gen && $ap && $en && $cdrc && $cfg && $utl +exit $gen && $ap1 && $ap2 && $en && $cdrc && $cfg && $utl