summaryrefslogtreecommitdiff
path: root/src/rhctl/switch_control.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-09-23 21:51:19 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-09-23 21:51:19 (GMT)
commit325fdfbf6fe7c10a2e4145d870d7f5310a1d4d2b (patch)
treed2df322a9496d948b45be11f15b75f01888f1f8f /src/rhctl/switch_control.go
parent52f05d3ff1231c2ab4cf4034d0ea2279eb7448c5 (diff)
implemented server command channel for handover
Diffstat (limited to 'src/rhctl/switch_control.go')
-rw-r--r--src/rhctl/switch_control.go33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go
index ad0611f..de1496e 100644
--- a/src/rhctl/switch_control.go
+++ b/src/rhctl/switch_control.go
@@ -98,21 +98,32 @@ type SwitchControl struct {
func (ctrl *SwitchControl) handleCommand(cmd *Command) {
switch cmd.Type {
case CmdState:
- cmd.Response <- ctrl.state
+ if cmd.Response != nil {
+ cmd.Response <- ctrl.state
+ }
case CmdServer:
if len(cmd.Args) == 0 {
- cmd.Response <- fmt.Errorf("no server specified")
+ if cmd.Response != nil {
+ cmd.Response <- fmt.Errorf("no server specified")
+ }
return
}
- cmd.Response <- ctrl.reconcile(cmd.Args[0])
+ result := ctrl.reconcile(cmd.Args[0])
+ if cmd.Response != nil {
+ cmd.Response <- result
+ }
case CmdSwitch:
if len(cmd.Args) == 0 {
- cmd.Response <- fmt.Errorf("no command specified")
+ if cmd.Response != nil {
+ cmd.Response <- fmt.Errorf("no command specified")
+ }
return
}
c, err := NewSwitchCommandFromStrings(cmd.Args[0], cmd.Args[1:]...)
if err != nil {
- cmd.Response <- fmt.Errorf("switch command syntax error: %s", err.Error())
+ if cmd.Response != nil {
+ cmd.Response <- fmt.Errorf("switch command syntax error: %s", err.Error())
+ }
return
}
c.Response = cmd.Response
@@ -120,10 +131,14 @@ func (ctrl *SwitchControl) handleCommand(cmd *Command) {
}
}
-func handleServer(in <-chan ServerState, out chan<- ServerState) {
+func handleServer(sin <-chan ServerState, sout chan<- ServerState, cin <-chan Command, cout chan<- *Command) {
for {
- update := <-in
- out <- update
+ select {
+ case update := <-sin:
+ sout <- update
+ case cmd := <-cin:
+ cout <- &cmd
+ }
}
}
@@ -264,7 +279,7 @@ func (ctrl *SwitchControl) Run() {
serverStateChanges := make(chan ServerState, 8)
for _, srv := range ctrl.servers {
- go handleServer(srv.StateChanges, serverStateChanges)
+ go handleServer(srv.StateChanges, serverStateChanges, srv.Commands, ctrl.Commands)
}
// send out commands to switch and/or server to get missing infos