mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 13:19:53 +05:00
ActionS - ActionProfile initial definition
This commit is contained in:
68
actions/actions.go
Normal file
68
actions/actions.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
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)
|
||||
}
|
||||
51
actions/libactions.go
Normal file
51
actions/libactions.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
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
|
||||
}
|
||||
1
data/tariffplans/tutactions/ActionProfiles.csv
Normal file
1
data/tariffplans/tutactions/ActionProfiles.csv
Normal file
@@ -0,0 +1 @@
|
||||
#Tenant,ID,FilterIDs,ActivationInterval,Weight,Schedule,AccountIDs,ActionID,ActionFilterIDs,ActionBlocker,ActionTTL,ActionType,ActionOpts,ActionPath,ActionValue
|
||||
|
55
engine/actionprofile.go
Normal file
55
engine/actionprofile.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
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
|
||||
}
|
||||
@@ -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))
|
||||
|
||||
@@ -879,6 +879,7 @@ const (
|
||||
StatsNA = -1.0
|
||||
RateProfileMatched = "RateProfileMatched"
|
||||
InvalidDuration = time.Duration(-1)
|
||||
ActionS = "ActionS"
|
||||
)
|
||||
|
||||
// Migrator Action
|
||||
|
||||
Reference in New Issue
Block a user