From 243666dbc0b25d55a6d457d9454f4a59c70d868d Mon Sep 17 00:00:00 2001 From: "insanity@loafle.com" Date: Wed, 17 May 2017 13:00:30 +0900 Subject: [PATCH] agent --- agent.go | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/agent.go b/agent.go index f5b34e4..8b74401 100644 --- a/agent.go +++ b/agent.go @@ -17,9 +17,10 @@ const ( PATH = "/home/insanity/Develop/gopath/src/loafle.com/overflow/config_manager_go/test_agent" ) +var wg sync.WaitGroup + func main() { log.SetPrefix("Agent : ") - var wg sync.WaitGroup wg.Add(1) go StartAgent() wg.Wait() @@ -66,7 +67,11 @@ func (agt *Agent) startAgent() { <-polStarted agt.taskCh = pol.GetTaskCh() - //5. scm start(authKey) + /** + Todo : Getting an auth key from API server. + */ + + //5. scm start() scmStarted := make(chan config_manager.ConfigManager, 1) if err := cfg.StartSensorConfig(scmStarted, "temp"); err != nil { log.Println(err) @@ -90,8 +95,6 @@ func (agt *Agent) startAgent() { evt.AddEventData(res) go agt.processCollectingData(dataCh) - - //8. processing tasks go agt.waitAgentTask() } @@ -168,32 +171,29 @@ func (agt *Agent) stopAgent() { } <-polStopped - //evt result evt.AddEventData(msg.Event{msg.EVT_TYPE_NONE, msg.AGT_STOP, nil}) - //evt stop() evt.Stop() + wg.Done() } func (agt *Agent) processStartSensor(task msg.AgentTask) { - //col startSensor() -> evt result id := task.Params["sensorId"] col.StartSensor(id) evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil}) } func (agt *Agent) processStopSensor(task msg.AgentTask) { - //col stopSensor() -> evt result id := task.Params["sensorId"] col.StopSensor(id) evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil}) } func (agt *Agent) processAddSensor(task msg.AgentTask) { - id := task.Params["sensorId"] - //scm addSensor() - //crm addSensor() - //col addSensor() + path := task.Params["path"] + id := task.Params["id"] + cfg.AddSensor(path) + crm.AddSensor(id) err := col.AddSensor(id) if err != nil { return @@ -203,28 +203,25 @@ func (agt *Agent) processAddSensor(task msg.AgentTask) { func (agt *Agent) processRemoveSensor(task msg.AgentTask) { id := task.Params["sensorId"] - //col removeSensor() err := col.RemSensor(id) if err != nil { log.Println(err) return } - //crm removeSensor() - //scm removeSensor() - //evt.AddEventData(msg.TaskResult{msg.TASK_SENSOR_REMOVE, true, nil }) + crm.RemoveSensor(id) + cfg.RemoveSensor(id) evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil}) } func (agt *Agent) processUpdateSensor(task msg.AgentTask) { - id := task.Params["sensorId"] - //col stopSensor() + path := task.Params["path"] + id := task.Params["id"] if err := col.StopSensor(id); err != nil { log.Println(err) return } - //scm updateSensor() - //crm updateSensor() - //col updateSensor() + cfg.UpdateSensor(path) + crm.UpdateSensor(id) if err := col.UpdateSensor(id); err != nil { log.Println(err) return @@ -240,13 +237,12 @@ func (agt *Agent) processUpdateCRM(task msg.AgentTask) { } func (agt *Agent) processUpdateAgent(task msg.AgentTask) { - //mola + //Todo. Updating agent evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil}) } func (agt *Agent) processSendLog(task msg.AgentTask) { - //mola - //evt.AddEventData(msg.TaskResult{msg.TASK_LOG_SEND, true, nil }) + //Todo. Sending logs evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil}) }