diff --git a/actions/actions.go b/actions/actions.go new file mode 100644 index 000000000..301a3fa23 --- /dev/null +++ b/actions/actions.go @@ -0,0 +1,68 @@ +/* +Real-time Online/Offline Charging System (OerS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +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 +*/ + +package actions + +import ( + "fmt" + + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +// NewActionS instantiates the ActionS +func NewActionS(cfg *config.CGRConfig, fltrS *engine.FilterS, dm *engine.DataManager) *ActionS { + return &ActionS{ + cfg: cfg, + fltrS: fltrS, + dm: dm, + } +} + +// ActionS manages exection of Actions +type ActionS struct { + cfg *config.CGRConfig + fltrS *engine.FilterS + dm *engine.DataManager +} + +// ListenAndServe keeps the service alive +func (aS *ActionS) ListenAndServe(stopChan, cfgRld chan struct{}) { + utils.Logger.Info(fmt.Sprintf("<%s> starting <%s>", + utils.CoreS, utils.ActionS)) + for { + select { + case <-stopChan: + return + case rld := <-cfgRld: // configuration was reloaded + cfgRld <- rld + } + } +} + +// Shutdown is called to shutdown the service +func (aS *ActionS) Shutdown() (err error) { + utils.Logger.Info(fmt.Sprintf("<%s> shutdown <%s>", utils.CoreS, utils.ActionS)) + return +} + +// Call implements rpcclient.ClientConnector interface for internal RPC +func (aS *ActionS) Call(serviceMethod string, args interface{}, reply interface{}) error { + return utils.RPCCall(aS, serviceMethod, args, reply) +} diff --git a/actions/libactions.go b/actions/libactions.go new file mode 100644 index 000000000..2866bff29 --- /dev/null +++ b/actions/libactions.go @@ -0,0 +1,51 @@ +/* +Real-time Online/Offline Charging System (OerS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +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 +*/ + +package actions + +import ( + "context" + "fmt" + + "github.com/cgrates/cgrates/utils" +) + +// Action is implemented by each action type +type actioner interface { + execute(ctx context.Context, data interface{}) (err error) +} + +// newAction is the constructor to create actioner +func newActioner(typ string) (act actioner, err error) { + switch typ { + case utils.LOG: + return new(actLog), nil + default: + return nil, fmt.Errorf("unsupported action type: <%s>", typ) + + } + return +} + +// actLogger will log data to CGRateS logger +type actLog struct{} + +// execute implements actioner interface +func (aL *actLog) execute(ctx context.Context, data interface{}) (err error) { + return +} diff --git a/data/tariffplans/tutactions/ActionProfiles.csv b/data/tariffplans/tutactions/ActionProfiles.csv new file mode 100644 index 000000000..356f74cab --- /dev/null +++ b/data/tariffplans/tutactions/ActionProfiles.csv @@ -0,0 +1 @@ +#Tenant,ID,FilterIDs,ActivationInterval,Weight,Schedule,AccountIDs,ActionID,ActionFilterIDs,ActionBlocker,ActionTTL,ActionType,ActionOpts,ActionPath,ActionValue diff --git a/engine/actionprofile.go b/engine/actionprofile.go new file mode 100644 index 000000000..d56eb6511 --- /dev/null +++ b/engine/actionprofile.go @@ -0,0 +1,55 @@ +/* +Real-time Online/Offline Charging System (OerS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +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 +*/ + +package engine + +import ( + "time" + + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/utils" +) + +// ActionProfile represents the configuration of a Action profile +type ActionProfile struct { + Tenant string + ID string + FilterIDs []string + ActivationInterval *utils.ActivationInterval + Weight float64 + Schedule string + AccountIDs utils.StringSet + + Actions []*APAction +} + +func (aP *ActionProfile) TenantID() string { + return utils.ConcatenatedKey(aP.Tenant, aP.ID) +} + +// APAction defines action related information used within a ActionProfile +type APAction struct { + ID string // Action ID + FilterIDs []string // Action FilterIDs + Blocker bool // Blocker will stop further actions running in the chain + TTL time.Duration // Cancel Action if not executed within TTL + Type string // Type of Action + Opts map[string]interface{} // Extra options to pass depending on action type + Path string // Path to execute + Value config.RSRParsers // Value to execute on path +} diff --git a/rates/rates.go b/rates/rates.go index 04f648a26..ac5994b58 100644 --- a/rates/rates.go +++ b/rates/rates.go @@ -177,28 +177,6 @@ func (rS *RateS) rateProfileCostForEvent(rtPfl *engine.RateProfile, args *utils. return } -// ArgsCostForEvent arguments used for proccess event -type ArgsCostForEvent struct { - RateProfileIDs []string - *utils.CGREventWithOpts -} - -// StartTime returns the event time used to check active rate profiles -func (args *ArgsCostForEvent) StartTime(tmz string) (sTime time.Time, err error) { - if tIface, has := args.Opts[utils.OptsRatesStartTime]; has { - return utils.IfaceAsTime(tIface, tmz) - } - return time.Now(), nil -} - -// Usage returns the event time used to check active rate profiles -func (args *ArgsCostForEvent) Usage() (usage time.Duration, err error) { - if uIface, has := args.Opts[utils.OptsRatesUsage]; has { - return utils.IfaceAsDuration(uIface) - } - return time.Duration(time.Minute), nil -} - // V1CostForEvent will be called to calculate the cost for an event func (rS *RateS) V1CostForEvent(args *utils.ArgsCostForEvent, rpCost *engine.RateProfileCost) (err error) { rPfIDs := make([]string, len(args.RateProfileIDs)) diff --git a/utils/consts.go b/utils/consts.go index eb0e150b2..97d558c90 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -879,6 +879,7 @@ const ( StatsNA = -1.0 RateProfileMatched = "RateProfileMatched" InvalidDuration = time.Duration(-1) + ActionS = "ActionS" ) // Migrator Action