2017-12-04 11:59:11 +00:00
|
|
|
package service
|
|
|
|
|
2017-12-13 14:10:52 +00:00
|
|
|
import (
|
|
|
|
configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
|
2017-12-14 06:17:58 +00:00
|
|
|
"git.loafle.net/overflow/overflow_probe_container_network/crawler/impl"
|
2017-12-13 14:10:52 +00:00
|
|
|
)
|
|
|
|
|
2017-12-04 11:59:11 +00:00
|
|
|
type ConfigService struct {
|
|
|
|
}
|
|
|
|
|
2017-12-14 06:17:58 +00:00
|
|
|
func (s *ConfigService) Add(crawlerName string, config *configM.Config) error {
|
|
|
|
c := impl.GetCrawler(crawlerName)
|
|
|
|
return c.Add(config)
|
2017-12-04 11:59:11 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 06:17:58 +00:00
|
|
|
func (s *ConfigService) Remove(crawlerName string, id string) error {
|
|
|
|
c := impl.GetCrawler(crawlerName)
|
|
|
|
return c.Remove(id)
|
2017-12-04 11:59:11 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 06:17:58 +00:00
|
|
|
func (s *ConfigService) Init(configs []map[string]*configM.Config) error {
|
|
|
|
var err error
|
|
|
|
sensorIDs := make([]map[string]*configM.Config, 0)
|
|
|
|
ok := true
|
|
|
|
Loop:
|
2017-12-13 14:10:52 +00:00
|
|
|
for _, item := range configs {
|
|
|
|
for k, v := range item {
|
2017-12-14 06:17:58 +00:00
|
|
|
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())
|
|
|
|
}
|
2017-12-13 14:10:52 +00:00
|
|
|
}
|
2017-12-14 06:17:58 +00:00
|
|
|
return err
|
2017-12-13 14:10:52 +00:00
|
|
|
}
|
2017-12-04 11:59:11 +00:00
|
|
|
|
2017-12-14 06:17:58 +00:00
|
|
|
return nil
|
2017-12-04 11:59:11 +00:00
|
|
|
}
|