2018-04-19 11:36:56 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
cdr "git.loafle.net/commons/di-go/registry"
|
|
|
|
logging "git.loafle.net/commons/logging-go"
|
2018-04-19 14:45:39 +00:00
|
|
|
crpj "git.loafle.net/commons/rpc-go/protocol/json"
|
2018-04-19 11:36:56 +00:00
|
|
|
crr "git.loafle.net/commons/rpc-go/registry"
|
|
|
|
cssn "git.loafle.net/commons/server-go/socket/net"
|
|
|
|
occa "git.loafle.net/overflow/commons-go/core/annotation"
|
|
|
|
"git.loafle.net/overflow/container-go"
|
|
|
|
"git.loafle.net/overflow/container_discovery/crawler"
|
|
|
|
"git.loafle.net/overflow/container_discovery/service"
|
|
|
|
"git.loafle.net/overflow/container_discovery/servlet"
|
|
|
|
)
|
|
|
|
|
|
|
|
func New(pidFilePath string) *cssn.Server {
|
2018-04-19 14:45:39 +00:00
|
|
|
rpcWriteChan := make(chan *container.RPCNotification, 256)
|
|
|
|
|
2018-04-19 11:36:56 +00:00
|
|
|
cdr.RegisterResource(container.CONTAINER_CRAWLERS, crawler.GetCrawlers())
|
2018-04-19 14:45:39 +00:00
|
|
|
cdr.RegisterResource(container.CONTAINER_RPC_WRITE_CHAN, rpcWriteChan)
|
2018-04-19 11:36:56 +00:00
|
|
|
|
|
|
|
services, err := cdr.GetInstancesByAnnotationType(occa.RPCServiceAnnotationType)
|
|
|
|
if nil != err {
|
|
|
|
logging.Logger().Panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcRegistry := crr.NewRPCRegistry()
|
|
|
|
rpcRegistry.RegisterServices(services...)
|
|
|
|
|
|
|
|
ds := &servlet.DiscoveryServlets{}
|
|
|
|
ds.RPCInvoker = rpcRegistry
|
2018-04-19 14:45:39 +00:00
|
|
|
ds.RPCWriteChan = rpcWriteChan
|
|
|
|
ds.RPCServerCodec = crpj.NewServerCodec()
|
2018-04-19 11:36:56 +00:00
|
|
|
|
|
|
|
sh := &ServerHandlers{}
|
|
|
|
sh.Name = "Container Discovery"
|
|
|
|
sh.PIDFilePath = pidFilePath
|
|
|
|
sh.Services = services
|
|
|
|
sh.OrderedServices = service.OrderedServices
|
|
|
|
|
|
|
|
sh.RegisterServlet(ds)
|
|
|
|
|
|
|
|
s := &cssn.Server{
|
|
|
|
ServerHandler: sh,
|
|
|
|
}
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|