mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-19 22:28:45 +05:00
Add infrastructure for DispatcherProfile
This commit is contained in:
committed by
Dan Christian Bogos
parent
79a69b5aa7
commit
473d8dbc5a
@@ -127,7 +127,7 @@ func (self *SQLStorage) GetTpIds(colName string) ([]string, error) {
|
||||
qryStr := fmt.Sprintf(" (SELECT tpid FROM %s)", colName)
|
||||
if colName == "" {
|
||||
qryStr = fmt.Sprintf(
|
||||
"(SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s)",
|
||||
"(SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s)",
|
||||
utils.TBLTPTimings,
|
||||
utils.TBLTPDestinations,
|
||||
utils.TBLTPRates,
|
||||
@@ -148,7 +148,8 @@ func (self *SQLStorage) GetTpIds(colName string) ([]string, error) {
|
||||
utils.TBLTPActionPlans,
|
||||
utils.TBLTPSuppliers,
|
||||
utils.TBLTPAttributes,
|
||||
utils.TBLTPChargers)
|
||||
utils.TBLTPChargers,
|
||||
utils.TBLTPDispatchers)
|
||||
}
|
||||
rows, err = self.Db.Query(qryStr)
|
||||
if err != nil {
|
||||
@@ -239,7 +240,8 @@ func (self *SQLStorage) RemTpData(table, tpid string, args map[string]string) er
|
||||
utils.TBLTPSharedGroups, utils.TBLTPActions, utils.TBLTPActionPlans,
|
||||
utils.TBLTPActionTriggers, utils.TBLTPAccountActions,
|
||||
utils.TBLTPDerivedChargers, utils.TBLTPAliases, utils.TBLTPUsers, utils.TBLTPResources,
|
||||
utils.TBLTPStats, utils.TBLTPFilters, utils.TBLTPSuppliers, utils.TBLTPAttributes, utils.TBLTPChargers} {
|
||||
utils.TBLTPStats, utils.TBLTPFilters, utils.TBLTPSuppliers, utils.TBLTPAttributes,
|
||||
utils.TBLTPChargers, utils.TBLTPDispatchers} {
|
||||
if err := tx.Table(tblName).Where("tpid = ?", tpid).Delete(nil).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
@@ -709,6 +711,28 @@ func (self *SQLStorage) SetTPChargers(tpCPPs []*utils.TPChargerProfile) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) SetTPDispatchers(tpDPPs []*utils.TPDispatcherProfile) error {
|
||||
if len(tpDPPs) == 0 {
|
||||
return nil
|
||||
}
|
||||
tx := self.db.Begin()
|
||||
for _, dpp := range tpDPPs {
|
||||
// Remove previous
|
||||
if err := tx.Where(&TPDispatcher{Tpid: dpp.TPid, ID: dpp.ID}).Delete(TPDispatcher{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
for _, mst := range APItoModelTPDispatcher(dpp) {
|
||||
if err := tx.Save(&mst).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
tx.Commit()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) SetSMCost(smc *SMCost) error {
|
||||
if smc.CostDetails == nil {
|
||||
return nil
|
||||
@@ -1607,6 +1631,25 @@ func (self *SQLStorage) GetTPChargers(tpid, tenant, id string) ([]*utils.TPCharg
|
||||
return arls, nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) GetTPDispatchers(tpid, tenant, id string) ([]*utils.TPDispatcherProfile, error) {
|
||||
var dpps TPDispatchers
|
||||
q := self.db.Where("tpid = ?", tpid)
|
||||
if len(id) != 0 {
|
||||
q = q.Where("id = ?", id)
|
||||
}
|
||||
if len(tenant) != 0 {
|
||||
q = q.Where("tenant = ?", tenant)
|
||||
}
|
||||
if err := q.Find(&dpps).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
arls := dpps.AsTPDispatchers()
|
||||
if len(arls) == 0 {
|
||||
return arls, utils.ErrNotFound
|
||||
}
|
||||
return arls, nil
|
||||
}
|
||||
|
||||
// GetVersions returns slice of all versions or a specific version if tag is specified
|
||||
func (self *SQLStorage) GetVersions(itm string) (vrs Versions, err error) {
|
||||
q := self.db.Model(&TBLVersion{})
|
||||
|
||||
Reference in New Issue
Block a user