ing
This commit is contained in:
parent
a15effa1ad
commit
3ebe20681f
20
crawler/crawler.go
Normal file
20
crawler/crawler.go
Normal file
|
@ -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
|
||||||
|
}
|
|
@ -8,7 +8,9 @@ import (
|
||||||
crr "git.loafle.net/commons_go/rpc/registry"
|
crr "git.loafle.net/commons_go/rpc/registry"
|
||||||
"git.loafle.net/commons_go/server"
|
"git.loafle.net/commons_go/server"
|
||||||
ooca "git.loafle.net/overflow/overflow_commons_go/annotation"
|
ooca "git.loafle.net/overflow/overflow_commons_go/annotation"
|
||||||
|
"git.loafle.net/overflow/overflow_discovery/crawler"
|
||||||
oods "git.loafle.net/overflow/overflow_discovery/service"
|
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"
|
oopcs "git.loafle.net/overflow/overflow_probe_container/server"
|
||||||
oopcService "git.loafle.net/overflow/overflow_probe_container/service"
|
oopcService "git.loafle.net/overflow/overflow_probe_container/service"
|
||||||
)
|
)
|
||||||
|
@ -20,6 +22,7 @@ func New(pidPath string) server.Server {
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
oods.InitService()
|
oods.InitService()
|
||||||
|
cdr.RegisterResource(oopc.PROBE_CONTAINER_CRAWLERS, crawler.GetCrawlers())
|
||||||
|
|
||||||
rpcRegistry := crr.NewRPCRegistry()
|
rpcRegistry := crr.NewRPCRegistry()
|
||||||
|
|
||||||
|
@ -40,7 +43,7 @@ func New(pidPath string) server.Server {
|
||||||
rpcSH := oopcs.NewRPCServletHandler(rpcRegistry)
|
rpcSH := oopcs.NewRPCServletHandler(rpcRegistry)
|
||||||
socketHandler := newSocketHandler(rpcSH, probeService)
|
socketHandler := newSocketHandler(rpcSH, probeService)
|
||||||
|
|
||||||
sh := newServerHandler(pidPath, socketHandler)
|
sh := newServerHandler(pidPath, socketHandler, services, oods.ServicesToStartAndStop)
|
||||||
s := oopcs.New(sh)
|
s := oopcs.New(sh)
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"git.loafle.net/commons_go/server"
|
"git.loafle.net/commons_go/server"
|
||||||
"git.loafle.net/overflow/overflow_discovery/discovery"
|
|
||||||
oopcs "git.loafle.net/overflow/overflow_probe_container/server"
|
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 := &ServerHandlers{}
|
||||||
sh.ServerHandler = oopcs.NewServerHandler(pidPath, "Discovery Containter", socketHandler)
|
sh.ServerHandler = oopcs.NewServerHandler(pidPath, "Discovery Containter", socketHandler, services, servicesToStartAndStop)
|
||||||
|
|
||||||
return sh
|
return sh
|
||||||
}
|
}
|
||||||
|
@ -28,16 +29,18 @@ func (sh *ServerHandlers) Init(serverCTX server.ServerContext) error {
|
||||||
func (sh *ServerHandlers) OnStart(serverCTX server.ServerContext) {
|
func (sh *ServerHandlers) OnStart(serverCTX server.ServerContext) {
|
||||||
sh.ServerHandler.OnStart(serverCTX)
|
sh.ServerHandler.OnStart(serverCTX)
|
||||||
|
|
||||||
discovery.DiscoveryInit()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *ServerHandlers) OnStop(serverCTX server.ServerContext) {
|
func (sh *ServerHandlers) OnStop(serverCTX server.ServerContext) {
|
||||||
|
|
||||||
discovery.DiscoveryDestroy()
|
|
||||||
|
|
||||||
sh.ServerHandler.OnStop(serverCTX)
|
sh.ServerHandler.OnStop(serverCTX)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sh *ServerHandlers) Destroy(serverCTX server.ServerContext) {
|
||||||
|
|
||||||
|
sh.ServerHandler.Destroy(serverCTX)
|
||||||
|
}
|
||||||
|
|
||||||
func (sh *ServerHandlers) Validate() {
|
func (sh *ServerHandlers) Validate() {
|
||||||
sh.ServerHandler.Validate()
|
sh.ServerHandler.Validate()
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -1,10 +1,12 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
cda "git.loafle.net/commons_go/di/annotation"
|
cda "git.loafle.net/commons_go/di/annotation"
|
||||||
cdr "git.loafle.net/commons_go/di/registry"
|
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"
|
discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model"
|
||||||
"git.loafle.net/overflow/overflow_discovery/discovery"
|
"git.loafle.net/overflow/overflow_discovery/discovery"
|
||||||
oopcs "git.loafle.net/overflow/overflow_probe_container/service"
|
oopcs "git.loafle.net/overflow/overflow_probe_container/service"
|
||||||
|
@ -16,10 +18,23 @@ func init() {
|
||||||
|
|
||||||
type DiscoveryService struct {
|
type DiscoveryService struct {
|
||||||
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
|
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
|
||||||
|
oocmci.Service
|
||||||
|
|
||||||
ProbeService *oopcs.ProbeService `annotation:"@Inject()"`
|
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 {
|
func (ds *DiscoveryService) DiscoverZone(requesterID string, dz *discoveryM.DiscoveryZone) error {
|
||||||
|
|
||||||
discovery.DiscoverZone(ds.ProbeService, requesterID, dz)
|
discovery.DiscoverZone(ds.ProbeService, requesterID, dz)
|
||||||
|
@ -41,8 +56,3 @@ func (ds *DiscoveryService) DiscoverService(requesterID string, port *discoveryM
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DiscoveryService) Stop() error {
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,9 +1,21 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
oopcs "git.loafle.net/overflow/overflow_probe_container/service"
|
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() {
|
func InitService() {
|
||||||
oopcs.InitService()
|
oopcs.InitService()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user