mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated AttributeS
This commit is contained in:
committed by
Dan Christian Bogos
parent
8ea5446df4
commit
82c64e22b7
@@ -806,10 +806,7 @@ func startAttributeService(internalAttributeSChan chan rpcclient.RpcClientConnec
|
||||
<-cacheS.GetPrecacheChannel(utils.CacheAttributeProfiles)
|
||||
<-cacheS.GetPrecacheChannel(utils.CacheAttributeFilterIndexes)
|
||||
|
||||
aS, err := engine.NewAttributeService(dm, filterS,
|
||||
cfg.AttributeSCfg().StringIndexedFields,
|
||||
cfg.AttributeSCfg().PrefixIndexedFields,
|
||||
cfg.AttributeSCfg().ProcessRuns)
|
||||
aS, err := engine.NewAttributeService(dm, filterS, cfg)
|
||||
if err != nil {
|
||||
utils.Logger.Crit(
|
||||
fmt.Sprintf("<%s> Could not init, error: %s",
|
||||
|
||||
@@ -1148,7 +1148,10 @@ func (cfg *CGRConfig) DNSAgentCfg() *DNSAgentCfg {
|
||||
return cfg.dnsAgentCfg
|
||||
}
|
||||
|
||||
// AttributeSCfg returns the config for AttributeS
|
||||
func (cfg *CGRConfig) AttributeSCfg() *AttributeSCfg {
|
||||
cfg.lks[ATTRIBUTE_JSN].Lock()
|
||||
defer cfg.lks[ATTRIBUTE_JSN].Unlock()
|
||||
return cfg.attributeSCfg
|
||||
}
|
||||
|
||||
|
||||
@@ -28,20 +28,18 @@ import (
|
||||
)
|
||||
|
||||
func NewAttributeService(dm *DataManager, filterS *FilterS,
|
||||
stringIndexedFields, prefixIndexedFields *[]string,
|
||||
processRuns int) (*AttributeService, error) {
|
||||
return &AttributeService{dm: dm, filterS: filterS,
|
||||
stringIndexedFields: stringIndexedFields,
|
||||
prefixIndexedFields: prefixIndexedFields,
|
||||
processRuns: processRuns}, nil
|
||||
cgrcfg *config.CGRConfig) (*AttributeService, error) {
|
||||
return &AttributeService{
|
||||
dm: dm,
|
||||
filterS: filterS,
|
||||
cgrcfg: cgrcfg,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type AttributeService struct {
|
||||
dm *DataManager
|
||||
filterS *FilterS
|
||||
stringIndexedFields *[]string
|
||||
prefixIndexedFields *[]string
|
||||
processRuns int
|
||||
dm *DataManager
|
||||
filterS *FilterS
|
||||
cgrcfg *config.CGRConfig
|
||||
}
|
||||
|
||||
// ListenAndServe will initialize the service
|
||||
@@ -70,13 +68,13 @@ func (alS *AttributeService) attributeProfileForEvent(args *AttrArgsProcessEvent
|
||||
if len(args.AttributeIDs) != 0 {
|
||||
attrIDs = args.AttributeIDs
|
||||
} else {
|
||||
aPrflIDs, err := MatchingItemIDsForEvent(args.Event, alS.stringIndexedFields, alS.prefixIndexedFields,
|
||||
aPrflIDs, err := MatchingItemIDsForEvent(args.Event, alS.cgrcfg.AttributeSCfg().StringIndexedFields, alS.cgrcfg.AttributeSCfg().PrefixIndexedFields,
|
||||
alS.dm, utils.CacheAttributeFilterIndexes, attrIdxKey, alS.filterS.cfg.AttributeSCfg().IndexedSelects)
|
||||
if err != nil {
|
||||
if err != utils.ErrNotFound {
|
||||
return nil, err
|
||||
}
|
||||
if aPrflIDs, err = MatchingItemIDsForEvent(args.Event, alS.stringIndexedFields, alS.prefixIndexedFields,
|
||||
if aPrflIDs, err = MatchingItemIDsForEvent(args.Event, alS.cgrcfg.AttributeSCfg().StringIndexedFields, alS.cgrcfg.AttributeSCfg().PrefixIndexedFields,
|
||||
alS.dm, utils.CacheAttributeFilterIndexes, utils.ConcatenatedKey(args.Tenant, utils.META_ANY),
|
||||
alS.filterS.cfg.AttributeSCfg().IndexedSelects); err != nil {
|
||||
return nil, err
|
||||
@@ -287,7 +285,7 @@ func (alS *AttributeService) V1ProcessEvent(args *AttrArgsProcessEvent,
|
||||
return utils.NewErrMandatoryIeMissing(utils.Event)
|
||||
}
|
||||
if args.ProcessRuns == nil || *args.ProcessRuns == 0 {
|
||||
args.ProcessRuns = utils.IntPointer(alS.processRuns)
|
||||
args.ProcessRuns = utils.IntPointer(alS.cgrcfg.AttributeSCfg().ProcessRuns)
|
||||
}
|
||||
var apiRply *AttrSProcessEventReply // aggregate response here
|
||||
for i := 0; i < *args.ProcessRuns; i++ {
|
||||
|
||||
@@ -156,10 +156,13 @@ func TestAttributePopulateAttrService(t *testing.T) {
|
||||
data, _ := NewMapStorage()
|
||||
dmAtr = NewDataManager(data)
|
||||
defaultCfg, err := config.NewDefaultCGRConfig()
|
||||
defaultCfg.AttributeSCfg().ProcessRuns = 1
|
||||
defaultCfg.AttributeSCfg().StringIndexedFields = nil
|
||||
defaultCfg.AttributeSCfg().PrefixIndexedFields = nil
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
attrService, err = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, nil, nil, 1)
|
||||
attrService, err = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
@@ -1698,10 +1701,11 @@ func BenchmarkAttributeProcessEventConstant(b *testing.B) {
|
||||
data, _ := NewMapStorage()
|
||||
dmAtr = NewDataManager(data)
|
||||
defaultCfg, err := config.NewDefaultCGRConfig()
|
||||
defaultCfg.AttributeSCfg().ProcessRuns = 1
|
||||
if err != nil {
|
||||
b.Errorf("Error: %+v", err)
|
||||
}
|
||||
attrService, err = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, nil, nil, 1)
|
||||
attrService, err = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
|
||||
if err != nil {
|
||||
b.Errorf("Error: %+v", err)
|
||||
}
|
||||
@@ -1761,10 +1765,11 @@ func BenchmarkAttributeProcessEventVariable(b *testing.B) {
|
||||
data, _ := NewMapStorage()
|
||||
dmAtr = NewDataManager(data)
|
||||
defaultCfg, err := config.NewDefaultCGRConfig()
|
||||
defaultCfg.AttributeSCfg().ProcessRuns = 1
|
||||
if err != nil {
|
||||
b.Errorf("Error: %+v", err)
|
||||
}
|
||||
attrService, err = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, nil, nil, 1)
|
||||
attrService, err = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
|
||||
if err != nil {
|
||||
b.Errorf("Error: %+v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user