This commit is contained in:
crusader 2017-12-08 21:01:38 +09:00
parent fb7d1ca4d6
commit 14c4949480
10 changed files with 150 additions and 17 deletions

View File

@ -4,9 +4,11 @@ import (
"fmt"
"sync"
cdr "git.loafle.net/commons_go/di/registry"
"git.loafle.net/commons_go/logging"
crr "git.loafle.net/commons_go/rpc/registry"
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"
oopccp "git.loafle.net/overflow/overflow_probes/client/central/probe"
"git.loafle.net/overflow/overflow_probes/service"
@ -34,28 +36,38 @@ func (pm *probeManagers) Start() error {
}
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)
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 {
return err
}
centralDataClient := oopccd.New()
if err := centralDataClient.Connect(); nil != 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.stopWg.Add(1)

View File

@ -1,15 +1,23 @@
package service
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"
)
func init() {
cdr.RegisterType(reflect.TypeOf((*CentralService)(nil)), &cda.ComponentAnnotation{})
}
type CentralService struct {
clients map[string]oogwc.Client
CentralClients map[string]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 {
@ -24,11 +32,11 @@ func (cs *CentralService) Send(entryPath string, method string, params ...interf
}
func (cs *CentralService) GetClient(entryPath string) oogwc.Client {
return cs.clients[entryPath]
return cs.CentralClients[entryPath]
}
func (cs *CentralService) CheckClient(entryPath string) bool {
c, ok := cs.clients[entryPath]
c, ok := cs.CentralClients[entryPath]
if !ok || nil == c {
return false
}

View File

@ -1,4 +1,15 @@
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 {
}

View File

@ -1,9 +1,17 @@
package service
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"
)
func init() {
cdr.RegisterType(reflect.TypeOf((*ContainerService)(nil)), &cda.ComponentAnnotation{})
}
type ContainerService struct {
clients map[string]*containerState
}

View File

@ -1,9 +1,17 @@
package service
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"
)
func init() {
cdr.RegisterType(reflect.TypeOf((*CrawlerService)(nil)), &cda.ComponentAnnotation{})
}
type CrawlerService struct {
}

View File

@ -1,11 +1,19 @@
package service
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"
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/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 {
ContainerService *ContainerService `annotation:"@Inject()"`
CentralService *CentralService `annotation:"@Inject()"`

View File

@ -1,5 +1,16 @@
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 {
}

View File

@ -1,5 +1,16 @@
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 {
}

View File

@ -1,9 +1,17 @@
package service
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"
)
func init() {
cdr.RegisterType(reflect.TypeOf((*SensorService)(nil)), &cda.ComponentAnnotation{})
}
type SensorService struct {
}

48
service/service.go Normal file
View 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
}