Tutorial rates fixup, apier reload cache after loading from file, init script creates rundir

This commit is contained in:
DanB
2014-01-15 15:23:32 +01:00
parent d8f2fc8521
commit 6c82f01a10
9 changed files with 52 additions and 11 deletions

View File

@@ -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
}

View File

@@ -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.

View File

@@ -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
1 #Tag DestinationRatesTag TimingTag Weight
2 RP_RETAIL1 DR_FS_40CNT PEAK 10
3 RP_RETAIL1 DR_FS_10CNT OFFPEAK OFFPEAK_MORNING 10
4 RP_RETAIL1 DR_FS_10CNT OFFPEAK_EVENING 10
5 RP_RETAIL1 DR_FS_10CNT OFFPEAK_WEEKEND 10
6 RP_RETAIL2 DR_1002_20CNT PEAK 10
7 RP_RETAIL2 DR_1003_20CNT PEAK 10
8 RP_RETAIL2 DR_FS_10CNT OFFPEAK_MORNING 10
9 RP_RETAIL2 DR_FS_10CNT OFFPEAK_EVENING 10
10 RP_RETAIL2 DR_FS_10CNT OFFPEAK_WEEKEND 10

View File

@@ -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
1 #Tag Years Months MonthDays WeekDays Time
2 ALWAYS *any *any *any *any 00:00:00
3 ASAP *any *any *any *any *asap
4 PEAK *any *any *any 1;2;3;4;5 08:00:00
5 OFFPEAK OFFPEAK_MORNING *any *any *any 1;2;3;4;5 1 00:00:00
6 OFFPEAK OFFPEAK_EVENING *any *any *any 1;2;3;4;5 19:00:00
7 OFFPEAK OFFPEAK_WEEKEND *any *any *any 6;7 00:00:00

View File

@@ -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.

View File

@@ -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 {

View File

@@ -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

View File

@@ -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)

View File

@@ -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