Added Tenant field to TPstats

This commit is contained in:
edwardro22
2017-09-12 08:45:53 +00:00
parent df31455316
commit 40cd82dc26
15 changed files with 125 additions and 48 deletions

View File

@@ -36,6 +36,7 @@ func (self *ApierV1) SetTPStat(attr utils.TPStats, reply *string) error {
type AttrGetTPStat struct {
TPid string // Tariff plan id
Tenant string
ID string
}
@@ -57,6 +58,7 @@ func (self *ApierV1) GetTPStat(attr AttrGetTPStat, reply *utils.TPStats) error {
type AttrGetTPStatIds struct {
TPid string // Tariff plan id
Tenant string
utils.Paginator
}

View File

@@ -126,6 +126,7 @@ func testTPStatsGetTPStatBeforeSet(t *testing.T) {
func testTPStatsSetTPStat(t *testing.T) {
tpStat = &utils.TPStats{
Tenant: "Tester",
TPid: "TPS1",
ID: "Stat1",
Filters: []*utils.TPRequestFilter{

View File

@@ -6,19 +6,20 @@
# ^ the script will "move" the collections if source and target server are the same
# but will "copy" (dump/restore) if source and target servers are different
from_host = '127.0.0.1'
from_port = '27017'
from_db = '11'
from_auth_db = 'cgrates' # Auth db on source server
from_user = 'cgrates'
from_pass = ''
to_host = '127.0.0.1'
to_port = '27017'
to_db = '10'
to_auth_db = "cgrates" # Auth db on target server
to_user = 'cgrates'
to_pass = ''
from_host =os.environ["from_host"]
from_port =os.environ["from_port"]
from_auth_db =os.environ["from_auth_db"]
from_user =os.environ["from_user"]
from_pass =os.environ["from_pass"]
to_host =os.environ["to_host"]
to_port =os.environ["to_port"]
to_auth_db =os.environ["to_auth_db"]
to_user =os.environ["to_user"]
to_pass =os.environ["to_pass"]
ignore_empty_cols = True
# Do not migrate collections with 0 document count.

View File

@@ -23,6 +23,19 @@ timeout = 2000
import time
import redis
import os
from_host =os.environ["from_host"]
from_port =os.environ["from_port"]
from_db =os.environ["from_db"]
from_pass =os.environ["from_pass"]
to_host =os.environ["to_host"]
to_port =os.environ["to_port"]
to_db =os.environ["to_db"]
to_pass =os.environ["to_pass"]
from_redis = redis.Redis(host = from_host, port = from_port, password=from_pass, db = from_db)
to_redis = redis.Redis(host = to_host, port = to_port, db = to_db)

View File

@@ -1,28 +1,80 @@
#! /usr/bin/env sh
if test $# -lt 2; then
echo ""
echo "setup_cgr_db.sh <datadb_name> <stordb_name> <User> <host>"
echo ""
exit 0
#settings
echo ""
echo "rc7_to_rc8.sh"
echo ""
$datadb="redis"
if [$datadb="redis"];then
#Redis Config
export from_host = '192.168.100.40'
export from_port = 6379
export from_db = 11
export from_pass = ''
export to_host = '192.168.100.40'
export to_port = 6379
export to_db = 10
export to_pass = '' # Not used
else if [$datadb="mongo"];then
#Mongo Config
export from_host = '127.0.0.1'
export from_port = '27017'
export from_db = '11'
export from_auth_db = 'cgrates' # Auth db on source server
export from_user = 'cgrates'
export from_pass = ''
export to_host = '127.0.0.1'
export to_port = '27017'
export to_db = '10'
export to_auth_db = "cgrates" # Auth db on target server
export to_user = 'cgrates'
export to_pass = ''
fi
user=$3
if [ -z "$3" ]; then
user="cgrates"
if [$stordb="redis"];then
#Redis Config
export from_host = '192.168.100.40'
export from_port = 6379
export from_db = 11
export from_pass = ''
export to_host = '192.168.100.40'
export to_port = 6379
export to_db = 10
export to_pass = '' # Not used
else if [$stordb="mysql"];then
#Mongo Config
export from_host = '127.0.0.1'
export from_port = '27017'
export from_db = '11'
export from_auth_db = 'cgrates' # Auth db on source server
export from_user = 'cgrates'
export from_pass = ''
export to_host = '127.0.0.1'
export to_port = '27017'
export to_db = '10'
export to_auth_db = "cgrates" # Auth db on target server
export to_user = 'cgrates'
export to_pass = ''
fi
host=$4
if [ -z "$4" ]; then
host="localhost"
fi
export PGPASSWORD="CGRateS.org"
DIR="$(dirname "$(readlink -f "$0")")"
case $1 in
case $datadb in
"redis")
./dbsmerge_redis.py
;;
@@ -31,20 +83,18 @@ case $1 in
;;
esac
case $2 in
case $stordb in
"mysql")
mysql -u$user -p$PGPASSWORD -h $host < "$DIR"/mysql_tables_update.sql
up=$?
mysql -u$user -p$PGPASSWORD -h $host -D cgrates < "$DIR"/mysql_cdr_migration.sql
mig=$?
#./usage_mysql.py What's the point of those changes?
;;
"postgres")
psql -U $user -h $host -d cgrates -f "$DIR"/pq_tables_update.sql
up=$?
psql -U $user -h $host -d cgrates -f "$DIR"/pg_cdr_migration.sql
mig=$?
#./usage_postgres.py What's the point of those changes?
;;
esac

View File

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

View File

@@ -419,6 +419,7 @@ CREATE INDEX tp_resources_unique ON tp_resources ("tpid", "tag", "filter_type",
DROP TABLE IF EXISTS tp_stats;
CREATE TABLE tp_stats (
"tenant"varchar(64) NOT NULL,
"id" SERIAL PRIMARY KEY,
"tpid" varchar(64) NOT NULL,
"tag" varchar(64) NOT NULL,

View File

@@ -1,2 +1,2 @@
#Id[0],FilterType[1],FilterFieldName[2],FilterFieldValues[3],ActivationInterval[4],QueueLength[5],TTL[6],Metrics[7],Blocker[8],Stored[9],Weight[10],Thresholds[11]
Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,true,20,THRESH1;THRESH2
#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]
Tester,Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,true,20,THRESH1;THRESH2
1 #Id[0] #Tenant[0] FilterType[1] Id[1] FilterFieldName[2] FilterType[2] FilterFieldValues[3] FilterFieldName[3] ActivationInterval[4] FilterFieldValues[4] QueueLength[5] ActivationInterval[5] TTL[6] QueueLength[6] Metrics[7] TTL[7] Blocker[8] Metrics[8] Stored[9] Blocker[9] Weight[10] Stored[10] Thresholds[11] Weight[11] Thresholds[12]
2 Stats1 Tester *string Stats1 Account *string 1001;1002 Account 2014-07-29T15:00:00Z 1001;1002 100 2014-07-29T15:00:00Z 1s 100 *asr;*acd;*acc 1s true *asr;*acd;*acc true true 20 true THRESH1;THRESH2 20 THRESH1;THRESH2

View File

@@ -1,2 +1,2 @@
#Id[0],FilterType[1],FilterFieldName[2],FilterFieldValues[3],ActivationInterval[4],QueueLength[5],TTL[6],Metrics[7],Blocker[8],Stored[9],Weight[10],Thresholds[11]
Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,true,20,THRESH1;THRESH2
#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]
Tester,Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,true,20,THRESH1;THRESH2
1 #Id[0] #Tenant[0] FilterType[1] Id[1] FilterFieldName[2] FilterType[2] FilterFieldValues[3] FilterFieldName[3] ActivationInterval[4] FilterFieldValues[4] QueueLength[5] ActivationInterval[5] TTL[6] QueueLength[6] Metrics[7] TTL[7] Blocker[8] Metrics[8] Stored[9] Blocker[9] Weight[10] Stored[10] Thresholds[11] Weight[11] Thresholds[12]
2 Stats1 Tester *string Stats1 Account *string 1001;1002 Account 2014-07-29T15:00:00Z 1001;1002 100 2014-07-29T15:00:00Z 1s 100 *asr;*acd;*acc 1s true *asr;*acd;*acc true true 20 true THRESH1;THRESH2 20 THRESH1;THRESH2

View File

@@ -273,12 +273,13 @@ 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,
`
stats = `
#Id[0],FilterType[1],FilterFieldName[2],FilterFieldValues[3],ActivationInterval[4],QueueLength[5],TTL[6],Metrics[7],Blocker[8],Stored[9],Weight[10],Thresholds[11]
Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,true,20,THRESH1;THRESH2
#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]
Tester,Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,true,20,THRESH1;THRESH2
`
thresholds = `
#Id[0],FilterType[1],FilterFieldName[2],FilterFieldValues[3],ActivationInterval[4],ThresholdType[5],ThresholdValue[6],MinItems[7],Recurrent[8],MinSleep[9],Blocker[10],Stored[11],Weight[12],ActionIDs[13]
Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,,1.2,10,true,1s,true,true,10,
`
)
@@ -1435,6 +1436,7 @@ func TestLoadResourceProfiles(t *testing.T) {
func TestLoadStats(t *testing.T) {
eStats := map[string]*utils.TPStats{
"Stats1": &utils.TPStats{
Tenant:"Tester",
TPid: testTPID,
ID: "Stats1",
Filters: []*utils.TPRequestFilter{

View File

@@ -1960,6 +1960,7 @@ func (tps TpStatsS) AsTPStats() (result []*utils.TPStats) {
st, found := mst[tp.Tag]
if !found {
st = &utils.TPStats{
Tenant: tp.Tenant,
TPid: tp.Tpid,
ID: tp.Tag,
Blocker: tp.Blocker,
@@ -2027,6 +2028,7 @@ func APItoModelStats(st *utils.TPStats) (mdls TpStatsS) {
}
for i, fltr := range st.Filters {
mdl := &TpStats{
Tenant: st.Tenant,
Tpid: st.TPid,
Tag: st.ID,
}
@@ -2072,6 +2074,7 @@ func APItoModelStats(st *utils.TPStats) (mdls TpStatsS) {
func APItoStats(tpST *utils.TPStats, timezone string) (st *StatQueueProfile, err error) {
st = &StatQueueProfile{
Tenant: tpST.Tenant,
ID: tpST.ID,
QueueLength: tpST.QueueLength,
Weight: tpST.Weight,

View File

@@ -482,18 +482,19 @@ func (t TBLVersion) TableName() string {
type TpStats 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:""`
QueueLength int `index:"5" re:""`
TTL string `index:"6" re:""`
Metrics 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:""`
QueueLength int `index:"6" re:""`
TTL string `index:"7" re:""`
Metrics 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

@@ -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, Tag: stq.ID}).Delete(TpStats{}).Error; err != nil {
if err := tx.Where(&TpStats{Tpid: stq.TPid,Tenant: stq.Tenant,Tag: stq.ID}).Delete(TpStats{}).Error; err != nil {
tx.Rollback()
return err
}

View File

@@ -1541,6 +1541,7 @@ func testStorDBitCRUDTpStats(t *testing.T) {
eTPs := []*utils.TPStats{
&utils.TPStats{
TPid: "TEST_TPID",
Tenant:"Test",
ID: "Stats1",
Filters: []*utils.TPRequestFilter{
&utils.TPRequestFilter{

View File

@@ -1335,6 +1335,7 @@ type AttrDisconnectSession struct {
// TPStats is used in APIs to manage remotely offline Stats config
type TPStats struct {
TPid string
Tenant string
ID string
Filters []*TPRequestFilter
ActivationInterval *TPActivationInterval