From 264c1fc72b333eafb9f07ccb7b3c13bcc36fa8bc Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 20 Apr 2018 00:03:58 +0900 Subject: [PATCH] ing --- service/ContainerService.go | 21 ++++++++++++++++++--- service/DiscoveryService.go | 13 ++++++++++--- service/ProbeClientService.go | 4 ++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/service/ContainerService.go b/service/ContainerService.go index 0e1f015..6be1889 100644 --- a/service/ContainerService.go +++ b/service/ContainerService.go @@ -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 { diff --git a/service/DiscoveryService.go b/service/DiscoveryService.go index 28c151b..578773d 100644 --- a/service/DiscoveryService.go +++ b/service/DiscoveryService.go @@ -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) } diff --git a/service/ProbeClientService.go b/service/ProbeClientService.go index c71052c..d4b5e70 100644 --- a/service/ProbeClientService.go +++ b/service/ProbeClientService.go @@ -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 }