agent
This commit is contained in:
parent
35fa492fd5
commit
1bceb63bc4
62
agent.go
62
agent.go
|
@ -11,42 +11,53 @@ import (
|
||||||
cm "loafle.com/overflow/agent_api/config_manager"
|
cm "loafle.com/overflow/agent_api/config_manager"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetPrefix("Agent : ")
|
log.SetPrefix("Agent : ")
|
||||||
agt := &Agent{}
|
StartAgent()
|
||||||
agt.start()
|
}
|
||||||
|
|
||||||
|
type AgentTask struct {
|
||||||
|
command string
|
||||||
|
params interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Agent struct {
|
type Agent struct {
|
||||||
taskCh chan string
|
taskCh chan interface{}
|
||||||
conf *cm.ConfigManager
|
cm cm.ConfigManager
|
||||||
}
|
}
|
||||||
|
|
||||||
func (agt *Agent) start() {
|
func StartAgent() {
|
||||||
|
agt := Agent{}
|
||||||
agt.startAgent()
|
agt.startAgent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (agt *Agent) startAgent() {
|
func (agt *Agent) startAgent() {
|
||||||
//cfg start() (chan bool, error)
|
//cfg start() (chan confmanager, error)
|
||||||
//evt start() (chan bool, error)
|
//evt start() (chan bool, error)
|
||||||
//dat start() (chan bool, error)
|
//dat start() (chan bool, error)
|
||||||
|
|
||||||
//pol start() (chan string, error) -> getting an Auth key from API server and store that key.
|
//pol start() (chan string, error) -> getting an Auth key from API server and store that key.
|
||||||
agt.taskCh = pol.Start()
|
ch, err := pol.Start(agt.cm.GetGlobalConfig())
|
||||||
|
if err != nil {
|
||||||
|
processError(err)
|
||||||
|
}
|
||||||
|
agt.taskCh = ch
|
||||||
|
|
||||||
//scm start() with the Auth key (chan bool, error)
|
//scm start() with the Auth key (chan bool, error)
|
||||||
//crm start() (chan bool, error)
|
//crm start() (chan bool, error)
|
||||||
//col start() -> evt result
|
//col start() -> evt result
|
||||||
|
|
||||||
go agt.waitTask()
|
go agt.waitAgentTask()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (agt *Agent)waitTask() {
|
func (agt *Agent)waitAgentTask() {
|
||||||
for {
|
for {
|
||||||
task := <- agt.taskCh
|
task := <- agt.taskCh
|
||||||
switch task {
|
switch task.(AgentTask).command {
|
||||||
case messages.AGT_WILL_STOP:
|
|
||||||
agt.stopAgent()
|
|
||||||
break;
|
|
||||||
case messages.TASK_SENSOR_START:
|
case messages.TASK_SENSOR_START:
|
||||||
|
agt.processStartSensor()
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
|
@ -64,43 +75,52 @@ func (agt *Agent) stopAgent() {
|
||||||
//evt stop() -> evt result (before stop)
|
//evt stop() -> evt result (before stop)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (agt *Agent) ProcessStartSensor() {
|
func (agt *Agent) processStartSensor() {
|
||||||
//col startSensor() -> evt result
|
//col startSensor() -> evt result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (agt *Agent) ProcessstopSensor() {
|
func (agt *Agent) processstopSensor() {
|
||||||
//col stopSensor() -> evt result
|
//col stopSensor() -> evt result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (agt *Agent) ProcessAddSensor() {
|
func (agt *Agent) processAddSensor() {
|
||||||
//scm addSensor() (id chan string, error)
|
//scm addSensor() (id chan string, error)
|
||||||
//crm addSensor() (id chan string, error)
|
//crm addSensor() (id chan string, error)
|
||||||
//col addSensor() -> evt result
|
//col addSensor() -> evt result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (agt *Agent) ProcessRemoveSensor() {
|
func (agt *Agent) processRemoveSensor() {
|
||||||
//col removeSensor() (id chan string, error)
|
//col removeSensor() (id chan string, error)
|
||||||
//crm removeSensor() (id chan string, error)
|
//crm removeSensor() (id chan string, error)
|
||||||
//scm removeSensor() -> evt result
|
//scm removeSensor() -> evt result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (agt *Agent) ProcessUpdateSensor() {
|
func (agt *Agent) processUpdateSensor() {
|
||||||
//col stopSensor() (id chan string, error)
|
//col stopSensor() (id chan string, error)
|
||||||
//scm updateSensor() (id chan string, error)
|
//scm updateSensor() (id chan string, error)
|
||||||
//crm updateSensor() (id chan string, error)
|
//crm updateSensor() (id chan string, error)
|
||||||
//col updateSensor() -> evt result
|
//col updateSensor() -> evt result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (agt *Agent) ProcessUpdateCRM() {
|
func (agt *Agent) processUpdateCRM() {
|
||||||
//(loop)col stopSensor() (chan []string?, error)
|
//(loop)col stopSensor() (chan []string?, error)
|
||||||
//crm updateCRM()
|
//crm updateCRM()
|
||||||
//(loop)col startSensor() -> evt result
|
//(loop)col startSensor() -> evt result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (agt *Agent) ProcessUpdateAgent() {
|
func (agt *Agent) processUpdateAgent() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
func (agt *Agent) ProcessSendLog() {
|
func (agt *Agent) processSendLog() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (agt *Agent) processUpdatePolInterval() {
|
||||||
|
//pol updateInterval()
|
||||||
|
}
|
||||||
|
|
||||||
|
func processError(err error) {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user