overflow_probe_container_ne.../service/ConfigService.go
crusader 8dd32aedb8 ing
2018-03-26 11:58:39 +09:00

58 lines
1.2 KiB
Go

package service
import (
"reflect"
cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry"
configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
"git.loafle.net/overflow/overflow_probe_container_network/crawler/impl"
)
func init() {
cdr.RegisterType(reflect.TypeOf((*ConfigService)(nil)))
}
type ConfigService struct {
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
}
func (s *ConfigService) Add(crawlerName string, config *configM.Config) error {
c := impl.GetCrawler(crawlerName)
return c.Add(config)
}
func (s *ConfigService) Remove(crawlerName string, id string) error {
c := impl.GetCrawler(crawlerName)
return c.Remove(id)
}
func (s *ConfigService) Init(configs []map[string]*configM.Config) error {
var err error
sensorIDs := make([]map[string]*configM.Config, 0)
ok := true
Loop:
for _, item := range configs {
for k, v := range item {
c := impl.GetCrawler(k)
if err = c.Init(v); nil != err {
ok = false
break Loop
}
sensorIDs = append(sensorIDs, item)
}
}
if !ok {
for _, item := range sensorIDs {
for k, v := range item {
s.Remove(k, v.ID.String())
}
}
return err
}
return nil
}