diff --git a/XenAdmin/Diagnostics/Checks/AssertCanEvacuateCheck.cs b/XenAdmin/Diagnostics/Checks/AssertCanEvacuateCheck.cs index d7037f017..79fe332ba 100644 --- a/XenAdmin/Diagnostics/Checks/AssertCanEvacuateCheck.cs +++ b/XenAdmin/Diagnostics/Checks/AssertCanEvacuateCheck.cs @@ -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 RunAllChecks() @@ -279,9 +274,6 @@ public override List 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; } } diff --git a/XenAdmin/Diagnostics/Checks/HaWlbOffCheck.cs b/XenAdmin/Diagnostics/Checks/HaWlbOffCheck.cs index 84c9d6c31..b82e35083 100644 --- a/XenAdmin/Diagnostics/Checks/HaWlbOffCheck.cs +++ b/XenAdmin/Diagnostics/Checks/HaWlbOffCheck.cs @@ -28,7 +28,6 @@ * SUCH DAMAGE. */ -using XenAdmin.Core; using XenAdmin.Diagnostics.Problems; using XenAdmin.Diagnostics.Problems.PoolProblem; using XenAPI; @@ -36,25 +35,37 @@ 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); } diff --git a/XenAdmin/Diagnostics/Problems/PoolProblem/HAEnabledProblem.cs b/XenAdmin/Diagnostics/Problems/PoolProblem/HAEnabledProblem.cs index 2e015f1ca..6e129a531 100644 --- a/XenAdmin/Diagnostics/Problems/PoolProblem/HAEnabledProblem.cs +++ b/XenAdmin/Diagnostics/Problems/PoolProblem/HAEnabledProblem.cs @@ -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; + } + } } } diff --git a/XenAdmin/Diagnostics/Problems/PoolProblem/WLBEnabledProblem.cs b/XenAdmin/Diagnostics/Problems/PoolProblem/WLBEnabledProblem.cs index db23d4cdb..24b3179a5 100644 --- a/XenAdmin/Diagnostics/Problems/PoolProblem/WLBEnabledProblem.cs +++ b/XenAdmin/Diagnostics/Problems/PoolProblem/WLBEnabledProblem.cs @@ -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; @@ -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.opaque_ref)); - public override string Title => Check.Description; + if (pool == null) + { + foreach (var xenConnection in ConnectionsManager.XenConnectionsCopy) + { + pool = xenConnection.Resolve(new XenRef(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); + } } } diff --git a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs index 4bef97a92..e78395cf3 100644 --- a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs +++ b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs @@ -359,13 +359,16 @@ private List GenerateCommonChecks(List applicableServers) groups.Add(new CheckGroup(Messages.CHECKING_HOST_LIVENESS_STATUS, livenessChecks)); - //HA checks + //HA and WLB checks - var haChecks = new List(); + var haWlbChecks = new List(); 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(); diff --git a/XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizardPrecheckPage.cs b/XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizardPrecheckPage.cs index 877dd915b..b9d9a3940 100644 --- a/XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizardPrecheckPage.cs +++ b/XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizardPrecheckPage.cs @@ -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(); + 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 diff --git a/XenModel/Actions/WLB/DisableWLBAction.cs b/XenModel/Actions/WLB/DisableWLBAction.cs index 60ff88b4e..185fb9a05 100644 --- a/XenModel/Actions/WLB/DisableWLBAction.cs +++ b/XenModel/Actions/WLB/DisableWLBAction.cs @@ -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 } @@ -66,31 +65,27 @@ 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 @@ -98,27 +93,25 @@ protected override void Run() 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); + } } } diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index 2d47ae38c..c9719a457 100755 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -7948,9 +7948,9 @@ public static string CHECKING_FOR_PENDING_RESTART { /// /// Looks up a localized string similar to Checking HA and WLB status. /// - public static string CHECKING_HA_STATUS { + public static string CHECKING_HA_AND_WLB_STATUS { get { - return ResourceManager.GetString("CHECKING_HA_STATUS", resourceCulture); + return ResourceManager.GetString("CHECKING_HA_AND_WLB_STATUS", resourceCulture); } } @@ -18835,6 +18835,15 @@ public static string HA_CANNOT_EVACUATE_COORDINATOR { } } + /// + /// Looks up a localized string similar to HA check. + /// + public static string HA_CHECK_DESCRIPTION { + get { + return ResourceManager.GetString("HA_CHECK_DESCRIPTION", resourceCulture); + } + } + /// /// Looks up a localized string similar to Choose a heartbeat SR. /// @@ -19498,15 +19507,6 @@ public static string HA_WIZARD_FINISH_PAGE_TITLE { } } - /// - /// Looks up a localized string similar to HA and WLB check. - /// - public static string HA_WLB_CHECK_DESCRIPTION { - get { - return ResourceManager.GetString("HA_WLB_CHECK_DESCRIPTION", resourceCulture); - } - } - /// /// Looks up a localized string similar to Has any custom field. /// @@ -38036,6 +38036,15 @@ public static string UPDATES_WIZARD_FILE_NOT_FOUND { } } + /// + /// Looks up a localized string similar to {0}: Check skipped because HA and WLB are enabled on pool {1}.. + /// + public static string UPDATES_WIZARD_HA_AND_WLB_ON_WARNING { + get { + return ResourceManager.GetString("UPDATES_WIZARD_HA_AND_WLB_ON_WARNING", resourceCulture); + } + } + /// /// Looks up a localized string similar to Pool '{0}' cannot have HA enabled.. /// @@ -41499,6 +41508,15 @@ public static string WLB_AUTOMATION_SUBTEXT { } } + /// + /// Looks up a localized string similar to WLB check. + /// + public static string WLB_CHECK_DESCRIPTION { + get { + return ResourceManager.GetString("WLB_CHECK_DESCRIPTION", resourceCulture); + } + } + /// /// Looks up a localized string similar to Workload &Balancing. /// diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index 2e4f0691d..4a08d6a28 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -2866,7 +2866,7 @@ Do you want to assign these VMs to the schedule '{0}' instead? Checking for pending restart - + Checking HA and WLB status @@ -6580,6 +6580,9 @@ not currently live: Server '{0}' cannot be placed in Maintenance Mode because it is the coordinator of an HA-enabled pool. + + HA check + Choose a heartbeat SR @@ -6817,9 +6820,6 @@ Click Configure HA to alter the settings displayed below. Review configuration and activate HA - - HA and WLB check - Has any custom field @@ -13136,6 +13136,9 @@ Note that if RBAC is enabled, only updates which you have privileges to dismiss Check your settings and try again. + + {0}: Check skipped because HA and WLB are enabled on pool {1}. + Pool '{0}' cannot have HA enabled. @@ -14301,6 +14304,9 @@ Schedule: Configure WLB Automation + + WLB check + Workload &Balancing