ConfigManager implements
This commit is contained in:
parent
7c70d2ca1f
commit
19afde84eb
|
@ -11,7 +11,6 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type configManager struct {
|
||||
|
@ -36,8 +35,10 @@ func init() {
|
|||
agentStartHandler()
|
||||
addSensorHandler()
|
||||
removeSensorHandler()
|
||||
agentEndHandler()
|
||||
}
|
||||
|
||||
|
||||
func NewConfigManager() *configManager {
|
||||
c := &configManager{
|
||||
configs: make(map[string]*config_manager.Config, 0),
|
||||
|
@ -184,6 +185,8 @@ func (c *configManager) removeConfig() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// implements methods
|
||||
func (c *configManager) GetGlobalConfig() *config_manager.GlobalConfig {
|
||||
return &c.globalConfig
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
|
||||
// +build !test
|
||||
package config_manager_go
|
||||
|
||||
import (
|
||||
|
@ -22,13 +24,6 @@ func TestLoadConfig(t *testing.T) {
|
|||
data :=<- ch
|
||||
c := data.(config_manager.ConfigManager)
|
||||
cc := c.GetSensors()
|
||||
|
||||
//ccc := cc["75045c53-a78d-4589-b8c1-4482cab720b6"]
|
||||
//
|
||||
//mmmm := ccc.Items[0].Keys[0].Metric
|
||||
//
|
||||
//fmt.Println(mmmm)
|
||||
//
|
||||
assert.NotEqual(t, len(cc),0)
|
||||
}()
|
||||
|
||||
|
@ -44,7 +39,6 @@ func TestLoadConfig(t *testing.T) {
|
|||
|
||||
|
||||
func TestAddConfig(t *testing.T) {
|
||||
|
||||
_configManager.loadGlobalConfig("/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/global.yaml")
|
||||
|
||||
// 원본 테스트 설정 파일 로드
|
||||
|
@ -73,6 +67,6 @@ func TestRemoveConfig(t *testing.T) {
|
|||
_configManager.loadCrawlerConfigAll()
|
||||
|
||||
// remove test
|
||||
observer.Notify(messages.REMOVE_SENSOR_0,"289575d2-4a34-4475-b91d-7fb0992cc3de")
|
||||
observer.Notify(messages.REMOVE_SENSOR_0,"d0fcc7b1-43a7-4acd-a7bf-c9572a9d4c9e")
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
func agentStartHandler() {
|
||||
agentStart := make(chan interface{}, 0)
|
||||
observer.Add("AGENT_STARTED", agentStart)
|
||||
observer.Add(messages.AGENT_STARTED, agentStart)
|
||||
go func() {
|
||||
data := <-agentStart
|
||||
path := data.(string)
|
||||
|
@ -24,12 +24,25 @@ func agentStartHandler() {
|
|||
}()
|
||||
}
|
||||
|
||||
func removeSensorHandler() {
|
||||
observer.Add(messages.REMOVE_SENSOR_0,_configManager.removeCh)
|
||||
go _configManager.removeConfig()
|
||||
func agentEndHandler() {
|
||||
agentEnd := make(chan interface{}, 0)
|
||||
observer.Add(messages.AGENT_WILL_STOPPED, agentEnd)
|
||||
go func() {
|
||||
_ = <-agentEnd
|
||||
observer.Remove(messages.AGENT_WILL_STOPPED, agentEnd)
|
||||
observer.Remove(messages.ADD_SENSOR_0,_configManager.addCh)
|
||||
observer.Remove(messages.REMOVE_SENSOR_0,_configManager.removeCh)
|
||||
}()
|
||||
}
|
||||
|
||||
func addSensorHandler() {
|
||||
observer.Add(messages.ADD_SENSOR_0,_configManager.addCh)
|
||||
go _configManager.addConfig()
|
||||
}
|
||||
|
||||
func removeSensorHandler() {
|
||||
observer.Add(messages.REMOVE_SENSOR_0,_configManager.removeCh)
|
||||
go _configManager.removeConfig()
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user