ing
This commit is contained in:
parent
d2d34699aa
commit
264c1fc72b
|
@ -32,7 +32,7 @@ func init() {
|
||||||
type ContainerService struct {
|
type ContainerService struct {
|
||||||
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
|
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
|
||||||
|
|
||||||
discoveryService *DiscoveryService
|
DiscoveryService *DiscoveryService `annotation:"@Inject()"`
|
||||||
|
|
||||||
rpcServiceMap map[ocpcc.ContainerType][]interface{}
|
rpcServiceMap map[ocpcc.ContainerType][]interface{}
|
||||||
containerStates map[ocpcc.ContainerType]*containerState
|
containerStates map[ocpcc.ContainerType]*containerState
|
||||||
|
@ -49,7 +49,7 @@ func (s *ContainerService) InitService() error {
|
||||||
|
|
||||||
func (s *ContainerService) StartService() error {
|
func (s *ContainerService) StartService() error {
|
||||||
s.rpcServiceMap[ocpcc.ContainerDiscovery] = []interface{}{
|
s.rpcServiceMap[ocpcc.ContainerDiscovery] = []interface{}{
|
||||||
s.discoveryService,
|
s.DiscoveryService,
|
||||||
}
|
}
|
||||||
s.rpcServiceMap[ocpcc.ContainerNetwork] = []interface{}{}
|
s.rpcServiceMap[ocpcc.ContainerNetwork] = []interface{}{}
|
||||||
s.rpcServiceMap[ocpcc.ContainerGenernal] = []interface{}{}
|
s.rpcServiceMap[ocpcc.ContainerGenernal] = []interface{}{}
|
||||||
|
@ -86,7 +86,8 @@ func (s *ContainerService) Send(containerType ocpcc.ContainerType, method string
|
||||||
func (s *ContainerService) getClient(containerType ocpcc.ContainerType) (*crc.Client, error) {
|
func (s *ContainerService) getClient(containerType ocpcc.ContainerType) (*crc.Client, error) {
|
||||||
cs := s.checkContainer(containerType)
|
cs := s.checkContainer(containerType)
|
||||||
if nil == cs {
|
if nil == cs {
|
||||||
_cs, err := s.runContainer(containerType)
|
// _cs, err := s.runContainer(containerType)
|
||||||
|
_cs, err := s.debugContainer(containerType)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -100,6 +101,10 @@ func (s *ContainerService) getClient(containerType ocpcc.ContainerType) (*crc.Cl
|
||||||
s.removeContainerState(containerType)
|
s.removeContainerState(containerType)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if err := client.Start(); nil != err {
|
||||||
|
s.removeContainerState(containerType)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
cs.client = client
|
cs.client = client
|
||||||
cs.client.Connector.SetOnDisconnected(s.onDisconnected)
|
cs.client.Connector.SetOnDisconnected(s.onDisconnected)
|
||||||
s.connectorMap[cs.client.Connector] = cs
|
s.connectorMap[cs.client.Connector] = cs
|
||||||
|
@ -150,6 +155,16 @@ func (s *ContainerService) runContainer(containerType ocpcc.ContainerType) (*con
|
||||||
return cs, nil
|
return cs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ContainerService) debugContainer(containerType ocpcc.ContainerType) (*containerState, error) {
|
||||||
|
cs := &containerState{
|
||||||
|
containerType: containerType,
|
||||||
|
cmd: nil,
|
||||||
|
port: 60000,
|
||||||
|
}
|
||||||
|
|
||||||
|
return cs, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ContainerService) checkContainer(containerType ocpcc.ContainerType) *containerState {
|
func (s *ContainerService) checkContainer(containerType ocpcc.ContainerType) *containerState {
|
||||||
cs, ok := s.containerStates[containerType]
|
cs, ok := s.containerStates[containerType]
|
||||||
if !ok || nil == cs {
|
if !ok || nil == cs {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"time"
|
||||||
|
|
||||||
cda "git.loafle.net/commons/di-go/annotation"
|
cda "git.loafle.net/commons/di-go/annotation"
|
||||||
cdr "git.loafle.net/commons/di-go/registry"
|
cdr "git.loafle.net/commons/di-go/registry"
|
||||||
|
@ -26,8 +27,6 @@ type DiscoveryService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DiscoveryService) InitService() error {
|
func (s *DiscoveryService) InitService() error {
|
||||||
s.ProbeClientService.discoveryService = s
|
|
||||||
s.ContainerService.discoveryService = s
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -58,10 +57,18 @@ func (s *DiscoveryService) DiscoverPort(requesterID string, host *ocdm.Host, dp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DiscoveryService) DiscoverService(requesterID string, port *ocdm.Port, dService *ocdm.DiscoveryService) error {
|
func (s *DiscoveryService) DiscoverService(requesterID string, port *ocdm.Port, dService *ocdm.DiscoveryService) error {
|
||||||
return s.ContainerService.Send(ocpcc.ContainerDiscovery, "DiscoveryService.DiscoverZone", requesterID, port, dService)
|
return s.ContainerService.Send(ocpcc.ContainerDiscovery, "DiscoveryService.DiscoverService", requesterID, port, dService)
|
||||||
}
|
}
|
||||||
|
|
||||||
// use by discovery
|
// use by discovery
|
||||||
|
func (s *DiscoveryService) DiscoveryStart(requesterID string, t *time.Time) error {
|
||||||
|
return s.ProbeClientService.Send("DiscoveryService.discoveryStart", requesterID, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DiscoveryService) DiscoveryStop(requesterID string, t *time.Time) error {
|
||||||
|
return s.ProbeClientService.Send("DiscoveryService.discoveryStop", requesterID, t)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *DiscoveryService) DiscoveredZone(requesterID string, zone *ocdm.Zone) error {
|
func (s *DiscoveryService) DiscoveredZone(requesterID string, zone *ocdm.Zone) error {
|
||||||
return s.ProbeClientService.Send("DiscoveryService.discoveredZone", requesterID, zone)
|
return s.ProbeClientService.Send("DiscoveryService.discoveredZone", requesterID, zone)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ type ProbeClientService struct {
|
||||||
|
|
||||||
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
|
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
|
||||||
|
|
||||||
discoveryService *DiscoveryService
|
DiscoveryService *DiscoveryService `annotation:"@Inject()"`
|
||||||
|
|
||||||
EncryptionKey string
|
EncryptionKey string
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ func (s *ProbeClientService) StartService() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := central.NewProbe(s.HandleEncryptionKey, s.discoveryService)
|
client, err := central.NewProbe(s.HandleEncryptionKey, s.DiscoveryService)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user