From 3936bd8d097b019f4c73381decee3745044147fd Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 4 Aug 2016 16:56:34 +0300 Subject: [PATCH 1/3] ospis docker better start.sh --- data/docker/devel/start.sh | 1 - data/docker/osips_training/Dockerfile | 25 ++++++++++--------------- data/docker/osips_training/start.sh | 9 +++++++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/data/docker/devel/start.sh b/data/docker/devel/start.sh index 0a4a75591..23fd27a1e 100755 --- a/data/docker/devel/start.sh +++ b/data/docker/devel/start.sh @@ -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 diff --git a/data/docker/osips_training/Dockerfile b/data/docker/osips_training/Dockerfile index dcad1ee8a..c9da1e9ac 100644 --- a/data/docker/osips_training/Dockerfile +++ b/data/docker/osips_training/Dockerfile @@ -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 diff --git a/data/docker/osips_training/start.sh b/data/docker/osips_training/start.sh index 070ef5385..3b22b081d 100755 --- a/data/docker/osips_training/start.sh +++ b/data/docker/osips_training/start.sh @@ -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 +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 From a91ca0c729a4b2f127e0326fc4d150319e99ab79 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 4 Aug 2016 18:23:33 +0300 Subject: [PATCH 2/3] full path for cgr-engine --- data/docker/osips_training/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/docker/osips_training/start.sh b/data/docker/osips_training/start.sh index 3b22b081d..dd4d1e81d 100755 --- a/data/docker/osips_training/start.sh +++ b/data/docker/osips_training/start.sh @@ -5,7 +5,7 @@ sed -i 's/127.0.0.1/0.0.0.0/g' /etc/redis/redis.conf /etc/mysql/my.cnf /etc/init.d/rsyslog start /etc/init.d/mysql start /etc/init.d/redis-server start -cgr-engine -config_dir=/root/cgr/data/conf/samples/osips_training +/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 From bfa4a67dad4060f6debec48f0b0abd4b55512e58 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 4 Aug 2016 20:21:43 +0300 Subject: [PATCH 3/3] fix for refund information not found --- engine/account.go | 10 +++++++++- engine/account_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ engine/calldesc.go | 4 +++- engine/calldesc_test.go | 29 +++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/engine/account.go b/engine/account.go index fa7de7369..866668e1e 100644 --- a/engine/account.go +++ b/engine/account.go @@ -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...) diff --git a/engine/account_test.go b/engine/account_test.go index ba3e3a0c7..21a6b07ea 100644 --- a/engine/account_test.go +++ b/engine/account_test.go @@ -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{ diff --git a/engine/calldesc.go b/engine/calldesc.go index b2e804ce1..d6a0e8ceb 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -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) { diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go index 8ecf80774..ab3bb981d 100644 --- a/engine/calldesc_test.go +++ b/engine/calldesc_test.go @@ -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()