StorDB fixes and additions

This commit is contained in:
alin104n
2017-02-27 00:49:11 +02:00
parent 04c7fb8a84
commit 22c47cf61b
18 changed files with 1078 additions and 531 deletions

View File

@@ -50,7 +50,7 @@ CREATE TABLE sm_costs (
created_at TIMESTAMP NULL,
deleted_at TIMESTAMP NULL,
PRIMARY KEY (`id`),
UNIQUE KEY costid (cgrid,run_id),
UNIQUE KEY costid (cgrid, run_id),
KEY origin_idx (origin_host, origin_id),
KEY deleted_at_idx (deleted_at)
);

View File

@@ -402,7 +402,7 @@ CREATE TABLE tp_resource_limits (
`activation_time` varchar(24) NOT NULL,
`weight` decimal(8,2) NOT NULL,
`limit` varchar(64) NOT NULL,
`action_triggers` varchar(64) NOT NULL,
`action_trigger_ids` varchar(64) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`id`),
KEY `tpid` (`tpid`),

View File

@@ -18,21 +18,21 @@ CREATE TABLE cdrs (
account VARCHAR(128) NOT NULL,
subject VARCHAR(128) NOT NULL,
destination VARCHAR(128) NOT NULL,
setup_time TIMESTAMP NOT NULL,
setup_time TIMESTAMP WITH TIME ZONE NOT NULL,
pdd NUMERIC(12,9) NOT NULL,
answer_time TIMESTAMP NOT NULL,
answer_time TIMESTAMP WITH TIME ZONE NOT NULL,
usage NUMERIC(30,9) NOT NULL,
supplier VARCHAR(128) NOT NULL,
disconnect_cause VARCHAR(64) NOT NULL,
extra_fields jsonb,
extra_fields jsonb NOT NULL,
cost_source VARCHAR(64) NOT NULL,
cost NUMERIC(20,4) DEFAULT NULL,
cost_details jsonb,
account_summary jsonb,
extra_info text,
created_at TIMESTAMP,
updated_at TIMESTAMP NULL,
deleted_at TIMESTAMP NULL,
created_at TIMESTAMP WITH TIME ZONE,
updated_at TIMESTAMP WITH TIME ZONE NULL,
deleted_at TIMESTAMP WITH TIME ZONE NULL,
UNIQUE (cgrid, run_id, origin_id)
);
;
@@ -50,8 +50,8 @@ CREATE TABLE sm_costs (
cost_source VARCHAR(64) NOT NULL,
usage NUMERIC(30,9) NOT NULL,
cost_details jsonb,
created_at TIMESTAMP,
deleted_at TIMESTAMP NULL,
created_at TIMESTAMP WITH TIME ZONE,
deleted_at TIMESTAMP WITH TIME ZONE NULL,
UNIQUE (cgrid, run_id)
);
DROP INDEX IF EXISTS cgrid_smcost_idx;

View File

@@ -11,7 +11,7 @@ CREATE TABLE tp_timings (
month_days VARCHAR(255) NOT NULL,
week_days VARCHAR(255) NOT NULL,
time VARCHAR(32) NOT NULL,
created_at TIMESTAMP,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag)
);
CREATE INDEX tptimings_tpid_idx ON tp_timings (tpid);
@@ -27,7 +27,7 @@ CREATE TABLE tp_destinations (
tpid VARCHAR(64) NOT NULL,
tag VARCHAR(64) NOT NULL,
prefix VARCHAR(24) NOT NULL,
created_at TIMESTAMP,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag, prefix)
);
CREATE INDEX tpdests_tpid_idx ON tp_destinations (tpid);
@@ -47,7 +47,7 @@ CREATE TABLE tp_rates (
rate_unit VARCHAR(16) NOT NULL,
rate_increment VARCHAR(16) NOT NULL,
group_interval_start VARCHAR(16) NOT NULL,
created_at TIMESTAMP,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag, group_interval_start)
);
CREATE INDEX tprates_tpid_idx ON tp_rates (tpid);
@@ -68,7 +68,7 @@ CREATE TABLE tp_destination_rates (
rounding_decimals SMALLINT NOT NULL,
max_cost NUMERIC(7,4) NOT NULL,
max_cost_strategy VARCHAR(16) NOT NULL,
created_at TIMESTAMP,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag , destinations_tag)
);
CREATE INDEX tpdestrates_tpid_idx ON tp_destination_rates (tpid);
@@ -86,7 +86,7 @@ CREATE TABLE tp_rating_plans (
destrates_tag VARCHAR(64) NOT NULL,
timing_tag VARCHAR(64) NOT NULL,
weight NUMERIC(8,2) NOT NULL,
created_at TIMESTAMP,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag, destrates_tag, timing_tag)
);
CREATE INDEX tpratingplans_tpid_idx ON tp_rating_plans (tpid);
@@ -110,7 +110,7 @@ CREATE TABLE tp_rating_profiles (
rating_plan_tag VARCHAR(64) NOT NULL,
fallback_subjects VARCHAR(64),
cdr_stat_queue_ids VARCHAR(64),
created_at TIMESTAMP,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, loadid, tenant, category, direction, subject, activation_time)
);
CREATE INDEX tpratingprofiles_tpid_idx ON tp_rating_profiles (tpid);
@@ -128,7 +128,7 @@ CREATE TABLE tp_shared_groups (
account VARCHAR(64) NOT NULL,
strategy VARCHAR(24) NOT NULL,
rating_subject VARCHAR(24) NOT NULL,
created_at TIMESTAMP,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag, account , strategy , rating_subject)
);
CREATE INDEX tpsharedgroups_tpid_idx ON tp_shared_groups (tpid);
@@ -160,7 +160,7 @@ CREATE TABLE tp_actions (
extra_parameters VARCHAR(256) NOT NULL,
filter VARCHAR(256) NOT NULL,
weight NUMERIC(8,2) NOT NULL,
created_at TIMESTAMP,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag, action, balance_tag, balance_type, directions, expiry_time, timing_tags, destination_tags, shared_groups, balance_weight, weight)
);
CREATE INDEX tpactions_tpid_idx ON tp_actions (tpid);
@@ -178,7 +178,7 @@ CREATE TABLE tp_action_plans (
actions_tag VARCHAR(64) NOT NULL,
timing_tag VARCHAR(64) NOT NULL,
weight NUMERIC(8,2) NOT NULL,
created_at TIMESTAMP,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag, actions_tag)
);
CREATE INDEX tpactionplans_tpid_idx ON tp_action_plans (tpid);
@@ -215,7 +215,7 @@ CREATE TABLE tp_action_triggers (
min_queued_items INTEGER NOT NULL,
actions_tag VARCHAR(64) NOT NULL,
weight NUMERIC(8,2) NOT NULL,
created_at TIMESTAMP,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag, balance_tag, balance_type, balance_directions, threshold_type, threshold_value, balance_destination_tags, actions_tag)
);
CREATE INDEX tpactiontrigers_tpid_idx ON tp_action_triggers (tpid);
@@ -236,7 +236,7 @@ CREATE TABLE tp_account_actions (
action_triggers_tag VARCHAR(64),
allow_negative BOOLEAN NOT NULL,
disabled BOOLEAN NOT NULL,
created_at TIMESTAMP,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, loadid, tenant, account)
);
CREATE INDEX tpaccountactions_tpid_idx ON tp_account_actions (tpid);
@@ -261,7 +261,7 @@ CREATE TABLE tp_lcr_rules (
strategy_params VARCHAR(256) NOT NULL,
activation_time VARCHAR(24) NOT NULL,
weight NUMERIC(8,2) NOT NULL,
created_at TIMESTAMP
created_at TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tplcr_tpid_idx ON tp_lcr_rules (tpid);
CREATE INDEX tplcr_idx ON tp_lcr_rules (tpid,tenant,category,direction,account,subject,destination_tag);
@@ -298,7 +298,7 @@ CREATE TABLE tp_derived_chargers (
disconnect_cause_field VARCHAR(64) NOT NULL,
rated_field VARCHAR(64) NOT NULL,
cost_field VARCHAR(64) NOT NULL,
created_at TIMESTAMP
created_at TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tpderivedchargers_tpid_idx ON tp_derived_chargers (tpid);
CREATE INDEX tpderivedchargers_idx ON tp_derived_chargers (tpid,loadid,direction,tenant,category,account,subject);
@@ -337,7 +337,7 @@ CREATE TABLE tp_cdr_stats (
rated_subjects VARCHAR(64) NOT NULL,
cost_interval VARCHAR(24) NOT NULL,
action_triggers VARCHAR(64) NOT NULL,
created_at TIMESTAMP
created_at TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tpcdrstats_tpid_idx ON tp_cdr_stats (tpid);
CREATE INDEX tpcdrstats_idx ON tp_cdr_stats (tpid,tag);
@@ -356,7 +356,7 @@ CREATE TABLE tp_users (
attribute_name VARCHAR(64) NOT NULL,
attribute_value VARCHAR(64) NOT NULL,
weight NUMERIC(8,2) NOT NULL,
created_at TIMESTAMP
created_at TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tpusers_tpid_idx ON tp_users (tpid);
CREATE INDEX tpusers_idx ON tp_users (tpid,tenant,user_name);
@@ -381,7 +381,7 @@ CREATE TABLE tp_aliases (
"original" varchar(64) NOT NULL,
"alias" varchar(64) NOT NULL,
"weight" NUMERIC(8,2) NOT NULL,
"created_at" TIMESTAMP
"created_at" TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tpaliases_tpid_idx ON tp_aliases (tpid);
CREATE INDEX tpaliases_idx ON tp_aliases ("tpid","direction","tenant","category","account","subject","context","target");
@@ -397,9 +397,19 @@ CREATE TABLE tp_resource_limits (
"activation_time" varchar(24) NOT NULL,
"weight" decimal(8,2) NOT NULL,
"limit" varchar(64) NOT NULL,
"action_triggers" varchar(64) NOT NULL,
"created_at" TIMESTAMP
"action_trigger_ids" varchar(64) NOT NULL,
"created_at" TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tp_resource_limits_idx ON tp_resource_limits (tpid);
CREATE INDEX tp_resource_limits_unique ON tp_resource_limits ("tpid", "tag");
DROP TABLE IF EXISTS versions;
CREATE TABLE versions (
"id" SERIAL PRIMARY KEY,
"item" varchar(64) NOT NULL,
"version" INTEGER NOT NULL,
UNIQUE (item)
);

View File

@@ -1,4 +1,4 @@
#Id,FilterType,FilterFieldName,FilterValues,ActivationTime,Weight,Limit,ActionTriggers
#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationTime,Weight,Limit,ActionTriggers
ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,10,2,
ResGroup1,*string_prefix,Destination,10;20,2014-07-29T15:00:00Z,10,,
ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,
1 #Id FilterType FilterFieldName FilterValues FilterFieldValues ActivationTime Weight Limit ActionTriggers
2 ResGroup1 *string Account 1001;1002 1001;1002 2014-07-29T15:00:00Z 10 2
3 ResGroup1 *string_prefix Destination 10;20 10;20 2014-07-29T15:00:00Z 10
4 ResGroup1 *rsr_fields Subject(~^1.*1$);Destination(1002) Subject(~^1.*1$);Destination(1002)

View File

@@ -1,12 +1,12 @@
4.2. Tariff Plans
=================
Major concept within CGRateS architecture, implement mechanisms to load rating as well as account data into CGRateS.
For importing the data into CGRateS database(s) we are using **csv** *files*.
Major concept within CGRateS architecture, implement mechanisms to load rating as well as account data into CGRateS.
For importing the data into CGRateS database(s) we are using **csv** *files*.
The import process can be started as many times it is desired with one ore more csv files
and the existing values are overwritten.
.. important:: If **-flushdb** option is used when importing data with cgr-loader,
then the database **is cleaned** before importing.
.. important:: If **-flushdb** option is used when importing data with cgr-loader,
then the database **is cleaned** before importing.
For more details see the **cgr-loader** tool from the tutorial chapter.
@@ -52,7 +52,7 @@ Describes the time periods that have different rates attached to them.
[1] - Years:
Integers separated by semicolons (;) specifying the years for this time period.
**\*any** in case of always.
[2] - Months:
@@ -72,7 +72,7 @@ Describes the time periods that have different rates attached to them.
[5] - Time:
The start time for this time period.
If you set it to **\*asap** (was **\*now**) it will be replaced with the time of the data importing.
4.2.3. Rates
@@ -119,12 +119,12 @@ various timings.
4.2.4. Destination Rates
~~~~~~~~~~~~~~~~~~~~~~~
Attach rates to destinations.
Attach rates to destinations.
::
"DestinationRates.csv" - csv
"tp_destination_rates" - stor_db
"tp_destination_rates" - stor_db
.. csv-table::
:file: ../data/tariffplans/tutorial/DestinationRates.csv
@@ -340,7 +340,7 @@ trigger resetting.
TBD
[8] - BalanceTag:
Specifies the balance counter by which this action will be triggered.
Specifies the balance counter by which this action will be triggered.
Can be:
+ **MONETARY**
@@ -495,7 +495,7 @@ TBD
TBD
[8] - DestinationIds:
The destination id/tag described in the **Destinations** file. (*Destinations.csv* - Id)
The destination id/tag described in the **Destinations** file. (*Destinations.csv* - Id)
This field is used only if the BalanceId is MINUTES. Specifies the
destination of the minutes to be operated.
@@ -866,7 +866,7 @@ TBD
[2] - FilterFieldName
TBD
[3] - FilterValues
[3] - FilterFieldValues
TBD
[4] - ActivationTime

View File

@@ -268,7 +268,7 @@ cgrates.org,mas,true,another,value,10
`
resLimits = `
#Id,FilterType,FilterFieldName,FilterValues,ActivationTime,Weight,Limit,ActionTriggers
#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationTime,Weight,Limit,ActionTriggers
ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,10,2,
ResGroup1,*string_prefix,Destination,10;20,2014-07-29T15:00:00Z,10,,
ResGroup1,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,,,,

View File

@@ -867,7 +867,7 @@ func (tps TpResourceLimits) AsTPResourceLimits() map[string]*utils.TPResourceLim
resLimit.Filters = append(resLimit.Filters, &utils.TPRequestFilter{
Type: tp.FilterType,
FieldName: tp.FilterFieldName,
Values: strings.Split(tp.FilterValues, utils.INFIELD_SEP)})
Values: strings.Split(tp.FilterFieldValues, utils.INFIELD_SEP)})
}
if tp.ActionTriggerIds != "" {
resLimit.ActionTriggerIDs = append(resLimit.ActionTriggerIDs, strings.Split(tp.ActionTriggerIds, utils.INFIELD_SEP)...)

View File

@@ -670,31 +670,31 @@ func TestTPAccountActionsAsExportSlice(t *testing.T) {
func TestTpResourceLimitsAsTPResourceLimits(t *testing.T) {
tps := []*TpResourceLimit{
&TpResourceLimit{
Tpid: "TEST_TPID",
Tag: "ResGroup1",
FilterType: MetaStringPrefix,
FilterFieldName: "Destination",
FilterValues: "+49151;+49161",
ActivationTime: "2014-07-29T15:00:00Z",
Weight: 10.0,
Limit: "45",
ActionTriggerIds: "WARN_RES1;WARN_RES2"},
Tpid: "TEST_TPID",
Tag: "ResGroup1",
FilterType: MetaStringPrefix,
FilterFieldName: "Destination",
FilterFieldValues: "+49151;+49161",
ActivationTime: "2014-07-29T15:00:00Z",
Weight: 10.0,
Limit: "45",
ActionTriggerIds: "WARN_RES1;WARN_RES2"},
&TpResourceLimit{
Tpid: "TEST_TPID",
Tag: "ResGroup1",
FilterType: MetaStringPrefix,
FilterFieldName: "Category",
FilterValues: "call;inbound_call",
ActionTriggerIds: "WARN3"},
Tpid: "TEST_TPID",
Tag: "ResGroup1",
FilterType: MetaStringPrefix,
FilterFieldName: "Category",
FilterFieldValues: "call;inbound_call",
ActionTriggerIds: "WARN3"},
&TpResourceLimit{
Tpid: "TEST_TPID",
Tag: "ResGroup2",
FilterType: MetaStringPrefix,
FilterFieldName: "Destination",
FilterValues: "+40",
ActivationTime: "2014-07-29T15:00:00Z",
Weight: 10.0,
Limit: "20"},
Tpid: "TEST_TPID",
Tag: "ResGroup2",
FilterType: MetaStringPrefix,
FilterFieldName: "Destination",
FilterFieldValues: "+40",
ActivationTime: "2014-07-29T15:00:00Z",
Weight: 10.0,
Limit: "20"},
}
eTPs := map[string]*utils.TPResourceLimit{
tps[0].Tag: &utils.TPResourceLimit{

View File

@@ -451,17 +451,17 @@ func (t TBLSMCosts) TableName() string {
}
type TpResourceLimit struct {
ID int64
Tpid string
Tag string `index:"0" re:""`
FilterType string `index:"1" re:"^\*[A-Za-z].*"`
FilterFieldName string `index:"2" re:""`
FilterValues string `index:"3" re:""`
ActivationTime string `index:"4" re:""`
Weight float64 `index:"5" re:"\d+\.?\d*"`
Limit string `index:"6" re:""`
ActionTriggerIds string `index:"7" re:""`
CreatedAt time.Time
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:""`
ActivationTime string `index:"4" re:""`
Weight float64 `index:"5" re:"\d+\.?\d*"`
Limit string `index:"6" re:""`
ActionTriggerIds string `index:"7" re:""`
CreatedAt time.Time
}
type TBLVersion struct {

View File

@@ -34,7 +34,7 @@ type Storage interface {
GetKeysForPrefix(string) ([]string, error)
RebuildReverseForPrefix(string) error
GetVersions(itm string) (vrs Versions, err error)
SetVersions(vrs Versions) (err error)
SetVersions(vrs Versions, overwrite bool) (err error)
RemoveVersions(vrs Versions) (err error)
SelectDatabase(dbName string) (err error)
}
@@ -196,6 +196,7 @@ type CdrStorage interface {
SetCDR(*CDR, bool) error
SetSMCost(smc *SMCost) error
GetSMCosts(cgrid, runid, originHost, originIDPrfx string) ([]*SMCost, error)
RemoveSMCost(*SMCost) error
GetCDRs(*utils.CDRsFilter, bool) ([]*CDR, int64, error)
}
@@ -246,6 +247,7 @@ type LoadWriter interface {
SetTpActionPlans([]TpActionPlan) error
SetTpActionTriggers([]TpActionTrigger) error
SetTpAccountActions([]TpAccountAction) error
SetTpResourceLimits(TpResourceLimits) error
}
type Marshaler interface {

View File

@@ -1340,7 +1340,7 @@ func (ms *MapStorage) GetVersions(itm string) (vrs Versions, err error) {
return
}
func (ms *MapStorage) SetVersions(vrs Versions) (err error) {
func (ms *MapStorage) SetVersions(vrs Versions, overwrite bool) (err error) {
return
}

View File

@@ -53,6 +53,7 @@ func (ms *MongoStorage) GetTpIds() ([]string, error) {
}
return tpids, nil
}
func (ms *MongoStorage) GetTpTableIds(tpid, table string, distinct utils.TPDistinctIds, filter map[string]string, pag *utils.Paginator) ([]string, error) {
selectors := bson.M{}
for _, d := range distinct {
@@ -124,6 +125,9 @@ func (ms *MongoStorage) GetTpTimings(tpid, tag string) ([]TpTiming, error) {
session, col := ms.conn(utils.TBL_TP_TIMINGS)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
@@ -138,6 +142,9 @@ func (ms *MongoStorage) GetTPDestinations(tpid, tag string) ([]*utils.TPDestinat
session, col := ms.conn(utils.TBL_TP_DESTINATIONS)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
@@ -152,6 +159,9 @@ func (ms *MongoStorage) GetTpRates(tpid, tag string) ([]TpRate, error) {
session, col := ms.conn(utils.TBL_TP_RATES)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
@@ -175,6 +185,9 @@ func (ms *MongoStorage) GetTpDestinationRates(tpid, tag string, pag *utils.Pagin
}
}
err := q.All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
@@ -198,6 +211,9 @@ func (ms *MongoStorage) GetTpRatingPlans(tpid, tag string, pag *utils.Paginator)
}
}
err := q.All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
@@ -222,6 +238,9 @@ func (ms *MongoStorage) GetTpRatingProfiles(tp *TpRatingProfile) ([]TpRatingProf
session, col := ms.conn(utils.TBL_TP_RATE_PROFILES)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
@@ -236,6 +255,9 @@ func (ms *MongoStorage) GetTpSharedGroups(tpid, tag string) ([]TpSharedGroup, er
session, col := ms.conn(utils.TBL_TP_SHARED_GROUPS)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
@@ -250,8 +272,12 @@ func (ms *MongoStorage) GetTpCdrStats(tpid, tag string) ([]TpCdrstat, error) {
session, col := ms.conn(utils.TBL_TP_CDR_STATS)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
func (ms *MongoStorage) GetTpLCRs(tp *TpLcrRule) ([]TpLcrRule, error) {
filter := bson.M{"tpid": tp.Tpid}
if tp.Direction != "" {
@@ -273,6 +299,9 @@ func (ms *MongoStorage) GetTpLCRs(tp *TpLcrRule) ([]TpLcrRule, error) {
session, col := ms.conn(utils.TBL_TP_LCRS)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
@@ -288,6 +317,9 @@ func (ms *MongoStorage) GetTpUsers(tp *TpUser) ([]TpUser, error) {
session, col := ms.conn(utils.TBL_TP_USERS)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
@@ -315,11 +347,27 @@ func (ms *MongoStorage) GetTpAliases(tp *TpAlias) ([]TpAlias, error) {
session, col := ms.conn(utils.TBL_TP_ALIASES)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
func (ms *MongoStorage) GetTpResourceLimits(tpid, tag string) (TpResourceLimits, error) {
return nil, nil
filter := bson.M{
"tpid": tpid,
}
if tag != "" {
filter["tag"] = tag
}
var results TpResourceLimits
session, col := ms.conn(utils.TBLTPResourceLimits)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
func (ms *MongoStorage) GetTpDerivedChargers(tp *TpDerivedCharger) ([]TpDerivedCharger, error) {
@@ -346,6 +394,9 @@ func (ms *MongoStorage) GetTpDerivedChargers(tp *TpDerivedCharger) ([]TpDerivedC
session, col := ms.conn(utils.TBL_TP_DERIVED_CHARGERS)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
@@ -360,6 +411,9 @@ func (ms *MongoStorage) GetTpActions(tpid, tag string) ([]TpAction, error) {
session, col := ms.conn(utils.TBL_TP_ACTIONS)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
@@ -374,6 +428,9 @@ func (ms *MongoStorage) GetTpActionPlans(tpid, tag string) ([]TpActionPlan, erro
session, col := ms.conn(utils.TBL_TP_ACTION_PLANS)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
@@ -388,6 +445,9 @@ func (ms *MongoStorage) GetTpActionTriggers(tpid, tag string) ([]TpActionTrigger
session, col := ms.conn(utils.TBL_TP_ACTION_TRIGGERS)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
@@ -406,6 +466,9 @@ func (ms *MongoStorage) GetTpAccountActions(tp *TpAccountAction) ([]TpAccountAct
session, col := ms.conn(utils.TBL_TP_ACCOUNT_ACTIONS)
defer session.Close()
err := col.Find(filter).All(&results)
if len(results) == 0 {
return results, utils.ErrNotFound
}
return results, err
}
@@ -439,15 +502,11 @@ func (ms *MongoStorage) SetTpTimings(tps []TpTiming) error {
if len(tps) == 0 {
return nil
}
m := make(map[string]bool)
session, col := ms.conn(utils.TBL_TP_TIMINGS)
defer session.Close()
tx := col.Bulk()
for _, tp := range tps {
if found, _ := m[tp.Tag]; !found {
m[tp.Tag] = true
tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp)
}
tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp)
}
_, err := tx.Run()
return err
@@ -478,8 +537,9 @@ func (ms *MongoStorage) SetTpRates(tps []TpRate) error {
for _, tp := range tps {
if found, _ := m[tp.Tag]; !found {
m[tp.Tag] = true
tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp)
tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag})
}
tx.Insert(tp)
}
_, err := tx.Run()
return err
@@ -496,8 +556,9 @@ func (ms *MongoStorage) SetTpDestinationRates(tps []TpDestinationRate) error {
for _, tp := range tps {
if found, _ := m[tp.Tag]; !found {
m[tp.Tag] = true
tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp)
tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag})
}
tx.Insert(tp)
}
_, err := tx.Run()
return err
@@ -514,8 +575,9 @@ func (ms *MongoStorage) SetTpRatingPlans(tps []TpRatingPlan) error {
for _, tp := range tps {
if found, _ := m[tp.Tag]; !found {
m[tp.Tag] = true
tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp)
tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag})
}
tx.Insert(tp)
}
_, err := tx.Run()
return err
@@ -525,22 +587,18 @@ func (ms *MongoStorage) SetTpRatingProfiles(tps []TpRatingProfile) error {
if len(tps) == 0 {
return nil
}
m := make(map[string]bool)
session, col := ms.conn(utils.TBL_TP_RATE_PROFILES)
defer session.Close()
tx := col.Bulk()
for _, tp := range tps {
if found, _ := m[tp.GetRatingProfileId()]; !found {
m[tp.GetRatingProfileId()] = true
tx.Upsert(bson.M{
"tpid": tp.Tpid,
"loadid": tp.Loadid,
"direction": tp.Direction,
"tenant": tp.Tenant,
"category": tp.Category,
"subject": tp.Subject,
}, tp)
}
tx.Upsert(bson.M{
"tpid": tp.Tpid,
"loadid": tp.Loadid,
"direction": tp.Direction,
"tenant": tp.Tenant,
"category": tp.Category,
"subject": tp.Subject,
}, tp)
}
_, err := tx.Run()
return err
@@ -557,8 +615,9 @@ func (ms *MongoStorage) SetTpSharedGroups(tps []TpSharedGroup) error {
for _, tp := range tps {
if found, _ := m[tp.Tag]; !found {
m[tp.Tag] = true
tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp)
tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag})
}
tx.Insert(tp)
}
_, err := tx.Run()
return err
@@ -575,8 +634,9 @@ func (ms *MongoStorage) SetTpCdrStats(tps []TpCdrstat) error {
for _, tp := range tps {
if found, _ := m[tp.Tag]; !found {
m[tp.Tag] = true
tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp)
tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag})
}
tx.Insert(tp)
}
_, err := tx.Run()
return err
@@ -593,12 +653,13 @@ func (ms *MongoStorage) SetTpUsers(tps []TpUser) error {
for _, tp := range tps {
if found, _ := m[tp.GetId()]; !found {
m[tp.GetId()] = true
tx.Upsert(bson.M{
tx.RemoveAll(bson.M{
"tpid": tp.Tpid,
"tenant": tp.Tenant,
"username": tp.UserName,
}, tp)
})
}
tx.Insert(tp)
}
_, err := tx.Run()
return err
@@ -615,15 +676,16 @@ func (ms *MongoStorage) SetTpAliases(tps []TpAlias) error {
for _, tp := range tps {
if found, _ := m[tp.GetId()]; !found {
m[tp.GetId()] = true
tx.Upsert(bson.M{
tx.RemoveAll(bson.M{
"tpid": tp.Tpid,
"direction": tp.Direction,
"tenant": tp.Tenant,
"category": tp.Category,
"account": tp.Account,
"subject": tp.Subject,
"context": tp.Context}, tp)
"context": tp.Context})
}
tx.Insert(tp)
}
_, err := tx.Run()
return err
@@ -640,14 +702,15 @@ func (ms *MongoStorage) SetTpDerivedChargers(tps []TpDerivedCharger) error {
for _, tp := range tps {
if found, _ := m[tp.GetDerivedChargersId()]; !found {
m[tp.GetDerivedChargersId()] = true
tx.Upsert(bson.M{
tx.RemoveAll(bson.M{
"tpid": tp.Tpid,
"direction": tp.Direction,
"tenant": tp.Tenant,
"category": tp.Category,
"account": tp.Account,
"subject": tp.Subject}, tp)
"subject": tp.Subject})
}
tx.Insert(tp)
}
_, err := tx.Run()
return err
@@ -657,21 +720,18 @@ func (ms *MongoStorage) SetTpLCRs(tps []TpLcrRule) error {
if len(tps) == 0 {
return nil
}
m := make(map[string]bool)
session, col := ms.conn(utils.TBL_TP_LCRS)
defer session.Close()
tx := col.Bulk()
for _, tp := range tps {
if found, _ := m[tp.GetLcrRuleId()]; !found {
m[tp.GetLcrRuleId()] = true
tx.Upsert(bson.M{
"tpid": tp.Tpid,
"direction": tp.Direction,
"tenant": tp.Tenant,
"category": tp.Category,
"account": tp.Account,
"subject": tp.Subject}, tp)
}
tx.Upsert(bson.M{
"tpid": tp.Tpid,
"direction": tp.Direction,
"tenant": tp.Tenant,
"category": tp.Category,
"account": tp.Account,
"subject": tp.Subject}, tp)
}
_, err := tx.Run()
return err
@@ -688,8 +748,9 @@ func (ms *MongoStorage) SetTpActions(tps []TpAction) error {
for _, tp := range tps {
if found, _ := m[tp.Tag]; !found {
m[tp.Tag] = true
tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp)
tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag})
}
tx.Insert(tp)
}
_, err := tx.Run()
return err
@@ -706,8 +767,9 @@ func (ms *MongoStorage) SetTpActionPlans(tps []TpActionPlan) error {
for _, tp := range tps {
if found, _ := m[tp.Tag]; !found {
m[tp.Tag] = true
tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp)
tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag})
}
tx.Insert(tp)
}
_, err := tx.Run()
return err
@@ -724,8 +786,9 @@ func (ms *MongoStorage) SetTpActionTriggers(tps []TpActionTrigger) error {
for _, tp := range tps {
if found, _ := m[tp.Tag]; !found {
m[tp.Tag] = true
tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp)
tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag})
}
tx.Insert(tp)
}
_, err := tx.Run()
return err
@@ -735,34 +798,70 @@ func (ms *MongoStorage) SetTpAccountActions(tps []TpAccountAction) error {
if len(tps) == 0 {
return nil
}
m := make(map[string]bool)
session, col := ms.conn(utils.TBL_TP_ACCOUNT_ACTIONS)
defer session.Close()
tx := col.Bulk()
for _, tp := range tps {
if found, _ := m[tp.GetAccountActionId()]; !found {
m[tp.GetAccountActionId()] = true
tx.Upsert(bson.M{
"tpid": tp.Tpid,
"loadid": tp.Loadid,
"tenant": tp.Tenant,
"account": tp.Account}, tp)
tx.Upsert(bson.M{
"tpid": tp.Tpid,
"loadid": tp.Loadid,
"tenant": tp.Tenant,
"account": tp.Account}, tp)
}
_, err := tx.Run()
return err
}
func (ms *MongoStorage) SetTpResourceLimits(rls TpResourceLimits) error {
if len(rls) == 0 {
return nil
}
m := make(map[string]bool)
session, col := ms.conn(utils.TBLTPResourceLimits)
defer session.Close()
tx := col.Bulk()
for _, rl := range rls {
if found, _ := m[rl.Tag]; !found {
m[rl.Tag] = true
tx.RemoveAll(bson.M{"tpid": rl.Tpid, "tag": rl.Tag})
}
tx.Insert(rl)
}
_, err := tx.Run()
return err
}
func (ms *MongoStorage) SetSMCost(smc *SMCost) error {
if smc.CostDetails == nil {
return nil
}
session, col := ms.conn(utils.TBLSMCosts)
defer session.Close()
return col.Insert(smc)
}
func (ms *MongoStorage) RemoveSMCost(smc *SMCost) error {
session, col := ms.conn(utils.TBLSMCosts)
defer session.Close()
tx := col.Bulk()
tx.Remove(bson.M{"cgrid": smc.CGRID, "runid": smc.RunID}, smc)
_, err = tx.Run()
return err
}
func (ms *MongoStorage) GetSMCosts(cgrid, runid, originHost, originIDPrefix string) (smcs []*SMCost, err error) {
filter := bson.M{CGRIDLow: cgrid, RunIDLow: runid}
filter := bson.M{}
if cgrid != "" {
filter[CGRIDLow] = cgrid
}
if runid != "" {
filter[RunIDLow] = runid
}
if originHost != "" {
filter[OriginHostLow] = originHost
}
if originIDPrefix != "" {
filter = bson.M{OriginIDLow: bson.M{"$regex": bson.RegEx{Pattern: fmt.Sprintf("^%s", originIDPrefix)}}, OriginHostLow: originHost, RunIDLow: runid}
filter["$regex"] = bson.RegEx{Pattern: fmt.Sprintf("^%s", originIDPrefix)}
}
// Execute query
session, col := ms.conn(utils.TBLSMCosts)
@@ -770,11 +869,15 @@ func (ms *MongoStorage) GetSMCosts(cgrid, runid, originHost, originIDPrefix stri
iter := col.Find(filter).Iter()
var smCost SMCost
for iter.Next(&smCost) {
smcs = append(smcs, &smCost)
clone := smCost
smcs = append(smcs, &clone)
}
if err := iter.Err(); err != nil {
return nil, err
}
if len(smcs) == 0 {
return smcs, utils.ErrNotFound
}
return smcs, nil
}
@@ -977,6 +1080,9 @@ func (ms *MongoStorage) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR,
clone := cdr
cdrs = append(cdrs, &clone)
}
if len(cdrs) == 0 {
return cdrs, 0, utils.ErrNotFound
}
return cdrs, 0, nil
}
@@ -984,7 +1090,7 @@ func (ms *MongoStorage) GetVersions(itm string) (vrs Versions, err error) {
return
}
func (ms *MongoStorage) SetVersions(vrs Versions) (err error) {
func (ms *MongoStorage) SetVersions(vrs Versions, overwrite bool) (err error) {
return
}

View File

@@ -20,14 +20,12 @@ package engine
import (
"fmt"
"github.com/cgrates/cgrates/utils"
"github.com/jinzhu/gorm"
_ "github.com/lib/pq"
)
type PostgresStorage struct {
*SQLStorage
}
func NewPostgresStorage(host, port, name, user, password string, maxConn, maxIdleConn int) (*PostgresStorage, error) {
connectString := fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s sslmode=disable", host, port, name, user, password)
db, err := gorm.Open("postgres", connectString)
@@ -44,3 +42,30 @@ func NewPostgresStorage(host, port, name, user, password string, maxConn, maxIdl
return &PostgresStorage{&SQLStorage{Db: db.DB(), db: db}}, nil
}
type PostgresStorage struct {
*SQLStorage
}
func (self *PostgresStorage) SetVersions(vrs Versions, overwrite bool) (err error) {
tx := self.db.Begin()
if overwrite {
tx.Table(utils.TBLVersions).Delete(nil)
}
for key, val := range vrs {
vrModel := &TBLVersion{Item: key, Version: val}
if !overwrite {
if err = tx.Model(&TBLVersion{}).Where(
TBLVersion{Item: vrModel.Item}).Delete(TBLVersion{Version: val}).Error; err != nil {
tx.Rollback()
return
}
}
if err = tx.Save(vrModel).Error; err != nil {
tx.Rollback()
return
}
}
tx.Commit()
return
}

View File

@@ -1506,7 +1506,7 @@ func (rs *RedisStorage) GetVersions(itm string) (vrs Versions, err error) {
return
}
func (rs *RedisStorage) SetVersions(vrs Versions) (err error) {
func (rs *RedisStorage) SetVersions(vrs Versions, overwrite bool) (err error) {
return
}

View File

@@ -181,7 +181,7 @@ func (self *SQLStorage) RemTpData(table, tpid string, args map[string]string) er
if len(table) == 0 { // Remove tpid out of all tables
for _, tblName := range []string{utils.TBL_TP_TIMINGS, utils.TBL_TP_DESTINATIONS, utils.TBL_TP_RATES, utils.TBL_TP_DESTINATION_RATES, utils.TBL_TP_RATING_PLANS, utils.TBL_TP_RATE_PROFILES,
utils.TBL_TP_SHARED_GROUPS, utils.TBL_TP_CDR_STATS, utils.TBL_TP_LCRS, utils.TBL_TP_ACTIONS, utils.TBL_TP_ACTION_PLANS, utils.TBL_TP_ACTION_TRIGGERS, utils.TBL_TP_ACCOUNT_ACTIONS,
utils.TBL_TP_DERIVED_CHARGERS, utils.TBL_TP_ALIASES, utils.TBLTPResourceLimits} {
utils.TBL_TP_DERIVED_CHARGERS, utils.TBL_TP_ALIASES, utils.TBL_TP_USERS, utils.TBLTPResourceLimits} {
if err := tx.Table(tblName).Where("tpid = ?", tpid).Delete(nil).Error; err != nil {
tx.Rollback()
return err
@@ -208,16 +208,11 @@ func (self *SQLStorage) SetTpTimings(timings []TpTiming) error {
if len(timings) == 0 {
return nil
}
m := make(map[string]bool)
tx := self.db.Begin()
for _, timing := range timings {
if found, _ := m[timing.Tag]; !found {
m[timing.Tag] = true
if err := tx.Where(&TpTiming{Tpid: timing.Tpid, Tag: timing.Tag}).Delete(TpTiming{}).Error; err != nil {
tx.Rollback()
return err
}
if err := tx.Where(&TpTiming{Tpid: timing.Tpid, Tag: timing.Tag}).Delete(TpTiming{}).Error; err != nil {
tx.Rollback()
return err
}
save := tx.Save(&timing)
if save.Error != nil {
@@ -292,13 +287,11 @@ func (self *SQLStorage) SetTpDestinationRates(drs []TpDestinationRate) error {
return err
}
}
saved := tx.Save(&dRate)
if saved.Error != nil {
tx.Rollback()
return saved.Error
}
}
tx.Commit()
return nil
@@ -333,16 +326,12 @@ func (self *SQLStorage) SetTpRatingProfiles(rpfs []TpRatingProfile) error {
if len(rpfs) == 0 {
return nil //Nothing to set
}
m := make(map[string]bool)
tx := self.db.Begin()
for _, rpf := range rpfs {
if found, _ := m[rpf.GetRatingProfileId()]; !found {
m[rpf.GetRatingProfileId()] = true
if err := tx.Where(&TpRatingProfile{Tpid: rpf.Tpid, Loadid: rpf.Loadid, Direction: rpf.Direction, Tenant: rpf.Tenant, Category: rpf.Category, Subject: rpf.Subject}).Delete(TpRatingProfile{}).Error; err != nil {
tx.Rollback()
return err
}
if err := tx.Where(&TpRatingProfile{Tpid: rpf.Tpid, Loadid: rpf.Loadid, Direction: rpf.Direction, Tenant: rpf.Tenant, Category: rpf.Category, Subject: rpf.Subject}).Delete(TpRatingProfile{}).Error; err != nil {
tx.Rollback()
return err
}
saved := tx.Save(&rpf)
if saved.Error != nil {
@@ -446,24 +435,19 @@ func (self *SQLStorage) SetTpLCRs(lcrs []TpLcrRule) error {
if len(lcrs) == 0 {
return nil //Nothing to set
}
m := make(map[string]bool)
tx := self.db.Begin()
for _, lcr := range lcrs {
if found, _ := m[lcr.GetLcrRuleId()]; !found {
m[lcr.GetLcrRuleId()] = true
if err := tx.Where(&TpLcrRule{
Tpid: lcr.Tpid,
Direction: lcr.Direction,
Tenant: lcr.Tenant,
Category: lcr.Category,
Account: lcr.Account,
Subject: lcr.Subject,
}).Delete(TpLcrRule{}).Error; err != nil {
tx.Rollback()
return err
}
if err := tx.Where(&TpLcrRule{
Tpid: lcr.Tpid,
Direction: lcr.Direction,
Tenant: lcr.Tenant,
Category: lcr.Category,
Account: lcr.Account,
Subject: lcr.Subject,
}).Delete(TpLcrRule{}).Error; err != nil {
tx.Rollback()
return err
}
if err := tx.Save(&lcr).Error; err != nil {
tx.Rollback()
@@ -545,7 +529,6 @@ func (self *SQLStorage) SetTpActionTriggers(ats []TpActionTrigger) error {
tx.Rollback()
return saved.Error
}
}
tx.Commit()
return nil
@@ -577,6 +560,33 @@ func (self *SQLStorage) SetTpAccountActions(aas []TpAccountAction) error {
return nil
}
func (self *SQLStorage) SetTpResourceLimits(rls TpResourceLimits) error {
if len(rls) == 0 {
return nil
}
m := make(map[string]bool)
tx := self.db.Begin()
for _, rl := range rls {
if found, _ := m[rl.Tag]; !found {
m[rl.Tag] = true
if err := tx.Where(&TpResourceLimit{Tpid: rl.Tpid, Tag: rl.Tag}).Delete(TpResourceLimit{}).Error; err != nil {
tx.Rollback()
return err
}
}
save := tx.Save(&rl)
if save.Error != nil {
fmt.Println(save.Error)
tx.Rollback()
return save.Error
}
}
tx.Commit()
return nil
}
func (self *SQLStorage) SetSMCost(smc *SMCost) error {
if smc.CostDetails == nil {
return nil
@@ -605,12 +615,33 @@ func (self *SQLStorage) SetSMCost(smc *SMCost) error {
return nil
}
func (self *SQLStorage) RemoveSMCost(smc *SMCost) error {
tx := self.db.Begin()
if err := tx.Where(&TBLSMCosts{Cgrid: smc.CGRID, RunID: smc.RunID}).Delete(SMCost{}).Error; err != nil {
tx.Rollback()
return err
}
tx.Commit()
return nil
}
// GetSMCosts is used to retrieve one or multiple SMCosts based on filter
func (self *SQLStorage) GetSMCosts(cgrid, runid, originHost, originIDPrefix string) ([]*SMCost, error) {
var smCosts []*SMCost
q := self.db.Where(&TBLSMCosts{Cgrid: cgrid, RunID: runid})
filter := &TBLSMCosts{}
if cgrid != "" {
filter.Cgrid = cgrid
}
if runid != "" {
filter.RunID = runid
}
if originHost != "" {
filter.OriginHost = originHost
}
q := self.db.Where(filter)
if originIDPrefix != "" {
q = self.db.Where(&TBLSMCosts{OriginHost: originHost, RunID: runid}).Where(fmt.Sprintf("origin_id LIKE '%s%%'", originIDPrefix))
q = self.db.Where(filter).Where(fmt.Sprintf("origin_id LIKE '%s%%'", originIDPrefix))
}
results := make([]*TBLSMCosts, 0)
if err := q.Find(&results).Error; err != nil {
@@ -634,7 +665,9 @@ func (self *SQLStorage) GetSMCosts(cgrid, runid, originHost, originIDPrefix stri
}
smCosts = append(smCosts, smc)
}
if len(smCosts) == 0 {
return smCosts, utils.ErrNotFound
}
return smCosts, nil
}
@@ -1020,6 +1053,9 @@ func (self *SQLStorage) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR,
}
cdrs = append(cdrs, storCdr)
}
if len(cdrs) == 0 && !remove {
return cdrs, 0, utils.ErrNotFound
}
return cdrs, 0, nil
}
@@ -1032,6 +1068,9 @@ func (self *SQLStorage) GetTPDestinations(tpid, tag string) (uTPDsts []*utils.TP
if err := q.Find(&tpDests).Error; err != nil {
return nil, err
}
if len(tpDests.AsTPDestinations()) == 0 {
return tpDests.AsTPDestinations(), utils.ErrNotFound
}
return tpDests.AsTPDestinations(), nil
}
@@ -1044,6 +1083,9 @@ func (self *SQLStorage) GetTpRates(tpid, tag string) ([]TpRate, error) {
if err := q.Find(&tpRates).Error; err != nil {
return nil, err
}
if len(tpRates) == 0 {
return tpRates, utils.ErrNotFound
}
return tpRates, nil
}
@@ -1064,7 +1106,9 @@ func (self *SQLStorage) GetTpDestinationRates(tpid, tag string, pagination *util
if err := q.Find(&tpDestinationRates).Error; err != nil {
return nil, err
}
if len(tpDestinationRates) == 0 {
return tpDestinationRates, utils.ErrNotFound
}
return tpDestinationRates, nil
}
@@ -1077,6 +1121,9 @@ func (self *SQLStorage) GetTpTimings(tpid, tag string) ([]TpTiming, error) {
if err := q.Find(&tpTimings).Error; err != nil {
return nil, err
}
if len(tpTimings) == 0 {
return tpTimings, utils.ErrNotFound
}
return tpTimings, nil
}
@@ -1097,7 +1144,9 @@ func (self *SQLStorage) GetTpRatingPlans(tpid, tag string, pagination *utils.Pag
q = q.Offset(*pagination.Offset)
}
}
if len(tpRatingPlans) == 0 {
return tpRatingPlans, utils.ErrNotFound
}
return tpRatingPlans, nil
}
@@ -1122,7 +1171,9 @@ func (self *SQLStorage) GetTpRatingProfiles(filter *TpRatingProfile) ([]TpRating
if err := q.Find(&tpRpfs).Error; err != nil {
return nil, err
}
if len(tpRpfs) == 0 {
return tpRpfs, utils.ErrNotFound
}
return tpRpfs, nil
}
@@ -1135,8 +1186,10 @@ func (self *SQLStorage) GetTpSharedGroups(tpid, tag string) ([]TpSharedGroup, er
if err := q.Find(&tpShareGroups).Error; err != nil {
return nil, err
}
if len(tpShareGroups) == 0 {
return tpShareGroups, utils.ErrNotFound
}
return tpShareGroups, nil
}
func (self *SQLStorage) GetTpLCRs(filter *TpLcrRule) ([]TpLcrRule, error) {
@@ -1161,7 +1214,9 @@ func (self *SQLStorage) GetTpLCRs(filter *TpLcrRule) ([]TpLcrRule, error) {
if err := q.Find(&tpLcrRule).Error; err != nil {
return nil, err
}
if len(tpLcrRule) == 0 {
return tpLcrRule, utils.ErrNotFound
}
return tpLcrRule, nil
}
@@ -1174,7 +1229,9 @@ func (self *SQLStorage) GetTpActions(tpid, tag string) ([]TpAction, error) {
if err := q.Find(&tpActions).Error; err != nil {
return nil, err
}
if len(tpActions) == 0 {
return tpActions, utils.ErrNotFound
}
return tpActions, nil
}
@@ -1187,7 +1244,9 @@ func (self *SQLStorage) GetTpActionTriggers(tpid, tag string) ([]TpActionTrigger
if err := q.Find(&tpActionTriggers).Error; err != nil {
return nil, err
}
if len(tpActionTriggers) == 0 {
return tpActionTriggers, utils.ErrNotFound
}
return tpActionTriggers, nil
}
@@ -1200,7 +1259,9 @@ func (self *SQLStorage) GetTpActionPlans(tpid, tag string) ([]TpActionPlan, erro
if err := q.Find(&tpActionPlans).Error; err != nil {
return nil, err
}
if len(tpActionPlans) == 0 {
return tpActionPlans, utils.ErrNotFound
}
return tpActionPlans, nil
}
@@ -1220,6 +1281,9 @@ func (self *SQLStorage) GetTpAccountActions(filter *TpAccountAction) ([]TpAccoun
if err := q.Find(&tpAccActs).Error; err != nil {
return nil, err
}
if len(tpAccActs) == 0 {
return tpAccActs, utils.ErrNotFound
}
return tpAccActs, nil
}
@@ -1247,6 +1311,9 @@ func (self *SQLStorage) GetTpDerivedChargers(filter *TpDerivedCharger) ([]TpDeri
if err := q.Find(&tpDerivedChargers).Error; err != nil {
return nil, err
}
if len(tpDerivedChargers) == 0 {
return tpDerivedChargers, utils.ErrNotFound
}
return tpDerivedChargers, nil
}
@@ -1259,7 +1326,9 @@ func (self *SQLStorage) GetTpCdrStats(tpid, tag string) ([]TpCdrstat, error) {
if err := q.Find(&tpCdrStats).Error; err != nil {
return nil, err
}
if len(tpCdrStats) == 0 {
return tpCdrStats, utils.ErrNotFound
}
return tpCdrStats, nil
}
@@ -1300,7 +1369,9 @@ func (self *SQLStorage) GetTpUsers(filter *TpUser) ([]TpUser, error) {
if err := q.Find(&tpUsers).Error; err != nil {
return nil, err
}
if len(tpUsers) == 0 {
return tpUsers, utils.ErrNotFound
}
return tpUsers, nil
}
@@ -1374,6 +1445,9 @@ func (self *SQLStorage) GetTpResourceLimits(tpid, tag string) (TpResourceLimits,
if err := q.Find(&tpResourceLimits).Error; err != nil {
return nil, err
}
if len(tpResourceLimits) == 0 {
return tpResourceLimits, utils.ErrNotFound
}
return tpResourceLimits, nil
}
@@ -1395,8 +1469,11 @@ func (self *SQLStorage) GetVersions(itm string) (vrs Versions, err error) {
}
// SetVersions will set a slice of versions, updating existing
func (self *SQLStorage) SetVersions(vrs Versions) (err error) {
func (self *SQLStorage) SetVersions(vrs Versions, overwrite bool) (err error) {
tx := self.db.Begin()
if overwrite {
tx.Table(utils.TBLVersions).Delete(nil)
}
for key, val := range vrs {
vrModel := &TBLVersion{Item: key, Version: val}
if err = tx.Save(vrModel).Error; err != nil {

File diff suppressed because it is too large Load Diff

View File

@@ -71,8 +71,8 @@ const (
TBL_TP_DERIVED_CHARGERS = "tp_derived_chargers"
TBL_TP_USERS = "tp_users"
TBL_TP_ALIASES = "tp_aliases"
TBLSMCosts = "sm_costs"
TBLTPResourceLimits = "tp_resource_limits"
TBLSMCosts = "sm_costs"
TBL_CDRS = "cdrs"
TBLVersions = "versions"
TIMINGS_CSV = "Timings.csv"