From b3badde1340b1060472b3355e62c5a6381187bb0 Mon Sep 17 00:00:00 2001 From: TeoV Date: Thu, 25 Jan 2018 13:17:12 +0200 Subject: [PATCH] Replacing SM-FreeSWITCH with utils.FreeSWITCHAgent --- agents/fsagent.go | 54 ++++++++++++++++++------------------ cmd/cgr-engine/cgr-engine.go | 2 +- config/config.go | 2 +- config/libconfig_json.go | 2 +- config/smconfig.go | 6 ++-- docs/overview.rst | 3 +- 6 files changed, 34 insertions(+), 35 deletions(-) diff --git a/agents/fsagent.go b/agents/fsagent.go index e51502c9f..84a51bb5a 100644 --- a/agents/fsagent.go +++ b/agents/fsagent.go @@ -87,8 +87,8 @@ func (sm *FSSessionManager) setMaxCallDuration(uuid, connId string, uuid, int(maxDur.Seconds()), destNr, sm.cfg.EmptyBalanceContext)) if err != nil { utils.Logger.Err( - fmt.Sprintf(" Could not transfer the call to empty balance context, error: <%s>, connId: %s", - err.Error(), connId)) + fmt.Sprintf("<%s> Could not transfer the call to empty balance context, error: <%s>, connId: %s", + utils.FreeSWITCHAgent, err.Error(), connId)) return err } return nil @@ -97,8 +97,8 @@ func (sm *FSSessionManager) setMaxCallDuration(uuid, connId string, fmt.Sprintf("sched_broadcast +%d %s playback!manager_request::%s aleg\n\n", int(maxDur.Seconds()), uuid, sm.cfg.EmptyBalanceAnnFile)); err != nil { utils.Logger.Err( - fmt.Sprintf(" Could not send uuid_broadcast to freeswitch, error: <%s>, connId: %s", - err.Error(), connId)) + fmt.Sprintf("<%s> Could not send uuid_broadcast to freeswitch, error: <%s>, connId: %s", + utils.FreeSWITCHAgent, err.Error(), connId)) return err } return nil @@ -108,8 +108,8 @@ func (sm *FSSessionManager) setMaxCallDuration(uuid, connId string, uuid, int(maxDur.Seconds()))) if err != nil { utils.Logger.Err( - fmt.Sprintf(" Could not send sched_hangup command to freeswitch, error: <%s>, connId: %s", - err.Error(), connId)) + fmt.Sprintf("<%s> Could not send sched_hangup command to freeswitch, error: <%s>, connId: %s", + utils.FreeSWITCHAgent, err.Error(), connId)) return err } return nil @@ -123,15 +123,15 @@ func (sm *FSSessionManager) unparkCall(uuid, connId, call_dest_nb, notify string fmt.Sprintf("uuid_setvar %s cgr_notify %s\n\n", uuid, notify)) if err != nil { utils.Logger.Err( - fmt.Sprintf(" Could not send unpark api notification to freeswitch, error: <%s>, connId: %s", - err.Error(), connId)) + fmt.Sprintf("<%s> Could not send unpark api notification to freeswitch, error: <%s>, connId: %s", + utils.FreeSWITCHAgent, err.Error(), connId)) return } if _, err = sm.conns[connId].SendApiCmd( fmt.Sprintf("uuid_transfer %s %s\n\n", uuid, call_dest_nb)); err != nil { utils.Logger.Err( - fmt.Sprintf(" Could not send unpark api call to freeswitch, error: <%s>, connId: %s", - err.Error(), connId)) + fmt.Sprintf("<%s> Could not send unpark api call to freeswitch, error: <%s>, connId: %s", + utils.FreeSWITCHAgent, err.Error(), connId)) } return } @@ -144,8 +144,8 @@ func (sm *FSSessionManager) onChannelPark(fsev FSEvent, connId string) { var authReply sessionmanager.V1AuthorizeReply if err := sm.smg.Call(utils.SessionSv1AuthorizeEvent, authArgs, &authReply); err != nil { utils.Logger.Err( - fmt.Sprintf(" Could not authorize event %s, error: %s", - fsev.GetUUID(), err.Error())) + fmt.Sprintf("<%s> Could not authorize event %s, error: %s", + utils.FreeSWITCHAgent, fsev.GetUUID(), err.Error())) sm.unparkCall(fsev.GetUUID(), connId, fsev.GetCallDestNr(utils.META_DEFAULT), utils.ErrServerError.Error()) return @@ -217,8 +217,8 @@ func (sm *FSSessionManager) onChannelAnswer(fsev FSEvent, connId string) { if err := sm.smg.Call(utils.SessionSv1InitiateSession, initSessionArgs, &initReply); err != nil { utils.Logger.Err( - fmt.Sprintf(" could not process answer for event %s, error: %s", - chanUUID, err.Error())) + fmt.Sprintf("<%s> could not process answer for event %s, error: %s", + utils.FreeSWITCHAgent, chanUUID, err.Error())) sm.disconnectSession(connId, chanUUID, "", utils.ErrServerError.Error()) return } @@ -239,16 +239,16 @@ func (sm *FSSessionManager) onChannelHangupComplete(fsev FSEvent, connId string) if err := sm.smg.Call(utils.SessionSv1TerminateSession, fsev.V1TerminateSessionArgs(), &reply); err != nil { utils.Logger.Err( - fmt.Sprintf(" Could not terminate session with event %s, error: %s", - fsev.GetUUID(), err.Error())) + fmt.Sprintf("<%s> Could not terminate session with event %s, error: %s", + utils.FreeSWITCHAgent, fsev.GetUUID(), err.Error())) return } } if sm.cfg.CreateCdr { cdr := fsev.AsCDR(sm.timezone) if err := sm.smg.Call(utils.SessionSv1ProcessCDR, cdr, &reply); err != nil { - utils.Logger.Err(fmt.Sprintf(" Failed processing CDR, cgrid: %s, accid: %s, error: <%s>", - cdr.CGRID, cdr.OriginID, err.Error())) + utils.Logger.Err(fmt.Sprintf("<%s> Failed processing CDR, cgrid: %s, accid: %s, error: <%s>", + utils.FreeSWITCHAgent, cdr.CGRID, cdr.OriginID, err.Error())) } } } @@ -302,16 +302,16 @@ func (sm *FSSessionManager) disconnectSession(connId, uuid, redirectNr, notify s if len(sm.cfg.EmptyBalanceContext) != 0 { if _, err := sm.conns[connId].SendApiCmd(fmt.Sprintf("uuid_transfer %s %s XML %s\n\n", uuid, redirectNr, sm.cfg.EmptyBalanceContext)); err != nil { - utils.Logger.Err(fmt.Sprintf(" Could not transfer the call to empty balance context, error: <%s>, connId: %s", - err.Error(), connId)) + utils.Logger.Err(fmt.Sprintf("<%s> Could not transfer the call to empty balance context, error: <%s>, connId: %s", + utils.FreeSWITCHAgent, err.Error(), connId)) return err } return nil } else if len(sm.cfg.EmptyBalanceAnnFile) != 0 { if _, err := sm.conns[connId].SendApiCmd(fmt.Sprintf("uuid_broadcast %s playback!manager_request::%s aleg\n\n", uuid, sm.cfg.EmptyBalanceAnnFile)); err != nil { - utils.Logger.Err(fmt.Sprintf(" Could not send uuid_broadcast to freeswitch, error: <%s>, connId: %s", - err.Error(), connId)) + utils.Logger.Err(fmt.Sprintf("<%s> Could not send uuid_broadcast to freeswitch, error: <%s>, connId: %s", + utils.FreeSWITCHAgent, err.Error(), connId)) return err } return nil @@ -320,8 +320,8 @@ func (sm *FSSessionManager) disconnectSession(connId, uuid, redirectNr, notify s if err := sm.conns[connId].SendMsgCmd(uuid, map[string]string{"call-command": "hangup", "hangup-cause": "MANAGER_REQUEST"}); err != nil { utils.Logger.Err( - fmt.Sprintf(" Could not send disconect msg to freeswitch, error: <%s>, connId: %s", - err.Error(), connId)) + fmt.Sprintf("<%s> Could not send disconect msg to freeswitch, error: <%s>, connId: %s", + utils.FreeSWITCHAgent, err.Error(), connId)) return err } return nil @@ -330,12 +330,12 @@ func (sm *FSSessionManager) disconnectSession(connId, uuid, redirectNr, notify s func (sm *FSSessionManager) Shutdown() (err error) { for connId, fSock := range sm.conns { if !fSock.Connected() { - utils.Logger.Err(fmt.Sprintf(" Cannot shutdown sessions, fsock not connected for connection id: %s", connId)) + utils.Logger.Err(fmt.Sprintf("<%s> Cannot shutdown sessions, fsock not connected for connection id: %s", utils.FreeSWITCHAgent, connId)) continue } - utils.Logger.Info(fmt.Sprintf(" Shutting down all sessions on connection id: %s", connId)) + utils.Logger.Info(fmt.Sprintf("<%s> Shutting down all sessions on connection id: %s", utils.FreeSWITCHAgent, connId)) if _, err = fSock.SendApiCmd("hupall MANAGER_REQUEST cgr_reqtype *prepaid"); err != nil { - utils.Logger.Err(fmt.Sprintf(" Error on calls shutdown: %s, connection id: %s", err.Error(), connId)) + utils.Logger.Err(fmt.Sprintf("<%s> Error on calls shutdown: %s, connection id: %s", utils.FreeSWITCHAgent, err.Error(), connId)) } } return diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index 72a2554d9..c44a33720 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -898,7 +898,7 @@ func main() { go startSessionS(internalSMGChan, internalRaterChan, internalRsChan, internalSupplierSChan, internalAttributeSChan, internalCdrSChan, server, exitChan) } - // Start SM-FreeSWITCH + // Start FreeSWITCHAgent if cfg.FsAgentCfg().Enabled { go startFsAgent(internalSMGChan, exitChan) // close all sessions on shutdown diff --git a/config/config.go b/config/config.go index cbdf9f663..f8fa9f1b6 100755 --- a/config/config.go +++ b/config/config.go @@ -511,7 +511,7 @@ func (self *CGRConfig) checkConfigSanity() error { } if connCfg.Address == utils.MetaInternal && !self.sessionSCfg.Enabled { - return errors.New("SMGeneric not enabled but referenced by SM-FreeSWITCH") + return errors.New("SMGeneric not enabled but referenced by FreeSWITCHAgent") } } } diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 90880e410..89e5b2cb5 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -214,7 +214,7 @@ type SessionSJsonCfg struct { Client_protocol *float64 } -// SM-FreeSWITCH config section +// FreeSWITCHAgent config section type FreeswitchAgentJsonCfg struct { Enabled *bool Sessions_conns *[]*HaPoolJsonCfg diff --git a/config/smconfig.go b/config/smconfig.go index b2bfd3a91..dbc9f1775 100644 --- a/config/smconfig.go +++ b/config/smconfig.go @@ -24,7 +24,7 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Returns the first cached default value for a SM-FreeSWITCH connection +// Returns the first cached default value for a FreeSWITCHAgent connection func NewDfltHaPoolConfig() *HaPoolConfig { if dfltHaPoolConfig == nil { return new(HaPoolConfig) // No defaults, most probably we are building the defaults now @@ -56,7 +56,7 @@ func (self *HaPoolConfig) loadFromJsonCfg(jsnCfg *HaPoolJsonCfg) error { return nil } -// Returns the first cached default value for a SM-FreeSWITCH connection +// Returns the first cached default value for a FreeSWITCHAgent connection func NewDfltFsConnConfig() *FsConnConfig { if dfltFsConnConfig == nil { return new(FsConnConfig) // No defaults, most probably we are building the defaults now @@ -272,7 +272,7 @@ func (self *FsAgentConfig) loadFromJsonCfg(jsnCfg *FreeswitchAgentJsonCfg) error return nil } -// Returns the first cached default value for a SM-FreeSWITCH connection +// Returns the first cached default value for a FreeSWITCHAgent connection func NewDfltKamConnConfig() *KamConnConfig { if dfltKamConnConfig == nil { return new(KamConnConfig) // No defaults, most probably we are building the defaults now diff --git a/docs/overview.rst b/docs/overview.rst index 32cc0c874..5d78de12f 100644 --- a/docs/overview.rst +++ b/docs/overview.rst @@ -177,7 +177,7 @@ CGRateS is capable of four charging modes - Asterisk specific communication over ARI and AMI interfaces - Bidirectional (subscribing for events as well as sending commands) -2.10.3. SM-FreeSWITCH +2.10.3. FreeSWITCHAgent ~~~~~~~~~~~~~~~~~~~~~ - FreeSWITCH specific communication interface via ESL - Bidirectional (subscribing for events as well as sending commands) @@ -251,4 +251,3 @@ Packaged together due to common usage ------------------------------------- - Thresholds are monitoring CDRStatS queues and reacting by calling synchronously or asynchronously a set of predefined actions. - Various stats metrics can be monitored (min-/max- ASR, ACD, TCD, ACC, TCC, PDD, DDC) -