mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Add cgr_max_usage variable to fsagent
This commit is contained in:
committed by
Dan Christian Bogos
parent
2137e141f6
commit
2f05395ec1
@@ -89,40 +89,45 @@ func (fsa *FSsessions) createHandlers() map[string][]func(string, int) {
|
||||
|
||||
// Sets the call timeout valid of starting of the call
|
||||
func (fsa *FSsessions) setMaxCallDuration(uuid string, connIdx int,
|
||||
maxDur time.Duration, destNr string) error {
|
||||
maxDur time.Duration, destNr string) (err error) {
|
||||
// set variable_cgr_max_usage to the fs channel
|
||||
if _, err = fsa.conns[connIdx].SendApiCmd(
|
||||
fmt.Sprintf("uuid_setvar %s %s %d \n\n",
|
||||
uuid, VarCGRMaxUsage, int(maxDur.Seconds()))); err != nil {
|
||||
utils.Logger.Err(
|
||||
fmt.Sprintf("<%s> Could not set %s variable to freeswitch channel, error: <%s>, connIdx: %v",
|
||||
utils.FreeSWITCHAgent, VarCGRMaxUsage, err.Error(), connIdx))
|
||||
return
|
||||
}
|
||||
if len(fsa.cfg.EmptyBalanceContext) != 0 {
|
||||
_, err := fsa.conns[connIdx].SendApiCmd(
|
||||
_, err = fsa.conns[connIdx].SendApiCmd(
|
||||
fmt.Sprintf("uuid_setvar %s execute_on_answer sched_transfer +%d %s XML %s\n\n",
|
||||
uuid, int(maxDur.Seconds()), destNr, fsa.cfg.EmptyBalanceContext))
|
||||
if err != nil {
|
||||
utils.Logger.Err(
|
||||
fmt.Sprintf("<%s> Could not transfer the call to empty balance context, error: <%s>, connIdx: %v",
|
||||
utils.FreeSWITCHAgent, err.Error(), connIdx))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return
|
||||
}
|
||||
if len(fsa.cfg.EmptyBalanceAnnFile) != 0 {
|
||||
if _, err := fsa.conns[connIdx].SendApiCmd(
|
||||
if _, err = fsa.conns[connIdx].SendApiCmd(
|
||||
fmt.Sprintf("sched_broadcast +%d %s playback!manager_request::%s aleg\n\n",
|
||||
int(maxDur.Seconds()), uuid, fsa.cfg.EmptyBalanceAnnFile)); err != nil {
|
||||
utils.Logger.Err(
|
||||
fmt.Sprintf("<%s> Could not send uuid_broadcast to freeswitch, error: <%s>, connIdx: %v",
|
||||
utils.FreeSWITCHAgent, err.Error(), connIdx))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return
|
||||
}
|
||||
_, err := fsa.conns[connIdx].SendApiCmd(
|
||||
if _, err = fsa.conns[connIdx].SendApiCmd(
|
||||
fmt.Sprintf("uuid_setvar %s execute_on_answer sched_hangup +%d alloted_timeout\n\n",
|
||||
uuid, int(maxDur.Seconds())))
|
||||
if err != nil {
|
||||
uuid, int(maxDur.Seconds()))); err != nil {
|
||||
utils.Logger.Err(
|
||||
fmt.Sprintf("<%s> Could not send sched_hangup command to freeswitch, error: <%s>, connIdx: %v",
|
||||
utils.FreeSWITCHAgent, err.Error(), connIdx))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
// Sends the transfer command to unpark the call to freeswitch
|
||||
|
||||
@@ -75,6 +75,7 @@ const (
|
||||
VarAnswerEpoch = "variable_answer_epoch"
|
||||
VarCGRACD = varPrefix + utils.CgrAcd
|
||||
VarCGROriginHost = varPrefix + utils.CGROriginHost
|
||||
VarCGRMaxUsage = "cgr_max_usage"
|
||||
)
|
||||
|
||||
func NewFSEvent(strEv string) (fsev FSEvent) {
|
||||
|
||||
@@ -2123,7 +2123,7 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(ctx *context.Context,
|
||||
|
||||
if !args.GetAttributes && !args.AuthorizeResources &&
|
||||
!args.GetMaxUsage && !args.GetRoutes {
|
||||
return utils.NewErrMandatoryIeMissing("subsystems")
|
||||
return utils.NewErrMandatoryIeMissing(utils.Subsystems)
|
||||
}
|
||||
if args.GetAttributes {
|
||||
rplyAttr, err := sS.processAttributes(args.CGREvent, args.AttributeIDs, false)
|
||||
@@ -2409,7 +2409,7 @@ func (sS *SessionS) BiRPCv1InitiateSession(ctx *context.Context,
|
||||
// end of RPC caching
|
||||
|
||||
if !args.GetAttributes && !args.AllocateResources && !args.InitSession {
|
||||
return utils.NewErrMandatoryIeMissing("subsystems")
|
||||
return utils.NewErrMandatoryIeMissing(utils.Subsystems)
|
||||
}
|
||||
originID, _ := args.CGREvent.FieldAsString(utils.OriginID)
|
||||
if args.GetAttributes {
|
||||
@@ -2650,7 +2650,7 @@ func (sS *SessionS) BiRPCv1UpdateSession(ctx *context.Context,
|
||||
// end of RPC caching
|
||||
|
||||
if !args.GetAttributes && !args.UpdateSession {
|
||||
return utils.NewErrMandatoryIeMissing("subsystems")
|
||||
return utils.NewErrMandatoryIeMissing(utils.Subsystems)
|
||||
}
|
||||
|
||||
if args.GetAttributes {
|
||||
@@ -2795,7 +2795,7 @@ func (sS *SessionS) BiRPCv1TerminateSession(ctx *context.Context,
|
||||
}
|
||||
// end of RPC caching
|
||||
if !args.TerminateSession && !args.ReleaseResources {
|
||||
return utils.NewErrMandatoryIeMissing("subsystems")
|
||||
return utils.NewErrMandatoryIeMissing(utils.Subsystems)
|
||||
}
|
||||
|
||||
ev := engine.MapEvent(args.CGREvent.Event)
|
||||
|
||||
@@ -2453,7 +2453,7 @@ func TestBiRPCv1AuthorizeEvent(t *testing.T) {
|
||||
args.CGREvent = cgrEvent
|
||||
//RPC caching
|
||||
sessions.cgrCfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = -1
|
||||
expected = "MANDATORY_IE_MISSING: [subsystems]"
|
||||
expected = "MANDATORY_IE_MISSING: [Subsystems]"
|
||||
|
||||
caches := engine.NewCacheS(cfg, dm, nil)
|
||||
value := &utils.CachedRPCResponse{
|
||||
@@ -2900,7 +2900,7 @@ func TestBiRPCv1InitiateSession1(t *testing.T) {
|
||||
args = NewV1InitSessionArgs(false, []string{},
|
||||
false, []string{}, false, []string{}, false, false,
|
||||
cgrEvent, true)
|
||||
expected = "MANDATORY_IE_MISSING: [subsystems]"
|
||||
expected = "MANDATORY_IE_MISSING: [Subsystems]"
|
||||
if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
@@ -3211,7 +3211,7 @@ func TestBiRPCv1UpdateSession1(t *testing.T) {
|
||||
|
||||
args = NewV1UpdateSessionArgs(false, []string{}, false,
|
||||
cgrEvent, true)
|
||||
expected = "MANDATORY_IE_MISSING: [subsystems]"
|
||||
expected = "MANDATORY_IE_MISSING: [Subsystems]"
|
||||
if err := sessions.BiRPCv1UpdateSession(context.Background(), args, rply); err == nil || err.Error() != expected {
|
||||
t.Errorf("Exepected %+v, received %+v", expected, err)
|
||||
}
|
||||
@@ -3346,7 +3346,7 @@ func TestBiRPCv1TerminateSession1(t *testing.T) {
|
||||
|
||||
cgrEvent.ID = utils.EmptyString
|
||||
args = NewV1TerminateSessionArgs(false, false, false, nil, false, nil, cgrEvent, true)
|
||||
expected = "MANDATORY_IE_MISSING: [subsystems]"
|
||||
expected = "MANDATORY_IE_MISSING: [Subsystems]"
|
||||
if err := sessions.BiRPCv1TerminateSession(context.Background(), args, &reply); err == nil || err.Error() != expected {
|
||||
t.Errorf("Exepected %+v, received %+v", expected, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user