This commit is contained in:
crusader 2018-04-20 00:03:58 +09:00
parent d2d34699aa
commit 264c1fc72b
3 changed files with 30 additions and 8 deletions

View File

@ -32,7 +32,7 @@ func init() {
type ContainerService struct {
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
discoveryService *DiscoveryService
DiscoveryService *DiscoveryService `annotation:"@Inject()"`
rpcServiceMap map[ocpcc.ContainerType][]interface{}
containerStates map[ocpcc.ContainerType]*containerState
@ -49,7 +49,7 @@ func (s *ContainerService) InitService() error {
func (s *ContainerService) StartService() error {
s.rpcServiceMap[ocpcc.ContainerDiscovery] = []interface{}{
s.discoveryService,
s.DiscoveryService,
}
s.rpcServiceMap[ocpcc.ContainerNetwork] = []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) {
cs := s.checkContainer(containerType)
if nil == cs {
_cs, err := s.runContainer(containerType)
// _cs, err := s.runContainer(containerType)
_cs, err := s.debugContainer(containerType)
if nil != err {
return nil, err
}
@ -100,6 +101,10 @@ func (s *ContainerService) getClient(containerType ocpcc.ContainerType) (*crc.Cl
s.removeContainerState(containerType)
return nil, err
}
if err := client.Start(); nil != err {
s.removeContainerState(containerType)
return nil, err
}
cs.client = client
cs.client.Connector.SetOnDisconnected(s.onDisconnected)
s.connectorMap[cs.client.Connector] = cs
@ -150,6 +155,16 @@ func (s *ContainerService) runContainer(containerType ocpcc.ContainerType) (*con
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 {
cs, ok := s.containerStates[containerType]
if !ok || nil == cs {

View File

@ -2,6 +2,7 @@ package service
import (
"reflect"
"time"
cda "git.loafle.net/commons/di-go/annotation"
cdr "git.loafle.net/commons/di-go/registry"
@ -26,8 +27,6 @@ type DiscoveryService struct {
}
func (s *DiscoveryService) InitService() error {
s.ProbeClientService.discoveryService = s
s.ContainerService.discoveryService = s
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 {
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
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 {
return s.ProbeClientService.Send("DiscoveryService.discoveredZone", requesterID, zone)
}

View File

@ -22,7 +22,7 @@ type ProbeClientService struct {
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
discoveryService *DiscoveryService
DiscoveryService *DiscoveryService `annotation:"@Inject()"`
EncryptionKey string
}
@ -40,7 +40,7 @@ func (s *ProbeClientService) StartService() error {
return err
}
client, err := central.NewProbe(s.HandleEncryptionKey, s.discoveryService)
client, err := central.NewProbe(s.HandleEncryptionKey, s.DiscoveryService)
if nil != err {
return err
}