overflow_probes/service/CrawlerService.go

83 lines
2.0 KiB
Go
Raw Normal View History

2017-12-02 03:13:08 +00:00
package service
2017-12-04 11:59:51 +00:00
2017-12-05 08:21:47 +00:00
import (
2018-03-26 06:55:38 +00:00
"context"
2017-12-08 12:01:38 +00:00
"reflect"
cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry"
2018-03-26 15:14:19 +00:00
"git.loafle.net/commons_go/logging"
2018-03-26 06:55:38 +00:00
oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces"
2018-03-26 15:14:19 +00:00
sensorConfigM "git.loafle.net/overflow/overflow_commons_go/modules/sensor_config/model"
2017-12-05 08:21:47 +00:00
)
2017-12-08 12:01:38 +00:00
func init() {
2018-03-15 13:52:23 +00:00
cdr.RegisterType(reflect.TypeOf((*CrawlerService)(nil)))
2017-12-08 12:01:38 +00:00
}
2017-12-04 11:59:51 +00:00
type CrawlerService struct {
2018-03-15 13:52:23 +00:00
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
2018-03-26 06:55:38 +00:00
oocmci.Service
2018-03-26 15:14:19 +00:00
SensorConfigService *SensorConfigService `annotation:"@Inject()"`
ContainerService *ContainerService `annotation:"@Inject()"`
2018-03-26 06:55:38 +00:00
}
func (cs *CrawlerService) Start() error {
2018-03-26 15:14:19 +00:00
sensorConfigs := cs.SensorConfigService.sensorConfigs
if nil == sensorConfigs || 0 == len(sensorConfigs) {
logging.Logger().Infof("Probe: There is no Sensor config")
return nil
}
sortedMap := sortSensorConfigPerContainer(sensorConfigs)
for containerName, configs := range sortedMap {
if err := cs.ContainerService.Send(containerName, "SensorConfigService.Init", configs); nil != err {
return err
}
}
2018-03-26 06:55:38 +00:00
return nil
}
func (cs *CrawlerService) Stop(ctx context.Context) error {
return nil
2017-12-04 11:59:51 +00:00
}
func (cs *CrawlerService) Install() error {
2017-12-05 08:21:47 +00:00
return nil
2017-12-04 11:59:51 +00:00
}
func (cs *CrawlerService) Uninstall() error {
2017-12-05 08:21:47 +00:00
return nil
2017-12-04 11:59:51 +00:00
}
func (cs *CrawlerService) Update() error {
2017-12-05 08:21:47 +00:00
return nil
2017-12-04 11:59:51 +00:00
}
2018-03-26 15:14:19 +00:00
func (cs *CrawlerService) Authenticate(crawler *sensorConfigM.Crawler, target *sensorConfigM.Target) error {
2017-12-05 08:21:47 +00:00
return nil
2017-12-04 11:59:51 +00:00
}
2018-03-26 15:14:19 +00:00
func sortSensorConfigPerContainer(sensorConfigMap map[string]*sensorConfigM.SensorConfig) map[string][]*sensorConfigM.SensorConfig {
if nil == sensorConfigMap || 0 == len(sensorConfigMap) {
return nil
}
m := make(map[string][]*sensorConfigM.SensorConfig)
for _, sensorConfig := range sensorConfigMap {
containerName := sensorConfig.Crawler.Container
scs, ok := m[containerName]
if !ok {
scs = make([]*sensorConfigM.SensorConfig, 0)
m[containerName] = scs
}
scs = append(scs, sensorConfig)
}
return m
}