From 91ac0fd3f262e3d80b21ec771be3307cf22cf16a Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Wed, 30 Jul 2014 18:41:45 +0300 Subject: [PATCH] more fixes for action trigger db load --- .../mysql/create_tariffplan_tables.sql | 6 ++++ engine/loader_db.go | 30 +++++++++++------ engine/storage_sql.go | 32 ++++++++++++------- utils/apitpdata.go | 23 ++++++++----- 4 files changed, 62 insertions(+), 29 deletions(-) diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 9aa46464d..6ff71521b 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -184,7 +184,13 @@ CREATE TABLE `tp_action_triggers` ( `threshold_type` char(12) NOT NULL, `threshold_value` double(20,4) NOT NULL, `recurrent` bool NOT NULL, + `min_sleep` int(11) NOT NULL, `destination_id` varchar(64) NOT NULL, + `balance_weight` double(8,2) NOT NULL, + `balance_expiry_time` varchar(24) NOT NULL, + `balance_rating_subject` varchar(64) NOT NULL, + `balance_shared_group` varchar(64) NOT NULL, + `min_queued_items` int(11) NOT NULL, `actions_id` varchar(64) NOT NULL, `weight` double(8,2) NOT NULL, PRIMARY KEY (`tbid`), diff --git a/engine/loader_db.go b/engine/loader_db.go index ae9c75839..5a4cd73e1 100644 --- a/engine/loader_db.go +++ b/engine/loader_db.go @@ -579,15 +579,23 @@ func (dbr *DbReader) LoadActionTriggers() (err error) { for key, atrsLst := range atrsMap { atrs := make([]*ActionTrigger, len(atrsLst)) for idx, apiAtr := range atrsLst { - atrs[idx] = &ActionTrigger{Id: utils.GenUUID(), - BalanceType: apiAtr.BalanceType, - Direction: apiAtr.Direction, - ThresholdType: apiAtr.ThresholdType, - ThresholdValue: apiAtr.ThresholdValue, - Recurrent: apiAtr.Recurrent, - DestinationId: apiAtr.DestinationId, - Weight: apiAtr.Weight, - ActionsId: apiAtr.ActionsId, + balance_expiration_date, _ := utils.ParseTimeDetectLayout(apiAtr.BalanceExpirationDate) + atrs[idx] = &ActionTrigger{ + Id: utils.GenUUID(), + BalanceType: apiAtr.BalanceType, + Direction: apiAtr.Direction, + ThresholdType: apiAtr.ThresholdType, + ThresholdValue: apiAtr.ThresholdValue, + Recurrent: apiAtr.Recurrent, + MinSleep: apiAtr.MinSleep, + DestinationId: apiAtr.DestinationId, + BalanceWeight: apiAtr.BalanceWeight, + BalanceExpirationDate: balance_expiration_date, + BalanceRatingSubject: apiAtr.BalanceRatingSubject, + BalanceSharedGroup: apiAtr.BalanceSharedGroup, + Weight: apiAtr.Weight, + ActionsId: apiAtr.ActionsId, + MinQueuedItems: apiAtr.MinQueuedItems, } } dbr.actionsTriggers[key] = atrs @@ -799,6 +807,10 @@ func (dbr *DbReader) LoadDerivedChargers() (err error) { return nil // Placeholder for now } +func (dbr *DbReader) LoadCdrStats() (err error) { + return nil // Placeholder for now +} + // Automated loading func (dbr *DbReader) LoadAll() error { var err error diff --git a/engine/storage_sql.go b/engine/storage_sql.go index bf4ce822b..7b8c29b80 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -1332,7 +1332,7 @@ func (self *SQLStorage) GetTpActions(tpid, tag string) (map[string][]*utils.TPAc func (self *SQLStorage) GetTpActionTriggers(tpid, tag string) (map[string][]*utils.TPActionTrigger, error) { ats := make(map[string][]*utils.TPActionTrigger) - q := fmt.Sprintf("SELECT tpid,id,balance_type,direction,threshold_type,threshold_value,recurrent,destination_id,actions_id,weight FROM %s WHERE tpid='%s'", + q := fmt.Sprintf("SELECT tpid,id,balance_type,direction,threshold_type,threshold_value,recurrent,min_sleep, ,destination_id, balance_weight, balance_expiration_time, balance_rating_subject, balance_expiration_time, balance_shared_group, min_queued_items, actions_id, weight FROM %s WHERE tpid='%s'", utils.TBL_TP_ACTION_TRIGGERS, tpid) if tag != "" { q += fmt.Sprintf(" AND id='%s'", tag) @@ -1343,22 +1343,30 @@ func (self *SQLStorage) GetTpActionTriggers(tpid, tag string) (map[string][]*uti } defer rows.Close() for rows.Next() { - var threshold, weight float64 - var tpid, tag, balances_type, direction, destinations_tag, actions_tag, thresholdType string + var threshold, balance_weight, weight float64 + var tpid, tag, balances_type, direction, destinations_tag, balance_expiration_time, balance_rating_subject, balance_shared_group, actions_tag, threshold_type string var recurrent bool - if err := rows.Scan(&tpid, &tag, &balances_type, &direction, &thresholdType, &threshold, &recurrent, &destinations_tag, &actions_tag, &weight); err != nil { + var min_sleep time.Duration + var min_queued_items int + if err := rows.Scan(&tpid, &tag, &balances_type, &direction, &threshold_type, &threshold, &recurrent, &min_sleep, &destinations_tag, &actions_tag, &weight); err != nil { return nil, err } at := &utils.TPActionTrigger{ - BalanceType: balances_type, - Direction: direction, - ThresholdType: thresholdType, - ThresholdValue: threshold, - Recurrent: recurrent, - DestinationId: destinations_tag, - ActionsId: actions_tag, - Weight: weight, + BalanceType: balances_type, + Direction: direction, + ThresholdType: threshold_type, + ThresholdValue: threshold, + Recurrent: recurrent, + MinSleep: min_sleep, + DestinationId: destinations_tag, + BalanceWeight: balance_weight, + BalanceExpirationDate: balance_expiration_time, + BalanceRatingSubject: balance_rating_subject, + BalanceSharedGroup: balance_shared_group, + Weight: weight, + ActionsId: actions_tag, + MinQueuedItems: min_queued_items, } ats[tag] = append(ats[tag], at) } diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 3686af663..7c69c09be 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -241,14 +241,21 @@ type TPActionTriggers struct { } type TPActionTrigger struct { - BalanceType string // Type of balance this trigger monitors - Direction string // Traffic direction - ThresholdType string // This threshold type - ThresholdValue float64 // Threshold - Recurrent bool // reset executed flag each run - DestinationId string // Id of the destination profile - ActionsId string // Actions which will execute on threshold reached - Weight float64 // weight + BalanceType string // Type of balance this trigger monitors + Direction string // Traffic direction + ThresholdType string // This threshold type + ThresholdValue float64 // Threshold + Recurrent bool // reset executed flag each run + MinSleep time.Duration // Minimum duration between two executions in case of recurrent triggers + DestinationId string // filter for balance + BalanceWeight float64 // filter for balance + BalanceExpirationDate string // filter for balance + BalanceRatingSubject string // filter for balance + BalanceSharedGroup string // filter for balance + MinQueuedItems int // Trigger actions only if this number is hit (stats only) + ActionsId string // Actions which will execute on threshold reached + Weight float64 // weight + } // Used to rebuild a TPAccountActions (empty ActionTimingsId and ActionTriggersId) out of it's key in nosqldb