This commit is contained in:
insanity@loafle.com 2017-05-16 18:03:18 +09:00
parent d61f2c58df
commit e812d2806f

View File

@ -19,7 +19,7 @@ const (
func main() {
log.SetPrefix("Agent : ")
var wg sync.WaitGroup
var wg sync.WaitGroup
wg.Add(1)
go StartAgent()
wg.Wait()
@ -28,7 +28,6 @@ func main() {
type Agent struct {
cm config_manager.ConfigManager
taskCh chan interface{}
}
func StartAgent() {
@ -87,7 +86,7 @@ func (agt *Agent) startAgent() {
<-colStarted
//8.evt result
res := msg.TaskResult{msg.AGT_START, true, nil}
res := msg.Event{msg.EVT_TYPE_NONE, msg.AGT_START, nil}
evt.AddEventData(res)
go agt.processCollectingData(dataCh)
@ -165,13 +164,12 @@ func (agt *Agent) stopAgent() {
//pol stop()
polStopped := make(chan bool, 1)
if err := pol.Stop(polStopped); err != nil {
evt.AddEventData(msg.TaskResult{msg.AGT_STOP, false, err})
return
}
<-polStopped
//evt result
evt.AddEventData(msg.TaskResult{msg.AGT_STOP, true, nil})
evt.AddEventData(msg.Event{msg.EVT_TYPE_NONE, msg.AGT_STOP, nil})
//evt stop()
evt.Stop()
@ -181,14 +179,14 @@ func (agt *Agent) processStartSensor(task msg.AgentTask) {
//col startSensor() -> evt result
id := task.Params["sensorId"]
col.StartSensor(id)
evt.AddEventData(msg.TaskResult{msg.TASK_SENSOR_START, true, nil})
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.TaskResult{msg.TASK_SENSOR_STOP, true, nil})
evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil})
}
func (agt *Agent) processAddSensor(task msg.AgentTask) {
@ -198,10 +196,9 @@ func (agt *Agent) processAddSensor(task msg.AgentTask) {
//col addSensor()
err := col.AddSensor(id)
if err != nil {
evt.AddEventData(msg.TaskResult{msg.TASK_SENSOR_ADD, false, err})
return
}
//evt.AddEventData(msg.TaskResult{msg.TASK_SENSOR_ADD, true, nil })
evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil})
}
func (agt *Agent) processRemoveSensor(task msg.AgentTask) {
@ -209,51 +206,56 @@ func (agt *Agent) processRemoveSensor(task msg.AgentTask) {
//col removeSensor()
err := col.RemSensor(id)
if err != nil {
evt.AddEventData(msg.TaskResult{msg.TASK_SENSOR_REMOVE, false, err})
log.Println(err)
return
}
//crm removeSensor()
//scm removeSensor()
//evt.AddEventData(msg.TaskResult{msg.TASK_SENSOR_REMOVE, true, nil })
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()
if err := col.StopSensor(id); err != nil {
evt.AddEventData(msg.TaskResult{msg.TASK_SENSOR_UPDATE, false, err})
log.Println(err)
return
}
//scm updateSensor()
//crm updateSensor()
//col updateSensor()
if err := col.UpdateSensor(id); err != nil {
evt.AddEventData(msg.TaskResult{msg.TASK_SENSOR_UPDATE, false, err})
log.Println(err)
return
}
//evt.AddEventData(msg.TaskResult{msg.TASK_SENSOR_UPDATE, true, nil })
evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil})
}
func (agt *Agent) processUpdateCRM(task msg.AgentTask) {
//(loop)col stopSensor()
//crm updateCRM()
//(loop)col startSensor()
//evt.AddEventData(msg.TaskResult{msg.TASK_CRAWLER_UPDATE, true, nil })
evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil})
}
func (agt *Agent) processUpdateAgent(task msg.AgentTask) {
//mola
//evt.AddEventData(msg.TaskResult{msg.TASK_AGENT_UPDATE, true, nil })
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 })
evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil})
}
func (agt *Agent) processUpdatePolInterval(task msg.AgentTask) {
interval := task.Params["interval"]
err := pol.UpdateInterval(interval)
if err != nil {
evt.AddEventData(msg.TaskResult{msg.TASK_POLLER_INTERVAL_UPDATE, false, err})
log.Println(err)
return
}
evt.AddEventData(msg.TaskResult{msg.TASK_POLLER_INTERVAL_UPDATE, true, nil})
evt.AddEventData(msg.Event{msg.EVT_TYPE_TASK, task.Params["id"], nil})
}