2017-04-27 09:07:56 +00:00
|
|
|
package crawler_manager
|
|
|
|
|
|
|
|
import (
|
|
|
|
"loafle.com/overflow/agent_api/observer"
|
|
|
|
"loafle.com/overflow/agent_api/config_manager"
|
|
|
|
"loafle.com/overflow/agent_api/observer/messages"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func listenEvent() {
|
|
|
|
|
|
|
|
go listenConfigLoaded();
|
2017-05-11 09:19:06 +00:00
|
|
|
go listenAgentStop()
|
|
|
|
|
2017-04-27 09:07:56 +00:00
|
|
|
go listenAddSensor();
|
2017-04-27 11:24:35 +00:00
|
|
|
go listenRemoveSensor();
|
2017-05-11 09:19:06 +00:00
|
|
|
go listenUpdateSensor();
|
2017-04-27 09:07:56 +00:00
|
|
|
|
2017-05-11 09:19:06 +00:00
|
|
|
go listenUpdateCrawler()
|
2017-04-27 09:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func listenConfigLoaded() {
|
|
|
|
|
|
|
|
ch := make(chan interface{}, 0)
|
2017-05-11 09:19:06 +00:00
|
|
|
observer.Add(messages.CFG_LOADED, ch)
|
2017-04-27 09:07:56 +00:00
|
|
|
|
|
|
|
o := <-ch
|
|
|
|
|
|
|
|
cm := o.(config_manager.ConfigManager)
|
|
|
|
|
|
|
|
GetInstance().ConfigMgr = cm;
|
|
|
|
|
2017-04-28 04:44:56 +00:00
|
|
|
SettingPath()
|
|
|
|
|
2017-05-11 09:19:06 +00:00
|
|
|
err := GetInstance().init();
|
|
|
|
if err != nil {
|
|
|
|
//FIXME:: noti err
|
|
|
|
return;
|
|
|
|
}
|
2017-04-27 09:07:56 +00:00
|
|
|
|
2017-04-28 04:44:56 +00:00
|
|
|
|
2017-05-11 11:37:39 +00:00
|
|
|
observer.Notify(messages.CRM_READY, cm)
|
2017-05-11 09:19:06 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2017-04-28 04:44:56 +00:00
|
|
|
|
2017-04-27 09:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func listenAddSensor() {
|
|
|
|
ch := make(chan interface{}, 0)
|
2017-05-11 09:19:06 +00:00
|
|
|
observer.Add(messages.SCF_SENSOR_ADD_DONE, ch);
|
2017-04-27 09:07:56 +00:00
|
|
|
|
|
|
|
o := <-ch
|
|
|
|
|
|
|
|
str := o.(string)
|
|
|
|
|
|
|
|
fmt.Println(str)
|
2017-04-27 11:24:35 +00:00
|
|
|
|
2017-05-11 09:19:06 +00:00
|
|
|
err := GetInstance().addSensor(str)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
//FIXME:: noti err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
observer.Notify(messages.CRM_SENSOR_ADD_DONE, nil)
|
2017-04-27 11:24:35 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func listenRemoveSensor() {
|
|
|
|
|
|
|
|
ch := make(chan interface{}, 0)
|
2017-05-11 09:19:06 +00:00
|
|
|
observer.Add(messages.CLT_SENSOR_REMOVE_DONE, ch);
|
2017-04-27 11:24:35 +00:00
|
|
|
|
|
|
|
o := <-ch
|
|
|
|
|
|
|
|
str := o.(string)
|
|
|
|
|
|
|
|
GetInstance().removeSensor(str)
|
|
|
|
|
2017-05-11 09:19:06 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2017-04-27 09:07:56 +00:00
|
|
|
}
|
|
|
|
|