conf manager is modifying

This commit is contained in:
insanity@loafle.com 2017-05-16 15:15:13 +09:00
parent 8ed361e75c
commit 56ef04f440
3 changed files with 72 additions and 66 deletions

View File

@ -5,48 +5,54 @@ import (
"gopkg.in/yaml.v2"
"io/ioutil"
"loafle.com/overflow/agent_api/config_manager"
"loafle.com/overflow/agent_api/observer"
"loafle.com/overflow/agent_api/observer/messages"
"log"
"os"
"strings"
"sync"
"loafle.com/overflow/agent_api/messages"
)
type configManager struct {
config_manager.ConfigManager // interface implements
addCh chan interface{}
removeCh chan interface{}
configs map[string] *config_manager.Config
globalConfig config_manager.GlobalConfig
}
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
once.Do(func() {
_configManager = NewConfigManager()
_configManager = &configManager{
configs: make(map[string]*config_manager.Config, 0),
}
})
// regist handlers
agentStartHandler()
addSensorHandler()
removeSensorHandler()
agentEndHandler()
return _configManager
}
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 {
return c.globalConfig.Paths.RootFolder + c.globalConfig.Paths.ConfigFolder

View File

@ -1,48 +1,48 @@
package config_manager_go
import (
"loafle.com/overflow/agent_api/observer"
"loafle.com/overflow/agent_api/observer/messages"
)
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()
}
//import (
// "loafle.com/overflow/agent_api/observer"
// "loafle.com/overflow/agent_api/messages"
//)
//
//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()
//}

View File

@ -3,7 +3,7 @@ central:
port: 443
logPath: "./bin/log.xml"
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/"
binaryFolder : "container/"
pidFolder : "pids/"