This commit is contained in:
crusader 2018-03-27 18:51:48 +09:00
parent a15effa1ad
commit 3ebe20681f
6 changed files with 60 additions and 33 deletions

20
crawler/crawler.go Normal file
View 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
}

View File

@ -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

View File

@ -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()

View File

@ -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
}

View File

@ -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
}

View File

@ -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()
}