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"
)
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})
}