mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 15:29:26 +01:00
Minor modifications to task polling:
- Consolidated Action.PollToCompletion overloads, among others, to reduce precision loss. - Logging the environment's stack trace is not very useful in the case of an API failure. - Log the task's opaque_ref so it's easier to trace errors in the server side logs. Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
parent
e895bc4168
commit
fbb25c7970
@ -266,24 +266,11 @@ namespace XenAdmin.Actions
|
||||
}
|
||||
}
|
||||
|
||||
public void PollToCompletion(int start, int finish)
|
||||
public void PollToCompletion(double start = 0, double finish = 100)
|
||||
{
|
||||
new TaskPoller(this, start, finish).PollToCompletion();
|
||||
}
|
||||
|
||||
public void PollToCompletion(double start, double finish)
|
||||
{
|
||||
PollToCompletion((int)start, (int)finish);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to PollToCompletion(0, 100).
|
||||
/// </summary>
|
||||
public void PollToCompletion()
|
||||
{
|
||||
PollToCompletion(0, 100);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the roles allowed to perform the API calls this action has listed as subject to RBAC checks.
|
||||
/// If the current user's role is not on the list, show the Role Elevation Dialog so they can enter
|
||||
|
@ -49,7 +49,7 @@ namespace XenAdmin.Actions
|
||||
|
||||
Description = string.Format(Messages.ACTION_TOOLSTACK_RESTARTING_ON, Host.Name().Ellipsise(30));
|
||||
RelatedTask = Host.async_restart_agent(session, Host.opaque_ref);
|
||||
PollToCompletion(0, 100);
|
||||
PollToCompletion();
|
||||
|
||||
//call interrupt so we can reconnect afterwards
|
||||
if (Helpers.HostIsMaster(Host))
|
||||
|
@ -58,7 +58,7 @@ namespace XenAdmin.Actions
|
||||
{
|
||||
Description = Messages.ENABLING;
|
||||
RelatedTask = PVS_proxy.async_create(Session, site.opaque_ref, vif.opaque_ref);
|
||||
PollToCompletion(0, 100);
|
||||
PollToCompletion();
|
||||
Description = Messages.ENABLED;
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ namespace XenAdmin.Actions
|
||||
{
|
||||
Description = Messages.DISABLING;
|
||||
RelatedTask = PVS_proxy.async_destroy(Session, proxy.opaque_ref);
|
||||
PollToCompletion(0, 100);
|
||||
PollToCompletion();
|
||||
Description = Messages.DISABLED;
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ namespace XenAdmin.Actions
|
||||
try
|
||||
{
|
||||
RelatedTask = Pool_patch.async_destroy(Session, patch.opaque_ref);
|
||||
PollToCompletion(0, 100);
|
||||
PollToCompletion();
|
||||
}
|
||||
catch (Failure f)
|
||||
{
|
||||
|
@ -59,7 +59,7 @@ namespace XenAdmin.Actions.VMActions
|
||||
this.Description = Messages.ACTION_VM_SHUTTING_DOWN;
|
||||
|
||||
RelatedTask = VM.async_clean_shutdown(Session, VM.opaque_ref);
|
||||
PollToCompletion(0, 100);
|
||||
PollToCompletion();
|
||||
this.Description = Messages.ACTION_VM_SHUT_DOWN;
|
||||
}
|
||||
}
|
||||
@ -76,7 +76,7 @@ namespace XenAdmin.Actions.VMActions
|
||||
this.Description = Messages.ACTION_VM_SHUTTING_DOWN;
|
||||
|
||||
RelatedTask = VM.async_hard_shutdown(Session, VM.opaque_ref);
|
||||
PollToCompletion(0, 100);
|
||||
PollToCompletion();
|
||||
|
||||
this.Description = Messages.ACTION_VM_SHUT_DOWN;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ namespace XenAdmin.Actions.VMActions
|
||||
{
|
||||
this.Description = Messages.ACTION_VM_SUSPENDING;
|
||||
RelatedTask = VM.async_suspend(Session, VM.opaque_ref);
|
||||
PollToCompletion(0, 100);
|
||||
PollToCompletion();
|
||||
this.Description = Messages.ACTION_VM_SUSPENDED;
|
||||
}
|
||||
}
|
||||
|
@ -45,15 +45,15 @@ namespace XenAdmin.Network
|
||||
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private AsyncAction _action;
|
||||
private readonly int _lo;
|
||||
private readonly double _lo;
|
||||
private readonly double _scale;
|
||||
private bool taskCompleted = false;
|
||||
private bool taskCompleted;
|
||||
|
||||
/// <summary>
|
||||
/// Polls the action regularly and updates the history item's progress from the task's progress,
|
||||
/// Polls the task regularly and updates the action's progress from the task's progress,
|
||||
/// scaled to a value between lo and hi.
|
||||
/// </summary>
|
||||
public TaskPoller(AsyncAction action, int lo, int hi)
|
||||
public TaskPoller(AsyncAction action, double lo, double hi)
|
||||
{
|
||||
_action = action;
|
||||
_lo = lo;
|
||||
@ -71,6 +71,7 @@ namespace XenAdmin.Network
|
||||
{
|
||||
DateTime startTime = DateTime.Now;
|
||||
int lastDebug = 0;
|
||||
log.InfoFormat("Started polling task {0}", _action.RelatedTask.opaque_ref);
|
||||
log.DebugFormat("Polling for action {0}", _action.Description);//log once we start
|
||||
|
||||
while (!taskCompleted)
|
||||
@ -86,7 +87,7 @@ namespace XenAdmin.Network
|
||||
log.DebugFormat("Polling for action {0}", _action.Description);
|
||||
}
|
||||
|
||||
poll();
|
||||
Poll();
|
||||
Thread.Sleep(SLEEP_TIME);
|
||||
}
|
||||
}
|
||||
@ -96,7 +97,7 @@ namespace XenAdmin.Network
|
||||
}
|
||||
}
|
||||
|
||||
private void poll()
|
||||
private void Poll()
|
||||
{
|
||||
Session session = _action.Session;
|
||||
Task task;
|
||||
@ -137,11 +138,13 @@ namespace XenAdmin.Network
|
||||
}
|
||||
else
|
||||
{
|
||||
log.WarnFormat("Action failed due to API failure:\n{0}", Environment.StackTrace);
|
||||
log.WarnFormat("Task {0} failed: {1}", _action.RelatedTask.opaque_ref,
|
||||
task.error_info.Length > 0 ? task.error_info[0] : "Unknown failure");
|
||||
throw new Failure(new List<string>(task.error_info));
|
||||
}
|
||||
|
||||
case task_status_type.success:
|
||||
log.InfoFormat("Task {0} finished successfully", _action.RelatedTask.opaque_ref);
|
||||
taskCompleted = true;
|
||||
_action.Result = task.result;
|
||||
// Work around CA-6597.
|
||||
@ -157,7 +160,7 @@ namespace XenAdmin.Network
|
||||
break;
|
||||
|
||||
case task_status_type.cancelled:
|
||||
log.Debug("Action cancelled");
|
||||
log.InfoFormat("Task {0} was cancelled", _action.RelatedTask.opaque_ref);
|
||||
throw new CancelledException();
|
||||
|
||||
case task_status_type.cancelling:
|
||||
@ -168,7 +171,7 @@ namespace XenAdmin.Network
|
||||
|
||||
private void GotInvalidHandle()
|
||||
{
|
||||
log.WarnFormat("Invalid task handle - task is finished:\n{0}", Environment.StackTrace);
|
||||
log.WarnFormat("Invalid task handle {0} - task is finished.", _action.RelatedTask.opaque_ref);
|
||||
taskCompleted = true;
|
||||
_action.PercentComplete = (int)(_scale + _lo);
|
||||
_action.Result = "";
|
||||
|
Loading…
Reference in New Issue
Block a user