116 lines
2.4 KiB
Go
116 lines
2.4 KiB
Go
package config_manager_go
|
|
|
|
import (
|
|
"loafle.com/overflow/agent_api/config_manager"
|
|
)
|
|
|
|
//import (
|
|
// "loafle.com/overflow/agent_api/observer"
|
|
// "loafle.com/overflow/agent_api/messages"
|
|
//)
|
|
//
|
|
|
|
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()
|
|
//}
|