From fb7d1ca4d63942f6ca7c8b4cde74b932d2090515 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 8 Dec 2017 17:31:45 +0900 Subject: [PATCH] ing --- auth/client/socket_builders.go | 5 +- client/central/data/client.go | 11 ++ .../central}/data/client_handlers.go | 9 +- client/central/data/socket_builders.go | 27 +++++ client/central/data/socket_handlers.go | 27 +++++ client/central/probe/client.go | 12 ++ .../central}/probe/client_handlers.go | 2 +- client/central/probe/socket_builders.go | 27 +++++ client/central/probe/socket_handlers.go | 31 +++++ client/central/socket_builders.go | 35 ++++++ .../client => client/container}/client.go | 0 .../container}/client_handlers.go | 0 .../container}/socket_handlers.go | 0 commons/central/client/socket_builders.go | 8 +- config.json | 8 +- manager/central/central.go | 17 --- manager/central/client/data/client.go | 11 -- .../central/client/data/socket_builders.go | 51 --------- .../central/client/data/socket_handlers.go | 41 ------- manager/central/client/file/client.go | 11 -- .../central/client/file/client_handlers.go | 31 ----- .../central/client/file/socket_builders.go | 51 --------- .../central/client/file/socket_handlers.go | 41 ------- manager/central/client/probe/client.go | 11 -- .../central/client/probe/socket_builders.go | 51 --------- .../central/client/probe/socket_handlers.go | 41 ------- manager/container/container.go | 106 ------------------ probe/probe.go | 54 +++++---- service/CentralService.go | 55 +++++++++ service/ContainerService.go | 91 +++++++++++++++ service/CrawlerService.go | 4 - service/DiscoveryService.go | 24 ++-- 32 files changed, 378 insertions(+), 515 deletions(-) create mode 100644 client/central/data/client.go rename {manager/central/client => client/central}/data/client_handlers.go (57%) create mode 100644 client/central/data/socket_builders.go create mode 100644 client/central/data/socket_handlers.go create mode 100644 client/central/probe/client.go rename {manager/central/client => client/central}/probe/client_handlers.go (91%) create mode 100644 client/central/probe/socket_builders.go create mode 100644 client/central/probe/socket_handlers.go create mode 100644 client/central/socket_builders.go rename {manager/container/client => client/container}/client.go (100%) rename {manager/container/client => client/container}/client_handlers.go (100%) rename {manager/container/client => client/container}/socket_handlers.go (100%) delete mode 100644 manager/central/central.go delete mode 100644 manager/central/client/data/client.go delete mode 100644 manager/central/client/data/socket_builders.go delete mode 100644 manager/central/client/data/socket_handlers.go delete mode 100644 manager/central/client/file/client.go delete mode 100644 manager/central/client/file/client_handlers.go delete mode 100644 manager/central/client/file/socket_builders.go delete mode 100644 manager/central/client/file/socket_handlers.go delete mode 100644 manager/central/client/probe/client.go delete mode 100644 manager/central/client/probe/socket_builders.go delete mode 100644 manager/central/client/probe/socket_handlers.go delete mode 100644 manager/container/container.go create mode 100644 service/CentralService.go create mode 100644 service/ContainerService.go diff --git a/auth/client/socket_builders.go b/auth/client/socket_builders.go index 08a75f2..3472f4b 100644 --- a/auth/client/socket_builders.go +++ b/auth/client/socket_builders.go @@ -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{} diff --git a/client/central/data/client.go b/client/central/data/client.go new file mode 100644 index 0000000..0c4eb8a --- /dev/null +++ b/client/central/data/client.go @@ -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) +} diff --git a/manager/central/client/data/client_handlers.go b/client/central/data/client_handlers.go similarity index 57% rename from manager/central/client/data/client_handlers.go rename to client/central/data/client_handlers.go index 2da6f47..a56a2da 100644 --- a/manager/central/client/data/client_handlers.go +++ b/client/central/data/client_handlers.go @@ -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")) } diff --git a/client/central/data/socket_builders.go b/client/central/data/socket_builders.go new file mode 100644 index 0000000..b16dc44 --- /dev/null +++ b/client/central/data/socket_builders.go @@ -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() + +} diff --git a/client/central/data/socket_handlers.go b/client/central/data/socket_handlers.go new file mode 100644 index 0000000..16f3937 --- /dev/null +++ b/client/central/data/socket_handlers.go @@ -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{} +} diff --git a/client/central/probe/client.go b/client/central/probe/client.go new file mode 100644 index 0000000..90e1dca --- /dev/null +++ b/client/central/probe/client.go @@ -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) +} diff --git a/manager/central/client/probe/client_handlers.go b/client/central/probe/client_handlers.go similarity index 91% rename from manager/central/client/probe/client_handlers.go rename to client/central/probe/client_handlers.go index e3f5b4b..b68ec7c 100644 --- a/manager/central/client/probe/client_handlers.go +++ b/client/central/probe/client_handlers.go @@ -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) diff --git a/client/central/probe/socket_builders.go b/client/central/probe/socket_builders.go new file mode 100644 index 0000000..b432f93 --- /dev/null +++ b/client/central/probe/socket_builders.go @@ -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() + +} diff --git a/client/central/probe/socket_handlers.go b/client/central/probe/socket_handlers.go new file mode 100644 index 0000000..ccce033 --- /dev/null +++ b/client/central/probe/socket_handlers.go @@ -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{} +} diff --git a/client/central/socket_builders.go b/client/central/socket_builders.go new file mode 100644 index 0000000..1d753f2 --- /dev/null +++ b/client/central/socket_builders.go @@ -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() + +} diff --git a/manager/container/client/client.go b/client/container/client.go similarity index 100% rename from manager/container/client/client.go rename to client/container/client.go diff --git a/manager/container/client/client_handlers.go b/client/container/client_handlers.go similarity index 100% rename from manager/container/client/client_handlers.go rename to client/container/client_handlers.go diff --git a/manager/container/client/socket_handlers.go b/client/container/socket_handlers.go similarity index 100% rename from manager/container/client/socket_handlers.go rename to client/container/socket_handlers.go diff --git a/commons/central/client/socket_builders.go b/commons/central/client/socket_builders.go index 5120f8c..029f955 100644 --- a/commons/central/client/socket_builders.go +++ b/commons/central/client/socket_builders.go @@ -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() + +} diff --git a/config.json b/config.json index e3ae483..2c5b959 100644 --- a/config.json +++ b/config.json @@ -4,5 +4,11 @@ "apiKey": "52abd6fd57e511e7ac52080027658d13", "readBufferSize": 8192, "writeBufferSize": 8192 + }, + "paths": { + "root": "", + "bin": "bin", + "config": "config", + "pid": "pid" } -} \ No newline at end of file +} diff --git a/manager/central/central.go b/manager/central/central.go deleted file mode 100644 index 538eb72..0000000 --- a/manager/central/central.go +++ /dev/null @@ -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 -} diff --git a/manager/central/client/data/client.go b/manager/central/client/data/client.go deleted file mode 100644 index 481baae..0000000 --- a/manager/central/client/data/client.go +++ /dev/null @@ -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) -} diff --git a/manager/central/client/data/socket_builders.go b/manager/central/client/data/socket_builders.go deleted file mode 100644 index 75c9e02..0000000 --- a/manager/central/client/data/socket_builders.go +++ /dev/null @@ -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") - } -} diff --git a/manager/central/client/data/socket_handlers.go b/manager/central/client/data/socket_handlers.go deleted file mode 100644 index dc6b002..0000000 --- a/manager/central/client/data/socket_handlers.go +++ /dev/null @@ -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, - } -} diff --git a/manager/central/client/file/client.go b/manager/central/client/file/client.go deleted file mode 100644 index 4bb9040..0000000 --- a/manager/central/client/file/client.go +++ /dev/null @@ -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) -} diff --git a/manager/central/client/file/client_handlers.go b/manager/central/client/file/client_handlers.go deleted file mode 100644 index 62696b4..0000000 --- a/manager/central/client/file/client_handlers.go +++ /dev/null @@ -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")) -} diff --git a/manager/central/client/file/socket_builders.go b/manager/central/client/file/socket_builders.go deleted file mode 100644 index 2cb5fd5..0000000 --- a/manager/central/client/file/socket_builders.go +++ /dev/null @@ -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") - } -} diff --git a/manager/central/client/file/socket_handlers.go b/manager/central/client/file/socket_handlers.go deleted file mode 100644 index adcfcbb..0000000 --- a/manager/central/client/file/socket_handlers.go +++ /dev/null @@ -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, - } -} diff --git a/manager/central/client/probe/client.go b/manager/central/client/probe/client.go deleted file mode 100644 index 9a23e1e..0000000 --- a/manager/central/client/probe/client.go +++ /dev/null @@ -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) -} diff --git a/manager/central/client/probe/socket_builders.go b/manager/central/client/probe/socket_builders.go deleted file mode 100644 index 130154f..0000000 --- a/manager/central/client/probe/socket_builders.go +++ /dev/null @@ -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") - } -} diff --git a/manager/central/client/probe/socket_handlers.go b/manager/central/client/probe/socket_handlers.go deleted file mode 100644 index fbab8fe..0000000 --- a/manager/central/client/probe/socket_handlers.go +++ /dev/null @@ -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, - } -} diff --git a/manager/container/container.go b/manager/container/container.go deleted file mode 100644 index 4fc33e8..0000000 --- a/manager/container/container.go +++ /dev/null @@ -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) { - -// } diff --git a/probe/probe.go b/probe/probe.go index 020d8ab..105bf85 100644 --- a/probe/probe.go +++ b/probe/probe.go @@ -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 { diff --git a/service/CentralService.go b/service/CentralService.go new file mode 100644 index 0000000..57a9d71 --- /dev/null +++ b/service/CentralService.go @@ -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 +} diff --git a/service/ContainerService.go b/service/ContainerService.go new file mode 100644 index 0000000..56c41f6 --- /dev/null +++ b/service/ContainerService.go @@ -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 +} diff --git a/service/CrawlerService.go b/service/CrawlerService.go index de0b85b..5d45478 100644 --- a/service/CrawlerService.go +++ b/service/CrawlerService.go @@ -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 { diff --git a/service/DiscoveryService.go b/service/DiscoveryService.go index 444f5b6..4cbd18c 100644 --- a/service/DiscoveryService.go +++ b/service/DiscoveryService.go @@ -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) }