diff --git a/apier/v1/apier.go b/apier/v1/apier.go index a944ebb30..f5f56ad17 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -542,6 +542,37 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs AttrLoadTPFromFolder, reply if err := loader.WriteToDatabase(attrs.FlushDb, false); err != nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) } + // Make sure the items are in the cache + dstIds, _ := loader.GetLoadedIds(engine.DESTINATION_PREFIX) + dstKeys := make([]string, len(dstIds)) + for idx, dId := range dstIds { + dstKeys[idx] = engine.DESTINATION_PREFIX + dId // Cache expects them as redis keys + } + rplIds, _ := loader.GetLoadedIds(engine.RATING_PLAN_PREFIX) + rpKeys := make([]string, len(rplIds)) + for idx, rpId := range rplIds { + rpKeys[idx] = engine.RATING_PLAN_PREFIX + rpId + } + rpfIds, _ := loader.GetLoadedIds(engine.RATING_PROFILE_PREFIX) + rpfKeys := make([]string, len(rpfIds)) + for idx, rpfId := range rpfIds { + rpfKeys[idx] = engine.RATING_PROFILE_PREFIX + rpfId + } + actIds, _ := loader.GetLoadedIds(engine.ACTION_PREFIX) + actKeys := make([]string, len(actIds)) + for idx, actId := range actIds { + actKeys[idx] = engine.ACTION_PREFIX + actId + } + if err := self.RatingDb.CacheRating(dstKeys, rpKeys, rpfKeys); err != nil { + return err + } + if err := self.AccountDb.CacheAccounting(actKeys); err != nil { + return err + } + if self.Sched != nil { + self.Sched.LoadActionTimings(self.AccountDb) + self.Sched.Restart() + } *reply = "OK" return nil } diff --git a/data/tutorials/fs_json/cgrates/tariffplans/README.md b/data/tutorials/fs_json/cgrates/tariffplans/README.md index 3e5b21c87..67087eab5 100644 --- a/data/tutorials/fs_json/cgrates/tariffplans/README.md +++ b/data/tutorials/fs_json/cgrates/tariffplans/README.md @@ -12,7 +12,7 @@ Scenario: - Rate id: *RT_20CNT* with connect fee of 40cents, 20cents per minute for the first 60s in 60s increments, followed by 10 cents per minute charged in 1s increments. - Rate id: *RT_40CNT* with connect fee of 80cents, 40cents per minute for the first 60s in 60s increments, follwed by 20cents per minute charged in 10s increments. - Will charge by default *RT_40CNT* for all FreeSWITCH_ destinations during peak times (Monday-Friday 08:00-19:00) and *RT_10CNT* during offpeatimes (rest). - - Account 1001 will receive a special *deal* for 1002 and 1003 destinations during peak times with *RT_20CNT*, otherwise failing over default rating. + - Account 1001 will receive a special *deal* for 1002 and 1003 destinations during peak times with *RT_20CNT*, otherwise same as default rating. - Create 4 accounts (equivalent of 2 FreeSWITCH default test users - 1001, 1002, 1003, 1004). - 1001, 1002, 1003, 1004 will receive 10units of *\*monetary* balance. diff --git a/data/tutorials/fs_json/cgrates/tariffplans/RatingPlans.csv b/data/tutorials/fs_json/cgrates/tariffplans/RatingPlans.csv index 27a8ce7a0..61af34466 100644 --- a/data/tutorials/fs_json/cgrates/tariffplans/RatingPlans.csv +++ b/data/tutorials/fs_json/cgrates/tariffplans/RatingPlans.csv @@ -1,5 +1,10 @@ #Tag,DestinationRatesTag,TimingTag,Weight RP_RETAIL1,DR_FS_40CNT,PEAK,10 -RP_RETAIL1,DR_FS_10CNT,OFFPEAK,10 +RP_RETAIL1,DR_FS_10CNT,OFFPEAK_MORNING,10 +RP_RETAIL1,DR_FS_10CNT,OFFPEAK_EVENING,10 +RP_RETAIL1,DR_FS_10CNT,OFFPEAK_WEEKEND,10 RP_RETAIL2,DR_1002_20CNT,PEAK,10 RP_RETAIL2,DR_1003_20CNT,PEAK,10 +RP_RETAIL2,DR_FS_10CNT,OFFPEAK_MORNING,10 +RP_RETAIL2,DR_FS_10CNT,OFFPEAK_EVENING,10 +RP_RETAIL2,DR_FS_10CNT,OFFPEAK_WEEKEND,10 diff --git a/data/tutorials/fs_json/cgrates/tariffplans/Timings.csv b/data/tutorials/fs_json/cgrates/tariffplans/Timings.csv index 5f22d1d07..2c5ad517e 100644 --- a/data/tutorials/fs_json/cgrates/tariffplans/Timings.csv +++ b/data/tutorials/fs_json/cgrates/tariffplans/Timings.csv @@ -2,6 +2,6 @@ ALWAYS,*any,*any,*any,*any,00:00:00 ASAP,*any,*any,*any,*any,*asap PEAK,*any,*any,*any,1;2;3;4;5,08:00:00 -OFFPEAK,*any,*any,*any,1;2;3;4;5,00:00:00 -OFFPEAK,*any,*any,*any,1;2;3;4;5,19:00:00 -OFFPEAK,*any,*any,*any,6;7,00:00:00 +OFFPEAK_MORNING,*any,*any,*any,1,00:00:00 +OFFPEAK_EVENING,*any,*any,*any,1;2;3;4;5,19:00:00 +OFFPEAK_WEEKEND,*any,*any,*any,6;7,00:00:00 diff --git a/docs/tut_freeswitch_json.rst b/docs/tut_freeswitch_json.rst index e14de8235..cdca3830a 100644 --- a/docs/tut_freeswitch_json.rst +++ b/docs/tut_freeswitch_json.rst @@ -59,7 +59,7 @@ For our tutorial we load again prepared data out of shared folder, containing fo - Rate id: *RT_20CNT* with connect fee of 40cents, 20cents per minute for the first 60s in 60s increments, followed by 10 cents per minute charged in 1s increments. - Rate id: *RT_40CNT* with connect fee of 80cents, 40cents per minute for the first 60s in 60s increments, follwed by 20cents per minute charged in 10s increments. - Will charge by default *RT_40CNT* for all FreeSWITCH_ destinations during peak times (Monday-Friday 08:00-19:00) and *RT_10CNT* during offpeatimes (rest). - - Account 1001 will receive a special *deal* for 1002 and 1003 destinations during peak times with *RT_20CNT*, otherwise failing over default rating. + - Account 1001 will receive a special *deal* for 1002 and 1003 destinations during peak times with *RT_20CNT*, otherwise having default rating. - Create 4 accounts (equivalent of 2 FreeSWITCH default test users - 1001, 1002, 1003, 1004). - 1001, 1002, 1003, 1004 will receive 10units of *\*monetary* balance. diff --git a/engine/storage_redis.go b/engine/storage_redis.go index c9860c2fb..4d9eb91c8 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -78,7 +78,7 @@ func (rs *RedisStorage) CacheRating(dKeys, rpKeys, rpfKeys []string) (err error) return } cache2go.RemPrefixKey(DESTINATION_PREFIX) - } else if len(rpKeys) != 0 { + } else if len(dKeys) != 0 { Logger.Info(fmt.Sprintf("Caching destinations: %v", dKeys)) } for _, key := range dKeys { diff --git a/pkg/debian/cgrates.init b/pkg/debian/cgrates.init index c16d528be..488c8b94f 100644 --- a/pkg/debian/cgrates.init +++ b/pkg/debian/cgrates.init @@ -21,7 +21,8 @@ DAEMON=/usr/bin/cgr-engine USER=cgrates GROUP=cgrates ENGINE_OPTS="" -PIDFILE=/var/run/$NAME/cgr-engine.pid +RUNDIR=/var/run/$NAME +PIDFILE=$RUNDIR/cgr-engine.pid SCRIPTNAME=/etc/init.d/$NAME DEFAULTS=/etc/default/$NAME ENABLE=false @@ -45,6 +46,12 @@ if [ "$ENABLE" != "true" ]; then exit 0 fi +# Install the run folder +if [ ! -d $RUNDIR ]; then + mkdir $RUNDIR + chown $USER:$GROUP $RUNDIR +fi + # # Function that starts the daemon/service diff --git a/pkg/debian/postinst b/pkg/debian/postinst index fe1460296..af3e428a3 100755 --- a/pkg/debian/postinst +++ b/pkg/debian/postinst @@ -27,10 +27,9 @@ set -e case "$1" in configure) - adduser --quiet --system --group --disabled-password --shell /bin/false --gecos "CGRateS" cgrates || true + adduser --quiet --system --group --disabled-password --shell /bin/false --home /var/run/cgrates --gecos "CGRateS" cgrates || true chown -R cgrates:cgrates /var/log/cgrates/ chown -R cgrates:cgrates /usr/share/cgrates/ - chown -R cgrates:cgrates /var/run/cgrates/ ;; abort-upgrade|abort-remove|abort-deconfigure) diff --git a/pkg/debian/rules b/pkg/debian/rules index 047c58cc1..889fbd6cb 100755 --- a/pkg/debian/rules +++ b/pkg/debian/rules @@ -33,7 +33,6 @@ binary-arch: clean mkdir -p $(PKGDIR)/var/log/cgrates/cdr/cdrc/out mkdir -p $(PKGDIR)/var/log/cgrates/cdr/cdrexport/csv mkdir -p $(PKGDIR)/var/log/cgrates/history - mkdir -p $(PKGDIR)/var/run/cgrates dh_strip dh_compress dh_fixperms