conf manager is modifying
This commit is contained in:
parent
8ed361e75c
commit
56ef04f440
|
@ -5,48 +5,54 @@ import (
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"loafle.com/overflow/agent_api/config_manager"
|
"loafle.com/overflow/agent_api/config_manager"
|
||||||
"loafle.com/overflow/agent_api/observer"
|
|
||||||
"loafle.com/overflow/agent_api/observer/messages"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"loafle.com/overflow/agent_api/messages"
|
||||||
)
|
)
|
||||||
|
|
||||||
type configManager struct {
|
type configManager struct {
|
||||||
config_manager.ConfigManager // interface implements
|
config_manager.ConfigManager // interface implements
|
||||||
|
|
||||||
addCh chan interface{}
|
|
||||||
removeCh chan interface{}
|
|
||||||
|
|
||||||
configs map[string] *config_manager.Config
|
configs map[string] *config_manager.Config
|
||||||
globalConfig config_manager.GlobalConfig
|
globalConfig config_manager.GlobalConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
var _configManager *configManager
|
var _configManager *configManager
|
||||||
|
|
||||||
func init() {
|
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 GetInstance() *configManager {
|
||||||
var once sync.Once
|
var once sync.Once
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
_configManager = NewConfigManager()
|
_configManager = &configManager{
|
||||||
|
configs: make(map[string]*config_manager.Config, 0),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// regist handlers
|
return _configManager
|
||||||
agentStartHandler()
|
|
||||||
addSensorHandler()
|
|
||||||
removeSensorHandler()
|
|
||||||
agentEndHandler()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *configManager) stop() {}
|
||||||
|
|
||||||
func NewConfigManager() *configManager {
|
|
||||||
c := &configManager{
|
|
||||||
configs: make(map[string]*config_manager.Config, 0),
|
|
||||||
addCh: make(chan interface{}, 0),
|
|
||||||
removeCh: make(chan interface{}, 0),
|
|
||||||
}
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *configManager) getConfigPath() string {
|
func (c *configManager) getConfigPath() string {
|
||||||
return c.globalConfig.Paths.RootFolder + c.globalConfig.Paths.ConfigFolder
|
return c.globalConfig.Paths.RootFolder + c.globalConfig.Paths.ConfigFolder
|
||||||
|
|
|
@ -1,48 +1,48 @@
|
||||||
package config_manager_go
|
package config_manager_go
|
||||||
|
|
||||||
import (
|
//import (
|
||||||
"loafle.com/overflow/agent_api/observer"
|
// "loafle.com/overflow/agent_api/observer"
|
||||||
"loafle.com/overflow/agent_api/observer/messages"
|
// "loafle.com/overflow/agent_api/messages"
|
||||||
)
|
//)
|
||||||
|
//
|
||||||
func agentStartHandler() {
|
//func agentStartHandler() {
|
||||||
agentStart := make(chan interface{}, 0)
|
// agentStart := make(chan interface{}, 0)
|
||||||
observer.Add(messages.AGT_STARTING, agentStart)
|
// observer.Add(messages.AGT_STARTING, agentStart)
|
||||||
go func() {
|
// go func() {
|
||||||
data := <-agentStart
|
// data := <-agentStart
|
||||||
path := data.(string)
|
// path := data.(string)
|
||||||
// load global config
|
// // load global config
|
||||||
_configManager.loadGlobalConfig(path + "/" + "global.yaml")
|
// _configManager.loadGlobalConfig(path + "/" + "global.yaml")
|
||||||
|
//
|
||||||
// load all crawler configs
|
// // load all crawler configs
|
||||||
if err := _configManager.loadCrawlerConfigAll(); err != nil {
|
// if err := _configManager.loadCrawlerConfigAll(); err != nil {
|
||||||
// error process
|
// // error process
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
observer.Remove(messages.AGT_STARTING, agentStart)
|
// observer.Remove(messages.AGT_STARTING, agentStart)
|
||||||
observer.Notify(messages.CFG_LOADED, _configManager)
|
// observer.Notify(messages.CFG_LOADED, _configManager)
|
||||||
}()
|
// }()
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func agentEndHandler() {
|
//func agentEndHandler() {
|
||||||
agentEnd := make(chan interface{}, 0)
|
// agentEnd := make(chan interface{}, 0)
|
||||||
observer.Add(messages.AGT_WILL_STOP, agentEnd)
|
// observer.Add(messages.AGT_WILL_STOP, agentEnd)
|
||||||
go func() {
|
// go func() {
|
||||||
_ = <-agentEnd
|
// _ = <-agentEnd
|
||||||
observer.Remove(messages.AGT_WILL_STOP, agentEnd)
|
// observer.Remove(messages.AGT_WILL_STOP, agentEnd)
|
||||||
observer.Remove(messages.TASK_SENSOR_ADD,_configManager.addCh)
|
// observer.Remove(messages.TASK_SENSOR_ADD,_configManager.addCh)
|
||||||
observer.Remove(messages.TASK_SENSOR_REMOVE,_configManager.removeCh)
|
// observer.Remove(messages.TASK_SENSOR_REMOVE,_configManager.removeCh)
|
||||||
}()
|
// }()
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func addSensorHandler() {
|
//func addSensorHandler() {
|
||||||
observer.Add(messages.TASK_SENSOR_ADD,_configManager.addCh)
|
// observer.Add(messages.TASK_SENSOR_ADD,_configManager.addCh)
|
||||||
go _configManager.addConfig()
|
// go _configManager.addConfig()
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func removeSensorHandler() {
|
//func removeSensorHandler() {
|
||||||
observer.Add(messages.TASK_SENSOR_REMOVE,_configManager.removeCh)
|
// observer.Add(messages.TASK_SENSOR_REMOVE,_configManager.removeCh)
|
||||||
go _configManager.removeConfig()
|
// go _configManager.removeConfig()
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ central:
|
||||||
port: 443
|
port: 443
|
||||||
logPath: "./bin/log.xml"
|
logPath: "./bin/log.xml"
|
||||||
paths:
|
paths:
|
||||||
rootFolder : "/home/snoop/develop/path/go/src/loafle.com/overflow/config_manager_go/test_agent/"
|
rootFolder : "/home/insanity/Develop/gopath/src/loafle.com/overflow/config_manager_go/test_agent/"
|
||||||
configFolder : "config/"
|
configFolder : "config/"
|
||||||
binaryFolder : "container/"
|
binaryFolder : "container/"
|
||||||
pidFolder : "pids/"
|
pidFolder : "pids/"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user