apier V1 tests passing

This commit is contained in:
Radu Ioan Fericean
2016-08-14 19:40:50 +03:00
parent fe0341aeec
commit 5a26a89b7e
4 changed files with 20 additions and 100 deletions

View File

@@ -20,7 +20,6 @@ package v1
import (
"errors"
"log"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
@@ -75,7 +74,7 @@ func (self *ApierV1) RemRatingSubjectAliases(tenantRatingSubject engine.TenantRa
return utils.NewErrServerError(err)
}
var ignr string
log.Print("RVAL: ", reverseAliases)
// log.Print("RVAL: ", reverseAliases)
for _, aliass := range reverseAliases {
for _, alias := range aliass {
if alias.Tenant != tenantRatingSubject.Tenant {

View File

@@ -1,63 +0,0 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2012-2015 ITsysCOM
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package console
import "github.com/cgrates/cgrates/engine"
func init() {
c := &CmdRemoveReverseAliases{
name: "aliases_reverse_remove",
rpcMethod: "AliasesV1.RemoveReverseAlias",
rpcParams: &engine.AttrReverseAlias{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdRemoveReverseAliases struct {
name string
rpcMethod string
rpcParams *engine.AttrReverseAlias
*CommandExecuter
}
func (self *CmdRemoveReverseAliases) Name() string {
return self.name
}
func (self *CmdRemoveReverseAliases) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdRemoveReverseAliases) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &engine.AttrReverseAlias{}
}
return self.rpcParams
}
func (self *CmdRemoveReverseAliases) PostprocessRpcParams() error {
return nil
}
func (self *CmdRemoveReverseAliases) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -6,7 +6,6 @@ import (
"strings"
"sync"
"github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/rpcclient"
)
@@ -174,6 +173,10 @@ func (am *AliasHandler) SetAlias(attr *AttrAddAlias, reply *string) error {
*reply = err.Error()
return err
}
if err := am.accountingDb.SetReverseAlias(attr.Alias); err != nil {
*reply = err.Error()
return err
}
} else {
for _, value := range attr.Alias.Values {
found := false
@@ -203,11 +206,15 @@ func (am *AliasHandler) SetAlias(attr *AttrAddAlias, reply *string) error {
*reply = err.Error()
return err
}
// FIXME!!!!
err := am.accountingDb.UpdateReverseAlias(oldAlias, oldAlias)
if err != nil {
if err := am.accountingDb.SetReverseAlias(oldAlias); err != nil {
*reply = err.Error()
return err
}
//FIXME: optimize by creating better update reverse alias
/*err := am.accountingDb.UpdateReverseAlias(oldAlias, oldAlias)
if err != nil {
return err
}*/
}
*reply = utils.OK
@@ -225,29 +232,6 @@ func (am *AliasHandler) RemoveAlias(al *Alias, reply *string) error {
return nil
}
func (am *AliasHandler) RemoveReverseAlias(attr *AttrReverseAlias, reply *string) error {
am.mu.Lock()
defer am.mu.Unlock()
rKey := utils.REVERSE_ALIASES_PREFIX + attr.Alias + attr.Target + attr.Context
if x, ok := cache2go.Get(rKey); ok {
existingKeys := x.(map[interface{}]struct{})
for iKey := range existingKeys {
key := iKey.(string)
// get destination id
elems := strings.Split(key, utils.CONCATENATED_KEY_SEP)
if len(elems) > 0 {
key = strings.Join(elems[:len(elems)-1], utils.CONCATENATED_KEY_SEP)
}
if err := am.accountingDb.RemoveAlias(key); err != nil {
*reply = err.Error()
return err
}
}
}
*reply = utils.OK
return nil
}
func (am *AliasHandler) GetAlias(al *Alias, result *Alias) error {
am.mu.RLock()
defer am.mu.RUnlock()
@@ -265,10 +249,9 @@ func (am *AliasHandler) GetReverseAlias(attr *AttrReverseAlias, result *map[stri
am.mu.Lock()
defer am.mu.Unlock()
aliases := make(map[string][]*Alias)
rKey := utils.REVERSE_ALIASES_PREFIX + attr.Alias + attr.Target + attr.Context
if x, ok := cache2go.Get(rKey); ok {
existingKeys := x.(map[string]struct{})
for key := range existingKeys {
rKey := attr.Alias + attr.Target + attr.Context
if ids, err := am.accountingDb.GetReverseAlias(rKey, false); err == nil {
for _, key := range ids {
// get destination id
elems := strings.Split(key, utils.CONCATENATED_KEY_SEP)
var destID string

View File

@@ -726,12 +726,11 @@ func (rs *RedisStorage) GetReverseAlias(reverseID string, skipCache bool) (ids [
return nil, utils.ErrNotFound
}
}
var values []string
if values, err = rs.db.Cmd("SMEMBERS", key).List(); len(values) == 0 || err != nil {
if ids, err = rs.db.Cmd("SMEMBERS", key).List(); len(ids) == 0 || err != nil {
cache2go.Set(key, nil)
return nil, utils.ErrNotFound
}
cache2go.Set(key, values)
cache2go.Set(key, ids)
return
}
@@ -787,7 +786,9 @@ func (rs *RedisStorage) RemoveAlias(id string) (err error) {
}
func (rs *RedisStorage) UpdateReverseAlias(oldAl, newAl *Alias) error {
// FIXME: thi can be optimized
cache2go.RemPrefixKey(utils.REVERSE_ALIASES_PREFIX)
rs.SetReverseAlias(newAl)
return nil
}