diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-09-23 22:44:12 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-09-23 22:44:12 (GMT) |
commit | aee5b144821e995513a3646d71a981a21d44200f (patch) | |
tree | 2ebb0720fc802bb9ed96436dfa72e62251fd4444 /src/rhctl | |
parent | 325fdfbf6fe7c10a2e4145d870d7f5310a1d4d2b (diff) |
try requested server...
Diffstat (limited to 'src/rhctl')
-rw-r--r-- | src/rhctl/switch_control.go | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go index de1496e..6ee8527 100644 --- a/src/rhctl/switch_control.go +++ b/src/rhctl/switch_control.go @@ -201,14 +201,32 @@ func (ctrl *SwitchControl) selectServer(server string) bool { return true } -func (ctrl *SwitchControl) selectNextValidServer() { +func (ctrl *SwitchControl) checkAndSelectServer(server string) bool { + if state, exists := ctrl.state.Server[server]; exists { + if state.Health == ServerAlive && state.Channel != "" { + return ctrl.selectServer(server) + } + } + return false +} + +func (ctrl *SwitchControl) selectNextValidServer(preferred string) { + if preferred != "" { + if ctrl.checkAndSelectServer(preferred) { + ctrl.state.Mood = MoodNervous + rhl.Printf("SwitchCTRL: switched to preferred server '%s' -> now in mood: %s", preferred, ctrl.state.Mood) + return + } + rhl.Printf("SwitchCTRL: preferred server '%s' is not selectable, keeping on searching...", preferred) + } + for name, state := range ctrl.state.Server { if state.Health == ServerAlive && state.Channel != "" { if !ctrl.selectServer(name) { continue } ctrl.state.Mood = MoodNervous - rhl.Printf("SwitchCTRL: found another valid server -> now in mood: %s", ctrl.state.Mood) + rhl.Printf("SwitchCTRL: found another valid server '%s' -> now in mood: %s", preferred, ctrl.state.Mood) return } } @@ -217,7 +235,6 @@ func (ctrl *SwitchControl) selectNextValidServer() { } func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) { - // TODO: requested server is ignored in any case... fix this if !ctrl.state.Settled { return } @@ -231,7 +248,11 @@ func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) { rhl.Printf("SwitchCTRL: ignoreing preferred server requests while waking-up") return } - rhdl.Printf("SwitchCTRL: reconciling state... (requested server: '%s')", requestedServer) + reqSrvSuffix := "" + if requestedServer != "" { + reqSrvSuffix = " (requested server: '" + requestedServer + "')" + } + rhdl.Printf("SwitchCTRL: reconciling state...%s", reqSrvSuffix) swsrv, swch, err := ctrl.getSwitchServerAssignment() if err != nil { @@ -244,19 +265,27 @@ func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) { s, exists := ctrl.state.Server[swsrv] if !exists || s.Health != ServerAlive || s.Channel == "" { rhl.Printf("SwitchCTRL: server '%s' is unknown, dead or has invalid channel!", swsrv) - ctrl.selectNextValidServer() + ctrl.selectNextValidServer(requestedServer) return } ctrl.state.ActiveServer = swsrv - if s.Channel != swch { - // TODO: during normal operation switching server channels is expected and shouldn't lead to mood nervous?!?!? - ctrl.state.Mood = MoodNervous - rhl.Printf("SwitchCTRL: switch and server channel mismatch: '%s' != '%s' -> now in mood: %s", swch, s.Channel, ctrl.state.Mood) - if !ctrl.selectServer(ctrl.state.ActiveServer) { - ctrl.selectNextValidServer() + if ctrl.state.ActiveServer != requestedServer { + if ctrl.checkAndSelectServer(requestedServer) { + rhl.Printf("SwitchCTRL: switching to requested server '%s' ...", requestedServer) + } else { + rhl.Printf("SwitchCTRL: requested server '%s' is not selectable, ignoring request", requestedServer) + } + } else { + if s.Channel != swch { + // TODO: during normal operation switching server channels is expected and shouldn't lead to mood nervous?!?!? + ctrl.state.Mood = MoodNervous + rhl.Printf("SwitchCTRL: switch and server channel mismatch: '%s' != '%s' -> now in mood: %s", swch, s.Channel, ctrl.state.Mood) + if !ctrl.selectServer(ctrl.state.ActiveServer) { + ctrl.selectNextValidServer("") + } + return } - return } for _, s := range ctrl.state.Server { @@ -283,7 +312,6 @@ func (ctrl *SwitchControl) Run() { } // send out commands to switch and/or server to get missing infos - // TODO: this should be called from reconcile but with some sort of rate-limiting... ctrl.checkMissingOrStaleStates(2 * time.Hour) // TODO: hardcoded value ctrl.reconcile("") |