ing
This commit is contained in:
parent
fb7d1ca4d6
commit
14c4949480
|
@ -4,9 +4,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
cdr "git.loafle.net/commons_go/di/registry"
|
||||||
"git.loafle.net/commons_go/logging"
|
"git.loafle.net/commons_go/logging"
|
||||||
crr "git.loafle.net/commons_go/rpc/registry"
|
crr "git.loafle.net/commons_go/rpc/registry"
|
||||||
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
||||||
|
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||||
oopccd "git.loafle.net/overflow/overflow_probes/client/central/data"
|
oopccd "git.loafle.net/overflow/overflow_probes/client/central/data"
|
||||||
oopccp "git.loafle.net/overflow/overflow_probes/client/central/probe"
|
oopccp "git.loafle.net/overflow/overflow_probes/client/central/probe"
|
||||||
"git.loafle.net/overflow/overflow_probes/service"
|
"git.loafle.net/overflow/overflow_probes/service"
|
||||||
|
@ -34,28 +36,38 @@ func (pm *probeManagers) Start() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
probeRPCRegistry := crr.NewRPCRegistry()
|
probeRPCRegistry := crr.NewRPCRegistry()
|
||||||
probeRPCRegistry.RegisterService(&service.CentralService{}, "")
|
|
||||||
probeRPCRegistry.RegisterService(&service.ConfigService{}, "")
|
|
||||||
probeRPCRegistry.RegisterService(&service.CrawlerService{}, "")
|
|
||||||
probeRPCRegistry.RegisterService(&service.DiscoveryService{}, "")
|
|
||||||
probeRPCRegistry.RegisterService(&service.LogService{}, "")
|
|
||||||
probeRPCRegistry.RegisterService(&service.ProbeService{}, "")
|
|
||||||
probeRPCRegistry.RegisterService(&service.SensorService{}, "")
|
|
||||||
|
|
||||||
centralProbeClient := oopccp.New(probeRPCRegistry)
|
centralProbeClient := oopccp.New(probeRPCRegistry)
|
||||||
|
centralDataClient := oopccd.New()
|
||||||
|
centralClients := map[string]oogwc.Client{
|
||||||
|
oocmp.HTTPEntry_Probe: centralProbeClient,
|
||||||
|
oocmp.HTTPEntry_Data: centralDataClient,
|
||||||
|
}
|
||||||
|
cdr.RegisterResource("CentralClients", centralClients)
|
||||||
|
|
||||||
|
centralService := service.GetService("CentralService").(*service.CentralService)
|
||||||
|
configService := service.GetService("ConfigService").(*service.ConfigService)
|
||||||
|
crawlerService := service.GetService("CrawlerService").(*service.CrawlerService)
|
||||||
|
discoveryService := service.GetService("DiscoveryService").(*service.DiscoveryService)
|
||||||
|
logService := service.GetService("LogService").(*service.LogService)
|
||||||
|
probeService := service.GetService("ProbeService").(*service.ProbeService)
|
||||||
|
sensorService := service.GetService("SensorService").(*service.SensorService)
|
||||||
|
|
||||||
|
probeRPCRegistry.RegisterService(centralService, "")
|
||||||
|
probeRPCRegistry.RegisterService(configService, "")
|
||||||
|
probeRPCRegistry.RegisterService(crawlerService, "")
|
||||||
|
probeRPCRegistry.RegisterService(discoveryService, "")
|
||||||
|
probeRPCRegistry.RegisterService(logService, "")
|
||||||
|
probeRPCRegistry.RegisterService(probeService, "")
|
||||||
|
probeRPCRegistry.RegisterService(sensorService, "")
|
||||||
|
|
||||||
if err := centralProbeClient.Connect(); nil != err {
|
if err := centralProbeClient.Connect(); nil != err {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
centralDataClient := oopccd.New()
|
|
||||||
if err := centralDataClient.Connect(); nil != err {
|
if err := centralDataClient.Connect(); nil != err {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
centralS := probeRPCRegistry.GetService("CentralService").(*service.CentralService)
|
|
||||||
centralS.PutClient(oocmp.HTTPEntry_Probe, centralProbeClient)
|
|
||||||
centralS.PutClient(oocmp.HTTPEntry_Data, centralDataClient)
|
|
||||||
|
|
||||||
pm.stopChan = make(chan struct{})
|
pm.stopChan = make(chan struct{})
|
||||||
|
|
||||||
pm.stopWg.Add(1)
|
pm.stopWg.Add(1)
|
||||||
|
|
|
@ -1,15 +1,23 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
cda "git.loafle.net/commons_go/di/annotation"
|
||||||
|
cdr "git.loafle.net/commons_go/di/registry"
|
||||||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cdr.RegisterType(reflect.TypeOf((*CentralService)(nil)), &cda.ComponentAnnotation{})
|
||||||
|
}
|
||||||
|
|
||||||
type CentralService struct {
|
type CentralService struct {
|
||||||
clients map[string]oogwc.Client
|
CentralClients map[string]oogwc.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *CentralService) PutClient(entryPath string, c oogwc.Client) {
|
func (cs *CentralService) PutClient(entryPath string, c oogwc.Client) {
|
||||||
cs.clients[entryPath] = c
|
cs.CentralClients[entryPath] = c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *CentralService) Call(entryPath string, result interface{}, method string, params ...interface{}) error {
|
func (cs *CentralService) Call(entryPath string, result interface{}, method string, params ...interface{}) error {
|
||||||
|
@ -24,11 +32,11 @@ func (cs *CentralService) Send(entryPath string, method string, params ...interf
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *CentralService) GetClient(entryPath string) oogwc.Client {
|
func (cs *CentralService) GetClient(entryPath string) oogwc.Client {
|
||||||
return cs.clients[entryPath]
|
return cs.CentralClients[entryPath]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *CentralService) CheckClient(entryPath string) bool {
|
func (cs *CentralService) CheckClient(entryPath string) bool {
|
||||||
c, ok := cs.clients[entryPath]
|
c, ok := cs.CentralClients[entryPath]
|
||||||
if !ok || nil == c {
|
if !ok || nil == c {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,15 @@
|
||||||
package service
|
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((*ConfigService)(nil)), &cda.ComponentAnnotation{})
|
||||||
|
}
|
||||||
|
|
||||||
type ConfigService struct {
|
type ConfigService struct {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
cda "git.loafle.net/commons_go/di/annotation"
|
||||||
|
cdr "git.loafle.net/commons_go/di/registry"
|
||||||
crc "git.loafle.net/commons_go/rpc/client"
|
crc "git.loafle.net/commons_go/rpc/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cdr.RegisterType(reflect.TypeOf((*ContainerService)(nil)), &cda.ComponentAnnotation{})
|
||||||
|
}
|
||||||
|
|
||||||
type ContainerService struct {
|
type ContainerService struct {
|
||||||
clients map[string]*containerState
|
clients map[string]*containerState
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
cda "git.loafle.net/commons_go/di/annotation"
|
||||||
|
cdr "git.loafle.net/commons_go/di/registry"
|
||||||
configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
|
configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cdr.RegisterType(reflect.TypeOf((*CrawlerService)(nil)), &cda.ComponentAnnotation{})
|
||||||
|
}
|
||||||
|
|
||||||
type CrawlerService struct {
|
type CrawlerService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
cda "git.loafle.net/commons_go/di/annotation"
|
||||||
|
cdr "git.loafle.net/commons_go/di/registry"
|
||||||
discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model"
|
discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model"
|
||||||
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
||||||
oocmpsp "git.loafle.net/overflow/overflow_commons_go/modules/probe/service/probe"
|
oocmpsp "git.loafle.net/overflow/overflow_commons_go/modules/probe/service/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cdr.RegisterType(reflect.TypeOf((*DiscoveryService)(nil)), &cda.ComponentAnnotation{})
|
||||||
|
}
|
||||||
|
|
||||||
type DiscoveryService struct {
|
type DiscoveryService struct {
|
||||||
ContainerService *ContainerService `annotation:"@Inject()"`
|
ContainerService *ContainerService `annotation:"@Inject()"`
|
||||||
CentralService *CentralService `annotation:"@Inject()"`
|
CentralService *CentralService `annotation:"@Inject()"`
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
package service
|
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((*LogService)(nil)), &cda.ComponentAnnotation{})
|
||||||
|
}
|
||||||
|
|
||||||
type LogService struct {
|
type LogService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
package service
|
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((*ProbeService)(nil)), &cda.ComponentAnnotation{})
|
||||||
|
}
|
||||||
|
|
||||||
type ProbeService struct {
|
type ProbeService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
cda "git.loafle.net/commons_go/di/annotation"
|
||||||
|
cdr "git.loafle.net/commons_go/di/registry"
|
||||||
configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
|
configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cdr.RegisterType(reflect.TypeOf((*SensorService)(nil)), &cda.ComponentAnnotation{})
|
||||||
|
}
|
||||||
|
|
||||||
type SensorService struct {
|
type SensorService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
48
service/service.go
Normal file
48
service/service.go
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
cdr "git.loafle.net/commons_go/di/registry"
|
||||||
|
"git.loafle.net/commons_go/logging"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitService() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func DestroyService() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetService(name string) interface{} {
|
||||||
|
var t reflect.Type
|
||||||
|
switch name {
|
||||||
|
case "CentralService":
|
||||||
|
t = reflect.TypeOf((*CentralService)(nil))
|
||||||
|
case "ConfigService":
|
||||||
|
t = reflect.TypeOf((*ConfigService)(nil))
|
||||||
|
case "ContainerService":
|
||||||
|
t = reflect.TypeOf((*ContainerService)(nil))
|
||||||
|
case "CrawlerService":
|
||||||
|
t = reflect.TypeOf((*CrawlerService)(nil))
|
||||||
|
case "DiscoveryService":
|
||||||
|
t = reflect.TypeOf((*DiscoveryService)(nil))
|
||||||
|
case "LogService":
|
||||||
|
t = reflect.TypeOf((*LogService)(nil))
|
||||||
|
case "ProbeService":
|
||||||
|
t = reflect.TypeOf((*ProbeService)(nil))
|
||||||
|
case "SensorService":
|
||||||
|
t = reflect.TypeOf((*SensorService)(nil))
|
||||||
|
default:
|
||||||
|
logging.Logger().Panic(fmt.Sprintf("Probe: Service[%s] is not exist", name))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
i, err := cdr.GetInstance(t)
|
||||||
|
if nil != err {
|
||||||
|
logging.Logger().Panic(fmt.Sprintf("Probe: Getting Service[%s] is failed %v", name, err))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user