diff --git a/agent.go b/agent.go index 035e2f1..e45096a 100644 --- a/agent.go +++ b/agent.go @@ -11,42 +11,53 @@ import ( cm "loafle.com/overflow/agent_api/config_manager" ) + func main() { log.SetPrefix("Agent : ") - agt := &Agent{} - agt.start() + StartAgent() +} + +type AgentTask struct { + command string + params interface{} } type Agent struct { - taskCh chan string - conf *cm.ConfigManager + taskCh chan interface{} + cm cm.ConfigManager } -func (agt *Agent) start() { +func StartAgent() { + agt := Agent{} agt.startAgent() } + func (agt *Agent) startAgent() { - //cfg start() (chan bool, error) + //cfg start() (chan confmanager, error) //evt 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. - 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) //crm start() (chan bool, error) //col start() -> evt result - go agt.waitTask() + go agt.waitAgentTask() } -func (agt *Agent)waitTask() { +func (agt *Agent)waitAgentTask() { for { task := <- agt.taskCh - switch task { - case messages.AGT_WILL_STOP: - agt.stopAgent() - break; + switch task.(AgentTask).command { case messages.TASK_SENSOR_START: + agt.processStartSensor() break; default: @@ -64,43 +75,52 @@ func (agt *Agent) stopAgent() { //evt stop() -> evt result (before stop) } -func (agt *Agent) ProcessStartSensor() { +func (agt *Agent) processStartSensor() { //col startSensor() -> evt result } -func (agt *Agent) ProcessstopSensor() { +func (agt *Agent) processstopSensor() { //col stopSensor() -> evt result } -func (agt *Agent) ProcessAddSensor() { +func (agt *Agent) processAddSensor() { //scm addSensor() (id chan string, error) //crm addSensor() (id chan string, error) //col addSensor() -> evt result } -func (agt *Agent) ProcessRemoveSensor() { +func (agt *Agent) processRemoveSensor() { //col removeSensor() (id chan string, error) //crm removeSensor() (id chan string, error) //scm removeSensor() -> evt result } -func (agt *Agent) ProcessUpdateSensor() { +func (agt *Agent) processUpdateSensor() { //col stopSensor() (id chan string, error) //scm updateSensor() (id chan string, error) //crm updateSensor() (id chan string, error) //col updateSensor() -> evt result } -func (agt *Agent) ProcessUpdateCRM() { +func (agt *Agent) processUpdateCRM() { //(loop)col stopSensor() (chan []string?, error) //crm updateCRM() //(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 } \ No newline at end of file