mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 07:19:18 +01:00
A couple of random corrrections on error handling (#2265)
* Correct out of range percentage and throw an assertion instead of silently logging it so we can fix the causes of it. Compacted method logic. Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com> * Exception handling: prevent InvalidOperationException if the health check service is not found on the computer (installation is optional). Do not throw exception and handle if the task handle is invalid, but rather throw it only for other cases of task.status being failure. Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
parent
877f656d15
commit
c0af621167
@ -456,14 +456,14 @@ namespace XenAdmin
|
||||
});
|
||||
}
|
||||
|
||||
void actionCompleted(ActionBase action)
|
||||
private void actionCompleted(ActionBase action)
|
||||
{
|
||||
actionChanged(action);
|
||||
if (action is SrAction)
|
||||
Program.Invoke(this, UpdateToolbars);
|
||||
}
|
||||
|
||||
void actionChanged(ActionBase action)
|
||||
private void actionChanged(ActionBase action)
|
||||
{
|
||||
if (Program.Exiting)
|
||||
return;
|
||||
@ -471,42 +471,45 @@ namespace XenAdmin
|
||||
Program.Invoke(this, () => actionChanged_(action));
|
||||
}
|
||||
|
||||
void actionChanged_(ActionBase action)
|
||||
private void actionChanged_(ActionBase action)
|
||||
{
|
||||
if (action.SuppressProgressReport) // suppress updates when the PureAsyncAction runs the action to populate the ApiMethodsToRoleCheck
|
||||
// suppress updates when the PureAsyncAction runs the action to populate the ApiMethodsToRoleCheck
|
||||
if (action.SuppressProgressReport)
|
||||
return;
|
||||
var meddlingAction = action as MeddlingAction;
|
||||
if (meddlingAction == null)
|
||||
statusProgressBar.Visible = action.ShowProgress && !action.IsCompleted;
|
||||
|
||||
// Be defensive against CA-8517.
|
||||
if (action.PercentComplete < 0 || action.PercentComplete > 100)
|
||||
{
|
||||
log.ErrorFormat("PercentComplete is erroneously {0}", action.PercentComplete);
|
||||
}
|
||||
else if (meddlingAction == null)
|
||||
{
|
||||
statusProgressBar.Value = action.PercentComplete;
|
||||
}
|
||||
var percentage = action.PercentComplete;
|
||||
Debug.Assert(0 <= percentage && percentage <= 100,
|
||||
"PercentComplete is out of range, the reporting action needs to be fixed."); //CA-8517
|
||||
|
||||
// Don't show cancelled exception
|
||||
if (action.Exception != null && !(action.Exception is CancelledException))
|
||||
var meddlingAction = action as MeddlingAction;
|
||||
if (meddlingAction == null)
|
||||
{
|
||||
if (meddlingAction == null)
|
||||
statusProgressBar.Visible = action.ShowProgress && !action.IsCompleted;
|
||||
|
||||
if (percentage < 0)
|
||||
percentage = 0;
|
||||
else if (percentage > 100)
|
||||
percentage = 100;
|
||||
statusProgressBar.Value = percentage;
|
||||
|
||||
// Don't show cancelled exception
|
||||
if (action.Exception != null && !(action.Exception is CancelledException))
|
||||
{
|
||||
SetStatusBar(Properties.Resources._000_error_h32bit_16, action.Exception.Message);
|
||||
}
|
||||
else if (meddlingAction == null)
|
||||
{
|
||||
SetStatusBar(null, action.IsCompleted
|
||||
? null
|
||||
: !string.IsNullOrEmpty(action.Description)
|
||||
? action.Description
|
||||
: !string.IsNullOrEmpty(action.Title)
|
||||
? action.Title
|
||||
: null);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetStatusBar(null, action.IsCompleted
|
||||
? null
|
||||
: !string.IsNullOrEmpty(action.Description)
|
||||
? action.Description
|
||||
: !string.IsNullOrEmpty(action.Title)
|
||||
? action.Title
|
||||
: null);
|
||||
}
|
||||
}
|
||||
|
||||
int errors = ConnectionsManager.History.Count(a => a.IsCompleted && !a.Succeeded && !((a is CancellingAction) && ((CancellingAction)a).Cancelled));
|
||||
int errors = ConnectionsManager.History.Count(a => a.IsCompleted && !a.Succeeded && !(a is CancellingAction && ((CancellingAction)a).Cancelled));
|
||||
navigationPane.UpdateNotificationsButton(NotificationsSubMode.Events, errors);
|
||||
|
||||
if (eventsPage.Visible)
|
||||
@ -516,7 +519,7 @@ namespace XenAdmin
|
||||
}
|
||||
}
|
||||
|
||||
public void SetStatusBar(Image image, string message)
|
||||
private void SetStatusBar(Image image, string message)
|
||||
{
|
||||
statusLabel.Image = image;
|
||||
statusLabel.Text = Helpers.FirstLine(message);
|
||||
|
@ -33,6 +33,7 @@ using XenAPI;
|
||||
using XenAdmin.Core;
|
||||
using System;
|
||||
using System.IO.Pipes;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.ServiceProcess;
|
||||
using XenAdmin.Model;
|
||||
@ -67,6 +68,10 @@ namespace XenAdmin.Actions
|
||||
ServiceController sc = new ServiceController(HEALTHCHECKSERVICENAME);
|
||||
try
|
||||
{
|
||||
var services = ServiceController.GetServices();
|
||||
var found = services.FirstOrDefault(s => s.ServiceName == HEALTHCHECKSERVICENAME);
|
||||
if (found == null)
|
||||
return;//the service is not installed
|
||||
if (sc.Status != ServiceControllerStatus.Running)
|
||||
return;
|
||||
}
|
||||
|
@ -98,55 +98,51 @@ namespace XenAdmin.Network
|
||||
|
||||
private void poll()
|
||||
{
|
||||
try
|
||||
{
|
||||
XenAPI.Task task = GetTask();
|
||||
_action.Tick((int)(task.progress * _scale + _lo),
|
||||
task.Description() == "" ? _action.Description : task.Description());
|
||||
switch (task.status)
|
||||
{
|
||||
case XenAPI.task_status_type.failure:
|
||||
log.Warn("Action failed due to API failure:\n" + Environment.StackTrace);
|
||||
throw new XenAPI.Failure(new List<string>(task.error_info));
|
||||
Task task = GetTask();
|
||||
_action.Tick((int)(task.progress * _scale + _lo),
|
||||
task.Description() == "" ? _action.Description : task.Description());
|
||||
|
||||
case XenAPI.task_status_type.success:
|
||||
switch (task.status)
|
||||
{
|
||||
case task_status_type.failure:
|
||||
if (task.error_info.Length > 1 &&
|
||||
task.error_info[0] == Failure.HANDLE_INVALID &&
|
||||
task.error_info[1] == "task")
|
||||
{
|
||||
log.WarnFormat("Invalid task handle - task is finished:\n{0}", Environment.StackTrace);
|
||||
taskCompleted = true;
|
||||
_action.Result = task.result;
|
||||
// Work around CA-6597.
|
||||
if (_action.Result != "")
|
||||
{
|
||||
Match m = Regex.Match(_action.Result, "<value>(.*)</value>");
|
||||
if (m.Success)
|
||||
{
|
||||
_action.Result = m.Groups[1].Value;
|
||||
}
|
||||
}
|
||||
_action.PercentComplete = (int)(_scale + _lo);
|
||||
_action.Result = "";
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.WarnFormat("Action failed due to API failure:\n{0}", Environment.StackTrace);
|
||||
throw new Failure(new List<string>(task.error_info));
|
||||
}
|
||||
|
||||
case XenAPI.task_status_type.cancelled:
|
||||
log.Debug("Action cancelled");
|
||||
throw new CancelledException();
|
||||
|
||||
case XenAPI.task_status_type.cancelling:
|
||||
case XenAPI.task_status_type.pending:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (XenAPI.Failure exn)
|
||||
{
|
||||
if (exn.ErrorDescription.Count > 1 &&
|
||||
exn.ErrorDescription[0] == XenAPI.Failure.HANDLE_INVALID &&
|
||||
exn.ErrorDescription[1] == "task")
|
||||
{
|
||||
// Task has gone away, which means it's finished.
|
||||
case task_status_type.success:
|
||||
taskCompleted = true;
|
||||
_action.PercentComplete = (int)(_scale + _lo);
|
||||
_action.Result = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
_action.Result = task.result;
|
||||
// Work around CA-6597.
|
||||
if (_action.Result != "")
|
||||
{
|
||||
Match m = Regex.Match(_action.Result, "<value>(.*)</value>");
|
||||
if (m.Success)
|
||||
{
|
||||
_action.Result = m.Groups[1].Value;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case task_status_type.cancelled:
|
||||
log.Debug("Action cancelled");
|
||||
throw new CancelledException();
|
||||
|
||||
case task_status_type.cancelling:
|
||||
case task_status_type.pending:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user