From 6aeb8743cabba63ca1835c416aed199f980bea83 Mon Sep 17 00:00:00 2001 From: "insanity@loafle.com" Date: Mon, 15 May 2017 18:19:37 +0900 Subject: [PATCH] const added --- messages/agent.go | 8 +++ {observer/messages => messages}/collector.go | 0 .../messages => messages}/config_manager.go | 6 +- {observer/messages => messages}/crawler.go | 4 +- messages/crawler_manager.go | 10 +++ .../messages => messages}/data_sender.go | 0 .../messages => messages}/event_sender.go | 2 +- messages/poller.go | 14 ++++ {observer/messages => messages}/queue.go | 3 +- messages/task.go | 6 ++ observer/messages/agent.go | 8 --- observer/messages/crawler_manager.go | 12 ---- observer/messages/poller.go | 14 ---- observer/observer_test.go | 69 +++++++++---------- 14 files changed, 79 insertions(+), 77 deletions(-) create mode 100644 messages/agent.go rename {observer/messages => messages}/collector.go (100%) rename {observer/messages => messages}/config_manager.go (75%) rename {observer/messages => messages}/crawler.go (64%) create mode 100644 messages/crawler_manager.go rename {observer/messages => messages}/data_sender.go (100%) rename {observer/messages => messages}/event_sender.go (96%) create mode 100644 messages/poller.go rename {observer/messages => messages}/queue.go (67%) create mode 100644 messages/task.go delete mode 100644 observer/messages/agent.go delete mode 100644 observer/messages/crawler_manager.go delete mode 100644 observer/messages/poller.go diff --git a/messages/agent.go b/messages/agent.go new file mode 100644 index 0000000..60547cb --- /dev/null +++ b/messages/agent.go @@ -0,0 +1,8 @@ +package messages + +const ( + AGT_STARTING = "AGT_STARTING" + AGT_WILL_STOP = "AGENT_WILL_STOP" + AGT_STOPPED = "AGENT_STOPPED" + AGT_INITIALIZED = "AGT_INITIALIZED" +) diff --git a/observer/messages/collector.go b/messages/collector.go similarity index 100% rename from observer/messages/collector.go rename to messages/collector.go diff --git a/observer/messages/config_manager.go b/messages/config_manager.go similarity index 75% rename from observer/messages/config_manager.go rename to messages/config_manager.go index 009f664..faea971 100644 --- a/observer/messages/config_manager.go +++ b/messages/config_manager.go @@ -7,9 +7,9 @@ const ( CFG_LOADED = "CONFIG_LOADED" - SCF_READY = "SENSOR_CONFIG_READY" - SCF_STOPPED = "SENSOR_CONFIG_STOPPED" + SCF_READY = "SENSOR_CONFIG_READY" + SCF_STOPPED = "SENSOR_CONFIG_STOPPED" SCF_SENSOR_ADD_DONE = "SENSOR_CONFIG_SENSOR_ADD_DONE" SCF_SENSOR_UPDATE_DONE = "SENSOR_CONFIG_SENSOR_UPDATE_DONE" -) \ No newline at end of file +) diff --git a/observer/messages/crawler.go b/messages/crawler.go similarity index 64% rename from observer/messages/crawler.go rename to messages/crawler.go index 418a789..46508ed 100644 --- a/observer/messages/crawler.go +++ b/messages/crawler.go @@ -1,6 +1,6 @@ package messages const ( - CRAWLER_ADD = "CRAWLER_ADD" + CRAWLER_ADD = "CRAWLER_ADD" CRAWLER_REMOVE = "CRAWLER_REMOVE" -) \ No newline at end of file +) diff --git a/messages/crawler_manager.go b/messages/crawler_manager.go new file mode 100644 index 0000000..907191b --- /dev/null +++ b/messages/crawler_manager.go @@ -0,0 +1,10 @@ +package messages + +const ( + CRM_READY = "CRAWLER_READY" + CRM_STOPPED = "CRAWLER_STOPPED" + CRM_SENSOR_ADD_DONE = "CRAWLER_SENSOR_ADD_DONE" + CRM_SENSOR_REMOVE_DONE = "CRAWLER_SENSOR_REMOVE_DONE" + CRM_SENSOR_UPDATE_DONE = "CRAWLER_SENSOR_UPDATE_DONE" + CRM_UPDATE_DONE = "CRAWLER_UPDATE_DONE" +) diff --git a/observer/messages/data_sender.go b/messages/data_sender.go similarity index 100% rename from observer/messages/data_sender.go rename to messages/data_sender.go diff --git a/observer/messages/event_sender.go b/messages/event_sender.go similarity index 96% rename from observer/messages/event_sender.go rename to messages/event_sender.go index 293a31f..b8ecd6a 100644 --- a/observer/messages/event_sender.go +++ b/messages/event_sender.go @@ -2,4 +2,4 @@ package messages const ( EVENT_ERROR = "EVENT_ERROR" -) \ No newline at end of file +) diff --git a/messages/poller.go b/messages/poller.go new file mode 100644 index 0000000..9942846 --- /dev/null +++ b/messages/poller.go @@ -0,0 +1,14 @@ +package messages + +const ( + TASK_SENSOR_START = "TASK_SENSOR_START" + TASK_SENSOR_STOP = "TASK_SENSOR_STOP" + TASK_SENSOR_ADD = "TASK_SENSOR_ADD" + TASK_SENSOR_REMOVE = "TASK_SENSOR_REMOVE" + TASK_SENSOR_UPDATE = "TASK_SENSOR_UPDATE" + TASK_CRAWLER_UPDATE = "TASK_CRAWLER_UPDATE" + TASK_AGENT_UPDATE = "TASK_AGENT_UPDATE" + TASK_LOG_SEND = "TASK_LOG_SEND" + TASK_DONE = "TASK_DONE" + TASK_POLLER_INTERVAL_UPDATE = "TASK_POLLER_INTERVAL_UPDATE" +) diff --git a/observer/messages/queue.go b/messages/queue.go similarity index 67% rename from observer/messages/queue.go rename to messages/queue.go index 685085b..df43c0b 100644 --- a/observer/messages/queue.go +++ b/messages/queue.go @@ -1,7 +1,6 @@ package messages const ( - QUEUE_DATA = "QUEUE_DATA" + QUEUE_DATA = "QUEUE_DATA" QUEUE_EVENT = "QUEUE_EVENT" ) - diff --git a/messages/task.go b/messages/task.go new file mode 100644 index 0000000..daf7773 --- /dev/null +++ b/messages/task.go @@ -0,0 +1,6 @@ +package messages + +type AgentTask struct { + Command string + Params map[string]string +} diff --git a/observer/messages/agent.go b/observer/messages/agent.go deleted file mode 100644 index 7962279..0000000 --- a/observer/messages/agent.go +++ /dev/null @@ -1,8 +0,0 @@ -package messages - -const ( - AGT_STARTING = "AGT_STARTING" - AGT_WILL_STOP = "AGENT_WILL_STOP" - AGT_STOPPED = "AGENT_STOPPED" - AGT_INITIALIZED = "AGT_INITIALIZED" -) diff --git a/observer/messages/crawler_manager.go b/observer/messages/crawler_manager.go deleted file mode 100644 index 05f8aa7..0000000 --- a/observer/messages/crawler_manager.go +++ /dev/null @@ -1,12 +0,0 @@ -package messages - - -const ( - CRM_READY = "CRAWLER_READY" - CRM_STOPPED = "CRAWLER_STOPPED" - CRM_SENSOR_ADD_DONE = "CRAWLER_SENSOR_ADD_DONE" - CRM_SENSOR_REMOVE_DONE = "CRAWLER_SENSOR_REMOVE_DONE" - CRM_SENSOR_UPDATE_DONE = "CRAWLER_SENSOR_UPDATE_DONE" - CRM_UPDATE_DONE = "CRAWLER_UPDATE_DONE" - -) \ No newline at end of file diff --git a/observer/messages/poller.go b/observer/messages/poller.go deleted file mode 100644 index 30a305b..0000000 --- a/observer/messages/poller.go +++ /dev/null @@ -1,14 +0,0 @@ -package messages - -const ( - TASK_SENSOR_START = "TASK_SENSOR_START" - TASK_SENSOR_STOP = "TASK_SENSOR_STOP" - TASK_SENSOR_ADD = "TASK_SENSOR_ADD" - TASK_SENSOR_REMOVE = "TASK_SENSOR_REMOVE" - TASK_SENSOR_UPDATE = "TASK_SENSOR_UPDATE" - TASK_CRAWLER_UPDATE = "TASK_CRAWLER_UPDATE" - TASK_AGENT_UPDATE = "TASK_AGENT_UPDATE" - TASK_LOG_SEND = "TASK_LOG_SEND" - TASK_DONE = "TASK_DONE" - TASK_POLLER_INTERVAL_UPDATE = "TASK_POLLER_INTERVAL_UPDATE" -) diff --git a/observer/observer_test.go b/observer/observer_test.go index 84f2e74..c7799cc 100644 --- a/observer/observer_test.go +++ b/observer/observer_test.go @@ -1,11 +1,11 @@ package observer import ( + "fmt" "github.com/stretchr/testify/assert" + "loafle.com/overflow/agent_api/messages" "testing" "time" - "loafle.com/overflow/agent_api/observer/messages" - "fmt" ) type Test struct { @@ -20,7 +20,7 @@ func TestAddNotifyObserver(t *testing.T) { Notify("test", Test{Id: "test"}) }() - ch := make(chan interface{},0) + ch := make(chan interface{}, 0) Add("test", ch) dd := <-ch @@ -30,7 +30,7 @@ func TestAddNotifyObserver(t *testing.T) { func TestRemoveObserver(t *testing.T) { - ch := make(chan interface{},0) + ch := make(chan interface{}, 0) Add("test", ch) err := Remove("test", ch) @@ -39,48 +39,48 @@ func TestRemoveObserver(t *testing.T) { // +build ignore func TestMultiAddObserver(t *testing.T) { - ch1 := make(chan interface{},0) - ch2 := make(chan interface{},0) - ch3 := make(chan interface{},0) - ch4 := make(chan interface{},0) - ch5 := make(chan interface{},0) - + ch1 := make(chan interface{}, 0) + ch2 := make(chan interface{}, 0) + ch3 := make(chan interface{}, 0) + ch4 := make(chan interface{}, 0) + ch5 := make(chan interface{}, 0) + go func() { - d:=<-ch1 + d := <-ch1 dd := d.(Test) - assert.Equal(t, dd.Id,"test") + assert.Equal(t, dd.Id, "test") }() - + go func() { - d:=<-ch2 + d := <-ch2 dd := d.(Test) - assert.Equal(t, dd.Id,"test") + assert.Equal(t, dd.Id, "test") }() - + go func() { - d:=<-ch3 + d := <-ch3 dd := d.(Test) - assert.Equal(t, dd.Id,"test") + assert.Equal(t, dd.Id, "test") }() - + go func() { - d:=<-ch4 + d := <-ch4 dd := d.(Test) - assert.Equal(t, dd.Id,"test") + assert.Equal(t, dd.Id, "test") }() - + go func() { - d:=<-ch4 + d := <-ch4 dd := d.(Test) - assert.Equal(t, dd.Id,"test") + assert.Equal(t, dd.Id, "test") }() - + Add("test", ch1) Add("test", ch2) Add("test", ch3) Add("test", ch4) Add("test", ch5) - + // others package notify call go func() { time.Sleep(1 * time.Second) @@ -93,22 +93,21 @@ func TestMultiAddObserver(t *testing.T) { Remove("test", ch4) Remove("test", ch5) }() - + time.Sleep(1 * time.Second) - + } - func TestStringNotify(t *testing.T) { - ch := make(chan interface{},0) - Add("test",ch) - + ch := make(chan interface{}, 0) + Add("test", ch) + go func() { - data :=<-ch + data := <-ch str := data.(string) fmt.Println(str) }() - - Notify("test","testsetasetaset") + + Notify("test", "testsetasetaset") time.Sleep(1 * time.Second) }