overflow_discovery/server/server.go

51 lines
1.4 KiB
Go
Raw Permalink Normal View History

2017-10-26 12:55:55 +00:00
package server
import (
2018-03-22 16:11:03 +00:00
"reflect"
2018-03-16 07:46:31 +00:00
cdr "git.loafle.net/commons_go/di/registry"
2018-03-21 10:34:40 +00:00
"git.loafle.net/commons_go/logging"
2017-12-01 08:29:54 +00:00
crr "git.loafle.net/commons_go/rpc/registry"
2017-10-26 12:55:55 +00:00
"git.loafle.net/commons_go/server"
2018-03-22 16:11:03 +00:00
ooca "git.loafle.net/overflow/overflow_commons_go/annotation"
2018-03-27 09:51:48 +00:00
"git.loafle.net/overflow/overflow_discovery/crawler"
2018-03-16 07:46:31 +00:00
oods "git.loafle.net/overflow/overflow_discovery/service"
2018-03-27 09:51:48 +00:00
oopc "git.loafle.net/overflow/overflow_probe_container"
2017-12-05 05:58:32 +00:00
oopcs "git.loafle.net/overflow/overflow_probe_container/server"
2018-03-22 16:11:03 +00:00
oopcService "git.loafle.net/overflow/overflow_probe_container/service"
2017-10-26 12:55:55 +00:00
)
2017-12-14 08:55:57 +00:00
func New(pidPath string) server.Server {
2018-03-21 10:34:40 +00:00
var (
2018-03-22 16:11:03 +00:00
services []interface{}
probeService *oopcService.ProbeService
err error
2018-03-21 10:34:40 +00:00
)
2018-03-16 07:46:31 +00:00
oods.InitService()
2018-03-27 09:51:48 +00:00
cdr.RegisterResource(oopc.PROBE_CONTAINER_CRAWLERS, crawler.GetCrawlers())
2018-03-16 07:46:31 +00:00
2017-12-01 08:29:54 +00:00
rpcRegistry := crr.NewRPCRegistry()
2018-03-16 07:46:31 +00:00
2018-03-22 16:11:03 +00:00
if services, err = cdr.GetInstancesByAnnotationName(ooca.ServiceTag); nil != err {
2018-03-21 10:34:40 +00:00
logging.Logger().Panic(err)
}
2018-03-16 07:46:31 +00:00
for _, s := range services {
rpcRegistry.RegisterService(s, "")
}
2017-11-15 06:59:43 +00:00
2018-03-22 16:11:03 +00:00
if _probeService, err := cdr.GetInstance(reflect.TypeOf((*oopcService.ProbeService)(nil))); nil != err {
logging.Logger().Panic(err)
} else {
probeService = _probeService.(*oopcService.ProbeService)
}
2017-12-05 05:58:32 +00:00
rpcSH := oopcs.NewRPCServletHandler(rpcRegistry)
2018-03-22 16:11:03 +00:00
socketHandler := newSocketHandler(rpcSH, probeService)
2017-10-26 12:55:55 +00:00
2018-03-27 09:51:48 +00:00
sh := newServerHandler(pidPath, socketHandler, services, oods.ServicesToStartAndStop)
2017-12-05 05:58:32 +00:00
s := oopcs.New(sh)
2017-10-26 12:55:55 +00:00
return s
}