This commit is contained in:
insanity@loafle.com 2017-05-17 13:00:30 +09:00
parent e812d2806f
commit 243666dbc0

View File

@ -17,9 +17,10 @@ const (
PATH = "/home/insanity/Develop/gopath/src/loafle.com/overflow/config_manager_go/test_agent" PATH = "/home/insanity/Develop/gopath/src/loafle.com/overflow/config_manager_go/test_agent"
) )
var wg sync.WaitGroup
func main() { func main() {
log.SetPrefix("Agent : ") log.SetPrefix("Agent : ")
var wg sync.WaitGroup
wg.Add(1) wg.Add(1)
go StartAgent() go StartAgent()
wg.Wait() wg.Wait()
@ -66,7 +67,11 @@ func (agt *Agent) startAgent() {
<-polStarted <-polStarted
agt.taskCh = pol.GetTaskCh() 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) scmStarted := make(chan config_manager.ConfigManager, 1)
if err := cfg.StartSensorConfig(scmStarted, "temp"); err != nil { if err := cfg.StartSensorConfig(scmStarted, "temp"); err != nil {
log.Println(err) log.Println(err)
@ -90,8 +95,6 @@ func (agt *Agent) startAgent() {
evt.AddEventData(res) evt.AddEventData(res)
go agt.processCollectingData(dataCh) go agt.processCollectingData(dataCh)
//8. processing tasks
go agt.waitAgentTask() go agt.waitAgentTask()
} }
@ -168,32 +171,29 @@ func (agt *Agent) stopAgent() {
} }
<-polStopped <-polStopped
//evt result
evt.AddEventData(msg.Event{msg.EVT_TYPE_NONE, msg.AGT_STOP, nil}) evt.AddEventData(msg.Event{msg.EVT_TYPE_NONE, msg.AGT_STOP, nil})
//evt stop()
evt.Stop() evt.Stop()
wg.Done()
} }
func (agt *Agent) processStartSensor(task msg.AgentTask) { func (agt *Agent) processStartSensor(task msg.AgentTask) {
//col startSensor() -> evt result
id := task.Params["sensorId"] id := task.Params["sensorId"]
col.StartSensor(id) col.StartSensor(id)
evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil}) evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil})
} }
func (agt *Agent) processStopSensor(task msg.AgentTask) { func (agt *Agent) processStopSensor(task msg.AgentTask) {
//col stopSensor() -> evt result
id := task.Params["sensorId"] id := task.Params["sensorId"]
col.StopSensor(id) col.StopSensor(id)
evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil}) evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil})
} }
func (agt *Agent) processAddSensor(task msg.AgentTask) { func (agt *Agent) processAddSensor(task msg.AgentTask) {
id := task.Params["sensorId"] path := task.Params["path"]
//scm addSensor() id := task.Params["id"]
//crm addSensor() cfg.AddSensor(path)
//col addSensor() crm.AddSensor(id)
err := col.AddSensor(id) err := col.AddSensor(id)
if err != nil { if err != nil {
return return
@ -203,28 +203,25 @@ func (agt *Agent) processAddSensor(task msg.AgentTask) {
func (agt *Agent) processRemoveSensor(task msg.AgentTask) { func (agt *Agent) processRemoveSensor(task msg.AgentTask) {
id := task.Params["sensorId"] id := task.Params["sensorId"]
//col removeSensor()
err := col.RemSensor(id) err := col.RemSensor(id)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
return return
} }
//crm removeSensor() crm.RemoveSensor(id)
//scm removeSensor() cfg.RemoveSensor(id)
//evt.AddEventData(msg.TaskResult{msg.TASK_SENSOR_REMOVE, true, nil })
evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil}) evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil})
} }
func (agt *Agent) processUpdateSensor(task msg.AgentTask) { func (agt *Agent) processUpdateSensor(task msg.AgentTask) {
id := task.Params["sensorId"] path := task.Params["path"]
//col stopSensor() id := task.Params["id"]
if err := col.StopSensor(id); err != nil { if err := col.StopSensor(id); err != nil {
log.Println(err) log.Println(err)
return return
} }
//scm updateSensor() cfg.UpdateSensor(path)
//crm updateSensor() crm.UpdateSensor(id)
//col updateSensor()
if err := col.UpdateSensor(id); err != nil { if err := col.UpdateSensor(id); err != nil {
log.Println(err) log.Println(err)
return return
@ -240,13 +237,12 @@ func (agt *Agent) processUpdateCRM(task msg.AgentTask) {
} }
func (agt *Agent) processUpdateAgent(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}) evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil})
} }
func (agt *Agent) processSendLog(task msg.AgentTask) { func (agt *Agent) processSendLog(task msg.AgentTask) {
//mola //Todo. Sending logs
//evt.AddEventData(msg.TaskResult{msg.TASK_LOG_SEND, true, nil })
evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil}) evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil})
} }