This commit is contained in:
insanity@loafle.com 2017-05-16 15:08:08 +09:00
parent 072de33afb
commit f7017e0021

View File

@ -2,7 +2,8 @@ package main
import ( import (
//crm "loafle.com/overflow/crawler_manager_go" //crm "loafle.com/overflow/crawler_manager_go"
cm "loafle.com/overflow/agent_api/config_manager" "loafle.com/overflow/agent_api/config_manager"
cfg "loafle.com/overflow/config_manager_go"
msg "loafle.com/overflow/agent_api/messages" msg "loafle.com/overflow/agent_api/messages"
col "loafle.com/overflow/collector_go" col "loafle.com/overflow/collector_go"
dat "loafle.com/overflow/data_sender_go" dat "loafle.com/overflow/data_sender_go"
@ -11,6 +12,10 @@ import (
"log" "log"
) )
const (
PATH = "/home/insanity/Develop/gopath/src/loafle.com/overflow/config_manager_go/test_agent"
)
func main() { func main() {
log.SetPrefix("Agent : ") log.SetPrefix("Agent : ")
StartAgent() StartAgent()
@ -18,7 +23,7 @@ func main() {
type Agent struct { type Agent struct {
cm cm.ConfigManager cm config_manager.ConfigManager
taskCh chan interface{} taskCh chan interface{}
} }
@ -29,28 +34,44 @@ func StartAgent() {
func (agt *Agent) startAgent() { func (agt *Agent) startAgent() {
//1. cfg start() //1. cfg start()
cfgStarted := make(chan *config_manager.GlobalConfig)
if err := cfg.Start(cfgStarted, PATH); err != nil {
log.Println(err)
return
}
globalConf := <-cfgStarted
//2. evt start() //2. evt start()
//3. dat start() //3. dat start()
datStarted := make(chan bool) datStarted := make(chan bool)
dat.Start(datStarted, agt.cm.GetGlobalConfig()) dat.Start(datStarted, globalConf)
<-datStarted <-datStarted
//4. pol start() -> getting an Auth key from API server and store that key. //4. pol start()
authKey := make(chan string) polStarted := make(chan bool)
ch, err := pol.Start(authKey, agt.cm.GetGlobalConfig()) err := pol.Start(polStarted, globalConf)
if err != nil { if err != nil {
evt.AddEventData(msg.TaskResult{msg.AGT_STOP, false, err }) log.Println(err)
return return
} }
<-authKey <-polStarted
agt.taskCh = ch agt.taskCh = pol.GetTaskCh()
//5. scm start(secretKey)
//5. scm start(authKey)
scmStarted := make(chan config_manager.ConfigManager)
if err := cfg.StartSensorConfig(scmStarted, "temp"); err != nil {
log.Println(err)
return
}
agt.cm = <-scmStarted
//6. crm start() //6. crm start()
//7. col start() -> evt result //7. col start()
dataCh := make(chan interface{}) dataCh := make(chan interface{})
colStarted := make(chan bool) colStarted := make(chan bool)
col.Start(colStarted, dataCh, agt.cm) col.Start(colStarted, dataCh, agt.cm)
<-colStarted <-colStarted
//8.evt result
res := msg.TaskResult{msg.AGT_START, true, nil} res := msg.TaskResult{msg.AGT_START, true, nil}
evt.AddEventData(res) evt.AddEventData(res)
@ -111,7 +132,10 @@ func (agt *Agent) stopAgent() {
col.Stop(colStopped) col.Stop(colStopped)
<-colStopped <-colStopped
//crm stop() //crm stop()
//scm stop() //cfg stop()
cfgStopped := make(chan bool)
cfg.Stop(cfgStopped)
<-cfgStopped
//dat stop() //dat stop()
datStopped := make(chan bool) datStopped := make(chan bool)
dat.Stop(datStopped) dat.Stop(datStopped)
@ -170,10 +194,17 @@ func (agt *Agent) processRemoveSensor(task msg.AgentTask) {
} }
func (agt *Agent) processUpdateSensor(task msg.AgentTask) { func (agt *Agent) processUpdateSensor(task msg.AgentTask) {
id := task.Params["sensorId"]
//col stopSensor() //col stopSensor()
if err := col.StopSensor(id); err != nil {
evt.AddEventData(msg.TaskResult{msg.TASK_SENSOR_UPDATE, false, err })
}
//scm updateSensor() //scm updateSensor()
//crm updateSensor() //crm updateSensor()
//col updateSensor() //col updateSensor()
if err := col.UpdateSensor(id); err != nil {
evt.AddEventData(msg.TaskResult{msg.TASK_SENSOR_UPDATE, false, err })
}
//evt.AddEventData(msg.TaskResult{msg.TASK_SENSOR_UPDATE, true, nil }) //evt.AddEventData(msg.TaskResult{msg.TASK_SENSOR_UPDATE, true, nil })
} }