summaryrefslogtreecommitdiff
path: root/src/rhctl
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-09-23 23:39:29 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-09-23 23:39:29 (GMT)
commit07f53fbec0571cbb923bc3431a4bb9b012fcaf78 (patch)
tree66fe85239be40ac7c21d676d50802e56b9a1cf12 /src/rhctl
parentaee5b144821e995513a3646d71a981a21d44200f (diff)
fixed server selection
Diffstat (limited to 'src/rhctl')
-rw-r--r--src/rhctl/switch_control.go27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go
index 6ee8527..043d682 100644
--- a/src/rhctl/switch_control.go
+++ b/src/rhctl/switch_control.go
@@ -210,23 +210,14 @@ func (ctrl *SwitchControl) checkAndSelectServer(server string) bool {
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)
- }
-
+func (ctrl *SwitchControl) selectNextValidServer() {
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 '%s' -> now in mood: %s", preferred, ctrl.state.Mood)
+ rhl.Printf("SwitchCTRL: found another valid server '%s' -> now in mood: %s", name, ctrl.state.Mood)
return
}
}
@@ -265,14 +256,22 @@ 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(requestedServer)
+ if requestedServer != "" {
+ if ctrl.checkAndSelectServer(requestedServer) {
+ rhl.Printf("SwitchCTRL: switching to requested server '%s' ...", requestedServer)
+ return true
+ }
+ rhl.Printf("SwitchCTRL: requested server '%s' is not selectable, ignoring request", requestedServer)
+ }
+ ctrl.selectNextValidServer()
return
}
ctrl.state.ActiveServer = swsrv
- if ctrl.state.ActiveServer != requestedServer {
+ if requestedServer != "" && ctrl.state.ActiveServer != requestedServer {
if ctrl.checkAndSelectServer(requestedServer) {
rhl.Printf("SwitchCTRL: switching to requested server '%s' ...", requestedServer)
+ result = true
} else {
rhl.Printf("SwitchCTRL: requested server '%s' is not selectable, ignoring request", requestedServer)
}
@@ -282,7 +281,7 @@ func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) {
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("")
+ ctrl.selectNextValidServer()
}
return
}