ing
This commit is contained in:
parent
47d4a0b57d
commit
fb7d1ca4d6
|
@ -18,6 +18,7 @@ func NewSocketBuilder(napService *oopas.NoAuthProbeService) cwfc.SocketBuilder {
|
|||
if nil == sb.SocketBuilders {
|
||||
return nil
|
||||
}
|
||||
sb.SocketHandler = newSocketHandler(sb.napService)
|
||||
|
||||
return sb
|
||||
}
|
||||
|
@ -28,10 +29,6 @@ type SocketBuilders struct {
|
|||
napService *oopas.NoAuthProbeService
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) SocketHandler() cwfc.SocketHandler {
|
||||
return newSocketHandler(sb.napService)
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) GetRequestHeader() http.Header {
|
||||
h := sb.napService.GetRequestHeader()
|
||||
header := http.Header{}
|
||||
|
|
11
client/central/data/client.go
Normal file
11
client/central/data/client.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||
)
|
||||
|
||||
func New() oogwc.Client {
|
||||
ch := newClientHandler()
|
||||
sb := newSocketBuilder()
|
||||
return oogwc.New(ch, sb)
|
||||
}
|
|
@ -5,13 +5,12 @@ import (
|
|||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
crc "git.loafle.net/commons_go/rpc/client"
|
||||
crr "git.loafle.net/commons_go/rpc/registry"
|
||||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||
)
|
||||
|
||||
func NewClientHandler(rpcInvoker crr.RPCInvoker) oogwc.ClientHandler {
|
||||
func newClientHandler() oogwc.ClientHandler {
|
||||
ch := &ClientHandlers{}
|
||||
ch.ClientHandler = oogwc.NewClientHandler(rpcInvoker)
|
||||
ch.ClientHandler = oogwc.NewClientHandler(nil)
|
||||
|
||||
return ch
|
||||
}
|
||||
|
@ -21,11 +20,11 @@ type ClientHandlers struct {
|
|||
}
|
||||
|
||||
func (ch *ClientHandlers) Init(clientCTX crc.ClientContext) error {
|
||||
logging.Logger().Info(fmt.Sprintf("Probe: client has been initialized"))
|
||||
logging.Logger().Info(fmt.Sprintf("Probe Data: client has been initialized"))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ch *ClientHandlers) Destroy(clientCTX crc.ClientContext) {
|
||||
logging.Logger().Info(fmt.Sprintf("Probe: client has been destroyed"))
|
||||
logging.Logger().Info(fmt.Sprintf("Probe Data: client has been destroyed"))
|
||||
}
|
27
client/central/data/socket_builders.go
Normal file
27
client/central/data/socket_builders.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
||||
oopcc "git.loafle.net/overflow/overflow_probes/client/central"
|
||||
)
|
||||
|
||||
func newSocketBuilder() cwfc.SocketBuilder {
|
||||
sb := &SocketBuilders{}
|
||||
sb.SocketBuilders = oopcc.NewSocketBuilder(oocmp.HTTPEntry_Probe)
|
||||
if nil == sb.SocketBuilders {
|
||||
return nil
|
||||
}
|
||||
sb.SocketHandler = newSocketHandler()
|
||||
|
||||
return sb
|
||||
}
|
||||
|
||||
type SocketBuilders struct {
|
||||
*oopcc.SocketBuilders
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) Validate() {
|
||||
sb.SocketBuilders.Validate()
|
||||
|
||||
}
|
27
client/central/data/socket_handlers.go
Normal file
27
client/central/data/socket_handlers.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
)
|
||||
|
||||
type SocketHandlers struct {
|
||||
cwfc.SocketHandlers
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnConnect(socketContext cwfc.SocketContext, res *http.Response) {
|
||||
logging.Logger().Info(fmt.Sprintf("Probe: client has been connected res[%v]", res))
|
||||
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnDisconnect(soc cwfc.Socket) {
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: client has been disconnected soc[%v]", soc))
|
||||
|
||||
}
|
||||
|
||||
func newSocketHandler() cwfc.SocketHandler {
|
||||
return &SocketHandlers{}
|
||||
}
|
12
client/central/probe/client.go
Normal file
12
client/central/probe/client.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package probe
|
||||
|
||||
import (
|
||||
crr "git.loafle.net/commons_go/rpc/registry"
|
||||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||
)
|
||||
|
||||
func New(rpcInvoker crr.RPCInvoker) oogwc.Client {
|
||||
ch := newClientHandler(rpcInvoker)
|
||||
sb := newSocketBuilder()
|
||||
return oogwc.New(ch, sb)
|
||||
}
|
|
@ -9,7 +9,7 @@ import (
|
|||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||
)
|
||||
|
||||
func NewClientHandler(rpcInvoker crr.RPCInvoker) oogwc.ClientHandler {
|
||||
func newClientHandler(rpcInvoker crr.RPCInvoker) oogwc.ClientHandler {
|
||||
ch := &ClientHandlers{}
|
||||
ch.ClientHandler = oogwc.NewClientHandler(rpcInvoker)
|
||||
|
27
client/central/probe/socket_builders.go
Normal file
27
client/central/probe/socket_builders.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package probe
|
||||
|
||||
import (
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
||||
oopcc "git.loafle.net/overflow/overflow_probes/client/central"
|
||||
)
|
||||
|
||||
func newSocketBuilder() cwfc.SocketBuilder {
|
||||
sb := &SocketBuilders{}
|
||||
sb.SocketBuilders = oopcc.NewSocketBuilder(oocmp.HTTPEntry_Probe)
|
||||
if nil == sb.SocketBuilders {
|
||||
return nil
|
||||
}
|
||||
sb.SocketHandler = newSocketHandler()
|
||||
|
||||
return sb
|
||||
}
|
||||
|
||||
type SocketBuilders struct {
|
||||
*oopcc.SocketBuilders
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) Validate() {
|
||||
sb.SocketBuilders.Validate()
|
||||
|
||||
}
|
31
client/central/probe/socket_handlers.go
Normal file
31
client/central/probe/socket_handlers.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package probe
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
||||
"git.loafle.net/overflow/overflow_probes/config"
|
||||
)
|
||||
|
||||
type SocketHandlers struct {
|
||||
cwfc.SocketHandlers
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnConnect(socketContext cwfc.SocketContext, res *http.Response) {
|
||||
logging.Logger().Info(fmt.Sprintf("Probe: client has been connected res[%v]", res))
|
||||
|
||||
encryptionKey := res.Header.Get(oocmp.HTTPResponseHeaderKey_Probe_SetEncryptionKey)
|
||||
config.EncryptionKey = &encryptionKey
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnDisconnect(soc cwfc.Socket) {
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: client has been disconnected soc[%v]", soc))
|
||||
|
||||
}
|
||||
|
||||
func newSocketHandler() cwfc.SocketHandler {
|
||||
return &SocketHandlers{}
|
||||
}
|
35
client/central/socket_builders.go
Normal file
35
client/central/socket_builders.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package central
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
||||
oopccc "git.loafle.net/overflow/overflow_probes/commons/central/client"
|
||||
"git.loafle.net/overflow/overflow_probes/config"
|
||||
)
|
||||
|
||||
func NewSocketBuilder(entryPath string) *SocketBuilders {
|
||||
sb := &SocketBuilders{}
|
||||
sb.SocketBuilders = oopccc.NewSocketBuilder(oocmp.HTTPEntry_Probe)
|
||||
if nil == sb.SocketBuilders {
|
||||
return nil
|
||||
}
|
||||
|
||||
return sb
|
||||
}
|
||||
|
||||
type SocketBuilders struct {
|
||||
*oopccc.SocketBuilders
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) GetRequestHeader() http.Header {
|
||||
header := http.Header{}
|
||||
header.Set(oocmp.HTTPRequestHeaderKey_Probe_Method, oocmp.HTTPRequestHeaderValue_Probe_Method_Connect)
|
||||
header.Set(oocmp.HTTPRequestHeaderKey_Probe_ProbeKey, *config.Config.Probe.Key)
|
||||
return header
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) Validate() {
|
||||
sb.SocketBuilders.Validate()
|
||||
|
||||
}
|
|
@ -6,7 +6,6 @@ import (
|
|||
"git.loafle.net/commons_go/logging"
|
||||
cunu "git.loafle.net/commons_go/util/net/url"
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
|
||||
"git.loafle.net/overflow/overflow_probes/config"
|
||||
)
|
||||
|
||||
|
@ -14,7 +13,7 @@ func NewSocketBuilder(entryPath string) *SocketBuilders {
|
|||
sb := &SocketBuilders{}
|
||||
url, err := cunu.Join(config.Config.Central.URL, entryPath)
|
||||
if nil != err {
|
||||
logging.Logger().Error(fmt.Sprintf("Auth: Cannot create SocketBuilder %v", err))
|
||||
logging.Logger().Error(fmt.Sprintf("Probe: Cannot create SocketBuilder %v", err))
|
||||
return nil
|
||||
}
|
||||
sb.URL = url
|
||||
|
@ -26,3 +25,8 @@ func NewSocketBuilder(entryPath string) *SocketBuilders {
|
|||
type SocketBuilders struct {
|
||||
cwfc.SocketBuilders
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) Validate() {
|
||||
sb.SocketBuilders.Validate()
|
||||
|
||||
}
|
||||
|
|
|
@ -4,5 +4,11 @@
|
|||
"apiKey": "52abd6fd57e511e7ac52080027658d13",
|
||||
"readBufferSize": 8192,
|
||||
"writeBufferSize": 8192
|
||||
},
|
||||
"paths": {
|
||||
"root": "",
|
||||
"bin": "bin",
|
||||
"config": "config",
|
||||
"pid": "pid"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package central
|
||||
|
||||
import (
|
||||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||
)
|
||||
|
||||
type CentralManager interface {
|
||||
GetClient(name string) oogwc.Client
|
||||
}
|
||||
|
||||
type centralManager struct {
|
||||
clients map[string]oogwc.Client
|
||||
}
|
||||
|
||||
func (cm *centralManager) GetClient(entryPath string) oogwc.Client {
|
||||
return nil
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||
)
|
||||
|
||||
func NewClient(ch oogwc.ClientHandler, sb cwfc.SocketBuilder) oogwc.Client {
|
||||
|
||||
return oogwc.New(ch, sb)
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
||||
oopccc "git.loafle.net/overflow/overflow_probes/commons/central/client"
|
||||
oops "git.loafle.net/overflow/overflow_probes/service"
|
||||
)
|
||||
|
||||
func NewSocketBuilder(napService *oops.NoAuthProbeService) cwfc.SocketBuilder {
|
||||
sb := &SocketBuilders{
|
||||
napService: napService,
|
||||
}
|
||||
sb.SocketBuilders = oopccc.NewSocketBuilder(oocmp.HTTPEntry_NoAuthProbe)
|
||||
if nil == sb.SocketBuilders {
|
||||
return nil
|
||||
}
|
||||
|
||||
return sb
|
||||
}
|
||||
|
||||
type SocketBuilders struct {
|
||||
*oopccc.SocketBuilders
|
||||
|
||||
napService *oops.NoAuthProbeService
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) SocketHandler() cwfc.SocketHandler {
|
||||
return newSocketHandler(sb.napService)
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) GetRequestHeader() http.Header {
|
||||
h := sb.napService.GetRequestHeader()
|
||||
header := http.Header{}
|
||||
for k, v := range h {
|
||||
header[k] = v
|
||||
}
|
||||
|
||||
return header
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) Validate() {
|
||||
sb.SocketBuilders.Validate()
|
||||
|
||||
if nil == sb.napService {
|
||||
logging.Logger().Panic("Auth: NoAuthProbeService must be specified")
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
ooccn "git.loafle.net/overflow/overflow_commons_go/config/noauthprobe"
|
||||
oocmn "git.loafle.net/overflow/overflow_commons_go/modules/noauthprobe"
|
||||
oops "git.loafle.net/overflow/overflow_probes/service"
|
||||
)
|
||||
|
||||
type SocketHandlers struct {
|
||||
cwfc.SocketHandlers
|
||||
|
||||
napService *oops.NoAuthProbeService
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnConnect(socketContext cwfc.SocketContext, res *http.Response) {
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: client has been connected res[%v]", res))
|
||||
|
||||
switch sh.napService.Config.State() {
|
||||
case ooccn.NoAuthProbeStateTypeNotRegisterd:
|
||||
tempProbeKey := res.Header.Get(oocmn.HTTPResponseHeaderKey_NoAuthProbe_SetTempProbeKey)
|
||||
sh.napService.SetTempProbeKey(tempProbeKey)
|
||||
case ooccn.NoAuthProbeStateTypeRegisterd:
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnDisconnect(soc cwfc.Socket) {
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: client has been disconnected soc[%v]", soc))
|
||||
|
||||
}
|
||||
|
||||
func newSocketHandler(napService *oops.NoAuthProbeService) cwfc.SocketHandler {
|
||||
return &SocketHandlers{
|
||||
napService: napService,
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package file
|
||||
|
||||
import (
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||
)
|
||||
|
||||
func NewClient(ch oogwc.ClientHandler, sb cwfc.SocketBuilder) oogwc.Client {
|
||||
|
||||
return oogwc.New(ch, sb)
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package file
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
crc "git.loafle.net/commons_go/rpc/client"
|
||||
crr "git.loafle.net/commons_go/rpc/registry"
|
||||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||
)
|
||||
|
||||
func NewClientHandler(rpcInvoker crr.RPCInvoker) oogwc.ClientHandler {
|
||||
ch := &ClientHandlers{}
|
||||
ch.ClientHandler = oogwc.NewClientHandler(rpcInvoker)
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
type ClientHandlers struct {
|
||||
oogwc.ClientHandler
|
||||
}
|
||||
|
||||
func (ch *ClientHandlers) Init(clientCTX crc.ClientContext) error {
|
||||
logging.Logger().Info(fmt.Sprintf("Probe: client has been initialized"))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ch *ClientHandlers) Destroy(clientCTX crc.ClientContext) {
|
||||
logging.Logger().Info(fmt.Sprintf("Probe: client has been destroyed"))
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package file
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
||||
oopccc "git.loafle.net/overflow/overflow_probes/commons/central/client"
|
||||
oops "git.loafle.net/overflow/overflow_probes/service"
|
||||
)
|
||||
|
||||
func NewSocketBuilder(napService *oops.NoAuthProbeService) cwfc.SocketBuilder {
|
||||
sb := &SocketBuilders{
|
||||
napService: napService,
|
||||
}
|
||||
sb.SocketBuilders = oopccc.NewSocketBuilder(oocmp.HTTPEntry_NoAuthProbe)
|
||||
if nil == sb.SocketBuilders {
|
||||
return nil
|
||||
}
|
||||
|
||||
return sb
|
||||
}
|
||||
|
||||
type SocketBuilders struct {
|
||||
*oopccc.SocketBuilders
|
||||
|
||||
napService *oops.NoAuthProbeService
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) SocketHandler() cwfc.SocketHandler {
|
||||
return newSocketHandler(sb.napService)
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) GetRequestHeader() http.Header {
|
||||
h := sb.napService.GetRequestHeader()
|
||||
header := http.Header{}
|
||||
for k, v := range h {
|
||||
header[k] = v
|
||||
}
|
||||
|
||||
return header
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) Validate() {
|
||||
sb.SocketBuilders.Validate()
|
||||
|
||||
if nil == sb.napService {
|
||||
logging.Logger().Panic("Auth: NoAuthProbeService must be specified")
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package file
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
ooccn "git.loafle.net/overflow/overflow_commons_go/config/noauthprobe"
|
||||
oocmn "git.loafle.net/overflow/overflow_commons_go/modules/noauthprobe"
|
||||
oops "git.loafle.net/overflow/overflow_probes/service"
|
||||
)
|
||||
|
||||
type SocketHandlers struct {
|
||||
cwfc.SocketHandlers
|
||||
|
||||
napService *oops.NoAuthProbeService
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnConnect(socketContext cwfc.SocketContext, res *http.Response) {
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: client has been connected res[%v]", res))
|
||||
|
||||
switch sh.napService.Config.State() {
|
||||
case ooccn.NoAuthProbeStateTypeNotRegisterd:
|
||||
tempProbeKey := res.Header.Get(oocmn.HTTPResponseHeaderKey_NoAuthProbe_SetTempProbeKey)
|
||||
sh.napService.SetTempProbeKey(tempProbeKey)
|
||||
case ooccn.NoAuthProbeStateTypeRegisterd:
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnDisconnect(soc cwfc.Socket) {
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: client has been disconnected soc[%v]", soc))
|
||||
|
||||
}
|
||||
|
||||
func newSocketHandler(napService *oops.NoAuthProbeService) cwfc.SocketHandler {
|
||||
return &SocketHandlers{
|
||||
napService: napService,
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package probe
|
||||
|
||||
import (
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||
)
|
||||
|
||||
func NewClient(ch oogwc.ClientHandler, sb cwfc.SocketBuilder) oogwc.Client {
|
||||
|
||||
return oogwc.New(ch, sb)
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package probe
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
||||
oopccc "git.loafle.net/overflow/overflow_probes/commons/central/client"
|
||||
oops "git.loafle.net/overflow/overflow_probes/service"
|
||||
)
|
||||
|
||||
func NewSocketBuilder(napService *oops.NoAuthProbeService) cwfc.SocketBuilder {
|
||||
sb := &SocketBuilders{
|
||||
napService: napService,
|
||||
}
|
||||
sb.SocketBuilders = oopccc.NewSocketBuilder(oocmp.HTTPEntry_Probe)
|
||||
if nil == sb.SocketBuilders {
|
||||
return nil
|
||||
}
|
||||
|
||||
return sb
|
||||
}
|
||||
|
||||
type SocketBuilders struct {
|
||||
*oopccc.SocketBuilders
|
||||
|
||||
napService *oops.NoAuthProbeService
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) SocketHandler() cwfc.SocketHandler {
|
||||
return newSocketHandler(sb.napService)
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) GetRequestHeader() http.Header {
|
||||
h := sb.napService.GetRequestHeader()
|
||||
header := http.Header{}
|
||||
for k, v := range h {
|
||||
header[k] = v
|
||||
}
|
||||
|
||||
return header
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) Validate() {
|
||||
sb.SocketBuilders.Validate()
|
||||
|
||||
if nil == sb.napService {
|
||||
logging.Logger().Panic("Auth: NoAuthProbeService must be specified")
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package probe
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
ooccn "git.loafle.net/overflow/overflow_commons_go/config/noauthprobe"
|
||||
oocmn "git.loafle.net/overflow/overflow_commons_go/modules/noauthprobe"
|
||||
oops "git.loafle.net/overflow/overflow_probes/service"
|
||||
)
|
||||
|
||||
type SocketHandlers struct {
|
||||
cwfc.SocketHandlers
|
||||
|
||||
napService *oops.NoAuthProbeService
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnConnect(socketContext cwfc.SocketContext, res *http.Response) {
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: client has been connected res[%v]", res))
|
||||
|
||||
switch sh.napService.Config.State() {
|
||||
case ooccn.NoAuthProbeStateTypeNotRegisterd:
|
||||
tempProbeKey := res.Header.Get(oocmn.HTTPResponseHeaderKey_NoAuthProbe_SetTempProbeKey)
|
||||
sh.napService.SetTempProbeKey(tempProbeKey)
|
||||
case ooccn.NoAuthProbeStateTypeRegisterd:
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnDisconnect(soc cwfc.Socket) {
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: client has been disconnected soc[%v]", soc))
|
||||
|
||||
}
|
||||
|
||||
func newSocketHandler(napService *oops.NoAuthProbeService) cwfc.SocketHandler {
|
||||
return &SocketHandlers{
|
||||
napService: napService,
|
||||
}
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
package container
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
crc "git.loafle.net/commons_go/rpc/client"
|
||||
oopmcc "git.loafle.net/overflow/overflow_probes/manager/container/client"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
)
|
||||
|
||||
type ContainerManager interface {
|
||||
GetClient(name string) crc.Client
|
||||
}
|
||||
|
||||
type containerManager struct {
|
||||
containerClients map[string]*containerState
|
||||
}
|
||||
|
||||
type containerState struct {
|
||||
socketName string
|
||||
pid int
|
||||
client crc.Client
|
||||
}
|
||||
|
||||
func (cm *containerManager) GetClient(name string) crc.Client {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cm *containerManager) CheckClient(name string) bool {
|
||||
cs, ok := cm.containerClients[name]
|
||||
if !ok || nil == cs || nil == cs.client {
|
||||
return false
|
||||
}
|
||||
|
||||
stateOk := false
|
||||
if err := cs.client.Call(&stateOk, "StateService.State"); nil != err {
|
||||
logging.Logger().Error(fmt.Sprintf("Probe: Call[%s(%s)] err %v", name, "StateService.State", err))
|
||||
return false
|
||||
}
|
||||
|
||||
return stateOk
|
||||
}
|
||||
|
||||
func (cm *containerManager) ConnectClient(name string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cm *containerManager) CloseClient(name string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cm *containerManager) runProcess(name string) error {
|
||||
sockFile := uuid.NewV4().String()
|
||||
sockArg := fmt.Sprintf("-sock=\"%s\"", sockFile)
|
||||
|
||||
cmd := exec.Command("", sockArg)
|
||||
if err := cmd.Start(); nil != err {
|
||||
logging.Logger().Error(fmt.Sprintf("Probe: To run container(%s) failed err %v", name, err))
|
||||
return err
|
||||
}
|
||||
time.Sleep(time.Duration(time.Second * 2))
|
||||
|
||||
cs := &containerState{
|
||||
socketName: sockFile,
|
||||
pid: cmd.Process.Pid,
|
||||
}
|
||||
cs.client = oopmcc.New(sockFile, nil)
|
||||
// write pid file
|
||||
cm.containerClients[name] = cs
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cm *containerManager) stopProcess(name string) error {
|
||||
cs, ok := cm.containerClients[name]
|
||||
if !ok || nil == cs || nil == cs.client {
|
||||
return fmt.Errorf("Probe: Container[%s] is not exist", name)
|
||||
}
|
||||
|
||||
p, err := os.FindProcess(cs.pid)
|
||||
if nil != err {
|
||||
return err
|
||||
}
|
||||
if err = p.Kill(); nil != err {
|
||||
return err
|
||||
}
|
||||
// remove pid file
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// func (cm *containerManager) {
|
||||
|
||||
// }
|
||||
// func (cm *containerManager) {
|
||||
|
||||
// }
|
||||
// func (cm *containerManager) {
|
||||
|
||||
// }
|
|
@ -6,7 +6,10 @@ import (
|
|||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
crr "git.loafle.net/commons_go/rpc/registry"
|
||||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
||||
oopccd "git.loafle.net/overflow/overflow_probes/client/central/data"
|
||||
oopccp "git.loafle.net/overflow/overflow_probes/client/central/probe"
|
||||
"git.loafle.net/overflow/overflow_probes/service"
|
||||
)
|
||||
|
||||
func New() ProbeManager {
|
||||
|
@ -21,8 +24,6 @@ type ProbeManager interface {
|
|||
}
|
||||
|
||||
type probeManagers struct {
|
||||
cClient oogwc.Client
|
||||
|
||||
stopChan chan struct{}
|
||||
stopWg sync.WaitGroup
|
||||
}
|
||||
|
@ -32,21 +33,28 @@ func (pm *probeManagers) Start() error {
|
|||
logging.Logger().Panic("Probe: already running. Stop it before starting it again")
|
||||
}
|
||||
|
||||
rpcRegistry := crr.NewRPCRegistry()
|
||||
probeRPCRegistry := crr.NewRPCRegistry()
|
||||
probeRPCRegistry.RegisterService(&service.CentralService{}, "")
|
||||
probeRPCRegistry.RegisterService(&service.ConfigService{}, "")
|
||||
probeRPCRegistry.RegisterService(&service.CrawlerService{}, "")
|
||||
probeRPCRegistry.RegisterService(&service.DiscoveryService{}, "")
|
||||
probeRPCRegistry.RegisterService(&service.LogService{}, "")
|
||||
probeRPCRegistry.RegisterService(&service.ProbeService{}, "")
|
||||
probeRPCRegistry.RegisterService(&service.SensorService{}, "")
|
||||
|
||||
// napService := &oopar.NoAuthProbeService{
|
||||
// DoneChan: pm.serviceDoneChan,
|
||||
// ConfigPath: pm.configPath,
|
||||
// Config: pm.config,
|
||||
// }
|
||||
// rpcRegistry.RegisterService(napService, "")
|
||||
centralProbeClient := oopccp.New(probeRPCRegistry)
|
||||
if err := centralProbeClient.Connect(); nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
// ch := client.NewClientHandler(rpcRegistry)
|
||||
// sb := client.NewSocketBuilder(napService)
|
||||
// if nil == sb {
|
||||
// return fmt.Errorf("Auth: Cannot create SocketBuilder")
|
||||
// }
|
||||
// pm.cClient = client.NewClient(ch, sb)
|
||||
centralDataClient := oopccd.New()
|
||||
if err := centralDataClient.Connect(); nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
centralS := probeRPCRegistry.GetService("CentralService").(*service.CentralService)
|
||||
centralS.PutClient(oocmp.HTTPEntry_Probe, centralProbeClient)
|
||||
centralS.PutClient(oocmp.HTTPEntry_Data, centralDataClient)
|
||||
|
||||
pm.stopChan = make(chan struct{})
|
||||
|
||||
|
@ -58,28 +66,28 @@ func (pm *probeManagers) Start() error {
|
|||
|
||||
func (pm *probeManagers) Stop() {
|
||||
if pm.stopChan == nil {
|
||||
logging.Logger().Warn("Auth: auth must be started before stopping it")
|
||||
logging.Logger().Warn("Probe: probe must be started before stopping it")
|
||||
}
|
||||
close(pm.stopChan)
|
||||
pm.stopWg.Wait()
|
||||
pm.stopChan = nil
|
||||
|
||||
pm.cClient.Close()
|
||||
// pm.cClient.Close()
|
||||
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: stopped"))
|
||||
logging.Logger().Info(fmt.Sprintf("Probe: stopped"))
|
||||
|
||||
}
|
||||
|
||||
func (pm *probeManagers) handleProbe() {
|
||||
var err error
|
||||
// var err error
|
||||
defer func() {
|
||||
pm.stopWg.Done()
|
||||
pm.Stop()
|
||||
}()
|
||||
|
||||
if err = pm.cClient.Connect(); nil != err {
|
||||
return
|
||||
}
|
||||
// if err = pm.cClient.Connect(); nil != err {
|
||||
// return
|
||||
// }
|
||||
|
||||
for {
|
||||
select {
|
||||
|
|
55
service/CentralService.go
Normal file
55
service/CentralService.go
Normal file
|
@ -0,0 +1,55 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||
)
|
||||
|
||||
type CentralService struct {
|
||||
clients map[string]oogwc.Client
|
||||
}
|
||||
|
||||
func (cs *CentralService) PutClient(entryPath string, c oogwc.Client) {
|
||||
cs.clients[entryPath] = c
|
||||
}
|
||||
|
||||
func (cs *CentralService) Call(entryPath string, result interface{}, method string, params ...interface{}) error {
|
||||
c := cs.GetClient(entryPath)
|
||||
return c.Call(result, method, params...)
|
||||
}
|
||||
|
||||
func (cs *CentralService) Send(entryPath string, method string, params ...interface{}) error {
|
||||
c := cs.GetClient(entryPath)
|
||||
|
||||
return c.Send(method, params...)
|
||||
}
|
||||
|
||||
func (cs *CentralService) GetClient(entryPath string) oogwc.Client {
|
||||
return cs.clients[entryPath]
|
||||
}
|
||||
|
||||
func (cs *CentralService) CheckClient(entryPath string) bool {
|
||||
c, ok := cs.clients[entryPath]
|
||||
if !ok || nil == c {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (cs *CentralService) Connect(entryPath string) error {
|
||||
// var c oogwc.Client
|
||||
// switch entryPath {
|
||||
// case oocmp.HTTPEntry_Probe:
|
||||
// c = oopccp.NewClient()
|
||||
// case oocmp.HTTPEntry_Data:
|
||||
// c = oopccd.NewClient()
|
||||
// case oocmp.HTTPEntry_File:
|
||||
// c = oopccf.NewClient()
|
||||
// default:
|
||||
// return fmt.Errorf("Gateway entry[%s] is not exist", entryPath)
|
||||
// }
|
||||
|
||||
// cs.clients[entryPath] = c
|
||||
|
||||
return nil
|
||||
}
|
91
service/ContainerService.go
Normal file
91
service/ContainerService.go
Normal file
|
@ -0,0 +1,91 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
crc "git.loafle.net/commons_go/rpc/client"
|
||||
)
|
||||
|
||||
type ContainerService struct {
|
||||
clients map[string]*containerState
|
||||
}
|
||||
|
||||
type containerState struct {
|
||||
socketName string
|
||||
pid int
|
||||
client crc.Client
|
||||
}
|
||||
|
||||
func (cs *ContainerService) Call(name string, result interface{}, method string, params ...interface{}) error {
|
||||
c, err := cs.GetClient(name)
|
||||
if nil != err {
|
||||
return err
|
||||
}
|
||||
return c.Call(result, method, params...)
|
||||
}
|
||||
|
||||
func (cs *ContainerService) Send(name string, method string, params ...interface{}) error {
|
||||
c, err := cs.GetClient(name)
|
||||
if nil != err {
|
||||
return err
|
||||
}
|
||||
return c.Send(method, params...)
|
||||
}
|
||||
|
||||
func (cs *ContainerService) GetClient(name string) (crc.Client, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (cs *ContainerService) Connect(name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cs *ContainerService) runProcess(name string) error {
|
||||
ok := cs.checkProcess(name)
|
||||
|
||||
if ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
// runCmd := config.Config.Paths["root"] + "/" + config.Config.Paths["bin"] + "/" + name + "/start"
|
||||
|
||||
// sockFile := uuid.NewV4().String()
|
||||
// sockArg := fmt.Sprintf("-sock=\"%s\"", sockFile)
|
||||
|
||||
// cmd := exec.Command(runCmd, sockArg)
|
||||
// if err := cmd.Start(); nil != err {
|
||||
// logging.Logger().Error(fmt.Sprintf("Probe: To run container(%s) failed err %v", name, err))
|
||||
// return err
|
||||
// }
|
||||
// time.Sleep(time.Duration(time.Second * 2))
|
||||
|
||||
// cs := &containerState{
|
||||
// socketName: sockFile,
|
||||
// pid: cmd.Process.Pid,
|
||||
// }
|
||||
// cs.client = oopmcc.New(sockFile, nil)
|
||||
// // write pid file
|
||||
// cs.containerClients[name] = cs
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cs *ContainerService) checkProcess(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (cs *ContainerService) killProcess(name string) error {
|
||||
// cs, ok := cs.containerClients[name]
|
||||
// if !ok || nil == cs || nil == cs.client {
|
||||
// return fmt.Errorf("Probe: Container[%s] is not exist", name)
|
||||
// }
|
||||
|
||||
// p, err := os.FindProcess(cs.pid)
|
||||
// if nil != err {
|
||||
// return err
|
||||
// }
|
||||
// if err = p.Kill(); nil != err {
|
||||
// return err
|
||||
// }
|
||||
// // remove pid file
|
||||
|
||||
return nil
|
||||
}
|
|
@ -2,13 +2,9 @@ package service
|
|||
|
||||
import (
|
||||
configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
|
||||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||
oopmc "git.loafle.net/overflow/overflow_probes/manager/container"
|
||||
)
|
||||
|
||||
type CrawlerService struct {
|
||||
ProbeClient oogwc.Client `annotation:"@inject{name:probeClient}"`
|
||||
ContainerManager oopmc.ContainerManager `annotation:"@inject{name:containerManager}"`
|
||||
}
|
||||
|
||||
func (cs *CrawlerService) Install() error {
|
||||
|
|
|
@ -2,44 +2,44 @@ package service
|
|||
|
||||
import (
|
||||
discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model"
|
||||
oopmCentral "git.loafle.net/overflow/overflow_probes/manager/central"
|
||||
oopmContainer "git.loafle.net/overflow/overflow_probes/manager/container"
|
||||
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
||||
oocmpsp "git.loafle.net/overflow/overflow_commons_go/modules/probe/service/probe"
|
||||
)
|
||||
|
||||
type DiscoveryService struct {
|
||||
CentralManager oopmCentral.CentralManager `annotation:"@inject{name:probeClient}"`
|
||||
ContainerManager oopmContainer.ContainerManager `annotation:"@inject{name:containerManager}"`
|
||||
ContainerService *ContainerService `annotation:"@Inject()"`
|
||||
CentralService *CentralService `annotation:"@Inject()"`
|
||||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoverZone(dz *discoveryM.DiscoveryZone) error {
|
||||
return ds.ContainerManager.GetClient("").Send("DiscoveryService.DiscoverZone", dz)
|
||||
return ds.ContainerService.Send(oocmpsp.ProbeContainerNameDiscovery, "DiscoveryService.DiscoverZone", dz)
|
||||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoverHost(zone *discoveryM.Zone, dh *discoveryM.DiscoveryHost) error {
|
||||
return ds.ContainerManager.GetClient("").Send("DiscoveryService.DiscoverHost", zone, dh)
|
||||
return ds.ContainerService.Send(oocmpsp.ProbeContainerNameDiscovery, "DiscoveryService.DiscoverHost", zone, dh)
|
||||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoverPort(host *discoveryM.Host, dp *discoveryM.DiscoveryPort) error {
|
||||
return ds.ContainerManager.GetClient("").Send("DiscoveryService.DiscoverPort", host, dp)
|
||||
return ds.ContainerService.Send(oocmpsp.ProbeContainerNameDiscovery, "DiscoveryService.DiscoverPort", host, dp)
|
||||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoverService(port *discoveryM.Port, dService *discoveryM.DiscoveryService) error {
|
||||
return ds.ContainerManager.GetClient("").Send("DiscoveryService.DiscoverZone", port, dService)
|
||||
return ds.ContainerService.Send(oocmpsp.ProbeContainerNameDiscovery, "DiscoveryService.DiscoverZone", port, dService)
|
||||
}
|
||||
|
||||
// use by discovery
|
||||
func (ds *DiscoveryService) DiscoveredZone(zone *discoveryM.Zone) error {
|
||||
return ds.CentralManager.GetClient("").Send("DiscoveryService.DiscoveredZone", zone)
|
||||
return ds.CentralService.Send(oocmp.HTTPEntry_Probe, "DiscoveryService.DiscoveredZone", zone)
|
||||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoveredHost(host *discoveryM.Host) error {
|
||||
return ds.CentralManager.GetClient("").Send("DiscoveryService.DiscoveredHost", host)
|
||||
return ds.CentralService.Send(oocmp.HTTPEntry_Probe, "DiscoveryService.DiscoveredHost", host)
|
||||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoveredPort(port *discoveryM.Port) error {
|
||||
return ds.CentralManager.GetClient("").Send("DiscoveryService.DiscoveredPort", port)
|
||||
return ds.CentralService.Send(oocmp.HTTPEntry_Probe, "DiscoveryService.DiscoveredPort", port)
|
||||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoveredService(service *discoveryM.Service) error {
|
||||
return ds.CentralManager.GetClient("").Send("DiscoveryService.DiscoveredService", service)
|
||||
return ds.CentralService.Send(oocmp.HTTPEntry_Probe, "DiscoveryService.DiscoveredService", service)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user