This commit is contained in:
DanB
2015-05-09 19:58:05 +02:00
9 changed files with 62 additions and 52 deletions

1
.gitignore vendored
View File

@@ -12,3 +12,4 @@ bin
dean*
data/vagrant/.vagrant
data/vagrant/vagrant_ansible_inventory_default
data/tutorials/fs_evsock/freeswitch/etc/freeswitch/

View File

@@ -5,9 +5,9 @@
// Starts rater, scheduler
"listen": {
"rpc_json": "127.0.0.1:2012", // RPC JSON listening address
"rpc_gob": "127.0.0.1:2013", // RPC GOB listening address
"http": "127.0.0.1:2080", // HTTP listening address
"rpc_json": ":2012", // RPC JSON listening address
"rpc_gob": ":2013", // RPC GOB listening address
"http": ":2080", // HTTP listening address
},
"rater": {

View File

@@ -11,7 +11,7 @@ RUN gpg --keyserver pool.sks-keyservers.net --recv-key D76EDC7725E010CF && gpg -
RUN echo 'deb http://files.freeswitch.org/repo/deb/debian/ jessie main' > /etc/apt/sources.list.d/freeswitch.list
# install dependencies
RUN apt-get -y update && apt-get -y install git bzr mercurial redis-server mysql-server python-pycurl python-mysqldb postgresql postgresql-client sudo wget freeswitch-meta-vanilla
RUN apt-get -y update && apt-get -y install git bzr mercurial redis-server mysql-server python-pycurl python-mysqldb postgresql postgresql-client sudo wget freeswitch-meta-vanilla vim zsh
# add cgrates user
RUN useradd -c CGRateS -d /var/run/cgrates -s /bin/false -r cgrates
@@ -19,6 +19,9 @@ RUN useradd -c CGRateS -d /var/run/cgrates -s /bin/false -r cgrates
# install golang
RUN wget -qO- https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz | tar xzf - -C /root/
#install oh-my-zsh
RUN wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | zsh
# cleanup
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

View File

@@ -6,6 +6,6 @@ From the project root:
``` bash
# build the image
docker build -t cgrates data/docker/devel
# create the container
docker run --rm -itv `pwd`:/root/code/src/github.com/cgrates/cgrates --name cgr cgrates
# create the container from the cgrates project roor
./data/docker/devel/run.sh
```

3
data/docker/devel/run.sh Executable file
View File

@@ -0,0 +1,3 @@
#/usr/bin/env sh
docker run --rm -p 3306:3306 -p 6379:6379 -p 2012:2012 -p 2013:2013 -p 2080:2080 -itv `pwd`:/root/code/src/github.com/cgrates/cgrates --name cgr cgrates

View File

@@ -2,6 +2,8 @@ export GOROOT=/root/go
export GOPATH=/root/code
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/redis/redis.conf /etc/mysql/my.cnf /etc/postgresql/9.4/main/pg_hba.conf
/etc/init.d/mysql start
/etc/init.d/postgresql start
/etc/init.d/redis-server start
@@ -25,4 +27,5 @@ ln -s /root/code/bin/cgr-engine /usr/bin/cgr-engine
cd /usr/share/cgrates/tutorials/fs_evsock/freeswitch/etc/ && tar xzf freeswitch_conf.tar.gz
cd /root/cgr
bash --rcfile /root/.bashrc
echo "for cgradmin run: cgr-engine -config_dir data/conf/samples/cgradmin"
zsh

View File

@@ -176,13 +176,13 @@ func TestDebitCreditZeroSecond(t *testing.T) {
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: OUTBOUND,
Destination: "0723045326",
Category: "0",
TOR: utils.VOICE,
test_callcost: cc,
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: OUTBOUND,
Destination: "0723045326",
Category: "0",
TOR: utils.VOICE,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{utils.VOICE + OUTBOUND: BalanceChain{b1}, utils.MONETARY + OUTBOUND: BalanceChain{&Balance{Category: "0", Value: 21}}}}
var err error
@@ -216,13 +216,13 @@ func TestDebitCreditZeroMinute(t *testing.T) {
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: OUTBOUND,
Destination: "0723045326",
Category: "0",
TOR: utils.VOICE,
test_callcost: cc,
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: OUTBOUND,
Destination: "0723045326",
Category: "0",
TOR: utils.VOICE,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.VOICE + OUTBOUND: BalanceChain{b1},
@@ -269,7 +269,7 @@ func TestDebitCreditZeroMixedMinute(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.Timespans[0].GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.VOICE + OUTBOUND: BalanceChain{b1, b2},
@@ -321,7 +321,7 @@ func TestDebitCreditNoCredit(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.VOICE + OUTBOUND: BalanceChain{b1},
@@ -372,7 +372,7 @@ func TestDebitCreditHasCredit(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.VOICE + OUTBOUND: BalanceChain{b1},
@@ -420,7 +420,7 @@ func TestDebitCreditSplitMinutesMoney(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.VOICE + OUTBOUND: BalanceChain{b1},
@@ -473,7 +473,7 @@ func TestDebitCreditMoreTimespans(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.VOICE + OUTBOUND: BalanceChain{b1},
@@ -522,7 +522,7 @@ func TestDebitCreditMoreTimespansMixed(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.VOICE + OUTBOUND: BalanceChain{b1, b2},
@@ -572,7 +572,7 @@ func TestDebitCreditNoConectFeeCredit(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.VOICE + OUTBOUND: BalanceChain{b1},
@@ -616,7 +616,7 @@ func TestDebitCreditMoneyOnly(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.MONETARY + OUTBOUND: BalanceChain{&Balance{Uuid: "money", Value: 50}},
@@ -669,7 +669,7 @@ func TestDebitCreditSubjectMinutes(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.VOICE + OUTBOUND: BalanceChain{b1},
@@ -724,7 +724,7 @@ func TestDebitCreditSubjectMoney(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.MONETARY + OUTBOUND: BalanceChain{&Balance{Uuid: "moneya", Value: 75, DestinationId: "NAT", RatingSubject: "minu"}},
@@ -774,7 +774,7 @@ func TestDebitCreditSubjectMoney(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.VOICE + OUTBOUND: BalanceChain{b1},
@@ -836,7 +836,7 @@ func TestDebitCreditSubjectMixedMoreTS(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.VOICE + OUTBOUND: BalanceChain{b1},
@@ -900,7 +900,7 @@ func TestDebitCreditSubjectMixedPartPay(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.VOICE + OUTBOUND: BalanceChain{b1},
@@ -1160,7 +1160,7 @@ func TestDebitShared(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rif := &Account{Id: "rif", BalanceMap: map[string]BalanceChain{
utils.MONETARY + OUTBOUND: BalanceChain{&Balance{Uuid: "moneya", Value: 0, SharedGroup: "SG_TEST"}},
@@ -1230,7 +1230,7 @@ func TestMaxDurationShared(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rif := &Account{Id: "rif", BalanceMap: map[string]BalanceChain{
utils.MONETARY + OUTBOUND: BalanceChain{&Balance{Uuid: "moneya", Value: 0, SharedGroup: "SG_TEST"}},
@@ -1276,7 +1276,7 @@ func TestDebitSMS(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.SMS + OUTBOUND: BalanceChain{&Balance{Uuid: "testm", Value: 100, Weight: 5, DestinationId: "NAT"}},
@@ -1326,7 +1326,7 @@ func TestDebitDataUnits(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.DATA + OUTBOUND: BalanceChain{&Balance{Uuid: "testm", Value: 100, Weight: 5, DestinationId: "NAT"}},
@@ -1375,7 +1375,7 @@ func TestDebitDataMoney(t *testing.T) {
Destination: cc.Destination,
TOR: cc.TOR,
DurationIndex: cc.GetDuration(),
test_callcost: cc,
testCallcost: cc,
}
rifsBalance := &Account{Id: "other", BalanceMap: map[string]BalanceChain{
utils.DATA + OUTBOUND: BalanceChain{&Balance{Uuid: "testm", Value: 0, Weight: 5, DestinationId: "NAT"}},

View File

@@ -219,8 +219,8 @@ func (b *Balance) GetMinutesForCredit(origCD *CallDescriptor, initialCredit floa
// retuns a callcost obtained using standard rating
func (b *Balance) GetCost(cd *CallDescriptor, getStandardIfEmpty bool) (*CallCost, error) {
// testing only
if cd.test_callcost != nil {
return cd.test_callcost, nil
if cd.testCallcost != nil {
return cd.testCallcost, nil
}
if b.RatingSubject != "" && !strings.HasPrefix(b.RatingSubject, utils.ZERO_RATING_SUBJECT_PREFIX) {
origSubject := cd.Subject
@@ -405,7 +405,7 @@ func (b *Balance) DebitMoney(cd *CallDescriptor, ub *Account, count bool, dryRun
if !b.IsActiveAt(cd.TimeStart) || b.Value <= 0 {
return
}
//log.Printf("}}}}}}} %+v", cd.test_callcost)
//log.Printf("}}}}}}} %+v", cd.testCallcost)
cc, err = b.GetCost(cd, true)
cc.Timespans.Decompress()
//log.Printf("CallCost In Debit: %+v", cc)
@@ -480,7 +480,7 @@ func (b *Balance) DebitMoney(cd *CallDescriptor, ub *Account, count bool, dryRun
}
}
}
//log.Printf("END: %+v", cd.test_callcost)
//log.Printf("END: %+v", cd.testCallcost)
if len(cc.Timespans) == 0 {
cc = nil
}

View File

@@ -119,11 +119,11 @@ type CallDescriptor struct {
Increments Increments
TOR string // used unit balances selector
// session limits
MaxRate float64
MaxRateUnit time.Duration
MaxCostSoFar float64
account *Account
test_callcost *CallCost // testing purpose only!
MaxRate float64
MaxRateUnit time.Duration
MaxCostSoFar float64
account *Account
testCallcost *CallCost // testing purpose only!
}
func (cd *CallDescriptor) ValidateCallData() error {
@@ -268,16 +268,16 @@ func (cd *CallDescriptor) addRatingInfos(ris RatingInfos) bool {
}
for _, ri := range cd.RatingInfos {
if ri.RateIntervals == nil {
for i, new_ri := range ris {
for i, newRi := range ris {
_ = i
_ = new_ri
_ = newRi
}
}
}
return true
}
// Constructs the key for the storage lookup.
// GetKey constructs the key for the storage lookup.
// The prefixLen is limiting the length of the destination prefix.
func (cd *CallDescriptor) GetKey(subject string) string {
// check if subject is alias
@@ -289,7 +289,7 @@ func (cd *CallDescriptor) GetKey(subject string) string {
return utils.ConcatenatedKey(cd.Direction, cd.Tenant, cd.Category, subject)
}
// Returns the key used to retrive the user balance involved in this call
// GetAccountKey returns the key used to retrive the user balance involved in this call
func (cd *CallDescriptor) GetAccountKey() string {
subj := cd.Subject
if cd.Account != "" {