mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
cassandra out, mongo in
This commit is contained in:
@@ -10,14 +10,17 @@ RUN gpg --keyserver pool.sks-keyservers.net --recv-key D76EDC7725E010CF && gpg -
|
||||
# add freeswitch apt repo
|
||||
RUN echo 'deb http://files.freeswitch.org/repo/deb/debian/ jessie main' > /etc/apt/sources.list.d/freeswitch.list
|
||||
|
||||
# add cassandra gpg keys
|
||||
RUN gpg --keyserver pgp.mit.edu --recv-keys F758CE318D77295D; gpg --export --armor F758CE318D77295D | apt-key add -;gpg --keyserver pgp.mit.edu --recv-keys 2B5C1B00;gpg --export --armor 2B5C1B00 | apt-key add -;gpg --keyserver pgp.mit.edu --recv-keys 0353B12C;gpg --export --armor 0353B12C | apt-key add -
|
||||
# add mongo repo keys
|
||||
RUN apt-key adv --keyserver 'keyserver.ubuntu.com' --recv '7F0CEB10'
|
||||
|
||||
# add cassandra repo
|
||||
RUN echo 'deb http://www.apache.org/dist/cassandra/debian 21x main' > /etc/apt/sources.list.d/cassandra.list
|
||||
# add mongo repo
|
||||
RUN echo 'deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main' | tee '/etc/apt/sources.list.d/mongodb-org-3.0.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 cassandra sudo wget freeswitch-meta-vanilla vim zsh
|
||||
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 mongodb-org
|
||||
|
||||
# add mongo conf
|
||||
COPY mongod.conf /etc/mongod.conf
|
||||
|
||||
# add cgrates user
|
||||
RUN useradd -c CGRateS -d /var/run/cgrates -s /bin/false -r cgrates
|
||||
|
||||
16
data/docker/devel/mongod.conf
Normal file
16
data/docker/devel/mongod.conf
Normal file
@@ -0,0 +1,16 @@
|
||||
storage:
|
||||
dbPath: "/var/lib/mongodb"
|
||||
engine: "wiredTiger"
|
||||
wiredTiger:
|
||||
collectionConfig:
|
||||
blockCompressor: snappy
|
||||
|
||||
systemLog:
|
||||
destination: file
|
||||
path: "/var/log/mongodb/mongodb.log"
|
||||
logAppend: true
|
||||
timeStampFormat: iso8601-utc
|
||||
|
||||
net:
|
||||
bindIp: "127.0.0.1"
|
||||
port: 27017
|
||||
@@ -1,14 +1,12 @@
|
||||
# edit servers config files
|
||||
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/redis/redis.conf /etc/mysql/my.cnf
|
||||
echo 'host all all 0.0.0.0/32 md5'>>/etc/postgresql/9.4/main/pg_hba.conf
|
||||
sed -i 's/ulimit/#ulimit/g' /etc/init.d/cassandra
|
||||
sed -i 's/AllowAllAuthenticator/PasswordAuthenticator/g' /etc/cassandra/cassandra.yaml
|
||||
sed -i 's/AllowAllAuthorizer/CassandraAuthorizer/g' /etc/cassandra/cassandra.yaml
|
||||
|
||||
/etc/init.d/mysql start
|
||||
/etc/init.d/postgresql start
|
||||
/etc/init.d/redis-server start
|
||||
/etc/init.d/cassandra start
|
||||
#/etc/init.d/cassandra start
|
||||
/etc/init.d/mongod start
|
||||
|
||||
# create a link to data dir
|
||||
ln -s /root/code/src/github.com/cgrates/cgrates/data /usr/share/cgrates
|
||||
@@ -21,12 +19,6 @@ cd /usr/share/cgrates/storage/mysql && ./setup_cgr_db.sh root CGRateS.org
|
||||
# setup postgres
|
||||
cd /usr/share/cgrates/storage/postgres && ./setup_cgr_db.sh
|
||||
|
||||
# setup cassandra
|
||||
(sleep 20 && \
|
||||
cqlsh -u cassandra -p cassandra -e "alter user cassandra with password 'CGRateS.org';" && \
|
||||
cd /usr/share/cgrates/storage/cassandra && ./setup_cgr_db.sh cassandra CGRateS.org && \
|
||||
cd /root/cgr)&
|
||||
|
||||
#env vars
|
||||
export GOROOT=/root/go; export GOPATH=/root/code; export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
|
||||
export GO15VENDOREXPERIMENT=1
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
|
||||
--
|
||||
-- Table structure for table cdrs_primary
|
||||
--
|
||||
|
||||
drop table if exists cgrates.cdrs_primary;
|
||||
create table cgrates.cdrs_primary (
|
||||
id uuid,
|
||||
cgrid text,
|
||||
tor text,
|
||||
accid text,
|
||||
cdrhost text,
|
||||
cdrsource text,
|
||||
reqtype text,
|
||||
direction text,
|
||||
tenant text,
|
||||
category text,
|
||||
account text,
|
||||
subject text,
|
||||
destination text,
|
||||
setup_time timestamp,
|
||||
pdd decimal,
|
||||
answer_time timestamp,
|
||||
usage decimal,
|
||||
supplier text,
|
||||
disconnect_cause text,
|
||||
created_at timestamp,
|
||||
deleted_at timestamp,
|
||||
PRIMARY KEY (id, cgrid),
|
||||
);
|
||||
|
||||
--
|
||||
-- Table structure for table cdrs_extra
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS cgrates.cdrs_extra;
|
||||
CREATE TABLE cgrates.cdrs_extra (
|
||||
id uuid,
|
||||
cgrid text,
|
||||
extra_fields text,
|
||||
created_at timestamp,
|
||||
deleted_at timestamp,
|
||||
PRIMARY KEY (id, cgrid),
|
||||
);
|
||||
|
||||
--
|
||||
-- Table structure for table cost_details
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS cgrates.cost_details;
|
||||
CREATE TABLE cgrates.cost_details (
|
||||
id uuid,
|
||||
cgrid text,
|
||||
runid text,
|
||||
tor text,
|
||||
direction text,
|
||||
tenant text,
|
||||
category text,
|
||||
account text,
|
||||
subject text,
|
||||
destination text,
|
||||
cost decimal,
|
||||
timespans text,
|
||||
cost_source text,
|
||||
created_at timestamp,
|
||||
updated_at timestamp,
|
||||
deleted_at timestamp,
|
||||
PRIMARY KEY (id, cgrid),
|
||||
);
|
||||
|
||||
--
|
||||
-- Table structure for table rated_cdrs
|
||||
--
|
||||
DROP TABLE IF EXISTS cgrates.rated_cdrs;
|
||||
CREATE TABLE cgrates.rated_cdrs (
|
||||
id uuid,
|
||||
cgrid text,
|
||||
runid text,
|
||||
reqtype text,
|
||||
direction text,
|
||||
tenant text,
|
||||
category text,
|
||||
account text,
|
||||
subject text,
|
||||
destination text,
|
||||
setup_time timestamp,
|
||||
pdd decimal,
|
||||
answer_time timestamp,
|
||||
usage decimal,
|
||||
supplier text,
|
||||
disconnect_cause text,
|
||||
cost decimal,
|
||||
extra_info text,
|
||||
created_at timestamp,
|
||||
updated_at timestamp,
|
||||
deleted_at timestamp,
|
||||
PRIMARY KEY (id, cgrid),
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS cgrates.string_index;
|
||||
CREATE TABLE cgrates.string_index (
|
||||
field text,
|
||||
value text,
|
||||
id uuid,
|
||||
PRIMARY KEY((field, value), id)
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS cgrates.decimal_index;
|
||||
CREATE TABLE cgrates.decimal_index (
|
||||
field text,
|
||||
value decimal,
|
||||
id uuid,
|
||||
PRIMARY KEY((field, value), id)
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS cgrates.time_index;
|
||||
CREATE TABLE cgrates.time_index (
|
||||
field text,
|
||||
value timestamp,
|
||||
id uuid,
|
||||
PRIMARY KEY((field, value), id)
|
||||
);
|
||||
@@ -1,6 +0,0 @@
|
||||
DROP KEYSPACE IF EXISTS cgrates;
|
||||
|
||||
create keyspace cgrates with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
|
||||
|
||||
create user cgrates with password 'CGRateS.org';
|
||||
grant all on keyspace cgrates to cgrates;
|
||||
@@ -1,27 +0,0 @@
|
||||
#! /usr/bin/env sh
|
||||
|
||||
|
||||
if test $# -lt 2; then
|
||||
echo ""
|
||||
echo "setup_cgr_db.sh <db_user> <db_password> [<db_host>]"
|
||||
echo ""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
user=$1
|
||||
pass=$2
|
||||
host=$3
|
||||
if [ -z "$3" ]; then
|
||||
host="localhost"
|
||||
fi
|
||||
cqlsh -u $user -p $pass $host -f create_db_with_users.cql
|
||||
cu=$?
|
||||
cqlsh -u $user -p $pass $host -f create_cdrs_tables.cql
|
||||
cdrt=$?
|
||||
|
||||
if [ $cu = 0 ] && [ $cdrt = 0 ]; then
|
||||
echo ""
|
||||
echo "\t+++ CGR-DB successfully set-up! +++"
|
||||
echo ""
|
||||
exit 0
|
||||
fi
|
||||
@@ -1,92 +0,0 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/gocql/gocql"
|
||||
)
|
||||
|
||||
type CassandraStorage struct {
|
||||
keyspace string
|
||||
db *gocql.Session
|
||||
ms Marshaler
|
||||
}
|
||||
|
||||
func NewCassandraStorage(addresses []string, keyspace, user, pass, mrshlerStr string) (*CassandraStorage, error) {
|
||||
cluster := gocql.NewCluster(addresses...)
|
||||
cluster.Keyspace = keyspace
|
||||
cluster.Authenticator = gocql.PasswordAuthenticator{
|
||||
Username: user,
|
||||
Password: pass,
|
||||
}
|
||||
session, err := cluster.CreateSession()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var mrshler Marshaler
|
||||
if mrshlerStr == utils.MSGPACK {
|
||||
mrshler = NewCodecMsgpackMarshaler()
|
||||
} else if mrshlerStr == utils.JSON {
|
||||
mrshler = new(JSONMarshaler)
|
||||
} else {
|
||||
return nil, fmt.Errorf("Unsupported marshaler: %v", mrshlerStr)
|
||||
}
|
||||
return &CassandraStorage{db: session, keyspace: keyspace, ms: mrshler}, nil
|
||||
}
|
||||
|
||||
func (cs *CassandraStorage) Close() {
|
||||
cs.db.Close()
|
||||
}
|
||||
|
||||
func (cs *CassandraStorage) Flush(ignore string) (err error) {
|
||||
return cs.db.Query(fmt.Sprintf("delete * from %s", cs.keyspace)).Exec()
|
||||
}
|
||||
|
||||
func (cs *CassandraStorage) SetRatedCdr(*StoredCdr) error { return nil }
|
||||
func (cs *CassandraStorage) LogCallCost(cgrid, source, runid string, cc *CallCost) error {
|
||||
if cc == nil {
|
||||
return nil
|
||||
}
|
||||
tss, err := json.Marshal(cc.Timespans)
|
||||
if err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("Error marshalling timespans to json: %v", err))
|
||||
return err
|
||||
}
|
||||
if err = cs.db.Query(fmt.Sprintf("INSERT INTO %s (cgrid,runid,tor,direction,tenant,category,account,subject,destination,cost,timespans,cost_source,created_at) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s',%f,'%s','%s','%s') tor=values(tor),direction=values(direction),tenant=values(tenant),category=values(category),account=values(account),subject=values(subject),destination=values(destination),cost=values(cost),timespans=values(timespans),cost_source=values(cost_source),updated_at='%s'",
|
||||
utils.TBL_COST_DETAILS,
|
||||
cgrid,
|
||||
runid,
|
||||
cc.TOR,
|
||||
cc.Direction,
|
||||
cc.Tenant,
|
||||
cc.Category,
|
||||
cc.Account,
|
||||
cc.Subject,
|
||||
cc.Destination,
|
||||
cc.Cost,
|
||||
tss,
|
||||
source,
|
||||
time.Now().Format(time.RFC3339),
|
||||
time.Now().Format(time.RFC3339))).Exec(); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("failed to execute insert statement: %v", err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (cs *CassandraStorage) GetCallCostLog(cgrid, source, runid string) (*CallCost, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (cs *CassandraStorage) GetStoredCdrs(*utils.CdrsFilter) ([]*StoredCdr, int64, error) {
|
||||
return nil, 0, nil
|
||||
}
|
||||
func (cs *CassandraStorage) RemStoredCdrs([]string) error { return nil }
|
||||
func (cs *CassandraStorage) LogError(uuid, source, runid, errstr string) error { return nil }
|
||||
func (cs *CassandraStorage) LogActionTrigger(ubId, source string, at *ActionTrigger, as Actions) error {
|
||||
return nil
|
||||
}
|
||||
func (cs *CassandraStorage) LogActionPlan(source string, at *ActionPlan, as Actions) error { return nil }
|
||||
Reference in New Issue
Block a user