Consider context ( for Attributes ) and subsystems ( for Dispatchers ) in case IndexSelects is false

This commit is contained in:
TeoV
2020-07-14 16:26:26 +03:00
committed by Dan Christian Bogos
parent 61c2fccd34
commit 328777c0ba
4 changed files with 71 additions and 89 deletions

View File

@@ -1,88 +0,0 @@
{
// CGRateS Configuration file
"general": {
"log_level": 7,
"reply_timeout": "30s",
},
"listen": {
"rpc_json": ":2012",
"rpc_gob": ":2013",
"http": ":2080",
},
"data_db": {
"db_type": "*internal",
},
"stor_db": {
"db_type": "*internal",
},
"rals": {
"enabled": true,
"thresholds_conns": ["*internal"],
},
"schedulers": {
"enabled": true,
},
"cdrs": {
"enabled": true,
},
"resources": {
"enabled": true,
"store_interval": "1s",
"thresholds_conns": ["*internal"]
},
"stats": {
"enabled": true,
"store_interval": "1s",
"thresholds_conns": ["*internal"],
},
"thresholds": {
"enabled": true,
"store_interval": "1s",
},
"routes": {
"enabled": true,
},
"attributes": { // Attribute service
"enabled": true, // starts Attribute service: <true|false>.
},
"sessions": {
"enabled": true,
},
"migrator": {
"out_datadb_type": "internal",
"out_stordb_type": "internal",
},
"apiers": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
}

View File

@@ -147,6 +147,10 @@ func (dS *DispatcherService) dispatcherProfileForEvent(ev *utils.CGREvent,
}
continue
}
if !(len(prfl.Subsystems) == 1 && prfl.Subsystems[0] == utils.META_ANY) &&
!utils.IsSliceMember(prfl.Subsystems, subsys) {
continue
}
if prfl.ActivationInterval != nil && ev.Time != nil &&
!prfl.ActivationInterval.IsActiveAtTime(*ev.Time) { // not active
continue

View File

@@ -107,6 +107,10 @@ func (alS *AttributeService) attributeProfileForEvent(args *AttrArgsProcessEvent
}
return nil, err
}
if !(len(aPrfl.Contexts) == 1 && aPrfl.Contexts[0] == utils.META_ANY) &&
!utils.IsSliceMember(aPrfl.Contexts, contextVal) {
continue
}
if aPrfl.ActivationInterval != nil && args.Time != nil &&
!aPrfl.ActivationInterval.IsActiveAtTime(*args.Time) { // not active
continue

View File

@@ -152,7 +152,6 @@ func TestAttributePopulateAttrService(t *testing.T) {
defaultCfg.AttributeSCfg().ProcessRuns = 1
defaultCfg.AttributeSCfg().StringIndexedFields = nil
defaultCfg.AttributeSCfg().PrefixIndexedFields = nil
defaultCfg.AttributeSCfg().PrefixIndexedFields = nil
data := NewInternalDB(nil, nil, true, defaultCfg.DataDbCfg().Items)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
attrService, err = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
@@ -2387,3 +2386,66 @@ func TestProcessAttributeUnixTimeStamp(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eRply), utils.ToJSON(rcv))
}
}
func TestAttributeIndexSelectsFalse(t *testing.T) {
// change the IndexedSelects to false
defaultCfg, _ := config.NewDefaultCGRConfig()
defaultCfg.AttributeSCfg().ProcessRuns = 1
defaultCfg.AttributeSCfg().StringIndexedFields = nil
defaultCfg.AttributeSCfg().PrefixIndexedFields = nil
defaultCfg.AttributeSCfg().IndexedSelects = false
data := NewInternalDB(nil, nil, true, defaultCfg.DataDbCfg().Items)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
attrService, err = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
if err != nil {
t.Errorf("Error: %+v", err)
}
//refresh the DM
if err := dmAtr.DataDB().Flush(""); err != nil {
t.Error(err)
}
if test, err := dmAtr.DataDB().IsDBEmpty(); err != nil {
t.Error(err)
} else if test != true {
t.Errorf("\nExpecting: true got :%+v", test)
}
attrPrf := &AttributeProfile{
Tenant: "cgrates.org",
ID: "AttrPrf",
Contexts: []string{utils.MetaCDRs},
FilterIDs: []string{"*string:~*req.Account:1007"},
ActivationInterval: &utils.ActivationInterval{
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
ExpiryTime: expTimeAttributes,
},
Attributes: []*Attribute{
{
Path: utils.MetaReq + utils.NestingSep + utils.Account,
Value: config.NewRSRParsersMustCompile("1010", utils.INFIELD_SEP),
},
},
Weight: 20,
}
if err := dmAtr.SetAttributeProfile(attrPrf, true); err != nil {
t.Error(err)
}
attrArgs := &AttrArgsProcessEvent{
Context: utils.StringPointer(utils.MetaSessionS),
ProcessRuns: utils.IntPointer(1),
CGREvent: &utils.CGREvent{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: utils.GenUUID(),
Event: map[string]interface{}{
"Account": "1007",
},
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(attrArgs, &reply); err == nil || err != utils.ErrNotFound {
t.Errorf("Expected not found, reveiced: %+v", err)
}
}