While researching the places where we use is_control_domain, I refactored some issues I noticed and were quick to fix:

- removed unnecessary casts
- no need to catch exception only to rethrow it; do not interrupt the call stack by using "throw ex"
- redundant check and value setting
This commit is contained in:
Konstantina Chremmou 2016-06-30 12:11:01 +01:00
parent 20cb3b4df1
commit 975fe4f303
3 changed files with 41 additions and 52 deletions

View File

@ -102,56 +102,46 @@ namespace XenAdmin.Actions.Wlb
foreach (KeyValuePair<VM, WlbOptimizationRecommendation> vmItem in vmOptList)
{
VM vm = vmItem.Key;
Host fromHost = null;
Host toHost = null;
if (vmItem.Key.is_control_domain)
{
log.Debug(vmItem.Value.powerOperation + " " + Helpers.GetName(vmItem.Value.toHost));
fromHost = vmItem.Value.fromHost;
Host fromHost = vmItem.Value.fromHost;
Helpers.SetOtherConfig(fromHost.Connection.Session, fromHost,WlbOptimizationRecommendation.OPTIMIZINGPOOL, vmItem.Value.recId.ToString());
try
AsyncAction hostAction = null;
int waitingInterval = 10 * 1000; // default to 10s
if (vmItem.Value.fromHost.IsLive)
{
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))
{
hostAction = new ShutdownHostAction(fromHost,AddHostToPoolCommand.NtolDialog);
throw new Exception(hostActionError);
}
else
{
hostAction = new HostPowerOnAction(fromHost);
waitingInterval = 30 * 1000; // wait for 30s
//wait
System.Threading.Thread.Sleep(waitingInterval);
}
hostAction.Completed += HostAction_Completed;
hostAction.RunAsync();
while (!moveToNext)
{
if (!String.IsNullOrEmpty(hostActionError))
{
throw new Exception(hostActionError);
}
else
{
//wait
System.Threading.Thread.Sleep(waitingInterval);
}
}
}
catch (Exception)
{
throw;
}
}
else
{
log.Debug("Migrating VM " + vm.Name);
fromHost = this.Pool.Connection.Resolve(vm.resident_on);
toHost = vmItem.Value.toHost;
Host toHost = vmItem.Value.toHost;
try
{
@ -162,7 +152,7 @@ namespace XenAdmin.Actions.Wlb
catch (Failure f)
{
// prompt to user if ha notl can be raised, if yes, continue
long newNtol = 0;
long newNtol;
if (RaiseHANotl(vm, f, out newNtol))
{
DelegatedAsyncAction action = new DelegatedAsyncAction(vm.Connection, Messages.HA_LOWERING_NTOL, null, null,
@ -180,7 +170,7 @@ namespace XenAdmin.Actions.Wlb
{
Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, Messages.WLB_OPT_FAILED);
this.Description = Messages.WLB_OPT_FAILED;
throw f;
throw;
}
}
}
@ -197,7 +187,7 @@ namespace XenAdmin.Actions.Wlb
catch (Failure ex)
{
Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, optId);
WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex);
WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, ex);
throw;
}
catch (CancelledException)

View File

@ -876,7 +876,7 @@ namespace XenAdmin.Dialogs
{
bool selected = false;
if (previousSelection != null && !selected)
if (previousSelection != null)
{
foreach (ToStringWrapper<Host> host in NewMasterComboBox.Items)
{
@ -892,7 +892,6 @@ namespace XenAdmin.Dialogs
if (NewMasterComboBox.Items.Count > 0 && !selected)
{
NewMasterComboBox.SelectedIndex = 0;
selected = true;
}
}

View File

@ -810,11 +810,11 @@ namespace XenAdmin.XenSearch
VM vm = o as VM;
if (vm.is_a_snapshot)
{
return (IComparable)ObjectTypes.Snapshot;
return ObjectTypes.Snapshot;
}
else if (vm.is_a_template)
{
return (IComparable)(vm.DefaultTemplate ? ObjectTypes.DefaultTemplate : ObjectTypes.UserTemplate);
return vm.DefaultTemplate ? ObjectTypes.DefaultTemplate : ObjectTypes.UserTemplate;
}
else if (vm.is_control_domain)
{
@ -822,41 +822,41 @@ namespace XenAdmin.XenSearch
}
else
{
return (IComparable)ObjectTypes.VM;
return ObjectTypes.VM;
}
}
else if (o is VM_appliance)
{
return (IComparable)ObjectTypes.Appliance;
}
else if (o is VM_appliance)
{
return ObjectTypes.Appliance;
}
else if (o is Host)
{
return (IComparable)((o.Connection.IsConnected) ? ObjectTypes.Server : ObjectTypes.DisconnectedServer);
return o.Connection.IsConnected ? ObjectTypes.Server : ObjectTypes.DisconnectedServer;
}
else if (o is Pool)
{
return (IComparable)ObjectTypes.Pool;
return ObjectTypes.Pool;
}
else if (o is SR)
{
SR sr = o as SR;
return (IComparable)(sr.IsLocalSR ? ObjectTypes.LocalSR : ObjectTypes.RemoteSR);
return sr.IsLocalSR ? ObjectTypes.LocalSR : ObjectTypes.RemoteSR;
}
else if (o is XenAPI.Network)
{
return (IComparable)ObjectTypes.Network;
return ObjectTypes.Network;
}
else if (o is VDI)
{
return (IComparable)ObjectTypes.VDI;
return ObjectTypes.VDI;
}
else if (o is Folder)
{
return (IComparable)ObjectTypes.Folder;
return ObjectTypes.Folder;
}
else if (o is DockerContainer)
{
return (IComparable)ObjectTypes.DockerContainer;
return ObjectTypes.DockerContainer;
}
return null;