ApierV2.GetAccountIds, remove utils.EMPTY symbol, fix /etc/cgrates folder in packaging, thanks esamuels

This commit is contained in:
DanB
2015-02-03 19:56:27 +01:00
parent bc169e24d0
commit 490bd9d573
5 changed files with 94 additions and 109 deletions

View File

@@ -175,18 +175,14 @@ func (self *ApierV1) ExecuteAction(attr *AttrExecuteAction, reply *string) error
}
type AttrLoadDestination struct {
TPid string
DestinationId string
PreventCacheReload bool // Set it on true in case of "batch mode" when reloads happen in the end of recursive API call
TPid string
DestinationId string
}
// Load destinations from storDb into dataDb.
func (self *ApierV1) LoadDestination(attrs AttrLoadDestination, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationId"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
if attrs.DestinationId == utils.EMPTY {
attrs.DestinationId = ""
if len(attrs.TPid) == 0 {
return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
}
dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid)
if loaded, err := dbReader.LoadDestinationByTag(attrs.DestinationId); err != nil {
@@ -194,12 +190,14 @@ func (self *ApierV1) LoadDestination(attrs AttrLoadDestination, reply *string) e
} else if !loaded {
return errors.New(utils.ERR_NOT_FOUND)
}
if !attrs.PreventCacheReload {
//Automatic cache of the newly inserted rating plan
didNotChange := []string{}
if err := self.RatingDb.CacheRating([]string{attrs.DestinationId}, didNotChange, didNotChange, didNotChange, didNotChange); err != nil {
return err
}
//Automatic cache of the newly inserted rating plan
didNotChange := []string{}
destIds := []string{engine.DESTINATION_PREFIX + attrs.DestinationId}
if len(attrs.DestinationId) == 0 {
destIds = nil // Cache all destinations, temporary here until we add ApierV2.LoadDestinations
}
if err := self.RatingDb.CacheRating(destIds, didNotChange, didNotChange, didNotChange, didNotChange); err != nil {
return err
}
*reply = OK
return nil
@@ -207,26 +205,8 @@ func (self *ApierV1) LoadDestination(attrs AttrLoadDestination, reply *string) e
// Load derived chargers from storDb into dataDb.
func (self *ApierV1) LoadDerivedChargers(attrs utils.TPDerivedChargers, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LoadId", "Tenant", "Category", "Direction", "Account", "Subject"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
if attrs.Loadid == utils.EMPTY {
attrs.Loadid = ""
}
if attrs.Tenant == utils.EMPTY {
attrs.Tenant = ""
}
if attrs.Category == utils.EMPTY {
attrs.Category = ""
}
if attrs.Direction == utils.EMPTY {
attrs.Direction = ""
}
if attrs.Account == utils.EMPTY {
attrs.Account = ""
}
if attrs.Subject == utils.EMPTY {
attrs.Subject = ""
if len(attrs.TPid) == 0 {
return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
}
dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid)
if err := dbReader.LoadDerivedChargersFiltered(&attrs); err != nil {
@@ -234,7 +214,11 @@ func (self *ApierV1) LoadDerivedChargers(attrs utils.TPDerivedChargers, reply *s
}
//Automatic cache of the newly inserted rating plan
didNotChange := []string{}
if err := self.AccountDb.CacheAccounting(didNotChange, didNotChange, didNotChange, nil); err != nil {
var derivedChargingKeys []string
if len(attrs.Direction) != 0 && len(attrs.Tenant) != 0 && len(attrs.Category) != 0 && len(attrs.Account) != 0 && len(attrs.Subject) != 0 {
derivedChargingKeys = []string{engine.DERIVEDCHARGERS_PREFIX + attrs.GetDerivedChargersKey()}
}
if err := self.AccountDb.CacheAccounting(didNotChange, didNotChange, didNotChange, derivedChargingKeys); err != nil {
return err
}
*reply = OK
@@ -248,11 +232,8 @@ type AttrLoadRatingPlan struct {
// Process dependencies and load a specific rating plan from storDb into dataDb.
func (self *ApierV1) LoadRatingPlan(attrs AttrLoadRatingPlan, reply *string) error {
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.EMPTY {
attrs.RatingPlanId = ""
if len(attrs.TPid) == 0 {
return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
}
dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid)
if loaded, err := dbReader.LoadRatingPlanByTag(attrs.RatingPlanId); err != nil {
@@ -262,7 +243,11 @@ func (self *ApierV1) LoadRatingPlan(attrs AttrLoadRatingPlan, reply *string) err
}
//Automatic cache of the newly inserted rating plan
didNotChange := []string{}
if err := self.RatingDb.CacheRating(nil, nil, didNotChange, didNotChange, didNotChange); err != nil {
var changedRPlKeys []string
if len(attrs.TPid) != 0 {
changedRPlKeys = []string{engine.RATING_PLAN_PREFIX + attrs.RatingPlanId}
}
if err := self.RatingDb.CacheRating(nil, changedRPlKeys, didNotChange, didNotChange, didNotChange); err != nil {
return err
}
*reply = OK
@@ -271,26 +256,9 @@ 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", "Category", "Direction", "Subject"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
if len(attrs.TPid) == 0 {
return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
}
if attrs.LoadId == utils.EMPTY {
attrs.LoadId = ""
}
if attrs.Tenant == utils.EMPTY {
attrs.Tenant = ""
}
if attrs.Category == utils.EMPTY {
attrs.Category = ""
}
if attrs.Direction == utils.EMPTY {
attrs.Direction = ""
}
if attrs.Subject == utils.EMPTY {
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())
@@ -315,11 +283,8 @@ type AttrLoadSharedGroup struct {
// Load destinations from storDb into dataDb.
func (self *ApierV1) LoadSharedGroup(attrs AttrLoadSharedGroup, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "SharedGroupId"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
if attrs.SharedGroupId == utils.EMPTY {
attrs.SharedGroupId = ""
if len(attrs.TPid) == 0 {
return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
}
dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid)
if err := dbReader.LoadSharedGroupByTag(attrs.SharedGroupId, true); err != nil {
@@ -327,7 +292,11 @@ func (self *ApierV1) LoadSharedGroup(attrs AttrLoadSharedGroup, reply *string) e
}
//Automatic cache of the newly inserted rating plan
didNotChange := []string{}
if err := self.AccountDb.CacheAccounting(didNotChange, nil, didNotChange, didNotChange); err != nil {
var changedSharedGroup []string
if len(attrs.SharedGroupId) != 0 {
changedSharedGroup = []string{engine.SHARED_GROUP_PREFIX + attrs.SharedGroupId}
}
if err := self.AccountDb.CacheAccounting(didNotChange, changedSharedGroup, didNotChange, didNotChange); err != nil {
return err
}
*reply = OK
@@ -341,11 +310,8 @@ type AttrLoadCdrStats struct {
// Load destinations from storDb into dataDb.
func (self *ApierV1) LoadCdrStats(attrs AttrLoadCdrStats, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "CdrStatsId"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
if attrs.CdrStatsId == utils.EMPTY {
attrs.CdrStatsId = ""
if len(attrs.TPid) == 0 {
return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
}
dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid)
if err := dbReader.LoadCdrStatsByTag(attrs.CdrStatsId, true); err != nil {
@@ -694,22 +660,10 @@ func (self *ApierV1) ResetTriggeredActions(attr AttrResetTriggeredAction, reply
// Process dependencies and load a specific AccountActions profile from storDb into dataDb.
func (self *ApierV1) LoadAccountActions(attrs utils.TPAccountActions, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LoadId", "Tenant", "Account", "Direction"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
if len(attrs.TPid) == 0 {
return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
}
dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid)
if attrs.LoadId == utils.EMPTY {
attrs.LoadId = ""
}
if attrs.Tenant == utils.EMPTY {
attrs.Tenant = ""
}
if attrs.Account == utils.EMPTY {
attrs.Account = ""
}
if attrs.Direction == utils.EMPTY {
attrs.Direction = ""
}
if _, err := engine.AccLock.Guard(attrs.KeyId(), func() (float64, error) {
if err := dbReader.LoadAccountActionsFiltered(&attrs); err != nil {
return 0, err

42
apier/v2/accounts.go Normal file
View File

@@ -0,0 +1,42 @@
/*
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 <http://www.gnu.org/licenses/>
*/
package v2
import (
"github.com/cgrates/cgrates/engine"
)
type AttrGetAccountIds struct {
Page int
ItemsPerPage int
SearchTerm string
}
func (self *ApierV2) GetAccountIds(attrs AttrGetAccountIds, reply *[]string) error {
prefix := engine.ACCOUNT_PREFIX
if attrs.SearchTerm != "" {
prefix += "*" + attrs.SearchTerm
}
accountKeys, err := self.AccountDb.GetKeysForPrefix(prefix)
if err != nil {
return err
}
*reply = accountKeys
return nil
}

View File

@@ -20,7 +20,6 @@ package v2
import (
"fmt"
"log"
"github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/engine"
@@ -38,12 +37,8 @@ type AttrLoadRatingProfile struct {
// 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 = ""
if len(attrs.TPid) == 0 {
return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
}
tpRpf := &utils.TPRatingProfile{TPid: attrs.TPid}
tpRpf.SetRatingProfilesId(attrs.RatingProfileId)
@@ -71,15 +66,10 @@ type AttrLoadAccountActions struct {
// 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)
if len(attrs.TPid) == 0 {
return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
}
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)
@@ -111,12 +101,8 @@ type AttrLoadDerivedChargers struct {
// 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 = ""
if len(attrs.TPid) == 0 {
return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
}
tpDc := &utils.TPDerivedChargers{TPid: attrs.TPid}
tpDc.SetDerivedChargersId(attrs.DerivedChargersId)
@@ -127,7 +113,11 @@ func (self *ApierV2) LoadDerivedChargers(attrs AttrLoadDerivedChargers, reply *s
}
//Automatic cache of the newly inserted rating plan
didNotChange := []string{}
if err := self.AccountDb.CacheAccounting(didNotChange, didNotChange, didNotChange, nil); err != nil {
var dcsChanged []string
if len(attrs.DerivedChargersId) != 0 {
dcsChanged = []string{engine.DERIVEDCHARGERS_PREFIX + attrs.DerivedChargersId}
}
if err := self.AccountDb.CacheAccounting(didNotChange, didNotChange, didNotChange, dcsChanged); err != nil {
return err
}
*reply = v1.OK

View File

@@ -25,8 +25,8 @@ binary-arch: clean
cd $(SRCDIR) && go install
mkdir -p $(PKGDIR)/usr/bin
cp $(GOPATH)/bin/cgr-* $(PKGDIR)/usr/bin/
mkdir -p $(PKGDIR)/etc/cgrates
cp -r $(SRCDIR)/data/conf/cgrates $(PKGDIR)/etc/cgrates
mkdir -p $(PKGDIR)/etc/
cp -r $(SRCDIR)/data/conf/cgrates $(PKGDIR)/etc/
mkdir -p $(PKGDIR)/usr/share/cgrates
cp -r $(SRCDIR)/data/* $(PKGDIR)/usr/share/cgrates/
mkdir -p $(PKGDIR)/var/log/cgrates/cdrc/in

View File

@@ -160,7 +160,6 @@ const (
CREATE_CDRS_TABLES_SQL = "create_cdrs_tables.sql"
CREATE_TARIFFPLAN_TABLES_SQL = "create_tariffplan_tables.sql"
TEST_SQL = "TEST_SQL"
EMPTY = "_empty_"
CONSTANT = "constant"
FILLER = "filler"
METATAG = "metatag"