mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Connect to dispatcher only when the call is made
This commit is contained in:
committed by
Dan Christian Bogos
parent
f14a704691
commit
a9d7b0698c
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/ltcache"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -2171,16 +2170,6 @@ func (dm *DataManager) GetDispatcherHost(tenant, id string, cacheRead, cacheWrit
|
||||
}
|
||||
}
|
||||
if cacheWrite {
|
||||
cfg := config.CgrConfig()
|
||||
if dH.rpcConn, err = NewRPCPool( // send it wil lazy connect on true and try to connect only when the call is make
|
||||
rpcclient.PoolFirst,
|
||||
cfg.TlsCfg().ClientKey,
|
||||
cfg.TlsCfg().ClientCerificate, cfg.TlsCfg().CaCertificate,
|
||||
cfg.GeneralCfg().ConnectAttempts, cfg.GeneralCfg().Reconnects,
|
||||
cfg.GeneralCfg().ConnectTimeout, cfg.GeneralCfg().ReplyTimeout,
|
||||
dH.Conns, IntRPC.GetInternalChanel(), true); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
Cache.Set(utils.CacheDispatcherHosts, tntID, dH, nil,
|
||||
cacheCommit(transactionID), transactionID)
|
||||
}
|
||||
|
||||
@@ -138,9 +138,18 @@ func (dH *DispatcherHost) TenantID() string {
|
||||
}
|
||||
|
||||
// GetRPCConnection builds or returns the cached connection
|
||||
func (dH *DispatcherHost) Call(serviceMethod string, args interface{}, reply interface{}) error {
|
||||
func (dH *DispatcherHost) Call(serviceMethod string, args interface{}, reply interface{}) (err error) {
|
||||
if dH.rpcConn == nil {
|
||||
return utils.ErrNotConnected
|
||||
cfg := config.CgrConfig()
|
||||
if dH.rpcConn, err = NewRPCPool(
|
||||
rpcclient.PoolFirst,
|
||||
cfg.TlsCfg().ClientKey,
|
||||
cfg.TlsCfg().ClientCerificate, cfg.TlsCfg().CaCertificate,
|
||||
cfg.GeneralCfg().ConnectAttempts, cfg.GeneralCfg().Reconnects,
|
||||
cfg.GeneralCfg().ConnectTimeout, cfg.GeneralCfg().ReplyTimeout,
|
||||
dH.Conns, IntRPC.GetInternalChanel(), false); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dH.rpcConn.Call(serviceMethod, args, reply)
|
||||
}
|
||||
|
||||
@@ -245,9 +245,6 @@ func TestDispatcherHostCall(t *testing.T) {
|
||||
reply: utils.StringPointer(""),
|
||||
}
|
||||
var reply string
|
||||
if err := dspHost.Call(utils.AttributeSv1Ping, &utils.CGREvent{}, &reply); err == nil || err.Error() != utils.ErrNotConnected.Error() {
|
||||
t.Errorf("Expected: %s , received: %v", utils.ErrNotConnected.Error(), err)
|
||||
}
|
||||
dspHost.rpcConn = tRPC
|
||||
if err := dspHost.Call(utils.AttributeSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"net"
|
||||
"net/rpc"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -244,11 +243,10 @@ func IsNetworkError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
if operr, ok := err.(*net.OpError); ok &&
|
||||
(strings.HasSuffix(operr.Err.Error(),
|
||||
syscall.ECONNRESET.Error()) ||
|
||||
(strings.HasSuffix(operr.Err.Error(),
|
||||
syscall.ECONNREFUSED.Error()))) { // connection reset
|
||||
if _, isNetError := err.(*net.OpError); isNetError { // connection reset
|
||||
return true
|
||||
}
|
||||
if _, isDNSError := err.(*net.DNSError); isDNSError {
|
||||
return true
|
||||
}
|
||||
return err.Error() == rpc.ErrShutdown.Error() ||
|
||||
@@ -256,8 +254,7 @@ func IsNetworkError(err error) bool {
|
||||
err.Error() == ErrDisconnected.Error() ||
|
||||
err.Error() == ErrReplyTimeout.Error() ||
|
||||
err.Error() == ErrSessionNotFound.Error() ||
|
||||
strings.HasPrefix(err.Error(), "rpc: can't find service") ||
|
||||
strings.HasSuffix(err.Error(), "no such host")
|
||||
strings.HasPrefix(err.Error(), "rpc: can't find service")
|
||||
}
|
||||
|
||||
func ErrPathNotReachable(path string) error {
|
||||
|
||||
Reference in New Issue
Block a user