Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CA-383040/XSI-1500: Resume WLB when reverting resolved actions after an update #3227

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions XenAdmin/Diagnostics/Checks/AssertCanEvacuateCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,11 @@ private static CannotMigrateVM.CannotMigrateVMReason GetMoreSpecificReasonForCan
protected override Problem RunHostCheck()
{
Pool pool = Helpers.GetPool(Host.Connection);
if (pool != null)
{
if (pool.ha_enabled)
return new HAEnabledWarning(this, pool, Host);

if (Helpers.WlbEnabled(pool.Connection))
return new WLBEnabledWarning(this, pool, Host);
}

return null;
if (pool == null || (!pool.ha_enabled && !pool.wlb_enabled))
return null;

return new HaWlbEnabledWarning(this, pool, Host);
}

public override List<Problem> RunAllChecks()
Expand All @@ -279,9 +274,6 @@ public override List<Problem> RunAllChecks()
return CheckHost();
}

public override string Description
{
get { return Messages.ASSERT_CAN_EVACUATE_CHECK_DESCRIPTION; }
}
public override string Description => Messages.ASSERT_CAN_EVACUATE_CHECK_DESCRIPTION;
}
}
29 changes: 20 additions & 9 deletions XenAdmin/Diagnostics/Checks/HaWlbOffCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,44 @@
* SUCH DAMAGE.
*/

using XenAdmin.Core;
using XenAdmin.Diagnostics.Problems;
using XenAdmin.Diagnostics.Problems.PoolProblem;
using XenAPI;


namespace XenAdmin.Diagnostics.Checks
{
class HaWlbOffCheck : PoolCheck
internal class HaOffCheck : PoolCheck
{
public HaWlbOffCheck(Pool pool)
public HaOffCheck(Pool pool)
: base(pool)
{
}

protected override Problem RunCheck()
{
if (Pool.ha_enabled)
return new HAEnabledProblem(this, Pool);
return Pool.ha_enabled ? new HAEnabledProblem(this, Pool) : null;
}

public override string Description => Messages.HA_CHECK_DESCRIPTION;

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


if (Helpers.WlbEnabled(Pool.Connection))
return new WLBEnabledProblem(this, Pool);
internal class WlbOffCheck : PoolCheck
{
public WlbOffCheck(Pool pool)
: base(pool)
{
}

return null;
protected override Problem RunCheck()
{
return Pool.wlb_enabled ? new WLBEnabledProblem(this, Pool) : null;
}

public override string Description => Messages.HA_WLB_CHECK_DESCRIPTION;
public override string Description => Messages.WLB_CHECK_DESCRIPTION;

public override string SuccessfulCheckDescription => string.Format(Messages.PATCHING_WIZARD_CHECK_ON_XENOBJECT_OK, Pool.Name(), Description);
}
Expand Down
29 changes: 22 additions & 7 deletions XenAdmin/Diagnostics/Problems/PoolProblem/HAEnabledProblem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,35 @@ public DrHAEnabledProblem(Check check, Pool pool)
public override string Description => Messages.DR_WIZARD_PROBLEM_HA_ENABLED;
}

class HAEnabledWarning : Warning
internal class HaWlbEnabledWarning : Warning
{
private readonly Pool pool;
private readonly Host host;
private readonly Pool _pool;
private readonly Host _host;

public HAEnabledWarning(Check check, Pool pool, Host host)
public HaWlbEnabledWarning(Check check, Pool pool, Host host)
: base(check)
{
this.pool = pool;
this.host = host;
_pool = pool;
_host = host;
}

public override string Title => Check.Description;

public override string Description => string.Format(Messages.UPDATES_WIZARD_HA_ON_WARNING, host, pool);
public override string Description
{
get
{
if (_pool.ha_enabled && _pool.wlb_enabled)
return string.Format(Messages.UPDATES_WIZARD_HA_AND_WLB_ON_WARNING, _host, _pool);

if (_pool.ha_enabled)
return string.Format(Messages.UPDATES_WIZARD_HA_ON_WARNING, _host, _pool);

if (_pool.wlb_enabled)
return string.Format(Messages.UPDATES_WIZARD_WLB_ON_WARNING, _host, _pool);

return string.Empty;
}
}
}
}
42 changes: 14 additions & 28 deletions XenAdmin/Diagnostics/Problems/PoolProblem/WLBEnabledProblem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
* SUCH DAMAGE.
*/

using System.Threading;
using XenAdmin.Actions;
using XenAdmin.Actions.Wlb;
using XenAdmin.Core;
using XenAdmin.Diagnostics.Checks;
using XenAPI;

Expand All @@ -52,36 +50,24 @@ public WLBEnabledProblem(Check check, Pool pool)
protected override AsyncAction CreateAction(out bool cancelled)
{
cancelled = false;
return new DelegatedAsyncAction(Pool.Connection, Messages.HELP_MESSAGE_DISABLE_WLB, "", "",
ss =>
{
var action = new DisableWLBAction(Pool, false);
action.RunSync(ss);
int count = 0;
while (Helpers.WlbEnabled(Pool.Connection) && count < 10)
{
Thread.Sleep(500);
count++;
}
}, true);

return new DisableWLBAction(Pool, false);
}
}

class WLBEnabledWarning : Warning
{
private readonly Pool pool;
private readonly Host host;

public WLBEnabledWarning(Check check, Pool pool, Host host)
: base(check)
public override AsyncAction CreateUnwindChangesAction()
{
this.pool = pool;
this.host = host;
}
var pool = Pool.Connection.Resolve(new XenRef<Pool>(Pool.opaque_ref));

public override string Title => Check.Description;
if (pool == null)
{
foreach (var xenConnection in ConnectionsManager.XenConnectionsCopy)
{
pool = xenConnection.Resolve(new XenRef<Pool>(Pool.opaque_ref));
if (pool != null)
break;
}
}

public override string Description => string.Format(Messages.UPDATES_WIZARD_WLB_ON_WARNING, host, pool);
return pool == null ? null : new EnableWLBAction(pool);
}
}
}
11 changes: 7 additions & 4 deletions XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,16 @@ private List<CheckGroup> GenerateCommonChecks(List<Host> applicableServers)

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

//HA checks
//HA and WLB checks

var haChecks = new List<Check>();
var haWlbChecks = new List<Check>();
foreach (Pool pool in SelectedPools)
haChecks.Add(new HaWlbOffCheck(pool));
{
haWlbChecks.Add(new HaOffCheck(pool));
haWlbChecks.Add(new WlbOffCheck(pool));
}

groups.Add(new CheckGroup(Messages.CHECKING_HA_STATUS, haChecks));
groups.Add(new CheckGroup(Messages.CHECKING_HA_AND_WLB_STATUS, haWlbChecks));

//PBDsPluggedCheck
var pbdChecks = new List<Check>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,16 @@ where check.CanRun()
if (pvChecks.Count > 0)
groups.Add(new CheckGroup(Messages.CHECKING_PV_GUESTS, pvChecks));

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

if (haChecks.Count > 0)
groups.Add(new CheckGroup(Messages.CHECKING_HA_STATUS, haChecks));
if (haWlbChecks.Count > 0)
groups.Add(new CheckGroup(Messages.CHECKING_HA_AND_WLB_STATUS, haWlbChecks));

//Checking can evacuate host - for hosts that will be upgraded or updated
var evacuateChecks = (from Host host in hostsToUpgradeOrUpdate
Expand Down
71 changes: 32 additions & 39 deletions XenModel/Actions/WLB/DisableWLBAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,23 @@ namespace XenAdmin.Actions.Wlb
public class DisableWLBAction : AsyncAction
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private bool _deconfigure = false;
private readonly bool _deconfigure;
private static string OPTIMIZINGPOOL = "wlb_optimizing_pool";

public DisableWLBAction(Pool pool, bool deconfigure)
: base(pool.Connection, string.Format(Messages.DISABLING_WLB_ON, Helpers.GetName(pool).Ellipsise(50)), Messages.DISABLING_WLB, false)
{
this.Pool = pool;
this._deconfigure = deconfigure;
Pool = pool;
_deconfigure = deconfigure;

if (deconfigure)
{
this.Title = String.Format(Messages.DECONFIGURING_WLB_ON, Helpers.GetName(pool).Ellipsise(50));
this.Description = Messages.DECONFIGURING_WLB;
Title = string.Format(Messages.DECONFIGURING_WLB_ON, Helpers.GetName(pool).Ellipsise(50));
Description = Messages.DECONFIGURING_WLB;
}

#region RBAC Dependencies
ApiMethodsToRoleCheck.Add("pool.set_wlb_enabled");
ApiMethodsToRoleCheck.Add("pool.deconfigure_wlb");
ApiMethodsToRoleCheck.AddRange("pool.set_wlb_enabled", "pool.deconfigure_wlb");
#endregion
}

Expand All @@ -66,59 +65,53 @@ protected override void Run()
{
try
{
if (!Helpers.WlbEnabled(Pool.Connection))
if (!Pool.wlb_enabled)
{
log.Debug("Resuming WLB (prior to disconnecting) for pool " + Pool.Name());
XenAPI.Pool.set_wlb_enabled(this.Session, Pool.opaque_ref, true);
Pool.set_wlb_enabled(Session, Pool.opaque_ref, true);
log.Debug("Success resuming WLB on pool " + Pool.Name());
}
log.Debug("Disconnecting Workload Balancing from pool " + Pool.Name() + " and removing all pool data");
XenAPI.Pool.deconfigure_wlb(this.Session);

log.Debug($"Disconnecting Workload Balancing from pool {Pool.Name()} and removing all pool data");
Pool.deconfigure_wlb(Session);
log.Debug("Success disconnecting Workload Balancing on pool " + Pool.Name());
this.Description = Messages.COMPLETED;

WlbServerState.SetState(this.Session, Pool, WlbServerState.ServerState.NotConfigured);
}
catch (Exception ex)
{
//Force disabling of WLB
XenAPI.Pool.set_wlb_enabled(this.Session, Pool.opaque_ref, false);
WlbServerState.SetState(this.Session, Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex);
log.Debug($"Disconnecting Workload Balancing failed on pool {Pool.Name()}. Workload Balancing has been paused.", ex);
throw new Exception(string.Format(Messages.ACTION_WLB_DECONFIGURE_FAILED, Pool.Name(), ex.Message));
WlbServerState.SetState(Session, Pool, WlbServerState.ServerState.NotConfigured);
Description = Messages.COMPLETED;
}
finally
catch (Failure f)
{
//Clear the Optimizing Pool flag in case it was left behind
Helpers.SetOtherConfig(this.Session, this.Pool, OPTIMIZINGPOOL, string.Empty);
Pool.set_wlb_enabled(Session, Pool.opaque_ref, false);
WlbServerState.SetState(Session, Pool, WlbServerState.ServerState.ConnectionError, f);
log.Debug($"Disconnecting Workload Balancing failed on pool {Pool.Name()}. Workload Balancing has been paused.", f);

throw new Exception(string.Format(Messages.ACTION_WLB_DECONFIGURE_FAILED, Pool.Name(), f));
}
}
else
{
try
{
log.Debug("Pausing Workload Balancing on pool " + Pool.Name());
XenAPI.Pool.set_wlb_enabled(this.Session, Pool.opaque_ref, false);
Pool.set_wlb_enabled(Session, Pool.opaque_ref, false);
log.Debug("Success pausing Workload Balancing on pool " + Pool.Name());
this.Description = Messages.COMPLETED;
WlbServerState.SetState(this.Session, Pool, WlbServerState.ServerState.Disabled);
}
catch (Exception ex)
{
if (ex is Failure)
{
WlbServerState.SetState(this.Session, Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex);
}
throw ex;

Connection.WaitFor(() => !Pool.wlb_enabled, null);
WlbServerState.SetState(Session, Pool, WlbServerState.ServerState.Disabled);
Description = Messages.COMPLETED;
}
finally
catch (Failure f)
{
//Clear the Optimizing Pool flag in case it was left behind
Helpers.SetOtherConfig(this.Session, this.Pool, OPTIMIZINGPOOL, string.Empty);
WlbServerState.SetState(Session, Pool, WlbServerState.ServerState.ConnectionError, f);
throw;
}
}

}

protected override void Clean()
{
//Clear the Optimizing Pool flag in case it was left behind
Helpers.SetOtherConfig(Session, Pool, OPTIMIZINGPOOL, string.Empty);
}
}
}
Loading
Loading