diff options
-rw-r--r-- | src/rhctl/playout_server.go | 4 | ||||
-rw-r--r-- | src/rhctl/switch_control.go | 33 |
2 files changed, 27 insertions, 10 deletions
diff --git a/src/rhctl/playout_server.go b/src/rhctl/playout_server.go index a8cb399..325a3f6 100644 --- a/src/rhctl/playout_server.go +++ b/src/rhctl/playout_server.go @@ -62,6 +62,7 @@ type PlayoutServer struct { hbcnt uint state ServerState StateChanges chan ServerState + Commands chan Command UpdateRequest chan bool SwitchUpdates chan SwitchUpdate } @@ -108,7 +109,7 @@ func (srv *PlayoutServer) handleMessage(data string) { rhl.Printf("Server(%s) sent empty handover", srv.name) return } - // TODO: send command to swichctrl: &Command{Type: CmdServer, Args: data[9:], Response: nil} + srv.Commands <- Command{Type: CmdServer, Args: []string{data[9:]}, Response: nil} return } rhl.Printf("Server(%s): ignoring unknown message: %q", srv.name, data) @@ -164,6 +165,7 @@ func ServerInit(name string, conf *Config) (srv *PlayoutServer, err error) { srv.state.Health = ServerDead srv.state.Channel = "" srv.StateChanges = make(chan ServerState, 16) + srv.Commands = make(chan Command, 8) srv.UpdateRequest = make(chan bool, 8) srv.SwitchUpdates = make(chan SwitchUpdate, 32) 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 |