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

View File

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