Skip to content

Commit ad8ef2e

Browse files
author
Konstantina Chremmou
authored
Merge pull request xenserver#3227 from kc284/xsi-1500-wlb-resume
CA-383040/XSI-1500: Resume WLB when reverting resolved actions after an update
2 parents 82ffd50 + ff0ce93 commit ad8ef2e

File tree

9 files changed

+148
-120
lines changed

9 files changed

+148
-120
lines changed

XenAdmin/Diagnostics/Checks/AssertCanEvacuateCheck.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,11 @@ private static CannotMigrateVM.CannotMigrateVMReason GetMoreSpecificReasonForCan
258258
protected override Problem RunHostCheck()
259259
{
260260
Pool pool = Helpers.GetPool(Host.Connection);
261-
if (pool != null)
262-
{
263-
if (pool.ha_enabled)
264-
return new HAEnabledWarning(this, pool, Host);
265-
266-
if (Helpers.WlbEnabled(pool.Connection))
267-
return new WLBEnabledWarning(this, pool, Host);
268-
}
269261

270-
return null;
262+
if (pool == null || (!pool.ha_enabled && !pool.wlb_enabled))
263+
return null;
264+
265+
return new HaWlbEnabledWarning(this, pool, Host);
271266
}
272267

273268
public override List<Problem> RunAllChecks()
@@ -279,9 +274,6 @@ public override List<Problem> RunAllChecks()
279274
return CheckHost();
280275
}
281276

282-
public override string Description
283-
{
284-
get { return Messages.ASSERT_CAN_EVACUATE_CHECK_DESCRIPTION; }
285-
}
277+
public override string Description => Messages.ASSERT_CAN_EVACUATE_CHECK_DESCRIPTION;
286278
}
287279
}

XenAdmin/Diagnostics/Checks/HaWlbOffCheck.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,44 @@
2828
* SUCH DAMAGE.
2929
*/
3030

31-
using XenAdmin.Core;
3231
using XenAdmin.Diagnostics.Problems;
3332
using XenAdmin.Diagnostics.Problems.PoolProblem;
3433
using XenAPI;
3534

3635

3736
namespace XenAdmin.Diagnostics.Checks
3837
{
39-
class HaWlbOffCheck : PoolCheck
38+
internal class HaOffCheck : PoolCheck
4039
{
41-
public HaWlbOffCheck(Pool pool)
40+
public HaOffCheck(Pool pool)
4241
: base(pool)
4342
{
4443
}
4544

4645
protected override Problem RunCheck()
4746
{
48-
if (Pool.ha_enabled)
49-
return new HAEnabledProblem(this, Pool);
47+
return Pool.ha_enabled ? new HAEnabledProblem(this, Pool) : null;
48+
}
49+
50+
public override string Description => Messages.HA_CHECK_DESCRIPTION;
51+
52+
public override string SuccessfulCheckDescription => string.Format(Messages.PATCHING_WIZARD_CHECK_ON_XENOBJECT_OK, Pool.Name(), Description);
53+
}
54+
5055

51-
if (Helpers.WlbEnabled(Pool.Connection))
52-
return new WLBEnabledProblem(this, Pool);
56+
internal class WlbOffCheck : PoolCheck
57+
{
58+
public WlbOffCheck(Pool pool)
59+
: base(pool)
60+
{
61+
}
5362

54-
return null;
63+
protected override Problem RunCheck()
64+
{
65+
return Pool.wlb_enabled ? new WLBEnabledProblem(this, Pool) : null;
5566
}
5667

57-
public override string Description => Messages.HA_WLB_CHECK_DESCRIPTION;
68+
public override string Description => Messages.WLB_CHECK_DESCRIPTION;
5869

5970
public override string SuccessfulCheckDescription => string.Format(Messages.PATCHING_WIZARD_CHECK_ON_XENOBJECT_OK, Pool.Name(), Description);
6071
}

XenAdmin/Diagnostics/Problems/PoolProblem/HAEnabledProblem.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,35 @@ public DrHAEnabledProblem(Check check, Pool pool)
8686
public override string Description => Messages.DR_WIZARD_PROBLEM_HA_ENABLED;
8787
}
8888

89-
class HAEnabledWarning : Warning
89+
internal class HaWlbEnabledWarning : Warning
9090
{
91-
private readonly Pool pool;
92-
private readonly Host host;
91+
private readonly Pool _pool;
92+
private readonly Host _host;
9393

94-
public HAEnabledWarning(Check check, Pool pool, Host host)
94+
public HaWlbEnabledWarning(Check check, Pool pool, Host host)
9595
: base(check)
9696
{
97-
this.pool = pool;
98-
this.host = host;
97+
_pool = pool;
98+
_host = host;
9999
}
100100

101101
public override string Title => Check.Description;
102102

103-
public override string Description => string.Format(Messages.UPDATES_WIZARD_HA_ON_WARNING, host, pool);
103+
public override string Description
104+
{
105+
get
106+
{
107+
if (_pool.ha_enabled && _pool.wlb_enabled)
108+
return string.Format(Messages.UPDATES_WIZARD_HA_AND_WLB_ON_WARNING, _host, _pool);
109+
110+
if (_pool.ha_enabled)
111+
return string.Format(Messages.UPDATES_WIZARD_HA_ON_WARNING, _host, _pool);
112+
113+
if (_pool.wlb_enabled)
114+
return string.Format(Messages.UPDATES_WIZARD_WLB_ON_WARNING, _host, _pool);
115+
116+
return string.Empty;
117+
}
118+
}
104119
}
105120
}

XenAdmin/Diagnostics/Problems/PoolProblem/WLBEnabledProblem.cs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@
2828
* SUCH DAMAGE.
2929
*/
3030

31-
using System.Threading;
3231
using XenAdmin.Actions;
3332
using XenAdmin.Actions.Wlb;
34-
using XenAdmin.Core;
3533
using XenAdmin.Diagnostics.Checks;
3634
using XenAPI;
3735

@@ -52,36 +50,24 @@ public WLBEnabledProblem(Check check, Pool pool)
5250
protected override AsyncAction CreateAction(out bool cancelled)
5351
{
5452
cancelled = false;
55-
return new DelegatedAsyncAction(Pool.Connection, Messages.HELP_MESSAGE_DISABLE_WLB, "", "",
56-
ss =>
57-
{
58-
var action = new DisableWLBAction(Pool, false);
59-
action.RunSync(ss);
60-
int count = 0;
61-
while (Helpers.WlbEnabled(Pool.Connection) && count < 10)
62-
{
63-
Thread.Sleep(500);
64-
count++;
65-
}
66-
}, true);
67-
53+
return new DisableWLBAction(Pool, false);
6854
}
69-
}
70-
71-
class WLBEnabledWarning : Warning
72-
{
73-
private readonly Pool pool;
74-
private readonly Host host;
7555

76-
public WLBEnabledWarning(Check check, Pool pool, Host host)
77-
: base(check)
56+
public override AsyncAction CreateUnwindChangesAction()
7857
{
79-
this.pool = pool;
80-
this.host = host;
81-
}
58+
var pool = Pool.Connection.Resolve(new XenRef<Pool>(Pool.opaque_ref));
8259

83-
public override string Title => Check.Description;
60+
if (pool == null)
61+
{
62+
foreach (var xenConnection in ConnectionsManager.XenConnectionsCopy)
63+
{
64+
pool = xenConnection.Resolve(new XenRef<Pool>(Pool.opaque_ref));
65+
if (pool != null)
66+
break;
67+
}
68+
}
8469

85-
public override string Description => string.Format(Messages.UPDATES_WIZARD_WLB_ON_WARNING, host, pool);
70+
return pool == null ? null : new EnableWLBAction(pool);
71+
}
8672
}
8773
}

XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,16 @@ private List<CheckGroup> GenerateCommonChecks(List<Host> applicableServers)
359359

360360
groups.Add(new CheckGroup(Messages.CHECKING_HOST_LIVENESS_STATUS, livenessChecks));
361361

362-
//HA checks
362+
//HA and WLB checks
363363

364-
var haChecks = new List<Check>();
364+
var haWlbChecks = new List<Check>();
365365
foreach (Pool pool in SelectedPools)
366-
haChecks.Add(new HaWlbOffCheck(pool));
366+
{
367+
haWlbChecks.Add(new HaOffCheck(pool));
368+
haWlbChecks.Add(new WlbOffCheck(pool));
369+
}
367370

368-
groups.Add(new CheckGroup(Messages.CHECKING_HA_STATUS, haChecks));
371+
groups.Add(new CheckGroup(Messages.CHECKING_HA_AND_WLB_STATUS, haWlbChecks));
369372

370373
//PBDsPluggedCheck
371374
var pbdChecks = new List<Check>();

XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizardPrecheckPage.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,16 @@ where check.CanRun()
259259
if (pvChecks.Count > 0)
260260
groups.Add(new CheckGroup(Messages.CHECKING_PV_GUESTS, pvChecks));
261261

262-
//HA checks - for each pool
263-
var haChecks = (from Pool pool in SelectedPools
264-
select new HaWlbOffCheck(pool) as Check).ToList();
262+
//HA and WLB checks - for each pool
263+
var haWlbChecks = new List<Check>();
264+
foreach (var pool in SelectedPools)
265+
{
266+
haWlbChecks.Add(new HaOffCheck(pool));
267+
haWlbChecks.Add(new WlbOffCheck(pool));
268+
}
265269

266-
if (haChecks.Count > 0)
267-
groups.Add(new CheckGroup(Messages.CHECKING_HA_STATUS, haChecks));
270+
if (haWlbChecks.Count > 0)
271+
groups.Add(new CheckGroup(Messages.CHECKING_HA_AND_WLB_STATUS, haWlbChecks));
268272

269273
//Checking can evacuate host - for hosts that will be upgraded or updated
270274
var evacuateChecks = (from Host host in hostsToUpgradeOrUpdate

XenModel/Actions/WLB/DisableWLBAction.cs

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,23 @@ namespace XenAdmin.Actions.Wlb
3939
public class DisableWLBAction : AsyncAction
4040
{
4141
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
42-
private bool _deconfigure = false;
42+
private readonly bool _deconfigure;
4343
private static string OPTIMIZINGPOOL = "wlb_optimizing_pool";
4444

4545
public DisableWLBAction(Pool pool, bool deconfigure)
4646
: base(pool.Connection, string.Format(Messages.DISABLING_WLB_ON, Helpers.GetName(pool).Ellipsise(50)), Messages.DISABLING_WLB, false)
4747
{
48-
this.Pool = pool;
49-
this._deconfigure = deconfigure;
48+
Pool = pool;
49+
_deconfigure = deconfigure;
5050

5151
if (deconfigure)
5252
{
53-
this.Title = String.Format(Messages.DECONFIGURING_WLB_ON, Helpers.GetName(pool).Ellipsise(50));
54-
this.Description = Messages.DECONFIGURING_WLB;
53+
Title = string.Format(Messages.DECONFIGURING_WLB_ON, Helpers.GetName(pool).Ellipsise(50));
54+
Description = Messages.DECONFIGURING_WLB;
5555
}
5656

5757
#region RBAC Dependencies
58-
ApiMethodsToRoleCheck.Add("pool.set_wlb_enabled");
59-
ApiMethodsToRoleCheck.Add("pool.deconfigure_wlb");
58+
ApiMethodsToRoleCheck.AddRange("pool.set_wlb_enabled", "pool.deconfigure_wlb");
6059
#endregion
6160
}
6261

@@ -66,59 +65,53 @@ protected override void Run()
6665
{
6766
try
6867
{
69-
if (!Helpers.WlbEnabled(Pool.Connection))
68+
if (!Pool.wlb_enabled)
7069
{
7170
log.Debug("Resuming WLB (prior to disconnecting) for pool " + Pool.Name());
72-
XenAPI.Pool.set_wlb_enabled(this.Session, Pool.opaque_ref, true);
71+
Pool.set_wlb_enabled(Session, Pool.opaque_ref, true);
7372
log.Debug("Success resuming WLB on pool " + Pool.Name());
7473
}
75-
log.Debug("Disconnecting Workload Balancing from pool " + Pool.Name() + " and removing all pool data");
76-
XenAPI.Pool.deconfigure_wlb(this.Session);
74+
75+
log.Debug($"Disconnecting Workload Balancing from pool {Pool.Name()} and removing all pool data");
76+
Pool.deconfigure_wlb(Session);
7777
log.Debug("Success disconnecting Workload Balancing on pool " + Pool.Name());
78-
this.Description = Messages.COMPLETED;
7978

80-
WlbServerState.SetState(this.Session, Pool, WlbServerState.ServerState.NotConfigured);
81-
}
82-
catch (Exception ex)
83-
{
84-
//Force disabling of WLB
85-
XenAPI.Pool.set_wlb_enabled(this.Session, Pool.opaque_ref, false);
86-
WlbServerState.SetState(this.Session, Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex);
87-
log.Debug($"Disconnecting Workload Balancing failed on pool {Pool.Name()}. Workload Balancing has been paused.", ex);
88-
throw new Exception(string.Format(Messages.ACTION_WLB_DECONFIGURE_FAILED, Pool.Name(), ex.Message));
79+
WlbServerState.SetState(Session, Pool, WlbServerState.ServerState.NotConfigured);
80+
Description = Messages.COMPLETED;
8981
}
90-
finally
82+
catch (Failure f)
9183
{
92-
//Clear the Optimizing Pool flag in case it was left behind
93-
Helpers.SetOtherConfig(this.Session, this.Pool, OPTIMIZINGPOOL, string.Empty);
84+
Pool.set_wlb_enabled(Session, Pool.opaque_ref, false);
85+
WlbServerState.SetState(Session, Pool, WlbServerState.ServerState.ConnectionError, f);
86+
log.Debug($"Disconnecting Workload Balancing failed on pool {Pool.Name()}. Workload Balancing has been paused.", f);
87+
88+
throw new Exception(string.Format(Messages.ACTION_WLB_DECONFIGURE_FAILED, Pool.Name(), f));
9489
}
9590
}
9691
else
9792
{
9893
try
9994
{
10095
log.Debug("Pausing Workload Balancing on pool " + Pool.Name());
101-
XenAPI.Pool.set_wlb_enabled(this.Session, Pool.opaque_ref, false);
96+
Pool.set_wlb_enabled(Session, Pool.opaque_ref, false);
10297
log.Debug("Success pausing Workload Balancing on pool " + Pool.Name());
103-
this.Description = Messages.COMPLETED;
104-
WlbServerState.SetState(this.Session, Pool, WlbServerState.ServerState.Disabled);
105-
}
106-
catch (Exception ex)
107-
{
108-
if (ex is Failure)
109-
{
110-
WlbServerState.SetState(this.Session, Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex);
111-
}
112-
throw ex;
98+
99+
Connection.WaitFor(() => !Pool.wlb_enabled, null);
100+
WlbServerState.SetState(Session, Pool, WlbServerState.ServerState.Disabled);
101+
Description = Messages.COMPLETED;
113102
}
114-
finally
103+
catch (Failure f)
115104
{
116-
//Clear the Optimizing Pool flag in case it was left behind
117-
Helpers.SetOtherConfig(this.Session, this.Pool, OPTIMIZINGPOOL, string.Empty);
105+
WlbServerState.SetState(Session, Pool, WlbServerState.ServerState.ConnectionError, f);
106+
throw;
118107
}
119108
}
120-
121109
}
122110

111+
protected override void Clean()
112+
{
113+
//Clear the Optimizing Pool flag in case it was left behind
114+
Helpers.SetOtherConfig(Session, Pool, OPTIMIZINGPOOL, string.Empty);
115+
}
123116
}
124117
}

0 commit comments

Comments
 (0)