fixes for loading apier methods

This commit is contained in:
Radu Ioan Fericean
2014-09-04 17:35:28 +03:00
parent 886ca68eb8
commit 46fc12e0cd
3 changed files with 51 additions and 16 deletions

View File

@@ -183,11 +183,14 @@ func (self *ApierV1) LoadRatingPlan(attrs AttrLoadRatingPlan, reply *string) err
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RatingPlanId"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
if attrs.RatingPlanId == utils.ANY {
attrs.RatingPlanId = ""
}
dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid)
if loaded, err := dbReader.LoadRatingPlanByTag(attrs.RatingPlanId); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
} else if !loaded {
return errors.New("NOT_FOUND")
return errors.New(utils.ERR_NOT_FOUND)
}
//Automatic cache of the newly inserted rating plan
didNotChange := []string{}
@@ -200,16 +203,37 @@ func (self *ApierV1) LoadRatingPlan(attrs AttrLoadRatingPlan, reply *string) err
// Process dependencies and load a specific rating profile from storDb into dataDb.
func (self *ApierV1) LoadRatingProfile(attrs utils.TPRatingProfile, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LoadId", "Tenant", "TOR", "Direction", "Subject"}); len(missing) != 0 {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LoadId", "Tenant", "Category", "Direction", "Subject"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
if attrs.LoadId == utils.ANY {
attrs.LoadId = ""
}
if attrs.Tenant == utils.ANY {
attrs.Tenant = ""
}
if attrs.Category == utils.ANY {
attrs.Category = ""
}
if attrs.Direction == utils.ANY {
attrs.Direction = ""
}
if attrs.Subject == utils.ANY {
attrs.Subject = ""
}
dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid)
if err := dbReader.LoadRatingProfileFiltered(&attrs); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
}
//Automatic cache of the newly inserted rating profile
didNotChange := []string{}
if err := self.RatingDb.CacheRating(didNotChange, didNotChange, []string{engine.RATING_PROFILE_PREFIX + attrs.KeyId()}, didNotChange, didNotChange); err != nil {
var ratingProfile []string
if attrs.KeyId() != ":::" { // if has some filters
ratingProfile = []string{engine.RATING_PROFILE_PREFIX + attrs.KeyId()}
}
if err := self.RatingDb.CacheRating(didNotChange, didNotChange, ratingProfile, didNotChange, didNotChange); err != nil {
return err
}
*reply = OK
@@ -556,7 +580,18 @@ func (self *ApierV1) LoadAccountActions(attrs utils.TPAccountActions, reply *str
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid)
if attrs.LoadId == utils.ANY {
attrs.LoadId = ""
}
if attrs.Tenant == utils.ANY {
attrs.Tenant = ""
}
if attrs.Account == utils.ANY {
attrs.Account = ""
}
if attrs.Direction == utils.ANY {
attrs.Direction = ""
}
if _, err := engine.AccLock.Guard(attrs.KeyId(), func() (float64, error) {
if err := dbReader.LoadAccountActionsFiltered(&attrs); err != nil {
return 0, err

View File

@@ -166,7 +166,7 @@ func (rp *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error)
return
}
return errors.New("not found")
return errors.New(utils.ERR_NOT_FOUND)
}
// history record method

View File

@@ -196,7 +196,7 @@ func (ms *MapStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPlan,
err = ms.ms.Unmarshal(out, rp)
cache2go.Cache(key, rp)
} else {
return nil, errors.New("not found")
return nil, errors.New(utils.ERR_NOT_FOUND)
}
return
}
@@ -231,7 +231,7 @@ func (ms *MapStorage) GetRatingProfile(key string, skipCache bool) (rpf *RatingP
err = ms.ms.Unmarshal(values, rpf)
cache2go.Cache(key, rpf)
} else {
return nil, errors.New("not found")
return nil, errors.New(utils.ERR_NOT_FOUND)
}
return
}
@@ -260,7 +260,7 @@ func (ms *MapStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error) {
err = ms.ms.Unmarshal(values, &lcr)
cache2go.Cache(key, lcr)
} else {
return nil, errors.New("not found")
return nil, errors.New(utils.ERR_NOT_FOUND)
}
return
}
@@ -285,7 +285,7 @@ func (ms *MapStorage) GetRpAlias(key string, skipCache bool) (alias string, err
alias = string(values)
cache2go.Cache(key, alias)
} else {
return "", errors.New("not found")
return "", errors.New(utils.ERR_NOT_FOUND)
}
return
}
@@ -352,7 +352,7 @@ func (ms *MapStorage) GetAccAlias(key string, skipCache bool) (alias string, err
alias = string(values)
cache2go.Cache(key, alias)
} else {
return "", errors.New("not found")
return "", errors.New(utils.ERR_NOT_FOUND)
}
return
}
@@ -405,7 +405,7 @@ func (ms *MapStorage) GetDestination(key string) (dest *Destination, err error)
cache2go.CachePush(DESTINATION_PREFIX+p, dest.Id)
}
} else {
return nil, errors.New("not found")
return nil, errors.New(utils.ERR_NOT_FOUND)
}
return
}
@@ -438,7 +438,7 @@ func (ms *MapStorage) GetActions(key string, skipCache bool) (as Actions, err er
err = ms.ms.Unmarshal(values, &as)
cache2go.Cache(key, as)
} else {
return nil, errors.New("not found")
return nil, errors.New(utils.ERR_NOT_FOUND)
}
return
}
@@ -463,7 +463,7 @@ func (ms *MapStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGrou
err = ms.ms.Unmarshal(values, &sg)
cache2go.Cache(key, sg)
} else {
return nil, errors.New("not found")
return nil, errors.New(utils.ERR_NOT_FOUND)
}
return
}
@@ -480,7 +480,7 @@ func (ms *MapStorage) GetAccount(key string) (ub *Account, err error) {
ub = &Account{Id: key}
err = ms.ms.Unmarshal(values, ub)
} else {
return nil, errors.New("not found")
return nil, errors.New(utils.ERR_NOT_FOUND)
}
return
}
@@ -502,7 +502,7 @@ func (ms *MapStorage) GetActionTimings(key string) (ats ActionPlan, err error) {
if values, ok := ms.dict[ACTION_TIMING_PREFIX+key]; ok {
err = ms.ms.Unmarshal(values, &ats)
} else {
return nil, errors.New("not found")
return nil, errors.New(utils.ERR_NOT_FOUND)
}
return
}
@@ -593,7 +593,7 @@ func (ms *MapStorage) GetCallCostLog(cgrid, source, runid string) (cc *CallCost,
if values, ok := ms.dict[LOG_CALL_COST_PREFIX+source+runid+"_"+cgrid]; ok {
err = ms.ms.Unmarshal(values, &cc)
} else {
return nil, errors.New("not found")
return nil, errors.New(utils.ERR_NOT_FOUND)
}
return
}