This commit is contained in:
DanB
2016-08-05 17:05:19 +02:00
7 changed files with 101 additions and 18 deletions

View File

@@ -35,7 +35,6 @@ cd /root/cgr
ln -s /root/code/bin/cgr-engine /usr/bin/
ln -s /root/code/bin/cgr-loader /usr/bin/
# expand freeswitch conf
cd /usr/share/cgrates/tutorials/fs_evsock/freeswitch/etc/ && tar xzf freeswitch_conf.tar.gz

View File

@@ -25,30 +25,25 @@ RUN chsh -s /usr/bin/zsh
# cleanup
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# create a link to data dir
RUN ln -s /root/code/src/github.com/cgrates/cgrates/data /usr/share/cgrates
# get cgrates from github
RUN mkdir -p /root/code/src/github.com/cgrates; cd /root/code/src/github.com/cgrates; git clone https://github.com/cgrates/cgrates.git
# create link to cgrates dir
RUN ln -s /root/code/src/github.com/cgrates/cgrates /root/cgr
# setup mysql for CGRateS
RUN cd /usr/share/cgrates/storage/mysql && ./setup_cgr_db.sh root CGRateS.org
# get deps
RUN cd /root/cgr; GOROOT=/root/go GOPATH=/root/code PATH=$GOROOT/bin:$GOPATH/bin:$PATH glide install
# build cgrates
RUN cd /root/cgr; GOROOT=/root/go GOPATH=/root/code PATH=$GOROOT/bin:$GOPATH/bin:$PATH ./build.sh
#env vars
RUN export GOROOT=/root/go; export GOPATH=/root/code; export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
# build and install cgrates
RUN cd /root/cgr
RUN glide install
# create cgr-engine and cgr-loader link
# create links
RUN ln -s /root/code/bin/cgr-engine /usr/bin/
RUN ln -s /root/code/bin/cgr-loader /usr/bin/
RUN ln -s /root/code/src/github.com/cgrates/cgrates/data /usr/share/cgrates
RUN cd /root/cgr
# prepare zshrc
RUN echo 'export GOROOT=/root/go; export GOPATH=/root/code; export PATH=$GOROOT/bin:$GOPATH/bin:$PATH'>>/root/.zshrc
# set start command
RUN CMD /root/code/src/github.com/cgrates/cgrates/data/docker/osips_training/start.sh
CMD /root/code/src/github.com/cgrates/cgrates/data/docker/osips_training/start.sh

View File

@@ -1,8 +1,17 @@
# edit servers config files
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/redis/redis.conf /etc/mysql/my.cnf
# start services
/etc/init.d/rsyslog start
/etc/init.d/mysql start
/etc/init.d/redis-server start
/root/code/bin/cgr-engine -config_dir /root/cgr/data/conf/samples/osips_training
# setup mysql
cd /usr/share/cgrates/storage/mysql && ./setup_cgr_db.sh root CGRateS.org
# load tariff plan data
cd /root/cgr/data/tariffplans/osips_training; cgr-loader
cd /root/cgr
DISABLE_AUTO_UPDATE="true" zsh

View File

@@ -478,10 +478,18 @@ func (ub *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun boo
utils.Logger.Err(fmt.Sprintf("Error getting new cost for balance subject: %v", err))
}
if leftCC.Cost == 0 && len(leftCC.Timespans) > 0 {
// put AccountID ubformation in increments
for _, ts := range leftCC.Timespans {
for _, inc := range ts.Increments {
if inc.BalanceInfo == nil {
inc.BalanceInfo = &DebitInfo{}
}
inc.BalanceInfo.AccountID = ub.ID
}
}
cc.Timespans = append(cc.Timespans, leftCC.Timespans...)
}
//log.Printf("HERE: %+v", leftCC)
if leftCC.Cost > 0 && goNegative {
initialLength := len(cc.Timespans)
cc.Timespans = append(cc.Timespans, leftCC.Timespans...)

View File

@@ -244,6 +244,47 @@ func TestDebitCreditBlocker(t *testing.T) {
}
}
func TestDebitFreeEmpty(t *testing.T) {
cc := &CallCost{
Direction: utils.OUT,
Destination: "112",
Timespans: []*TimeSpan{
&TimeSpan{
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
TimeEnd: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
DurationIndex: 0,
RateInterval: &RateInterval{Rating: &RIRate{ConnectFee: 0, Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 0, RateIncrement: time.Second, RateUnit: time.Second}}}},
},
},
deductConnectFee: true,
TOR: utils.VOICE,
}
cd := &CallDescriptor{
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
TimeEnd: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
Direction: utils.OUT,
Tenant: "CUSTOMER_1",
Subject: "rif:from:tm",
Destination: "112",
Category: "0",
TOR: utils.VOICE,
testCallcost: cc,
}
// empty account
rifsBalance := &Account{ID: "other", BalanceMap: map[string]Balances{utils.MONETARY: Balances{}}}
var err error
cc, err = rifsBalance.debitCreditBalance(cd, false, true, true)
if err != nil {
t.Error("Error debiting balance: ", err)
}
if len(cc.Timespans) == 0 || cc.Cost != 0 {
t.Error("Wrong call cost: ", utils.ToIJSON(cc))
}
if len(rifsBalance.BalanceMap[utils.MONETARY]) != 0 {
t.Error("should not have touched the balances: ", utils.ToIJSON(rifsBalance.BalanceMap[utils.MONETARY]))
}
}
func TestDebitCreditZeroMinute(t *testing.T) {
b1 := &Balance{Uuid: "testb", Value: 70, Weight: 10, DestinationIDs: utils.StringMap{"NAT": true}, RatingSubject: "*zero1m"}
cc := &CallCost{

View File

@@ -796,7 +796,9 @@ func (cd *CallDescriptor) RefundIncrements() error {
accMap := make(utils.StringMap)
cd.Increments.Decompress()
for _, increment := range cd.Increments {
accMap[increment.BalanceInfo.AccountID] = true
if increment.BalanceInfo.Monetary != nil || increment.BalanceInfo.Unit != nil {
accMap[increment.BalanceInfo.AccountID] = true
}
}
// start increment refunding loop
_, err := Guardian.Guard(func() (interface{}, error) {

View File

@@ -1587,6 +1587,35 @@ func TestCDRefundIncrements(t *testing.T) {
}
}
func TestCDRefundIncrementsZeroValue(t *testing.T) {
ub := &Account{
ID: "test:ref",
BalanceMap: map[string]Balances{
utils.MONETARY: Balances{
&Balance{Uuid: "moneya", Value: 100},
},
utils.VOICE: Balances{
&Balance{Uuid: "minutea", Value: 10, Weight: 20, DestinationIDs: utils.StringMap{"NAT": true}},
&Balance{Uuid: "minuteb", Value: 10, DestinationIDs: utils.StringMap{"RET": true}},
},
},
}
accountingStorage.SetAccount(ub)
increments := Increments{
&Increment{Cost: 0, BalanceInfo: &DebitInfo{AccountID: ub.ID}},
&Increment{Cost: 0, Duration: 3 * time.Second, BalanceInfo: &DebitInfo{AccountID: ub.ID}},
&Increment{Cost: 0, Duration: 4 * time.Second, BalanceInfo: &DebitInfo{AccountID: ub.ID}},
}
cd := &CallDescriptor{TOR: utils.VOICE, Increments: increments}
cd.RefundIncrements()
ub, _ = accountingStorage.GetAccount(ub.ID)
if ub.BalanceMap[utils.MONETARY][0].GetValue() != 100 ||
ub.BalanceMap[utils.VOICE][0].GetValue() != 10 ||
ub.BalanceMap[utils.VOICE][1].GetValue() != 10 {
t.Error("Error refunding money: ", utils.ToIJSON(ub.BalanceMap))
}
}
/*************** BENCHMARKS ********************/
func BenchmarkStorageGetting(b *testing.B) {
b.StopTimer()