added event

This commit is contained in:
snoop 2017-05-11 18:19:06 +09:00
parent 7d9a9a41de
commit c300dd6d49
2 changed files with 91 additions and 15 deletions

View File

@ -89,15 +89,19 @@ func (c *CrawlerManager)GetClient(container string) (*grpc.ClientConn, error) {
func (c *CrawlerManager)init() { func (c *CrawlerManager)init() error {
c.checkPid() c.checkPid()
cmap := c.ConfigMgr.GetCrawlers() cmap := c.ConfigMgr.GetSensors()
scm := sortContainer(cmap) scm := sortContainer(cmap)
for ctn := range scm { for ctn := range scm {
c.runAndInitContainer(&ctn, scm[ctn]) err := c.runAndInitContainer(&ctn, scm[ctn])
if err != nil {
return err
}
} }
} }
@ -154,7 +158,7 @@ func (c *CrawlerManager)runAndInitContainerOne(container *string) error {
return err return err
} }
cmap := c.ConfigMgr.GetCrawlers() cmap := c.ConfigMgr.GetSensors()
scm := sortContainer(cmap) scm := sortContainer(cmap)
b := callInitConfig(container, scm[*container]) b := callInitConfig(container, scm[*container])
@ -246,26 +250,28 @@ func (c *CrawlerManager)runContainer(container *string) error {
return nil return nil
} }
func (c *CrawlerManager)addSensor(id string) { func (c *CrawlerManager)addSensor(id string) error {
conf := c.ConfigMgr.GetCrawlerById(id) conf := c.ConfigMgr.GetSensorById(id)
b := c.checkAndRunContainer(&conf.Crawler.Name) b := c.checkAndRunContainer(&conf.Crawler.Name)
if b == false { if b == false {
return return errors.New("run container error")
} }
b = callAdd(&conf.Crawler.Container, conf) b = callAdd(&conf.Crawler.Container, conf)
if b { if b == false {
//FIXME :: Noti ADD_SENSOR_2_END return errors.New("Call Add Fail")
} }
return nil
} }
func (c *CrawlerManager)removeSensor(id string) { func (c *CrawlerManager)removeSensor(id string) {
conf := c.ConfigMgr.GetCrawlerById(id) conf := c.ConfigMgr.GetSensorById(id)
callRemove(&conf.Crawler.Name, conf) callRemove(&conf.Crawler.Name, conf)

View File

@ -12,15 +12,19 @@ import (
func listenEvent() { func listenEvent() {
go listenConfigLoaded(); go listenConfigLoaded();
go listenAgentStop()
go listenAddSensor(); go listenAddSensor();
go listenRemoveSensor(); go listenRemoveSensor();
go listenUpdateSensor();
go listenUpdateCrawler()
} }
func listenConfigLoaded() { func listenConfigLoaded() {
ch := make(chan interface{}, 0) ch := make(chan interface{}, 0)
observer.Add(messages.CONFIGMANAGER_LOADED, ch) observer.Add(messages.CFG_LOADED, ch)
o := <-ch o := <-ch
@ -30,15 +34,36 @@ func listenConfigLoaded() {
SettingPath() SettingPath()
GetInstance().init(); err := GetInstance().init();
if err != nil {
//FIXME:: noti err
return;
}
observer.Notify(messages.CRM_READY, nil)
}
func listenAgentStop() {
ch := make(chan interface{}, 0)
observer.Add(messages.CLT_STOPPED, ch)
o := <-ch
fmt.Println(o)
GetInstance().stopContainerAll()
observer.Notify(messages.CRM_STOPPED, nil)
} }
func listenAddSensor() { func listenAddSensor() {
ch := make(chan interface{}, 0) ch := make(chan interface{}, 0)
observer.Add(messages.ADD_SENSOR_1, ch); observer.Add(messages.SCF_SENSOR_ADD_DONE, ch);
o := <-ch o := <-ch
@ -46,14 +71,21 @@ func listenAddSensor() {
fmt.Println(str) fmt.Println(str)
GetInstance().addSensor(str) err := GetInstance().addSensor(str)
if err != nil {
//FIXME:: noti err
return
}
observer.Notify(messages.CRM_SENSOR_ADD_DONE, nil)
} }
func listenRemoveSensor() { func listenRemoveSensor() {
ch := make(chan interface{}, 0) ch := make(chan interface{}, 0)
//observer.Add(messages.REMOVE_SENSOR_2_END, ch); observer.Add(messages.CLT_SENSOR_REMOVE_DONE, ch);
o := <-ch o := <-ch
@ -61,5 +93,43 @@ func listenRemoveSensor() {
GetInstance().removeSensor(str) GetInstance().removeSensor(str)
observer.Notify(messages.CRM_SENSOR_REMOVE_DONE, nil)
}
func listenUpdateSensor() {
ch := make(chan interface{}, 0)
observer.Add(messages.SCF_SENSOR_UPDATE_DONE, ch);
o := <-ch
container := o.(string)
err := GetInstance().runAndInitContainerOne(&container)
if err != nil {
//FIXME:: noti err
return
}
observer.Notify(messages.CRM_SENSOR_UPDATE_DONE, nil)
}
func listenUpdateCrawler() {
ch := make(chan interface{}, 0)
observer.Add(messages.CLT_CRM_UPDATE_DONE, ch);
o := <-ch
fmt.Println(o)
//FIXME::update crawler
observer.Notify(messages.CRM_UPDATE_DONE, nil)
} }