HTTPAgent as handler via cmd/cgr-engine

This commit is contained in:
DanB
2018-06-06 12:39:54 +02:00
parent 9ca91cc401
commit 28a8a0b164
4 changed files with 79 additions and 0 deletions

47
agents/httpagent.go Normal file
View File

@@ -0,0 +1,47 @@
/*
Real-time Online/Offline Charging System (OCS) 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 agents
import (
"net/http"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/rpcclient"
)
// NewHttpAgent will construct a HttpAgent
func NewHttpAgent(sessionS rpcclient.RpcClientConnection,
timezone, reqPayload, rplyPayload string,
reqProcessors []*config.HttpAgntProcCfg) *HttpAgent {
return &HttpAgent{sessionS: sessionS, timezone: timezone,
reqPayload: reqPayload, rplyPayload: rplyPayload,
reqProcessors: reqProcessors}
}
type HttpAgent struct {
sessionS rpcclient.RpcClientConnection
timezone,
reqPayload,
rplyPayload string
reqProcessors []*config.HttpAgntProcCfg
}
// ServeHTTP implements http.Handler interface
func (ha *HttpAgent) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}

View File

@@ -350,6 +350,30 @@ func startKamAgent(internalSMGChan chan rpcclient.RpcClientConnection, exitChan
exitChan <- true
}
func startHTTPAgent(internalSMGChan chan rpcclient.RpcClientConnection, exitChan chan bool, server *utils.Server) {
utils.Logger.Info("Starting HTTP agent")
var err error
for _, agntCfg := range cfg.HttpAgentCfg() {
var sSConn *rpcclient.RpcClientPool
if len(agntCfg.SessionSConns) != 0 {
sSConn, err = engine.NewRPCPool(rpcclient.POOL_FIRST, cfg.TLSClientKey,
cfg.TLSClientCerificate, cfg.ConnectAttempts, cfg.Reconnects,
cfg.ConnectTimeout, cfg.ReplyTimeout,
agntCfg.SessionSConns, internalSMGChan, cfg.InternalTtl)
if err != nil {
utils.Logger.Crit(fmt.Sprintf("<%s> could not connect to %s, error: %s",
utils.HTTPAgent, utils.SessionS, err.Error()))
exitChan <- true
return
}
}
server.RegisterHttpHandler(agntCfg.Url,
agents.NewHttpAgent(sSConn, agntCfg.Timezone, agntCfg.RequestPayload,
agntCfg.ReplyPayload, agntCfg.RequestProcessors))
}
exitChan <- true
}
func startCDRS(internalCdrSChan chan rpcclient.RpcClientConnection,
cdrDb engine.CdrStorage, dm *engine.DataManager,
internalRaterChan, internalPubSubSChan, internalAttributeSChan, internalUserSChan, internalAliaseSChan,

View File

@@ -871,6 +871,7 @@ const (
DiameterAgent = "DiameterAgent"
FreeSWITCHAgent = "FreeSWITCHAgent"
AsteriskAgent = "AsteriskAgent"
HTTPAgent = "HTTPAgent"
)
func buildCacheInstRevPrefixes() {

View File

@@ -68,6 +68,13 @@ func (s *Server) RegisterHttpFunc(pattern string, handler func(http.ResponseWrit
s.Unlock()
}
func (s *Server) RegisterHttpHandler(pattern string, handler http.Handler) {
http.Handle(pattern, handler)
s.Lock()
s.httpEnabled = true
s.Unlock()
}
// Registers a new BiJsonRpc name
func (s *Server) BiRPCRegisterName(method string, handlerFunc interface{}) {
s.RLock()