From 3ebe20681f92c5010b69eb8534b680c6a28f4c54 Mon Sep 17 00:00:00 2001 From: crusader Date: Tue, 27 Mar 2018 18:51:48 +0900 Subject: [PATCH] ing --- crawler/crawler.go | 20 ++++++++++++++++++++ server/server.go | 5 ++++- server/server_handlers.go | 15 +++++++++------ service/ContainerService.go | 21 --------------------- service/DiscoveryService.go | 20 +++++++++++++++----- service/service.go | 12 ++++++++++++ 6 files changed, 60 insertions(+), 33 deletions(-) create mode 100644 crawler/crawler.go delete mode 100644 service/ContainerService.go diff --git a/crawler/crawler.go b/crawler/crawler.go new file mode 100644 index 0000000..85ba3d8 --- /dev/null +++ b/crawler/crawler.go @@ -0,0 +1,20 @@ +package crawler + +import ( + oopcc "git.loafle.net/overflow/overflow_probe_container/crawler" +) + +var crawlers map[string]oopcc.Crawler + +func init() { + crawlers = make(map[string]oopcc.Crawler, 0) + +} + +func addCrawler(c oopcc.Crawler) { + crawlers[c.Name()] = c +} + +func GetCrawlers() map[string]oopcc.Crawler { + return crawlers +} diff --git a/server/server.go b/server/server.go index a9f4520..693f6be 100644 --- a/server/server.go +++ b/server/server.go @@ -8,7 +8,9 @@ import ( crr "git.loafle.net/commons_go/rpc/registry" "git.loafle.net/commons_go/server" ooca "git.loafle.net/overflow/overflow_commons_go/annotation" + "git.loafle.net/overflow/overflow_discovery/crawler" oods "git.loafle.net/overflow/overflow_discovery/service" + oopc "git.loafle.net/overflow/overflow_probe_container" oopcs "git.loafle.net/overflow/overflow_probe_container/server" oopcService "git.loafle.net/overflow/overflow_probe_container/service" ) @@ -20,6 +22,7 @@ func New(pidPath string) server.Server { err error ) oods.InitService() + cdr.RegisterResource(oopc.PROBE_CONTAINER_CRAWLERS, crawler.GetCrawlers()) rpcRegistry := crr.NewRPCRegistry() @@ -40,7 +43,7 @@ func New(pidPath string) server.Server { rpcSH := oopcs.NewRPCServletHandler(rpcRegistry) socketHandler := newSocketHandler(rpcSH, probeService) - sh := newServerHandler(pidPath, socketHandler) + sh := newServerHandler(pidPath, socketHandler, services, oods.ServicesToStartAndStop) s := oopcs.New(sh) return s diff --git a/server/server_handlers.go b/server/server_handlers.go index 29f657f..96d1978 100644 --- a/server/server_handlers.go +++ b/server/server_handlers.go @@ -1,14 +1,15 @@ package server import ( + "reflect" + "git.loafle.net/commons_go/server" - "git.loafle.net/overflow/overflow_discovery/discovery" oopcs "git.loafle.net/overflow/overflow_probe_container/server" ) -func newServerHandler(pidPath string, socketHandler SocketHandler) ServerHandler { +func newServerHandler(pidPath string, socketHandler SocketHandler, services []interface{}, servicesToStartAndStop []reflect.Type) ServerHandler { sh := &ServerHandlers{} - sh.ServerHandler = oopcs.NewServerHandler(pidPath, "Discovery Containter", socketHandler) + sh.ServerHandler = oopcs.NewServerHandler(pidPath, "Discovery Containter", socketHandler, services, servicesToStartAndStop) return sh } @@ -28,16 +29,18 @@ func (sh *ServerHandlers) Init(serverCTX server.ServerContext) error { func (sh *ServerHandlers) OnStart(serverCTX server.ServerContext) { sh.ServerHandler.OnStart(serverCTX) - discovery.DiscoveryInit() } func (sh *ServerHandlers) OnStop(serverCTX server.ServerContext) { - discovery.DiscoveryDestroy() - sh.ServerHandler.OnStop(serverCTX) } +func (sh *ServerHandlers) Destroy(serverCTX server.ServerContext) { + + sh.ServerHandler.Destroy(serverCTX) +} + func (sh *ServerHandlers) Validate() { sh.ServerHandler.Validate() diff --git a/service/ContainerService.go b/service/ContainerService.go deleted file mode 100644 index e643016..0000000 --- a/service/ContainerService.go +++ /dev/null @@ -1,21 +0,0 @@ -package service - -import ( - "reflect" - - cda "git.loafle.net/commons_go/di/annotation" - cdr "git.loafle.net/commons_go/di/registry" -) - -func init() { - cdr.RegisterType(reflect.TypeOf((*ContainerService)(nil))) -} - -type ContainerService struct { - cda.TypeAnnotation `annotation:"@overFlow:Service()"` -} - -func (cs *ContainerService) State() (bool, error) { - - return true, nil -} diff --git a/service/DiscoveryService.go b/service/DiscoveryService.go index b36257d..6090caa 100644 --- a/service/DiscoveryService.go +++ b/service/DiscoveryService.go @@ -1,10 +1,12 @@ package service import ( + "context" "reflect" cda "git.loafle.net/commons_go/di/annotation" cdr "git.loafle.net/commons_go/di/registry" + oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces" discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model" "git.loafle.net/overflow/overflow_discovery/discovery" oopcs "git.loafle.net/overflow/overflow_probe_container/service" @@ -16,10 +18,23 @@ func init() { type DiscoveryService struct { cda.TypeAnnotation `annotation:"@overFlow:Service()"` + oocmci.Service ProbeService *oopcs.ProbeService `annotation:"@Inject()"` } +func (ds *DiscoveryService) Start() error { + discovery.DiscoveryInit() + + return nil +} + +func (ds *DiscoveryService) Stop(ctx context.Context) error { + discovery.DiscoveryDestroy() + + return nil +} + func (ds *DiscoveryService) DiscoverZone(requesterID string, dz *discoveryM.DiscoveryZone) error { discovery.DiscoverZone(ds.ProbeService, requesterID, dz) @@ -41,8 +56,3 @@ func (ds *DiscoveryService) DiscoverService(requesterID string, port *discoveryM return nil } - -func (ds *DiscoveryService) Stop() error { - - return nil -} diff --git a/service/service.go b/service/service.go index 83c4f6f..010af9d 100644 --- a/service/service.go +++ b/service/service.go @@ -1,9 +1,21 @@ package service import ( + "reflect" + oopcs "git.loafle.net/overflow/overflow_probe_container/service" ) +var ( + ServicesToStartAndStop = []reflect.Type{ + reflect.TypeOf((*oopcs.SensorConfigService)(nil)), + reflect.TypeOf((*oopcs.CrawlerService)(nil)), + reflect.TypeOf((*oopcs.ProbeService)(nil)), + reflect.TypeOf((*DiscoveryService)(nil)), + reflect.TypeOf((*oopcs.StateService)(nil)), + } +) + func InitService() { oopcs.InitService() }