protected override void Run() { try { log.Debug("Resuming WLB on pool " + Pool.Name()); XenAPI.Pool.set_wlb_enabled(this.Session, Pool.opaque_ref, true); log.Debug("Success resuming WLB on pool " + Pool.Name()); this.Description = Messages.COMPLETED; WlbServerState.SetState(this.Pool, WlbServerState.ServerState.Enabled); //Clear the Optimizing Pool flag in case it was left behind Helpers.SetOtherConfig(this.Session, this.Pool, OPTIMIZINGPOOL, string.Empty); log.Debug("Retrieving Workload Balancing configuration for pool " + Pool.Name()); this.WlbConfiguration = XenAPI.Pool.retrieve_wlb_configuration(this.Session); log.Debug("Success retrieving Workload Balancing configuration on pool " + Pool.Name()); this.Description = Messages.COMPLETED; } catch (Exception ex) { if (ex is Failure) { WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex); } throw ex; } }
protected override void Run() { try { log.DebugFormat("Retrieving recommendations for pool {0}", Pool.Name()); this.WLBOptPoolRecommendations = Pool.retrieve_wlb_recommendations(Session); log.DebugFormat("Success retrieving recommendations for pool {0}", Pool.Name()); //Retrieving the recommendations was successful, so update the WlbServerState to report the current state // This is here in case there was a previous communication error which has been fixed. if (WlbServerState.GetState(Pool) == WlbServerState.ServerState.ConnectionError || WlbServerState.GetState(Pool) == WlbServerState.ServerState.Unknown) { if (Helpers.WlbEnabled(Pool.Connection)) { WlbServerState.SetState(Pool, WlbServerState.ServerState.Enabled); } else { WlbServerState.SetState(Pool, WlbServerState.ServerState.Disabled); } } } catch (Exception ex) { if (ex is Failure) { WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex); } log.Error(ex, ex); } }
protected override void Run() { try { log.Debug("Retrieving Workload Balancing configuration for pool " + Pool.Name); this.WlbConfiguration = XenAPI.Pool.retrieve_wlb_configuration(this.Session); if (this.WlbConfiguration.Count == 0) { //We didn;t get a configuration, so there is somethign wrong log.Debug("Failure retrieving Workload Balancing configuration on pool " + Pool.Name); this.Description = Messages.FAILED; Failure f = new Failure(FriendlyErrorNames.WLB_NOT_INITIALIZED); throw f; } else { log.Debug("Success retrieving Workload Balancing configuration on pool " + Pool.Name); this.Description = Messages.COMPLETED; //Retrieving the configuration was successful, so update the WlbServerState to report the current state // This is here in case there was a previous communication error which has been fixed. if (Helpers.WlbEnabled(Pool.Connection)) { WlbServerState.SetState(Pool, WlbServerState.ServerState.Enabled); } else { WlbServerState.SetState(Pool, WlbServerState.ServerState.Disabled); } } } catch (Exception ex) { if (ex is Failure) { // Retrieving the configuration error could also because WLB is not initialized if (((Failure)ex).Message == FriendlyErrorNames.WLB_NOT_INITIALIZED) { WlbServerState.SetState(Pool, WlbServerState.ServerState.NotConfigured); } else { WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex); } if (((Failure)ex).Message == FriendlyErrorNames.WLB_INTERNAL_ERROR) { Failure f = new Failure(new string[] { Messages.ResourceManager.GetString("WLB_ERROR_" + ((Failure)ex).ErrorDescription[1]) }); throw (f); } else { throw (ex); } } } }
protected override void Run() { if (_deconfigure) { try { if (!Helpers.WlbEnabled(Pool.Connection)) { log.Debug("Resuming WLB (prior to disconnecting) for pool " + Pool.Name); XenAPI.Pool.set_wlb_enabled(this.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("Success disconnecting Workload Balancing on pool " + Pool.Name); this.Description = Messages.COMPLETED; WlbServerState.SetState(Pool, WlbServerState.ServerState.NotConfigured); } catch (Exception ex) { //Force disabling of WLB XenAPI.Pool.set_wlb_enabled(this.Session, Pool.opaque_ref, false); WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex); log.Debug(string.Format(Messages.ACTION_WLB_DECONFIGURE_FAILED, Pool.Name, ex.Message)); throw new Exception(string.Format(Messages.ACTION_WLB_DECONFIGURE_FAILED, Pool.Name, ex.Message)); } finally { //Clear the Optimizing Pool flag in case it was left behind Helpers.SetOtherConfig(this.Session, this.Pool, OPTIMIZINGPOOL, string.Empty); } } else { try { log.Debug("Pausing Workload Balancing on pool " + Pool.Name); XenAPI.Pool.set_wlb_enabled(this.Session, Pool.opaque_ref, false); log.Debug("Success pausing Workload Balancing on pool " + Pool.Name); this.Description = Messages.COMPLETED; WlbServerState.SetState(Pool, WlbServerState.ServerState.Disabled); } catch (Exception ex) { if (ex is Failure) { WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex); } throw ex; } finally { //Clear the Optimizing Pool flag in case it was left behind Helpers.SetOtherConfig(this.Session, this.Pool, OPTIMIZINGPOOL, string.Empty); } } }
protected override void Run() { log.Debug("Sending Workload Balancing configuration for pool " + Pool.Name); ClearKeys(); if ((_kind & SendWlbConfigurationKind.SetHostConfiguration) == SendWlbConfigurationKind.SetHostConfiguration) { this.WlbConfiguration.Add(SET_HOST_CONFIGURATION, "true"); } if ((_kind & SendWlbConfigurationKind.SetScheduledTask) == SendWlbConfigurationKind.SetScheduledTask) { this.WlbConfiguration.Add(SET_SCHEDULED_TASK, "true"); } if ((_kind & SendWlbConfigurationKind.DeleteScheduledTask) == SendWlbConfigurationKind.DeleteScheduledTask) { this.WlbConfiguration.Add(DELETE_SCHEDULED_TASK, "true"); } if ((_kind & SendWlbConfigurationKind.SetReportSubscription) == SendWlbConfigurationKind.SetReportSubscription) { this.WlbConfiguration.Add(SET_REPORT_SUBSCRIPTIONS, "true"); } if ((_kind & SendWlbConfigurationKind.DeleteReportSubscription) == SendWlbConfigurationKind.DeleteReportSubscription) { this.WlbConfiguration.Add(DELETE_REPORT_SUBSCRIPTIONS, "true"); } try { XenAPI.Pool.send_wlb_configuration(this.Session, this.WlbConfiguration); log.Debug("Successfully sent Workload Balancing configuration on pool " + Pool.Name); this.Description = Messages.COMPLETED; } catch (Exception ex) { if (ex is Failure) { WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex); if (((Failure)ex).Message == FriendlyErrorNames.WLB_INTERNAL_ERROR) { Failure f = new Failure(new string[] { Messages.ResourceManager.GetString("WLB_ERROR_" + ((Failure)ex).ErrorDescription[1]) }); throw (f); } else { throw (ex); } } } }
protected override void Run() { if (vmOptList.Count == 0) { log.ErrorFormat("{0} has no VMs need to be optimized", Helpers.GetName(Pool)); return; } this.Description = Messages.ACTION_WLB_POOL_OPTIMIZING; try { log.Debug("Optimizing " + Pool.Name()); // for checking whether to display recommendations on optimize pool listview Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, Messages.IN_PROGRESS); int start = 0; int each = 90 / vmOptList.Count; foreach (KeyValuePair <VM, WlbOptimizationRecommendation> vmItem in vmOptList) { VM vm = vmItem.Key; if (vmItem.Key.is_control_domain) { log.Debug(vmItem.Value.powerOperation + " " + Helpers.GetName(vmItem.Value.toHost)); Host fromHost = vmItem.Value.fromHost; Helpers.SetOtherConfig(fromHost.Connection.Session, fromHost, WlbOptimizationRecommendation.OPTIMIZINGPOOL, vmItem.Value.recId.ToString()); AsyncAction hostAction = null; int waitingInterval = 10 * 1000; // default to 10s if (vmItem.Value.fromHost.IsLive()) { hostAction = new ShutdownHostAction(fromHost, AddHostToPoolCommand.NtolDialog); } else { hostAction = new HostPowerOnAction(fromHost); waitingInterval = 30 * 1000; // wait for 30s } hostAction.Completed += HostAction_Completed; hostAction.RunAsync(); while (!moveToNext) { if (!String.IsNullOrEmpty(hostActionError)) { throw new Exception(hostActionError); } else { //wait System.Threading.Thread.Sleep(waitingInterval); } } } else { log.Debug("Migrating VM " + vm.Name()); Host toHost = vmItem.Value.toHost; try { // check if there is a conflict with HA, start optimize if we can RelocateVmWithHa(this, vm, toHost, start, start + each, vmItem.Value.recId); } catch (Failure f) { // prompt to user if ha notl can be raised, if yes, continue long newNtol; if (RaiseHANotl(vm, f, out newNtol)) { DelegatedAsyncAction action = new DelegatedAsyncAction(vm.Connection, Messages.HA_LOWERING_NTOL, null, null, delegate(Session session) { // Set new ntol, then retry action XenAPI.Pool.set_ha_host_failures_to_tolerate(session, this.Pool.opaque_ref, newNtol); // ntol set succeeded, start new action Program.MainWindow.CloseActiveWizards(vm); new VMMigrateAction(vm, toHost).RunAsync(); }); action.RunAsync(); } else { Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, Messages.WLB_OPT_FAILED); this.Description = Messages.WLB_OPT_FAILED; throw; } } } start += each; // stop if user cancels optimize pool if (Cancelling) { throw new CancelledException(); } } this.Description = Messages.WLB_OPT_OK_NOTICE_TEXT; Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, optId); log.Debug("Completed optimizing " + Pool.Name()); } catch (Failure ex) { Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, optId); WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, ex); throw; } catch (CancelledException) { Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, optId); throw; } catch (Exception ex) { log.Error(ex, ex); this.Description = Messages.WLB_OPT_FAILED; Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, optId); log.Debug("Optimizing " + Pool.Name() + " is failed"); } this.PercentComplete = 100; }