Consider ArgDispatcher for Agents and subsystems

This commit is contained in:
TeoV
2019-04-07 07:34:37 -04:00
committed by Dan Christian Bogos
parent 8519a40e34
commit c878c7b6e9
10 changed files with 469 additions and 20 deletions

View File

@@ -128,11 +128,33 @@ func (cS *ChargerService) processEvent(cgrEv *utils.CGREvent) (rply []*ChrgSProc
return nil, errors.New("no connection to AttributeS")
}
args := &AttrArgsProcessEvent{
AttributeIDs: cP.AttributeIDs,
Context: utils.StringPointer(utils.MetaChargers),
ProcessRuns: nil,
CGREvent: *clonedEv}
//check if we have APIKey in event and in case it has add it in ArgDispatcher
apiKeyIface, hasApiKey := clonedEv.Event[utils.MetaApiKey]
if hasApiKey {
args.ArgDispatcher = &utils.ArgDispatcher{
APIKey: utils.StringPointer(apiKeyIface.(string)),
}
}
//check if we have RouteID in event and in case it has add it in ArgDispatcher
routeIDIface, hasRouteID := clonedEv.Event[utils.MetaRouteID]
if hasRouteID {
if !hasApiKey { //in case we don't have APIKey, but we have RouteID we need to initialize the struct
args.ArgDispatcher = &utils.ArgDispatcher{
RouteID: utils.StringPointer(routeIDIface.(string)),
}
} else {
args.ArgDispatcher.RouteID = utils.StringPointer(routeIDIface.(string))
}
}
var evReply AttrSProcessEventReply
if err = cS.attrS.Call(utils.AttributeSv1ProcessEvent,
&AttrArgsProcessEvent{AttributeIDs: cP.AttributeIDs,
Context: utils.StringPointer(utils.MetaChargers), ProcessRuns: nil, CGREvent: *clonedEv},
&evReply); err != nil {
args, &evReply); err != nil {
return nil, err
}
rply[i].AttributeSProfiles = evReply.MatchedProfiles

View File

@@ -508,7 +508,7 @@ func (rS *ResourceService) matchingResourcesForEvent(ev *utils.CGREvent, usageTT
}
// processThresholds will pass the event for resource to ThresholdS
func (rS *ResourceService) processThresholds(r *Resource) (err error) {
func (rS *ResourceService) processThresholds(r *Resource, argDispatcher *utils.ArgDispatcher) (err error) {
if rS.thdS == nil {
return
}
@@ -527,6 +527,10 @@ func (rS *ResourceService) processThresholds(r *Resource) (err error) {
utils.EventType: utils.ResourceUpdate,
utils.ResourceID: r.ID,
utils.Usage: r.totalUsage()}}}
// in case we receive ArgDispatcher we add it to be used by DispatcherS
if argDispatcher != nil {
thEv.ArgDispatcher = argDispatcher
}
var tIDs []string
if err = rS.thdS.Call(utils.ThresholdSv1ProcessEvent, thEv, &tIDs); err != nil &&
err.Error() != utils.ErrNotFound.Error() {
@@ -647,7 +651,7 @@ func (rS *ResourceService) V1AllocateResource(args utils.ArgRSv1ResourceUsage, r
rS.storedResources[r.TenantID()] = true
rS.srMux.Unlock()
}
rS.processThresholds(r)
rS.processThresholds(r, args.ArgDispatcher)
}
*reply = alcMsg
return
@@ -686,7 +690,7 @@ func (rS *ResourceService) V1ReleaseResource(args utils.ArgRSv1ResourceUsage, re
rS.storedResources[r.TenantID()] = true
}
}
rS.processThresholds(r)
rS.processThresholds(r, args.ArgDispatcher)
}
if rS.storeInterval != -1 {
rS.srMux.Unlock()

View File

@@ -282,6 +282,10 @@ func (sS *StatService) processEvent(args *StatsArgsProcessEvent) (statQueueIDs [
Event: map[string]interface{}{
utils.EventType: utils.StatUpdate,
utils.StatID: sq.ID}}}
// in case we receive ArgDispatcher we add it to be used by DispatcherS
if args.ArgDispatcher != nil {
thEv.ArgDispatcher = args.ArgDispatcher
}
for metricID, metric := range sq.SQMetrics {
thEv.Event[metricID] = metric.GetValue()
}

View File

@@ -481,6 +481,10 @@ func (spS *SupplierService) V1GetSuppliers(args *ArgsGetSuppliers, reply *Sorted
Context: utils.StringPointer(utils.MetaSuppliers),
CGREvent: args.CGREvent,
}
// in case we receive ArgDispatcher we add it to be used by DispatcherS
if args.ArgDispatcher != nil {
attrArgs.ArgDispatcher = args.ArgDispatcher
}
var rplyEv AttrSProcessEventReply
if err := spS.attributeS.Call(utils.AttributeSv1ProcessEvent,
attrArgs, &rplyEv); err == nil && len(rplyEv.AlteredFields) != 0 {