2018-08-23 09:21:48 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2018-08-28 15:32:03 +00:00
|
|
|
"log"
|
2018-08-23 09:21:48 +00:00
|
|
|
"reflect"
|
|
|
|
|
|
|
|
oa "git.loafle.net/overflow/annotation-go"
|
|
|
|
od "git.loafle.net/overflow/di-go"
|
2018-08-28 15:32:03 +00:00
|
|
|
omd "git.loafle.net/overflow/model/discovery"
|
2018-08-29 12:04:23 +00:00
|
|
|
"git.loafle.net/overflow_scanner/probe/discovery"
|
2018-08-23 09:21:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
od.RegisterType(DiscoveryServiceType)
|
|
|
|
}
|
|
|
|
|
|
|
|
var DiscoveryServiceType = reflect.TypeOf((*DiscoveryService)(nil))
|
|
|
|
|
|
|
|
type DiscoveryService struct {
|
|
|
|
oa.TypeAnnotation `annotation:"@Injectable('name': 'DiscoveryService') @Service()"`
|
2018-08-29 12:04:23 +00:00
|
|
|
|
|
|
|
Discoverer discovery.Discoverer `annotation:"@Resource('name': 'Discoverer')"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DiscoveryService) InitService() error {
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DiscoveryService) StartService() error {
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case msg, ok := <-s.Discoverer.Message():
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Print(msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DiscoveryService) StopService() {
|
|
|
|
s.Discoverer.Shutdown()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DiscoveryService) DestroyService() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DiscoveryService) DiscoverHost(requesterID string, zone *omd.Zone, dh *omd.DiscoverHost) error {
|
|
|
|
s.Discoverer.DiscoverHost(requesterID, zone, dh)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DiscoveryService) DiscoverPort(requesterID string, host *omd.Host, dp *omd.DiscoverPort) error {
|
|
|
|
s.Discoverer.DiscoverPort(requesterID, host, dp)
|
|
|
|
return nil
|
2018-08-23 09:21:48 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 12:04:23 +00:00
|
|
|
func (s *DiscoveryService) DiscoverService(requesterID string, port *omd.Port, ds *omd.DiscoverService) error {
|
|
|
|
s.Discoverer.DiscoverService(requesterID, port, ds)
|
2018-08-23 10:00:34 +00:00
|
|
|
return nil
|
2018-08-23 09:21:48 +00:00
|
|
|
}
|
|
|
|
|
2018-08-23 10:00:34 +00:00
|
|
|
func (s *DiscoveryService) StopDiscover() error {
|
|
|
|
return nil
|
2018-08-23 09:21:48 +00:00
|
|
|
}
|