overflow_probe/config_manager/init_method.go

116 lines
2.5 KiB
Go
Raw Normal View History

2017-08-04 02:32:31 +00:00
package config_manager
2017-08-03 10:08:34 +00:00
import (
2017-08-04 02:32:31 +00:00
"git.loafle.net/overflow/overflow_probe/agent_api/config_manager"
2017-08-03 10:08:34 +00:00
)
//import (
2017-08-04 02:32:31 +00:00
// "git.loafle.net/overflow/overflow_probe/agent_api/observer"
// "git.loafle.net/overflow/overflow_probe/agent_api/messages"
2017-08-03 10:08:34 +00:00
//)
//
func Start(ch chan *config_manager.GlobalConfig, path string) error {
_configManager = GetInstance()
_configManager.loadGlobalConfig(path + "/" + "global.yaml")
ch <- _configManager.GetGlobalConfig()
return nil
}
func StartSensorConfig(ch chan config_manager.ConfigManager, authKey string) error {
if err := _configManager.loadCrawlerConfigAll(); err != nil {
return err
}
ch <- _configManager
return nil
}
func Stop(ch chan bool) {
GetInstance().stop()
ch <- true
}
func AddSensor(tmpFilePath string) {
GetInstance().addConfig(tmpFilePath)
////move file
//moveFile := tmpFilePath
////load file
//
//file, err := os.Open(moveFile)
//
//if err != nil {
// log.Panic(err)
//}
//
//b, err := ioutil.ReadFile(moveFile)
//if err != nil {
// log.Panic(err)
//}
//var m = config_manager.Config{}
//json.Unmarshal(b, &m)
//GetInstance().configs[file.Name()] = &m
}
func RemoveSensor(id string) {
//remove object
// remove file
GetInstance().removeConfig(id)
}
func UpdateSensor(tmpFile string) {
//GetInstance().
//overwrite file
// reload file
GetInstance().addConfig(tmpFile)
}
//func agentStartHandler() {
// agentStart := make(chan interface{}, 0)
// observer.Add(messages.AGT_STARTING, agentStart)
// go func() {
// data := <-agentStart
// path := data.(string)
// // load global config
// _configManager.loadGlobalConfig(path + "/" + "global.yaml")
//
// // load all crawler configs
// if err := _configManager.loadCrawlerConfigAll(); err != nil {
// // error process
// }
//
// observer.Remove(messages.AGT_STARTING, agentStart)
// observer.Notify(messages.CFG_LOADED, _configManager)
// }()
//}
//
//func agentEndHandler() {
// agentEnd := make(chan interface{}, 0)
// observer.Add(messages.AGT_WILL_STOP, agentEnd)
// go func() {
// _ = <-agentEnd
// observer.Remove(messages.AGT_WILL_STOP, agentEnd)
// observer.Remove(messages.TASK_SENSOR_ADD,_configManager.addCh)
// observer.Remove(messages.TASK_SENSOR_REMOVE,_configManager.removeCh)
// }()
//}
//
//func addSensorHandler() {
// observer.Add(messages.TASK_SENSOR_ADD,_configManager.addCh)
// go _configManager.addConfig()
//}
//
//func removeSensorHandler() {
// observer.Add(messages.TASK_SENSOR_REMOVE,_configManager.removeCh)
// go _configManager.removeConfig()
//}