Added Tenant to resources

This commit is contained in:
edwardro22
2017-09-13 09:08:09 +00:00
parent c5a1464d6b
commit d01f8b58dc
12 changed files with 52 additions and 34 deletions

View File

@@ -66,11 +66,15 @@ DIR="$(dirname "$(readlink -f "$0")")"
case $datadb in
"redis")
./dbsmerge_redis.py
echo "executing dbsmerge_redis.py"
./dbsmerge_redis.py
echo "done!"
;;
"mongo")
echo "executing dbsmerge_mongo.py"
./dbsmerge_mongo.py
echo "done!"
;;
esac

View File

@@ -397,6 +397,7 @@ CREATE TABLE tp_aliases (
DROP TABLE IF EXISTS tp_resources;
CREATE TABLE tp_resources (
`tenant` varchar(64) NOT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tag` varchar(64) NOT NULL,

View File

@@ -393,6 +393,7 @@ CREATE INDEX tpaliases_idx ON tp_aliases (tpid,direction,tenant,category,account
DROP TABLE IF EXISTS tp_resources;
CREATE TABLE tp_resources (
"tenant"varchar(64) NOT NULL,
"id" SERIAL PRIMARY KEY,
"tpid" varchar(64) NOT NULL,
"tag" varchar(64) NOT NULL,

View File

@@ -1,6 +1,6 @@
#Id[0],FilterType[1],FilterFieldName[2],FilterFieldValues[3],ActivationInterval[4],TTL[5],Limit[6],AllocationMessage[7],Blocker[8],Stored[9],Weight[10],Thresholds[11]
ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,true,true,20,
ResGroup1,*string_prefix,Destination,10;20,,,,,,,,
ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,,,,
ResGroup2,*destinations,Destination,DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1002,true,true,10,
ResGroup3,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,,,,,,,,
#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],TTL[6],Limit[7],AllocationMessage[8],Blocker[9],Stored[10],Weight[11],Thresholds[12]
Tester,ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,true,true,20,
Tester,ResGroup1,*string_prefix,Destination,10;20,,,,,,,,
Tester,ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,,,,
Tester,ResGroup2,*destinations,Destination,DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1002,true,true,10,
Tester,ResGroup3,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,,,,,,,,
1 #Id[0] #Tenant[0] FilterType[1] Id[1] FilterFieldName[2] FilterType[2] FilterFieldValues[3] FilterFieldName[3] ActivationInterval[4] FilterFieldValues[4] TTL[5] ActivationInterval[5] Limit[6] TTL[6] AllocationMessage[7] Limit[7] Blocker[8] AllocationMessage[8] Stored[9] Blocker[9] Weight[10] Stored[10] Thresholds[11] Weight[11] Thresholds[12]
2 ResGroup1 Tester *string ResGroup1 Account *string 1001;1002 Account 2014-07-29T15:00:00Z 1001;1002 1s 2014-07-29T15:00:00Z 7 1s 7 true true true 20 true 20
3 ResGroup1 Tester *string_prefix ResGroup1 Destination *string_prefix 10;20 Destination 10;20
4 ResGroup1 Tester *rsr_fields ResGroup1 *rsr_fields Subject(~^1.*1$);Destination(1002) Subject(~^1.*1$);Destination(1002)
5 ResGroup2 Tester *destinations ResGroup2 Destination *destinations DST_FS Destination 2014-07-29T15:00:00Z DST_FS 3600s 2014-07-29T15:00:00Z 8 3600s SPECIAL_1002 8 true SPECIAL_1002 true true 10 true 10
6 ResGroup3 Tester *cdr_stats ResGroup3 *cdr_stats CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20 CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20

View File

@@ -1,8 +1,8 @@
#Id[0],FilterType[1],FilterFieldName[2],FilterFieldValues[3],ActivationInterval[4],TTL[5],Limit[6],AllocationMessage[7],Blocker[8],Stored[9],Weight[10],Thresholds[11]
ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,true,true,20,
ResGroup1,*string_prefix,Destination,10;20,,,,,,,,
ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,,,,
ResGroup2,*destinations,Destination,DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1002,true,true,10,
ResGroup3,*string,Account,3001,2014-07-29T15:00:00Z,1s,3,,true,true,20,
#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],TTL[6],Limit[7],AllocationMessage[8],Blocker[9],Stored[10],Weight[11],Thresholds[12]
Tester,ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,true,true,20,
Tester,ResGroup1,*string_prefix,Destination,10;20,,,,,,,,
Tester,ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,,,,
Tester,ResGroup2,*destinations,Destination,DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1002,true,true,10,
Tester,ResGroup3,*string,Account,3001,2014-07-29T15:00:00Z,1s,3,,true,true,20,
#ResGroup3,*timings,SetupTime,PEAK,,,,,,,,
#ResGroup3,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,,,,,,,,
1 #Id[0] #Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],TTL[6],Limit[7],AllocationMessage[8],Blocker[9],Stored[10],Weight[11],Thresholds[12] FilterType[1] FilterFieldName[2] FilterFieldValues[3] ActivationInterval[4] TTL[5] Limit[6] AllocationMessage[7] Blocker[8] Stored[9] Weight[10] Thresholds[11]
2 ResGroup1 Tester,ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,true,true,20, *string Account 1001;1002 2014-07-29T15:00:00Z 1s 7 true true 20
3 ResGroup1 Tester,ResGroup1,*string_prefix,Destination,10;20,,,,,,,, *string_prefix Destination 10;20
4 ResGroup1 Tester,ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,,,, *rsr_fields Subject(~^1.*1$);Destination(1002)
5 ResGroup2 Tester,ResGroup2,*destinations,Destination,DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1002,true,true,10, *destinations Destination DST_FS 2014-07-29T15:00:00Z 3600s 8 SPECIAL_1002 true true 10
6 ResGroup3 Tester,ResGroup3,*string,Account,3001,2014-07-29T15:00:00Z,1s,3,,true,true,20, *string Account 3001 2014-07-29T15:00:00Z 1s 3 true true 20
7 #ResGroup3 #ResGroup3,*timings,SetupTime,PEAK,,,,,,,, *timings SetupTime PEAK
8 #ResGroup3 #ResGroup3,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,,,,,,,, *cdr_stats CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20

View File

@@ -266,11 +266,11 @@ cgrates.org,mas,true,another,value,10
*out,cgrates.org,call,remo,remo,*any,*rating,Account,remo,minu,10
`
resProfiles = `
#Id[0],FilterType[1],FilterFieldName[2],FilterFieldValues[3],ActivationInterval[4],TTL[5],Limit[6],AllocationMessage[7],Weight[8],Thresholds[9]
ResGroup21,*string,HdrAccount,1001;1002,2014-07-29T15:00:00Z,1s,2,call,true,true,10,
ResGroup21,*string_prefix,HdrDestination,10;20,,,,,,,,
ResGroup21,*rsr_fields,,HdrSubject(~^1.*1$);HdrDestination(1002),,,,,,,,
ResGroup22,*destinations,HdrDestination,DST_FS,2014-07-29T15:00:00Z,3600s,2,premium_call,true,true,10,
#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],TTL[6],Limit[7],AllocationMessage[8],Blocker[9],Stored[10],Weight[11],Thresholds[12]
Tester,ResGroup21,*string,HdrAccount,1001;1002,2014-07-29T15:00:00Z,1s,2,call,true,true,10,
Tester,ResGroup21,*string_prefix,HdrDestination,10;20,,,,,,,,
Tester,ResGroup21,*rsr_fields,,HdrSubject(~^1.*1$);HdrDestination(1002),,,,,,,,
Tester,ResGroup22,*destinations,HdrDestination,DST_FS,2014-07-29T15:00:00Z,3600s,2,premium_call,true,true,10,
`
stats = `
#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],QueueLength[6],TTL[7],Metrics[8],Blocker[9],Stored[10],Weight[11],Thresholds[12]
@@ -1393,6 +1393,7 @@ func TestLoadResourceProfiles(t *testing.T) {
eResProfiles := map[string]*utils.TPResource{
"ResGroup21": &utils.TPResource{
TPid: testTPID,
Tenant:"Tester",
ID: "ResGroup21",
Filters: []*utils.TPRequestFilter{
&utils.TPRequestFilter{Type: MetaString, FieldName: "HdrAccount", Values: []string{"1001", "1002"}},
@@ -1409,6 +1410,7 @@ func TestLoadResourceProfiles(t *testing.T) {
},
"ResGroup22": &utils.TPResource{
TPid: testTPID,
Tenant:"Tester",
ID: "ResGroup22",
Filters: []*utils.TPRequestFilter{
&utils.TPRequestFilter{Type: MetaDestinations, FieldName: "HdrDestination", Values: []string{"DST_FS"}},

View File

@@ -1821,6 +1821,7 @@ func (tps TpResources) AsTPResources() (result []*utils.TPResource) {
if !found {
rl = &utils.TPResource{
TPid: tp.Tpid,
Tenant: tp.Tenant,
ID: tp.Tag,
Blocker: tp.Blocker,
Stored: tp.Stored,
@@ -1880,6 +1881,7 @@ func APItoModelResource(rl *utils.TPResource) (mdls TpResources) {
for i, fltr := range rl.Filters {
mdl := &TpResource{
Tpid: rl.TPid,
Tenant: rl.Tenant,
Tag: rl.ID,
}
if i == 0 {
@@ -1921,6 +1923,7 @@ func APItoModelResource(rl *utils.TPResource) (mdls TpResources) {
func APItoResource(tpRL *utils.TPResource, timezone string) (rp *ResourceProfile, err error) {
rp = &ResourceProfile{
Tenant: tpRL.Tenant,
ID: tpRL.ID,
Weight: tpRL.Weight,
Blocker: tpRL.Blocker,

View File

@@ -713,6 +713,7 @@ func TestTpResourcesAsTpResources(t *testing.T) {
tps := []*TpResource{
&TpResource{
Tpid: "TEST_TPID",
Tenant: "Tester",
Tag: "ResGroup1",
FilterType: MetaStringPrefix,
FilterFieldName: "Destination",
@@ -726,12 +727,14 @@ func TestTpResourcesAsTpResources(t *testing.T) {
&TpResource{
Tpid: "TEST_TPID",
Tag: "ResGroup1",
Tenant: "Tester",
FilterType: MetaStringPrefix,
FilterFieldName: "Category",
FilterFieldValues: "call;inbound_call",
Thresholds: "WARN3"},
&TpResource{
Tpid: "TEST_TPID",
Tenant: "Tester",
Tag: "ResGroup2",
FilterType: MetaStringPrefix,
FilterFieldName: "Destination",
@@ -745,6 +748,7 @@ func TestTpResourcesAsTpResources(t *testing.T) {
eTPs := []*utils.TPResource{
&utils.TPResource{
TPid: tps[0].Tpid,
Tenant: tps[0].Tenant,
ID: tps[0].Tag,
Filters: []*utils.TPRequestFilter{
&utils.TPRequestFilter{
@@ -769,6 +773,7 @@ func TestTpResourcesAsTpResources(t *testing.T) {
},
&utils.TPResource{
TPid: tps[2].Tpid,
Tenant: tps[2].Tenant,
ID: tps[2].Tag,
Filters: []*utils.TPRequestFilter{
&utils.TPRequestFilter{

View File

@@ -454,18 +454,19 @@ func (t TBLSMCosts) TableName() string {
type TpResource struct {
ID int64
Tpid string
Tag string `index:"0" re:""`
FilterType string `index:"1" re:"^\*[A-Za-z].*"`
FilterFieldName string `index:"2" re:""`
FilterFieldValues string `index:"3" re:""`
ActivationInterval string `index:"4" re:""`
UsageTTL string `index:"5" re:""`
Limit string `index:"6" re:""`
AllocationMessage string `index:"7" re:""`
Blocker bool `index:"8" re:""`
Stored bool `index:"9" re:""`
Weight float64 `index:"10" re:"\d+\.?\d*"`
Thresholds string `index:"11" re:""`
Tenant string `index:"0" re:""`
Tag string `index:"1" re:""`
FilterType string `index:"2" re:"^\*[A-Za-z].*"`
FilterFieldName string `index:"3" re:""`
FilterFieldValues string `index:"4" re:""`
ActivationInterval string `index:"5" re:""`
UsageTTL string `index:"6" re:""`
Limit string `index:"7" re:""`
AllocationMessage string `index:"8" re:""`
Blocker bool `index:"9" re:""`
Stored bool `index:"10" re:""`
Weight float64 `index:"11" re:"\d+\.?\d*"`
Thresholds string `index:"12" re:""`
CreatedAt time.Time
}

View File

@@ -39,6 +39,7 @@ func init() {
// ResourceProfile represents the user configuration for the resource
type ResourceProfile struct {
Tenant string
ID string // identifier of this resource
Filters []*RequestFilter // filters for the request
ActivationInterval *utils.ActivationInterval // time when this resource becomes active and expires
@@ -53,6 +54,7 @@ type ResourceProfile struct {
// ResourceUsage represents an usage counted
type ResourceUsage struct {
Tenant string
ID string // Unique identifier of this ResourceUsage, Eg: FreeSWITCH UUID
ExpiryTime time.Time
Units float64 // Number of units used
@@ -66,6 +68,7 @@ func (ru *ResourceUsage) isActive(atTime time.Time) bool {
// Resource represents a resource in the system
// not thread safe, needs locking at process level
type Resource struct {
Tenant string
ID string
Usages map[string]*ResourceUsage
TTLIdx []string // holds ordered list of ResourceIDs based on their TTL, empty if feature is disabled

View File

@@ -588,7 +588,7 @@ func (self *SQLStorage) SetTPStats(sts []*utils.TPStats) error {
tx := self.db.Begin()
for _, stq := range sts {
// Remove previous
if err := tx.Where(&TpStats{Tpid: stq.TPid,Tenant: stq.Tenant,Tag: stq.ID}).Delete(TpStats{}).Error; err != nil {
if err := tx.Where(&TpStats{Tpid: stq.TPid,Tag: stq.ID}).Delete(TpStats{}).Error; err != nil {
tx.Rollback()
return err
}
@@ -1171,8 +1171,6 @@ func (self *SQLStorage) GetTPDestinationRates(tpid, id string, pagination *utils
func (self *SQLStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, error) {
var tpTimings TpTimings
q := self.db.Where("tpid = ?", tpid)
utils.Logger.Debug(fmt.Sprintf("#1 Id care trimite %s", id))
utils.Logger.Debug(fmt.Sprintf("#1 TPId care trimite %s", tpid))
if len(id) != 0 {
q = q.Where("tag = ?", id)
}
@@ -1180,7 +1178,6 @@ func (self *SQLStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, e
return nil, err
}
ts := tpTimings.AsTPTimings()
utils.Logger.Debug(fmt.Sprintf("#2 ce gaseste : %s", ts))
if len(ts) == 0 {
return ts, utils.ErrNotFound
}

View File

@@ -1270,6 +1270,7 @@ type AttrSetBalance struct {
type TPResource struct {
TPid string
Tenant string
ID string // Identifier of this limit
Filters []*TPRequestFilter // Filters for the request
ActivationInterval *TPActivationInterval // Time when this limit becomes active/expires