diff --git a/apier/apier.go b/apier/v1/apier.go
similarity index 83%
rename from apier/apier.go
rename to apier/v1/apier.go
index 4b1146cab..d666cae6d 100644
--- a/apier/apier.go
+++ b/apier/v1/apier.go
@@ -26,7 +26,11 @@ import (
"github.com/cgrates/cgrates/utils"
)
-type Apier struct {
+const (
+ OK = "OK"
+)
+
+type ApierV1 struct {
StorDb engine.DataStorage
DataDb engine.DataStorage
Sched *scheduler.Scheduler
@@ -37,7 +41,7 @@ type AttrDestination struct {
Prefixes []string
}
-func (self *Apier) GetDestination(attr *AttrDestination, reply *AttrDestination) error {
+func (self *ApierV1) GetDestination(attr *AttrDestination, reply *AttrDestination) error {
if dst, err := self.DataDb.GetDestination(attr.Id); err != nil {
return errors.New(utils.ERR_NOT_FOUND)
} else {
@@ -55,7 +59,7 @@ type AttrGetBalance struct {
}
// Get balance
-func (self *Apier) GetBalance(attr *AttrGetBalance, reply *float64) error {
+func (self *ApierV1) GetBalance(attr *AttrGetBalance, reply *float64) error {
tag := fmt.Sprintf("%s:%s:%s", attr.Direction, attr.Tenant, attr.Account)
userBalance, err := self.DataDb.GetUserBalance(tag)
if err != nil {
@@ -82,7 +86,7 @@ type AttrAddBalance struct {
Value float64
}
-func (self *Apier) AddBalance(attr *AttrAddBalance, reply *float64) error {
+func (self *ApierV1) AddBalance(attr *AttrAddBalance, reply *string) error {
// what storage instance do we use?
tag := fmt.Sprintf("%s:%s:%s", attr.Direction, attr.Tenant, attr.Account)
@@ -92,6 +96,7 @@ func (self *Apier) AddBalance(attr *AttrAddBalance, reply *float64) error {
Id: tag,
}
if err := self.DataDb.SetUserBalance(ub); err != nil {
+ *reply = err.Error()
return err
}
}
@@ -107,9 +112,10 @@ func (self *Apier) AddBalance(attr *AttrAddBalance, reply *float64) error {
at.SetActions(engine.Actions{&engine.Action{ActionType: engine.TOPUP, BalanceId: attr.BalanceId, Direction: attr.Direction, Units: attr.Value}})
if err := at.Execute(); err != nil {
+ *reply = err.Error()
return err
}
- // what to put in replay?
+ *reply = OK
return nil
}
@@ -120,7 +126,7 @@ type AttrExecuteAction struct {
ActionsId string
}
-func (self *Apier) ExecuteAction(attr *AttrExecuteAction, reply *float64) error {
+func (self *ApierV1) ExecuteAction(attr *AttrExecuteAction, reply *string) error {
tag := fmt.Sprintf("%s:%s:%s", attr.Direction, attr.Tenant, attr.Account)
at := &engine.ActionTiming{
UserBalanceIds: []string{tag},
@@ -128,9 +134,10 @@ func (self *Apier) ExecuteAction(attr *AttrExecuteAction, reply *float64) error
}
if err := at.Execute(); err != nil {
+ *reply = err.Error()
return err
}
- // what to put in replay
+ *reply = OK
return nil
}
@@ -140,7 +147,7 @@ type AttrSetRatingProfile struct {
}
// Process dependencies and load a specific rating profile from storDb into dataDb.
-func (self *Apier) SetRatingProfile(attrs AttrSetRatingProfile, reply *string) error {
+func (self *ApierV1) SetRatingProfile(attrs AttrSetRatingProfile, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RateProfileId"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -150,11 +157,11 @@ func (self *Apier) SetRatingProfile(attrs AttrSetRatingProfile, reply *string) e
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
}
- *reply = "OK"
+ *reply = OK
return nil
}
-type AttrActionTrigger struct {
+type AttrAddActionTrigger struct {
Tenant string
Account string
Direction string
@@ -165,7 +172,7 @@ type AttrActionTrigger struct {
ActionsId string
}
-func (self *Apier) AddTriggeredAction(attr AttrActionTrigger, reply *float64) error {
+func (self *ApierV1) AddTriggeredAction(attr AttrAddActionTrigger, reply *string) error {
if attr.Direction == "" {
attr.Direction = engine.OUTBOUND
}
@@ -182,27 +189,28 @@ func (self *Apier) AddTriggeredAction(attr AttrActionTrigger, reply *float64) er
}
tag := fmt.Sprintf("%s:%s:%s", attr.Direction, attr.Tenant, attr.Account)
- var dbErr error
- engine.AccLock.Guard(tag, func() (float64, error) {
+ _, err := engine.AccLock.Guard(tag, func() (float64, error) {
userBalance, err := self.DataDb.GetUserBalance(tag)
if err != nil {
- dbErr = err
return 0, err
}
userBalance.ActionTriggers = append(userBalance.ActionTriggers, at)
if err = self.DataDb.SetUserBalance(userBalance); err != nil {
- dbErr = err
return 0, err
}
return 0, nil
})
-
- return dbErr
+ if err != nil {
+ *reply = err.Error()
+ return err
+ }
+ *reply = OK
+ return nil
}
-type AttrAccount struct {
+type AttrAddAccount struct {
Tenant string
Direction string
Account string
@@ -211,8 +219,9 @@ type AttrAccount struct {
}
// Ads a new account into dataDb. If already defined, returns success.
-func (self *Apier) AddAccount(attr *AttrAccount, reply *float64) error {
+func (self *ApierV1) AddAccount(attr *AttrAddAccount, reply *string) error {
if missing := utils.MissingStructFields(&attr, []string{"Tenant", "Direction", "Account", "Type", "ActionTimingsId"}); len(missing) != 0 {
+ *reply = fmt.Sprintf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
tag := fmt.Sprintf("%s:%s:%s", attr.Direction, attr.Tenant, attr.Account)
@@ -234,12 +243,15 @@ func (self *Apier) AddAccount(attr *AttrAccount, reply *float64) error {
}
}
if err := self.DataDb.SetUserBalance(ub); err != nil {
+ *reply = fmt.Sprintf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
}
} else {
+ *reply = fmt.Sprintf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
}
}
+ *reply = OK
return nil
}
@@ -249,7 +261,7 @@ type AttrSetAccountActions struct {
}
// Process dependencies and load a specific AccountActions profile from storDb into dataDb.
-func (self *Apier) SetAccountActions(attrs AttrSetAccountActions, reply *string) error {
+func (self *ApierV1) SetAccountActions(attrs AttrSetAccountActions, 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)
}
@@ -267,6 +279,6 @@ func (self *Apier) SetAccountActions(attrs AttrSetAccountActions, reply *string)
self.Sched.LoadActionTimings(self.DataDb)
self.Sched.Restart()
}
- *reply = "OK"
+ *reply = OK
return nil
}
diff --git a/apier/tp.go b/apier/v1/tp.go
similarity index 93%
rename from apier/tp.go
rename to apier/v1/tp.go
index 0ee9ebc3d..d3d62599e 100644
--- a/apier/tp.go
+++ b/apier/v1/tp.go
@@ -30,7 +30,7 @@ type AttrGetTPIds struct {
}
// Queries tarrif plan identities gathered from all tables.
-func (self *Apier) GetTPIds(attrs AttrGetTPIds, reply *[]string) error {
+func (self *ApierV1) GetTPIds(attrs AttrGetTPIds, reply *[]string) error {
if ids, err := self.StorDb.GetTPIds(); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
} else if ids == nil {
diff --git a/apier/tpaccountactions.go b/apier/v1/tpaccountactions.go
similarity index 91%
rename from apier/tpaccountactions.go
rename to apier/v1/tpaccountactions.go
index 459a03645..5981dd8eb 100644
--- a/apier/tpaccountactions.go
+++ b/apier/v1/tpaccountactions.go
@@ -26,7 +26,7 @@ import (
)
// Creates a new AccountActions profile within a tariff plan
-func (self *Apier) SetTPAccountActions(attrs utils.ApiTPAccountActions, reply *string) error {
+func (self *ApierV1) SetTPAccountActions(attrs utils.ApiTPAccountActions, reply *string) error {
if missing := utils.MissingStructFields(&attrs,
[]string{"TPid", "AccountActionsId", "Tenant", "Account", "Direction", "ActionTimingsId", "ActionTriggersId"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
@@ -54,7 +54,7 @@ type AttrGetTPAccountActions struct {
}
// Queries specific AccountActions profile on tariff plan
-func (self *Apier) GetTPAccountActions(attrs AttrGetTPAccountActions, reply *utils.ApiTPAccountActions) error {
+func (self *ApierV1) GetTPAccountActions(attrs AttrGetTPAccountActions, reply *utils.ApiTPAccountActions) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "AccountActionsId"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -79,7 +79,7 @@ type AttrGetTPAccountActionIds struct {
}
// Queries AccountActions identities on specific tariff plan.
-func (self *Apier) GetTPAccountActionIds(attrs AttrGetTPAccountActionIds, reply *[]string) error {
+func (self *ApierV1) GetTPAccountActionIds(attrs AttrGetTPAccountActionIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
diff --git a/apier/tpactions.go b/apier/v1/tpactions.go
similarity index 93%
rename from apier/tpactions.go
rename to apier/v1/tpactions.go
index 099bd6ea0..a109dc526 100644
--- a/apier/tpactions.go
+++ b/apier/v1/tpactions.go
@@ -26,7 +26,7 @@ import (
)
// Creates a new Actions profile within a tariff plan
-func (self *Apier) SetTPActions(attrs utils.TPActions, reply *string) error {
+func (self *ApierV1) SetTPActions(attrs utils.TPActions, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ActionsId", "Actions"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -72,7 +72,7 @@ type AttrGetTPActions struct {
}
// Queries specific Actions profile on tariff plan
-func (self *Apier) GetTPActions(attrs AttrGetTPActions, reply *utils.TPActions) error {
+func (self *ApierV1) GetTPActions(attrs AttrGetTPActions, reply *utils.TPActions) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ActionsId"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -91,7 +91,7 @@ type AttrGetTPActionIds struct {
}
// Queries Actions identities on specific tariff plan.
-func (self *Apier) GetTPActionIds(attrs AttrGetTPActionIds, reply *[]string) error {
+func (self *ApierV1) GetTPActionIds(attrs AttrGetTPActionIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
diff --git a/apier/tpactiontimings.go b/apier/v1/tpactiontimings.go
similarity index 92%
rename from apier/tpactiontimings.go
rename to apier/v1/tpactiontimings.go
index 162c1b10f..7e916a0ae 100644
--- a/apier/tpactiontimings.go
+++ b/apier/v1/tpactiontimings.go
@@ -26,7 +26,7 @@ import (
)
// Creates a new ActionTimings profile within a tariff plan
-func (self *Apier) SetTPActionTimings(attrs utils.ApiTPActionTimings, reply *string) error {
+func (self *ApierV1) SetTPActionTimings(attrs utils.ApiTPActionTimings, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ActionTimingsId", "ActionTimings"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -63,7 +63,7 @@ type AttrGetTPActionTimings struct {
}
// Queries specific ActionTimings profile on tariff plan
-func (self *Apier) GetTPActionTimings(attrs AttrGetTPActionTimings, reply *utils.ApiTPActionTimings) error {
+func (self *ApierV1) GetTPActionTimings(attrs AttrGetTPActionTimings, reply *utils.ApiTPActionTimings) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ActionTimingsId"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -86,7 +86,7 @@ type AttrGetTPActionTimingIds struct {
}
// Queries ActionTimings identities on specific tariff plan.
-func (self *Apier) GetTPActionTimingIds(attrs AttrGetTPActionTimingIds, reply *[]string) error {
+func (self *ApierV1) GetTPActionTimingIds(attrs AttrGetTPActionTimingIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
diff --git a/apier/tpactiontriggers.go b/apier/v1/tpactiontriggers.go
similarity index 92%
rename from apier/tpactiontriggers.go
rename to apier/v1/tpactiontriggers.go
index cf9e560ff..51fe423fe 100644
--- a/apier/tpactiontriggers.go
+++ b/apier/v1/tpactiontriggers.go
@@ -26,7 +26,7 @@ import (
)
// Creates a new ActionTriggers profile within a tariff plan
-func (self *Apier) SetTPActionTriggers(attrs utils.ApiTPActionTriggers, reply *string) error {
+func (self *ApierV1) SetTPActionTriggers(attrs utils.ApiTPActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(&attrs,
[]string{"TPid", "ActionTriggersId"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
@@ -70,7 +70,7 @@ type AttrGetTPActionTriggers struct {
}
// Queries specific ActionTriggers profile on tariff plan
-func (self *Apier) GetTPActionTriggers(attrs AttrGetTPActionTriggers, reply *utils.ApiTPActionTriggers) error {
+func (self *ApierV1) GetTPActionTriggers(attrs AttrGetTPActionTriggers, reply *utils.ApiTPActionTriggers) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ActionTriggersId"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -103,7 +103,7 @@ type AttrGetTPActionTriggerIds struct {
}
// Queries ActionTriggers identities on specific tariff plan.
-func (self *Apier) GetTPActionTriggerIds(attrs AttrGetTPActionTriggerIds, reply *[]string) error {
+func (self *ApierV1) GetTPActionTriggerIds(attrs AttrGetTPActionTriggerIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
diff --git a/apier/tpdestinationrates.go b/apier/v1/tpdestinationrates.go
similarity index 90%
rename from apier/tpdestinationrates.go
rename to apier/v1/tpdestinationrates.go
index 874d4de33..9b4603457 100644
--- a/apier/tpdestinationrates.go
+++ b/apier/v1/tpdestinationrates.go
@@ -28,7 +28,7 @@ import (
)
// Creates a new DestinationRate profile within a tariff plan
-func (self *Apier) SetTPDestinationRate(attrs utils.TPDestinationRate, reply *string) error {
+func (self *ApierV1) SetTPDestinationRate(attrs utils.TPDestinationRate, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationRateId", "DestinationRates"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -54,7 +54,7 @@ type AttrGetTPDestinationRate struct {
}
// Queries specific DestinationRate profile on tariff plan
-func (self *Apier) GetTPDestinationRate(attrs AttrGetTPDestinationRate, reply *utils.TPDestinationRate) error {
+func (self *ApierV1) GetTPDestinationRate(attrs AttrGetTPDestinationRate, reply *utils.TPDestinationRate) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationRateId"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -73,7 +73,7 @@ type AttrTPDestinationRateIds struct {
}
// Queries DestinationRate identities on specific tariff plan.
-func (self *Apier) GetTPDestinationRateIds(attrs AttrGetTPRateIds, reply *[]string) error {
+func (self *ApierV1) GetTPDestinationRateIds(attrs AttrGetTPRateIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
diff --git a/apier/tpdestinations.go b/apier/v1/tpdestinations.go
similarity index 91%
rename from apier/tpdestinations.go
rename to apier/v1/tpdestinations.go
index 3b3f10e35..e8638471f 100644
--- a/apier/tpdestinations.go
+++ b/apier/v1/tpdestinations.go
@@ -32,7 +32,7 @@ type ApierTPDestination struct {
}
// Creates a new destination within a tariff plan
-func (self *Apier) SetTPDestination(attrs ApierTPDestination, reply *string) error {
+func (self *ApierV1) SetTPDestination(attrs ApierTPDestination, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationId", "Prefixes"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -54,7 +54,7 @@ type AttrGetTPDestination struct {
}
// Queries a specific destination
-func (self *Apier) GetTPDestination(attrs AttrGetTPDestination, reply *ApierTPDestination) error {
+func (self *ApierV1) GetTPDestination(attrs AttrGetTPDestination, reply *ApierTPDestination) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationId"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -73,7 +73,7 @@ type AttrGetTPDestinationIds struct {
}
// Queries destination identities on specific tariff plan.
-func (self *Apier) GetTPDestinationIds(attrs AttrGetTPDestinationIds, reply *[]string) error {
+func (self *ApierV1) GetTPDestinationIds(attrs AttrGetTPDestinationIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
diff --git a/apier/tpdestratetimings.go b/apier/v1/tpdestratetimings.go
similarity index 91%
rename from apier/tpdestratetimings.go
rename to apier/v1/tpdestratetimings.go
index f357c81e9..64683c38d 100644
--- a/apier/tpdestratetimings.go
+++ b/apier/v1/tpdestratetimings.go
@@ -28,7 +28,7 @@ import (
)
// Creates a new DestinationRateTiming profile within a tariff plan
-func (self *Apier) SetTPDestRateTiming(attrs utils.TPDestRateTiming, reply *string) error {
+func (self *ApierV1) SetTPDestRateTiming(attrs utils.TPDestRateTiming, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestRateTimingId", "DestRateTimings"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -58,7 +58,7 @@ type AttrGetTPDestRateTiming struct {
}
// Queries specific DestRateTiming profile on tariff plan
-func (self *Apier) GetTPDestRateTiming(attrs AttrGetTPDestRateTiming, reply *utils.TPDestRateTiming) error {
+func (self *ApierV1) GetTPDestRateTiming(attrs AttrGetTPDestRateTiming, reply *utils.TPDestRateTiming) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestRateTimingId"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -77,7 +77,7 @@ type AttrTPDestRateTimingIds struct {
}
// Queries DestRateTiming identities on specific tariff plan.
-func (self *Apier) GetTPDestRateTimingIds(attrs AttrGetTPRateIds, reply *[]string) error {
+func (self *ApierV1) GetTPDestRateTimingIds(attrs AttrGetTPRateIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
diff --git a/apier/tprates.go b/apier/v1/tprates.go
similarity index 92%
rename from apier/tprates.go
rename to apier/v1/tprates.go
index d55192cb7..b114b628a 100644
--- a/apier/tprates.go
+++ b/apier/v1/tprates.go
@@ -28,7 +28,7 @@ import (
)
// Creates a new rate within a tariff plan
-func (self *Apier) SetTPRate(attrs utils.TPRate, reply *string) error {
+func (self *ApierV1) SetTPRate(attrs utils.TPRate, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RateId", "RateSlots"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -55,7 +55,7 @@ type AttrGetTPRate struct {
}
// Queries specific Rate on tariff plan
-func (self *Apier) GetTPRate(attrs AttrGetTPRate, reply *utils.TPRate) error {
+func (self *ApierV1) GetTPRate(attrs AttrGetTPRate, reply *utils.TPRate) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RateId"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -74,7 +74,7 @@ type AttrGetTPRateIds struct {
}
// Queries rate identities on specific tariff plan.
-func (self *Apier) GetTPRateIds(attrs AttrGetTPRateIds, reply *[]string) error {
+func (self *ApierV1) GetTPRateIds(attrs AttrGetTPRateIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
diff --git a/apier/tpratingprofiles.go b/apier/v1/tpratingprofiles.go
similarity index 91%
rename from apier/tpratingprofiles.go
rename to apier/v1/tpratingprofiles.go
index 928c0d367..8f5e026f8 100644
--- a/apier/tpratingprofiles.go
+++ b/apier/v1/tpratingprofiles.go
@@ -28,7 +28,7 @@ import (
)
// Creates a new RatingProfile within a tariff plan
-func (self *Apier) SetTPRatingProfile(attrs utils.TPRatingProfile, reply *string) error {
+func (self *ApierV1) SetTPRatingProfile(attrs utils.TPRatingProfile, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RatingProfileId", "Tenant", "TOR", "Direction", "Subject", "RatingActivations"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -62,7 +62,7 @@ type AttrGetTPRatingProfile struct {
}
// Queries specific RatingProfile on tariff plan
-func (self *Apier) GetTPRatingProfile(attrs AttrGetTPRatingProfile, reply *utils.TPRatingProfile) error {
+func (self *ApierV1) GetTPRatingProfile(attrs AttrGetTPRatingProfile, reply *utils.TPRatingProfile) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RatingProfileId"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -77,7 +77,7 @@ func (self *Apier) GetTPRatingProfile(attrs AttrGetTPRatingProfile, reply *utils
}
// Queries RatingProfile identities on specific tariff plan.
-func (self *Apier) GetTPRatingProfileIds(attrs utils.AttrTPRatingProfileIds, reply *[]string) error {
+func (self *ApierV1) GetTPRatingProfileIds(attrs utils.AttrTPRatingProfileIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
diff --git a/apier/tptimings.go b/apier/v1/tptimings.go
similarity index 93%
rename from apier/tptimings.go
rename to apier/v1/tptimings.go
index 626dfc389..28fa25298 100644
--- a/apier/tptimings.go
+++ b/apier/v1/tptimings.go
@@ -36,7 +36,7 @@ type ApierTPTiming struct {
}
// Creates a new timing within a tariff plan
-func (self *Apier) SetTPTiming(attrs ApierTPTiming, reply *string) error {
+func (self *ApierV1) SetTPTiming(attrs ApierTPTiming, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "TimingId", "Years", "Months", "MonthDays", "WeekDays", "Time"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -59,7 +59,7 @@ type AttrGetTPTiming struct {
}
// Queries specific Timing on Tariff plan
-func (self *Apier) GetTPTiming(attrs AttrGetTPTiming, reply *ApierTPTiming) error {
+func (self *ApierV1) GetTPTiming(attrs AttrGetTPTiming, reply *ApierTPTiming) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "TimingId"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -79,7 +79,7 @@ type AttrGetTPTimingIds struct {
}
// Queries timing identities on specific tariff plan.
-func (self *Apier) GetTPTimingIds(attrs AttrGetTPTimingIds, reply *[]string) error {
+func (self *ApierV1) GetTPTimingIds(attrs AttrGetTPTimingIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
diff --git a/cmd/cgr-console/cgr-console.go b/cmd/cgr-console/cgr-console.go
index a83185f46..d3ccb16e2 100644
--- a/cmd/cgr-console/cgr-console.go
+++ b/cmd/cgr-console/cgr-console.go
@@ -19,6 +19,7 @@ along with this program. If not, see
package main
import (
+ "encoding/json"
"flag"
"fmt"
"github.com/cgrates/cgrates/console"
@@ -32,7 +33,7 @@ import (
var (
version = flag.Bool("version", false, "Prints the application version.")
server = flag.String("server", "127.0.0.1:2012", "server address host:port")
- rpc_encoding = flag.String("rpc_encoding", "gob", "RPC encoding used ")
+ rpc_encoding = flag.String("rpc_encoding", "json", "RPC encoding used ")
)
func main() {
@@ -61,7 +62,9 @@ func main() {
}
res := cmd.RpcResult()
if rpcErr := client.Call(cmd.RpcMethod(), cmd.RpcParams(), res); rpcErr != nil {
+ fmt.Println("Error executing command: " + rpcErr.Error())
}
- fmt.Println("Result:", res)
+ result, _ := json.Marshal(res)
+ fmt.Println(string(result))
}
diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go
index 4f28ea3b0..1a484bdef 100644
--- a/cmd/cgr-engine/cgr-engine.go
+++ b/cmd/cgr-engine/cgr-engine.go
@@ -22,7 +22,7 @@ import (
"errors"
"flag"
"fmt"
- "github.com/cgrates/cgrates/apier"
+ "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/balancer2go"
"github.com/cgrates/cgrates/cdrs"
"github.com/cgrates/cgrates/config"
@@ -64,7 +64,7 @@ var (
err error
)
-func listenToRPCRequests(rpcResponder interface{}, apier *apier.Apier, rpcAddress string, rpc_encoding string, getter engine.DataStorage, loggerDb engine.DataStorage) {
+func listenToRPCRequests(rpcResponder interface{}, apier *apier.ApierV1, rpcAddress string, rpc_encoding string, getter engine.DataStorage, loggerDb engine.DataStorage) {
l, err := net.Listen("tcp", rpcAddress)
if err != nil {
engine.Logger.Crit(fmt.Sprintf(" Could not listen to %v: %v", rpcAddress, err))
@@ -335,7 +335,7 @@ func main() {
go stopRaterSingnalHandler()
}
responder := &engine.Responder{ExitChan: exitChan}
- apier := &apier.Apier{StorDb: loggerDb, DataDb: getter}
+ apier := &apier.ApierV1{StorDb: loggerDb, DataDb: getter}
if cfg.RaterEnabled && !cfg.BalancerEnabled && cfg.RaterListen != INTERNAL {
engine.Logger.Info(fmt.Sprintf("Starting CGRateS Rater on %s.", cfg.RaterListen))
go listenToRPCRequests(responder, apier, cfg.RaterListen, cfg.RPCEncoding, getter, loggerDb)
diff --git a/cmd/cgr-loader/cgr-loader.go b/cmd/cgr-loader/cgr-loader.go
index ceba279a3..984122ae3 100644
--- a/cmd/cgr-loader/cgr-loader.go
+++ b/cmd/cgr-loader/cgr-loader.go
@@ -52,10 +52,10 @@ var (
dataPath = flag.String("path", ".", "The path containing the data files")
version = flag.Bool("version", false, "Prints the application version.")
verbose = flag.Bool("verbose", false, "Enable detailed verbose logging output")
- 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")
- historyServer = flag.String("history-server", "", "The history server address:port")
- rpcEncoding = flag.String("rpc-encoding", "json", "The history server rpc encoding json|gob")
+ 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")
+ historyServer = flag.String("history_server", "", "The history server address:port")
+ rpcEncoding = flag.String("rpc_encoding", "json", "The history server rpc encoding json|gob")
runId = flag.String("runid", "", "Uniquely identify an import/load, postpended to some automatic fields")
)
diff --git a/console/add_account.go b/console/add_account.go
new file mode 100644
index 000000000..797fcb87b
--- /dev/null
+++ b/console/add_account.go
@@ -0,0 +1,58 @@
+package console
+
+import (
+ "fmt"
+ "github.com/cgrates/cgrates/apier/v1"
+)
+
+func init() {
+ commands["add_account"] = &CmdAddAccount{}
+}
+
+// Commander implementation
+type CmdAddAccount struct {
+ rpcMethod string
+ rpcParams *apier.AttrAddAccount
+ rpcResult string
+}
+
+// name should be exec's name
+func (self *CmdAddAccount) Usage(name string) string {
+ return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] add_account []")
+}
+
+// set param defaults
+func (self *CmdAddAccount) defaults() error {
+ self.rpcMethod = "ApierV1.AddAccount"
+ self.rpcParams = &apier.AttrAddAccount{Direction: "*out"}
+ return nil
+}
+
+// Parses command line args and builds CmdBalance value
+func (self *CmdAddAccount) FromArgs(args []string) error {
+ if len(args) < 6 {
+ return fmt.Errorf(self.Usage(""))
+ }
+ // Args look OK, set defaults before going further
+ self.defaults()
+ self.rpcParams.Tenant = args[2]
+ self.rpcParams.Account = args[3]
+ self.rpcParams.Type = args[4]
+ self.rpcParams.ActionTimingsId = args[5]
+ if len(args) > 6 {
+ self.rpcParams.Direction = args[6]
+ }
+ return nil
+}
+
+func (self *CmdAddAccount) RpcMethod() string {
+ return self.rpcMethod
+}
+
+func (self *CmdAddAccount) RpcParams() interface{} {
+ return self.rpcParams
+}
+
+func (self *CmdAddAccount) RpcResult() interface{} {
+ return &self.rpcResult
+}
diff --git a/console/add_balance.go b/console/add_balance.go
new file mode 100644
index 000000000..623029031
--- /dev/null
+++ b/console/add_balance.go
@@ -0,0 +1,67 @@
+package console
+
+import (
+ "fmt"
+ "github.com/cgrates/cgrates/apier/v1"
+ "github.com/cgrates/cgrates/engine"
+ "strconv"
+)
+
+func init() {
+ commands["add_balance"] = &CmdAddBalance{}
+}
+
+// Commander implementation
+type CmdAddBalance struct {
+ rpcMethod string
+ rpcParams *apier.AttrAddBalance
+ rpcResult string
+}
+
+// name should be exec's name
+func (self *CmdAddBalance) Usage(name string) string {
+ return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] add_balance [ []]")
+}
+
+// set param defaults
+func (self *CmdAddBalance) defaults() error {
+ self.rpcMethod = "ApierV1.AddBalance"
+ self.rpcParams = &apier.AttrAddBalance{BalanceId: engine.CREDIT}
+ self.rpcParams.Direction = "*out"
+ return nil
+}
+
+// Parses command line args and builds CmdBalance value
+func (self *CmdAddBalance) FromArgs(args []string) error {
+ if len(args) < 5 {
+ return fmt.Errorf(self.Usage(""))
+ }
+ // Args look OK, set defaults before going further
+ self.defaults()
+ self.rpcParams.Tenant = args[2]
+ self.rpcParams.Account = args[3]
+ value, err := strconv.ParseFloat(args[4], 64)
+ if err != nil {
+ return err
+ }
+ self.rpcParams.Value = value
+ if len(args) > 5 {
+ self.rpcParams.BalanceId = args[5]
+ }
+ if len(args) > 6 {
+ self.rpcParams.Direction = args[6]
+ }
+ return nil
+}
+
+func (self *CmdAddBalance) RpcMethod() string {
+ return self.rpcMethod
+}
+
+func (self *CmdAddBalance) RpcParams() interface{} {
+ return self.rpcParams
+}
+
+func (self *CmdAddBalance) RpcResult() interface{} {
+ return &self.rpcResult
+}
diff --git a/console/add_triggeredaction.go b/console/add_triggeredaction.go
new file mode 100644
index 000000000..b9ab2b681
--- /dev/null
+++ b/console/add_triggeredaction.go
@@ -0,0 +1,71 @@
+package console
+
+import (
+ "fmt"
+ "github.com/cgrates/cgrates/apier/v1"
+ "strconv"
+)
+
+func init() {
+ commands["add_triggeredaction"] = &CmdAddTriggeredAction{}
+}
+
+// Commander implementation
+type CmdAddTriggeredAction struct {
+ rpcMethod string
+ rpcParams *apier.AttrAddActionTrigger
+ rpcResult string
+}
+
+// name should be exec's name
+func (self *CmdAddTriggeredAction) Usage(name string) string {
+ return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] add_triggeredaction []")
+}
+
+// set param defaults
+func (self *CmdAddTriggeredAction) defaults() error {
+ self.rpcMethod = "ApierV1.AddTriggeredAction"
+ self.rpcParams = &apier.AttrAddActionTrigger{Direction: "*out"}
+ return nil
+}
+
+// Parses command line args and builds CmdBalance value
+func (self *CmdAddTriggeredAction) FromArgs(args []string) error {
+ if len(args) < 9 {
+ return fmt.Errorf(self.Usage(""))
+ }
+ // Args look OK, set defaults before going further
+ self.defaults()
+ self.rpcParams.Tenant = args[2]
+ self.rpcParams.Account = args[3]
+ self.rpcParams.BalanceId = args[4]
+ thresholdvalue, err := strconv.ParseFloat(args[5], 64)
+ if err != nil {
+ return err
+ }
+ self.rpcParams.ThresholdValue = thresholdvalue
+ self.rpcParams.DestinationId = args[6]
+ weight, err := strconv.ParseFloat(args[7], 64)
+ if err != nil {
+ return err
+ }
+ self.rpcParams.Weight = weight
+ self.rpcParams.ActionsId = args[8]
+
+ if len(args) > 9 {
+ self.rpcParams.Direction = args[9]
+ }
+ return nil
+}
+
+func (self *CmdAddTriggeredAction) RpcMethod() string {
+ return self.rpcMethod
+}
+
+func (self *CmdAddTriggeredAction) RpcParams() interface{} {
+ return self.rpcParams
+}
+
+func (self *CmdAddTriggeredAction) RpcResult() interface{} {
+ return &self.rpcResult
+}
diff --git a/console/command.go b/console/command.go
index 9f1cfe491..db10d4bb2 100644
--- a/console/command.go
+++ b/console/command.go
@@ -2,6 +2,8 @@ package console
import (
"errors"
+ "fmt"
+ "strings"
)
var (
@@ -25,7 +27,11 @@ func GetCommandValue(args []string) (Commander, error) {
}
cmdVal, exists := commands[args[1]]
if !exists {
- return nil, errors.New("\n\tUsage: cgr-console [cfg_opts...{-h}] \n")
+ var keys []string
+ for key, _ := range commands {
+ keys = append(keys, key)
+ }
+ return nil, fmt.Errorf("\n\tUsage: cgr-console [cfg_opts...{-h}] <%s>\n", strings.Join(keys, "|"))
}
if err := cmdVal.FromArgs(args); err != nil {
return nil, err
diff --git a/console/destination.go b/console/destination.go
new file mode 100644
index 000000000..df6db730f
--- /dev/null
+++ b/console/destination.go
@@ -0,0 +1,53 @@
+package console
+
+import (
+ "fmt"
+ "github.com/cgrates/cgrates/apier/v1"
+)
+
+func init() {
+ commands["get_destination"] = &CmdGetDestination{}
+}
+
+// Commander implementation
+type CmdGetDestination struct {
+ rpcMethod string
+ rpcParams *apier.AttrDestination
+ rpcResult *apier.AttrDestination
+}
+
+// name should be exec's name
+func (self *CmdGetDestination) Usage(name string) string {
+ return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] get_destination ")
+}
+
+// set param defaults
+func (self *CmdGetDestination) defaults() error {
+ self.rpcMethod = "Apier.GetDestination"
+ self.rpcParams = &apier.AttrDestination{}
+ return nil
+}
+
+// Parses command line args and builds CmdBalance value
+func (self *CmdGetDestination) FromArgs(args []string) error {
+ if len(args) < 3 {
+ return fmt.Errorf(self.Usage(""))
+ }
+ // Args look OK, set defaults before going further
+ self.defaults()
+ self.rpcParams.Id = args[2]
+ return nil
+}
+
+func (self *CmdGetDestination) RpcMethod() string {
+ return self.rpcMethod
+}
+
+func (self *CmdGetDestination) RpcParams() interface{} {
+ return self.rpcParams
+}
+
+func (self *CmdGetDestination) RpcResult() interface{} {
+ self.rpcResult = &apier.AttrDestination{}
+ return self.rpcResult
+}
diff --git a/console/execute_action.go b/console/execute_action.go
new file mode 100644
index 000000000..69bfa0444
--- /dev/null
+++ b/console/execute_action.go
@@ -0,0 +1,57 @@
+package console
+
+import (
+ "fmt"
+ "github.com/cgrates/cgrates/apier/v1"
+)
+
+func init() {
+ commands["execute_action"] = &CmdExecuteAction{}
+}
+
+// Commander implementation
+type CmdExecuteAction struct {
+ rpcMethod string
+ rpcParams *apier.AttrExecuteAction
+ rpcResult string
+}
+
+// name should be exec's name
+func (self *CmdExecuteAction) Usage(name string) string {
+ return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] execute_action []")
+}
+
+// set param defaults
+func (self *CmdExecuteAction) defaults() error {
+ self.rpcMethod = "ApierV1.ExecuteAction"
+ self.rpcParams = &apier.AttrExecuteAction{Direction: "*out"}
+ return nil
+}
+
+// Parses command line args and builds CmdBalance value
+func (self *CmdExecuteAction) FromArgs(args []string) error {
+ if len(args) < 5 {
+ return fmt.Errorf(self.Usage(""))
+ }
+ // Args look OK, set defaults before going further
+ self.defaults()
+ self.rpcParams.Tenant = args[2]
+ self.rpcParams.Account = args[3]
+ self.rpcParams.ActionsId = args[4]
+ if len(args) > 5 {
+ self.rpcParams.Direction = args[5]
+ }
+ return nil
+}
+
+func (self *CmdExecuteAction) RpcMethod() string {
+ return self.rpcMethod
+}
+
+func (self *CmdExecuteAction) RpcParams() interface{} {
+ return self.rpcParams
+}
+
+func (self *CmdExecuteAction) RpcResult() interface{} {
+ return &self.rpcResult
+}
diff --git a/console/balance.go b/console/get_balance.go
similarity index 58%
rename from console/balance.go
rename to console/get_balance.go
index ec541ad07..d69991002 100644
--- a/console/balance.go
+++ b/console/get_balance.go
@@ -1,9 +1,8 @@
-/* Implementing balance related console commands.
- */
package console
import (
"fmt"
+ "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/engine"
)
@@ -14,19 +13,20 @@ func init() {
// Commander implementation
type CmdGetBalance struct {
rpcMethod string
- rpcParams *engine.CallDescriptor
- rpcResult *engine.CallCost
+ rpcParams *apier.AttrGetBalance
+ rpcResult float64
}
// name should be exec's name
func (self *CmdGetBalance) Usage(name string) string {
- return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] get_balance [ []]")
+ return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] get_balance [ []]")
}
// set param defaults
func (self *CmdGetBalance) defaults() error {
- self.rpcMethod = "Responder.GetMonetary"
- self.rpcParams = &engine.CallDescriptor{Direction: "*out"}
+ self.rpcMethod = "ApierV1.GetBalance"
+ self.rpcParams = &apier.AttrGetBalance{BalanceId: engine.CREDIT}
+ self.rpcParams.Direction = "*out"
return nil
}
@@ -35,25 +35,15 @@ func (self *CmdGetBalance) FromArgs(args []string) error {
if len(args) < 4 {
return fmt.Errorf(self.Usage(""))
}
- // Args look OK, set defaults before going further
+ // Args look OK, set defaults before going further
self.defaults()
self.rpcParams.Tenant = args[2]
self.rpcParams.Account = args[3]
if len(args) > 4 {
- switch args[4] {
- case "MONETARY":
- self.rpcMethod = "Responder.GetMonetary"
- case "SMS":
- self.rpcMethod = "Responder.GetSMS"
- case "INETRNET":
- self.rpcMethod = "Responder.GetInternet"
- case "INTERNET_TIME":
- self.rpcMethod = "Responder.GetInternetTime"
- case "MINUTES":
- self.rpcMethod = "Responder.GetMonetary"
- }
+ self.rpcParams.BalanceId = args[4]
}
if len(args) > 5 {
+
self.rpcParams.Direction = args[5]
}
return nil
@@ -68,6 +58,5 @@ func (self *CmdGetBalance) RpcParams() interface{} {
}
func (self *CmdGetBalance) RpcResult() interface{} {
- self.rpcResult = &engine.CallCost{}
- return self.rpcResult
+ return &self.rpcResult
}
diff --git a/console/set_accountactions.go b/console/set_accountactions.go
new file mode 100644
index 000000000..eff8059ea
--- /dev/null
+++ b/console/set_accountactions.go
@@ -0,0 +1,53 @@
+package console
+
+import (
+ "fmt"
+ "github.com/cgrates/cgrates/apier/v1"
+)
+
+func init() {
+ commands["set_accountactions"] = &CmdSetAccountActions{}
+}
+
+// Commander implementation
+type CmdSetAccountActions struct {
+ rpcMethod string
+ rpcParams *apier.AttrSetAccountActions
+ rpcResult string
+}
+
+// name should be exec's name
+func (self *CmdSetAccountActions) Usage(name string) string {
+ return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] set_accountactions ")
+}
+
+// set param defaults
+func (self *CmdSetAccountActions) defaults() error {
+ self.rpcMethod = "ApierV1.SetAccountActions"
+ self.rpcParams = &apier.AttrSetAccountActions{}
+ return nil
+}
+
+// Parses command line args and builds CmdBalance value
+func (self *CmdSetAccountActions) FromArgs(args []string) error {
+ if len(args) < 3 {
+ return fmt.Errorf(self.Usage(""))
+ }
+ // Args look OK, set defaults before going further
+ self.defaults()
+ self.rpcParams.TPid = args[2]
+ self.rpcParams.AccountActionsId = args[3]
+ return nil
+}
+
+func (self *CmdSetAccountActions) RpcMethod() string {
+ return self.rpcMethod
+}
+
+func (self *CmdSetAccountActions) RpcParams() interface{} {
+ return self.rpcParams
+}
+
+func (self *CmdSetAccountActions) RpcResult() interface{} {
+ return &self.rpcResult
+}
diff --git a/console/set_ratingprofile.go b/console/set_ratingprofile.go
new file mode 100644
index 000000000..35a6e09cc
--- /dev/null
+++ b/console/set_ratingprofile.go
@@ -0,0 +1,53 @@
+package console
+
+import (
+ "fmt"
+ "github.com/cgrates/cgrates/apier/v1"
+)
+
+func init() {
+ commands["set_ratingprofile"] = &CmdSetrRatingProfile{}
+}
+
+// Commander implementation
+type CmdSetrRatingProfile struct {
+ rpcMethod string
+ rpcParams *apier.AttrSetRatingProfile
+ rpcResult string
+}
+
+// name should be exec's name
+func (self *CmdSetrRatingProfile) Usage(name string) string {
+ return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] set_ratingprofile ")
+}
+
+// set param defaults
+func (self *CmdSetrRatingProfile) defaults() error {
+ self.rpcMethod = "ApierV1.SetRatingProfile"
+ self.rpcParams = &apier.AttrSetRatingProfile{}
+ return nil
+}
+
+// Parses command line args and builds CmdBalance value
+func (self *CmdSetrRatingProfile) FromArgs(args []string) error {
+ if len(args) < 3 {
+ return fmt.Errorf(self.Usage(""))
+ }
+ // Args look OK, set defaults before going further
+ self.defaults()
+ self.rpcParams.TPid = args[2]
+ self.rpcParams.RateProfileId = args[3]
+ return nil
+}
+
+func (self *CmdSetrRatingProfile) RpcMethod() string {
+ return self.rpcMethod
+}
+
+func (self *CmdSetrRatingProfile) RpcParams() interface{} {
+ return self.rpcParams
+}
+
+func (self *CmdSetrRatingProfile) RpcResult() interface{} {
+ return &self.rpcResult
+}
diff --git a/docs/api_accounts.rst b/docs/api_accounts.rst
index b6681f24f..d5d9f809f 100644
--- a/docs/api_accounts.rst
+++ b/docs/api_accounts.rst
@@ -1,4 +1,4 @@
-Apier.SetAccountActions
+ApierV1.SetAccountActions
+++++++++++++++++++++++
@@ -21,7 +21,7 @@ Process dependencies and load a specific AccountActions profile from storDb into
{
"id": 0,
- "method": "Apier.SetAccountActions",
+ "method": "ApierV1.SetAccountActions",
"params": [
{
"AccountActionsId": "SAMPLE_AA_1",
diff --git a/docs/api_ratingprofiles.rst b/docs/api_ratingprofiles.rst
index 8b3ec08ed..b7a749d83 100644
--- a/docs/api_ratingprofiles.rst
+++ b/docs/api_ratingprofiles.rst
@@ -1,4 +1,4 @@
-Apier.SetRatingProfile
+ApierV1.SetRatingProfile
++++++++++++++++++++++
Process dependencies and load a specific rating profile from storDb into dataDb.
@@ -20,7 +20,7 @@ Process dependencies and load a specific rating profile from storDb into dataDb.
{
"id": 0,
- "method": "Apier.SetRatingProfile",
+ "method": "ApierV1.SetRatingProfile",
"params": [
{
"RateProfileId": "RPF_SAMPLE_1",
diff --git a/docs/api_tp.rst b/docs/api_tp.rst
index 7d1e57cfc..fab65c0d4 100644
--- a/docs/api_tp.rst
+++ b/docs/api_tp.rst
@@ -1,4 +1,4 @@
-Apier.GetTPIds
+ApierV1.GetTPIds
+++++++++++++++++++++++++
// Queries tarrif plan identities gathered from all tables.
@@ -16,7 +16,7 @@ Apier.GetTPIds
{
"id": 9,
- "method": "Apier.GetTPIds",
+ "method": "ApierV1.GetTPIds",
"params": []
}
diff --git a/docs/api_tpaccountactions.rst b/docs/api_tpaccountactions.rst
index 113471c8d..3a535529b 100644
--- a/docs/api_tpaccountactions.rst
+++ b/docs/api_tpaccountactions.rst
@@ -1,4 +1,4 @@
-Apier.SetTPAccountActions
+ApierV1.SetTPAccountActions
+++++++++++++++++++++++++
Creates a new AccountActions profile within a tariff plan.
@@ -25,7 +25,7 @@ Creates a new AccountActions profile within a tariff plan.
{
"id": 2,
- "method": "Apier.SetTPAccountActions",
+ "method": "ApierV1.SetTPAccountActions",
"params": [
{
"Account": "ACNT1",
@@ -67,7 +67,7 @@ Creates a new AccountActions profile within a tariff plan.
``DUPLICATE`` - The specified combination of TPid/AccountActionsId already present in StorDb.
-Apier.GetTPAccountActions
+ApierV1.GetTPAccountActions
+++++++++++++++++++++++++
Queries specific AccountActions profile on tariff plan.
@@ -89,7 +89,7 @@ Queries specific AccountActions profile on tariff plan.
{
"id": 3,
- "method": "Apier.GetTPAccountActions",
+ "method": "ApierV1.GetTPAccountActions",
"params": [
{
"AccountActionsId": "AA_SAMPLE_2",
@@ -139,7 +139,7 @@ Queries specific AccountActions profile on tariff plan.
``NOT_FOUND`` - Requested AccountActions profile not found.
-Apier.GetTPAccountActionIds
+ApierV1.GetTPAccountActionIds
+++++++++++++++++++++++++++
Queries AccountActions identities on specific tariff plan.
@@ -160,7 +160,7 @@ Queries AccountActions identities on specific tariff plan.
{
"id": 4,
- "method": "Apier.GetTPAccountActionIds",
+ "method": "ApierV1.GetTPAccountActionIds",
"params": [
{
"TPid": "SAMPLE_TP_1"
diff --git a/docs/api_tpactions.rst b/docs/api_tpactions.rst
index cd7852b6c..e15a0fb63 100644
--- a/docs/api_tpactions.rst
+++ b/docs/api_tpactions.rst
@@ -1,4 +1,4 @@
-Apier.SetTPActions
+ApierV1.SetTPActions
++++++++++++++++++
Creates a new Actions profile within a tariff plan.
@@ -34,7 +34,7 @@ Creates a new Actions profile within a tariff plan.
{
"id": 3,
- "method": "Apier.SetTPActions",
+ "method": "ApierV1.SetTPActions",
"params": [
{
"Actions": [
@@ -85,7 +85,7 @@ Creates a new Actions profile within a tariff plan.
``DUPLICATE`` - The specified combination of TPid/ActionsId already present in StorDb.
-Apier.GetTPActions
+ApierV1.GetTPActions
++++++++++++++++++
Queries specific Actions profile on tariff plan.
@@ -107,7 +107,7 @@ Queries specific Actions profile on tariff plan.
{
"id": 5,
- "method": "Apier.GetTPActions",
+ "method": "ApierV1.GetTPActions",
"params": [
{
"ActionsId": "SAMPLE_ACTS_1",
@@ -175,7 +175,7 @@ Queries specific Actions profile on tariff plan.
``NOT_FOUND`` - Requested Actions profile not found.
-Apier.GetTPActionIds
+ApierV1.GetTPActionIds
++++++++++++++++++++
Queries Actions identities on specific tariff plan.
@@ -196,7 +196,7 @@ Queries Actions identities on specific tariff plan.
{
"id": 6,
- "method": "Apier.GetTPActionIds",
+ "method": "ApierV1.GetTPActionIds",
"params": [
{
"TPid": "SAMPLE_TP_1"
diff --git a/docs/api_tpactiontimings.rst b/docs/api_tpactiontimings.rst
index 93f281283..227783d1f 100644
--- a/docs/api_tpactiontimings.rst
+++ b/docs/api_tpactiontimings.rst
@@ -1,4 +1,4 @@
-Apier.SetTPActionTimings
+ApierV1.SetTPActionTimings
++++++++++++++++++++++++
Creates a new ActionTimings profile within a tariff plan.
@@ -27,7 +27,7 @@ Creates a new ActionTimings profile within a tariff plan.
{
"id": 7,
- "method": "Apier.SetTPActionTimings",
+ "method": "ApierV1.SetTPActionTimings",
"params": [
{
"ActionTimings": [
@@ -76,7 +76,7 @@ Creates a new ActionTimings profile within a tariff plan.
``DUPLICATE`` - The specified combination of TPid/ActionTimingsId already present in StorDb.
-Apier.GetTPActionTimings
+ApierV1.GetTPActionTimings
++++++++++++++++++++++++
Queries specific ActionTimings profile on tariff plan.
@@ -98,7 +98,7 @@ Queries specific ActionTimings profile on tariff plan.
{
"id": 8,
- "method": "Apier.GetTPActionTimings",
+ "method": "ApierV1.GetTPActionTimings",
"params": [
{
"ActionTimingsId": "SAMPLE_AT3",
@@ -157,7 +157,7 @@ Queries specific ActionTimings profile on tariff plan.
``NOT_FOUND`` - Requested ActionTimings profile not found.
-Apier.GetTPActionTimingIds
+ApierV1.GetTPActionTimingIds
++++++++++++++++++++++++++
Queries ActionTimings identities on specific tariff plan.
@@ -178,7 +178,7 @@ Queries ActionTimings identities on specific tariff plan.
{
"id": 9,
- "method": "Apier.GetTPActionTimingIds",
+ "method": "ApierV1.GetTPActionTimingIds",
"params": [
{
"TPid": "SAMPLE_TP_1"
diff --git a/docs/api_tpactiontriggers.rst b/docs/api_tpactiontriggers.rst
index 3518dc58f..dcb21e2e6 100644
--- a/docs/api_tpactiontriggers.rst
+++ b/docs/api_tpactiontriggers.rst
@@ -1,4 +1,4 @@
-Apier.SetTPActionTriggers
+ApierV1.SetTPActionTriggers
+++++++++++++++++++++++++
Creates a new ActionTriggers profile within a tariff plan.
@@ -32,7 +32,7 @@ Creates a new ActionTriggers profile within a tariff plan.
{
"id": 2,
- "method": "Apier.SetTPActionTriggers",
+ "method": "ApierV1.SetTPActionTriggers",
"params": [
{
"ActionTriggers": [
@@ -80,7 +80,7 @@ Creates a new ActionTriggers profile within a tariff plan.
``DUPLICATE`` - The specified combination of TPid/ActionTriggersId already present in StorDb.
-Apier.GetTPActionTriggers
+ApierV1.GetTPActionTriggers
+++++++++++++++++++++++++
Queries specific ActionTriggers profile on tariff plan.
@@ -102,7 +102,7 @@ Queries specific ActionTriggers profile on tariff plan.
{
"id": 0,
- "method": "Apier.GetTPActionTriggers",
+ "method": "ApierV1.GetTPActionTriggers",
"params": [
{
"ActionTriggersId": "SAMPLE_ATS_1",
@@ -165,7 +165,7 @@ Queries specific ActionTriggers profile on tariff plan.
``NOT_FOUND`` - Requested ActionTriggersId profile not found.
-Apier.GetTPActionTriggerIds
+ApierV1.GetTPActionTriggerIds
+++++++++++++++++++++++++++
Queries ActionTriggers identities on specific tariff plan.
@@ -186,7 +186,7 @@ Queries ActionTriggers identities on specific tariff plan.
{
"id": 5,
- "method": "Apier.GetTPActionTriggerIds",
+ "method": "ApierV1.GetTPActionTriggerIds",
"params": [
{
"TPid": "SAMPLE_TP_2"
diff --git a/docs/api_tpdestinationrates.rst b/docs/api_tpdestinationrates.rst
index 36b0e6407..7045c76d4 100644
--- a/docs/api_tpdestinationrates.rst
+++ b/docs/api_tpdestinationrates.rst
@@ -1,4 +1,4 @@
-Apier.SetTPDestinationRate
+ApierV1.SetTPDestinationRate
++++++++++++++++++++++++++
@@ -27,7 +27,7 @@ Creates a new DestinationRate profile within a tariff plan.
{
"id": 2,
- "method": "Apier.SetTPDestinationRate",
+ "method": "ApierV1.SetTPDestinationRate",
"params": [
{
"DestinationRateId": "DST_RATE_1",
@@ -78,7 +78,7 @@ Creates a new DestinationRate profile within a tariff plan.
``DUPLICATE`` - The specified combination of TPid/DestinationRateId already exists in StorDb.
-Apier.GetTPDestinationRate
+ApierV1.GetTPDestinationRate
+++++++++++++++
Queries specific DestinationRate profile on tariff plan.
@@ -100,7 +100,7 @@ Queries specific DestinationRate profile on tariff plan.
{
"id": 2,
- "method": "Apier.GetTPDestinationRate",
+ "method": "ApierV1.GetTPDestinationRate",
"params": [
{
"DestinationRateId": "DST_RATE_1",
@@ -161,7 +161,7 @@ Queries specific DestinationRate profile on tariff plan.
``NOT_FOUND`` - Requested DestinationRate id not found.
-Apier.GetTPDestinationRateIds
+ApierV1.GetTPDestinationRateIds
+++++++++++++++++++++++++++++
Queries DestinationRate identities on specific tariff plan.
@@ -182,7 +182,7 @@ Queries DestinationRate identities on specific tariff plan.
{
"id": 3,
- "method": "Apier.GetTPDestinationRateIds",
+ "method": "ApierV1.GetTPDestinationRateIds",
"params": [
{
"TPid": "FIST_TP"
diff --git a/docs/api_tpdestinations.rst b/docs/api_tpdestinations.rst
index c7abd844e..e457473f5 100644
--- a/docs/api_tpdestinations.rst
+++ b/docs/api_tpdestinations.rst
@@ -1,4 +1,4 @@
-Apier.SetTPDestination
+ApierV1.SetTPDestination
++++++++++++++++++++++
Creates a new destination within a tariff plan id.
@@ -21,7 +21,7 @@ Creates a new destination within a tariff plan id.
{
"id": 2,
- "method": "Apier.SetTPDestination",
+ "method": "ApierV1.SetTPDestination",
"params": [
{
"DestinationId": "FIST_DST2",
@@ -62,7 +62,7 @@ Creates a new destination within a tariff plan id.
``DUPLICATE`` - The specified combination of TPid/DestinationId already exists in StorDb.
-Apier.GetTPDestination
+ApierV1.GetTPDestination
++++++++++++++++++++++
Queries a specific destination.
@@ -84,7 +84,7 @@ Queries a specific destination.
{
"id": 0,
- "method": "Apier.GetTPDestination",
+ "method": "ApierV1.GetTPDestination",
"params": [
{
"DestinationId": "FIRST_DST2",
@@ -130,7 +130,7 @@ Queries a specific destination.
``NOT_FOUND`` - Requested destination id not found.
-Apier.GetTPDestinationIds
+ApierV1.GetTPDestinationIds
+++++++++++++++++++++++++
Queries destination identities on specific tariff plan.
@@ -151,7 +151,7 @@ Queries destination identities on specific tariff plan.
{
"id": 1,
- "method": "Apier.GetTPDestinationIds",
+ "method": "ApierV1.GetTPDestinationIds",
"params": [
{
"TPid": "FIST_TP"
diff --git a/docs/api_tpdestratetimings.rst b/docs/api_tpdestratetimings.rst
index d96c54b18..3f7e34cfa 100644
--- a/docs/api_tpdestratetimings.rst
+++ b/docs/api_tpdestratetimings.rst
@@ -1,4 +1,4 @@
-Apier.SetTPDestRateTiming
+ApierV1.SetTPDestRateTiming
+++++++++++++++++++++++++
Creates a new DestinationRateTiming profile within a tariff plan.
@@ -27,7 +27,7 @@ Creates a new DestinationRateTiming profile within a tariff plan.
{
"id": 0,
- "method": "Apier.SetTPDestRateTiming",
+ "method": "ApierV1.SetTPDestRateTiming",
"params": [
{
"DestRateTimingId": "SAMPLE_DRTIMING_1",
@@ -71,7 +71,7 @@ Creates a new DestinationRateTiming profile within a tariff plan.
``DUPLICATE`` - The specified combination of TPid/DestRateTimingId already exists in StorDb.
-Apier.GetTPDestRateTiming
+ApierV1.GetTPDestRateTiming
+++++++++++++++++++++++++
Queries specific DestRateTiming profile on tariff plan.
@@ -93,7 +93,7 @@ Queries specific DestRateTiming profile on tariff plan.
{
"id": 4,
- "method": "Apier.GetTPDestRateTiming",
+ "method": "ApierV1.GetTPDestRateTiming",
"params": [
{
"DestRateTimingId": "SAMPLE_DRTIMING_1",
@@ -147,7 +147,7 @@ Queries specific DestRateTiming profile on tariff plan.
``NOT_FOUND`` - Requested DestRateTiming profile not found.
-Apier.GetTPDestRateTimingIds
+ApierV1.GetTPDestRateTimingIds
++++++++++++++++++++++++++++
Queries DestRateTiming identities on specific tariff plan.
@@ -168,7 +168,7 @@ Queries DestRateTiming identities on specific tariff plan.
{
"id": 5,
- "method": "Apier.GetTPDestRateTimingIds",
+ "method": "ApierV1.GetTPDestRateTimingIds",
"params": [
{
"TPid": "SAMPLE_TP"
diff --git a/docs/api_tprates.rst b/docs/api_tprates.rst
index 98155f34e..81fce1650 100644
--- a/docs/api_tprates.rst
+++ b/docs/api_tprates.rst
@@ -1,4 +1,4 @@
-Apier.SetTPRate
+ApierV1.SetTPRate
+++++++++++++++
Creates a new rate within a tariff plan.
@@ -32,7 +32,7 @@ Creates a new rate within a tariff plan.
{
"id": 1,
- "method": "Apier.SetTPRate",
+ "method": "ApierV1.SetTPRate",
"params": [
{
"RateId": "SAMPLE_RATE_2",
@@ -91,7 +91,7 @@ Creates a new rate within a tariff plan.
``DUPLICATE`` - The specified combination of TPid/RateId already exists in StorDb.
-Apier.GetTPRate
+ApierV1.GetTPRate
+++++++++++++++
Queries specific rate on tariff plan.
@@ -113,7 +113,7 @@ Queries specific rate on tariff plan.
{
"id": 1,
- "method": "Apier.GetTPRate",
+ "method": "ApierV1.GetTPRate",
"params": [
{
"RateId": "SAMPLE_RATE_4",
@@ -187,7 +187,7 @@ Queries specific rate on tariff plan.
``NOT_FOUND`` - Requested rate id not found.
-Apier.GetTPRateIds
+ApierV1.GetTPRateIds
++++++++++++++++++
Queries rate identities on tariff plan.
@@ -208,7 +208,7 @@ Queries rate identities on tariff plan.
{
"id": 1,
- "method": "Apier.GetTPRateIds",
+ "method": "ApierV1.GetTPRateIds",
"params": [
{
"TPid": "SAMPLE_TP"
diff --git a/docs/api_tpratingprofiles.rst b/docs/api_tpratingprofiles.rst
index 5038bd9c4..d3fc22b93 100644
--- a/docs/api_tpratingprofiles.rst
+++ b/docs/api_tpratingprofiles.rst
@@ -1,4 +1,4 @@
-Apier.SetTPRatingProfile
+ApierV1.SetTPRatingProfile
++++++++++++++++++++++++
Creates a new RatingProfile within a tariff plan.
@@ -31,7 +31,7 @@ Creates a new RatingProfile within a tariff plan.
{
"id": 3,
- "method": "Apier.SetTPRatingProfile",
+ "method": "ApierV1.SetTPRatingProfile",
"params": [
{
"Direction": "*out",
@@ -82,7 +82,7 @@ Creates a new RatingProfile within a tariff plan.
``DUPLICATE`` - The specified combination of TPid/RatingProfileId already exists in StorDb.
-Apier.GetTPRatingProfile
+ApierV1.GetTPRatingProfile
++++++++++++++++++++++++
Queries specific RatingProfile on tariff plan.
@@ -104,7 +104,7 @@ Queries specific RatingProfile on tariff plan.
{
"id": 0,
- "method": "Apier.GetTPRatingProfile",
+ "method": "ApierV1.GetTPRatingProfile",
"params": [
{
"RatingProfileId": "SAMPLE_RP_2",
@@ -170,7 +170,7 @@ Queries specific RatingProfile on tariff plan.
``NOT_FOUND`` - Requested RatingProfile profile not found.
-Apier.GetTPRatingProfileIds
+ApierV1.GetTPRatingProfileIds
+++++++++++++++++++++++++++
Queries specific RatingProfile on tariff plan. Attribute parameters used as extra filters.
@@ -195,7 +195,7 @@ Queries specific RatingProfile on tariff plan. Attribute parameters used as extr
{
"id": 0,
- "method": "Apier.GetTPRatingProfileIds",
+ "method": "ApierV1.GetTPRatingProfileIds",
"params": [
{
"Subject": "dan",
diff --git a/docs/api_tptimings.rst b/docs/api_tptimings.rst
index 86ae29049..9d16a194a 100644
--- a/docs/api_tptimings.rst
+++ b/docs/api_tptimings.rst
@@ -1,4 +1,4 @@
-Apier.SetTPTiming
+ApierV1.SetTPTiming
+++++++++++++++++
Creates a new timing within a tariff plan.
@@ -25,7 +25,7 @@ Creates a new timing within a tariff plan.
{
"id": 3,
- "method": "Apier.SetTPTiming",
+ "method": "ApierV1.SetTPTiming",
"params": [
{
"MonthDays": "1;2;3;31",
@@ -67,7 +67,7 @@ Creates a new timing within a tariff plan.
``DUPLICATE`` - The specified combination of TPid/TimingId already exists in StorDb.
-Apier.GetTPTiming
+ApierV1.GetTPTiming
+++++++++++++++++
Queries specific Timing on tariff plan.
@@ -89,7 +89,7 @@ Queries specific Timing on tariff plan.
{
"id": 4,
- "method": "Apier.GetTPTiming",
+ "method": "ApierV1.GetTPTiming",
"params": [
{
"TPid": "SAMPLE_TP",
@@ -139,7 +139,7 @@ Queries specific Timing on tariff plan.
``NOT_FOUND`` - Requested timing id not found.
-Apier.GetTPTimingIds
+ApierV1.GetTPTimingIds
+++++++++++++++++++++++++
Queries timing identities on tariff plan.
@@ -160,7 +160,7 @@ Queries timing identities on tariff plan.
{
"id": 5,
- "method": "Apier.GetTPTimingIds",
+ "method": "ApierV1.GetTPTimingIds",
"params": [
{
"TPid": "SAMPLE_TP"
diff --git a/docs/apicalls.rst b/docs/apicalls.rst
index dc015cd7e..9a25d1c48 100644
--- a/docs/apicalls.rst
+++ b/docs/apicalls.rst
@@ -312,7 +312,7 @@ AddTriggeredAction
::
- type AttrActionTrigger struct {
+ type AttrAddActionTrigger struct {
Tenant string
Account string
Direction string
@@ -324,14 +324,14 @@ AddTriggeredAction
}
Example
- AddTriggeredAction(attr \*AttrActionTrigger, reply \*float64)
+ AddTriggeredAction(attr \*AttrAddActionTrigger, reply \*float64)
AddAcount
+++++++++
::
- type AttrAccount struct {
+ type AttrAddAccount struct {
Tenant string
Direction string
Account string
@@ -340,7 +340,7 @@ AddAcount
}
Example
- AddAccount(attr \*AttrAccount, reply \*float64)
+ AddAccount(attr \*AttrAddAccount, reply \*float64)
diff --git a/engine/action_timing.go b/engine/action_timing.go
index 27d956c51..5136242b9 100644
--- a/engine/action_timing.go
+++ b/engine/action_timing.go
@@ -221,6 +221,7 @@ func (at *ActionTiming) Execute() (err error) {
ub, err := storageGetter.GetUserBalance(ubId)
if err != nil {
Logger.Warning(fmt.Sprintf("Could not get user balances for this id: %s. Skipping!", ubId))
+ return 0, err
}
Logger.Info(fmt.Sprintf("Executing %v on %v", a.ActionType, ub.Id))
diff --git a/history/file_scribe.go b/history/file_scribe.go
index c0f3c08f6..c974876f7 100644
--- a/history/file_scribe.go
+++ b/history/file_scribe.go
@@ -37,7 +37,7 @@ const (
)
type FileScribe struct {
- mu sync.RWMutex
+ mu sync.Mutex
fileRoot string
gitCommand string
destinations records
@@ -65,8 +65,6 @@ func NewFileScribe(fileRoot string) (*FileScribe, error) {
}
func (s *FileScribe) Record(rec *Record, out *int) error {
- s.mu.Lock()
- defer s.mu.Unlock()
var fileToSave string
switch {
case strings.HasPrefix(rec.Key, DESTINATION_PREFIX):
@@ -104,6 +102,8 @@ func (s *FileScribe) Record(rec *Record, out *int) error {
}
func (s *FileScribe) gitInit() 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())
@@ -144,6 +144,8 @@ func (s *FileScribe) gitCommit() error {
}
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
@@ -167,6 +169,8 @@ func (s *FileScribe) load(filename string) error {
}
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
diff --git a/history/mock_scribe.go b/history/mock_scribe.go
index 152fce446..7b2a5af65 100644
--- a/history/mock_scribe.go
+++ b/history/mock_scribe.go
@@ -28,7 +28,7 @@ import (
)
type MockScribe struct {
- sync.RWMutex
+ sync.Mutex
destinations records
ratingProfiles records
DestBuf bytes.Buffer
@@ -40,8 +40,6 @@ func NewMockScribe() (*MockScribe, error) {
}
func (s *MockScribe) Record(rec *Record, out *int) error {
- s.Lock()
- defer s.Unlock()
switch {
case strings.HasPrefix(rec.Key, DESTINATION_PREFIX):
s.destinations = s.destinations.SetOrAdd(&Record{rec.Key[len(DESTINATION_PREFIX):], rec.Object})
@@ -55,6 +53,8 @@ func (s *MockScribe) Record(rec *Record, out *int) error {
}
func (s *MockScribe) save(filename string) error {
+ s.Lock()
+ defer s.Unlock()
switch filename {
case DESTINATIONS_FILE:
s.DestBuf.Reset()
diff --git a/mediator/mediator.go b/mediator/mediator.go
index 5bd2c2600..79f0f00f9 100644
--- a/mediator/mediator.go
+++ b/mediator/mediator.go
@@ -202,7 +202,7 @@ func (self *Mediator) getCostsFromRater(cdr utils.CDR) (*engine.CallCost, error)
// If the mediator calculated a price it will write it to logdb
self.storDb.LogCallCost(cdr.GetCgrId(), engine.MEDIATOR_SOURCE, cc)
}
- return cc, nil
+ return cc, err
}
// Parse the files and get cost for every record