mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-23 12:30:50 +01:00
CA-114482: Changed workflow of retrieving updates: the list of published updates
is downloaded and stored every time an update is performed (if manual all updates are downloaded, if automatic only as per the user's choices). If there are available updates, update alerts are generated if there are connected hosts and disappear when the hosts are disconnected. Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
parent
b20434ba24
commit
f8117cd4f5
@ -121,7 +121,7 @@ namespace CFUValidator
|
||||
var updateAlert = XenAdmin.Core.Updates.NewXenServerVersionAlert(xenServerVersions);
|
||||
|
||||
Status = "Determining patches required...";
|
||||
var patchAlerts = XenAdmin.Core.Updates.NewXenServerPatchAlerts(xenServerVersions, xenServerPatches);
|
||||
var patchAlerts = XenAdmin.Core.Updates.NewXenServerPatchAlerts(xenServerVersions, xenServerPatches).Where(alert => !alert.CanIgnore).ToList();
|
||||
|
||||
//Build patch checks list
|
||||
List<AlertFeatureValidator> validators = new List<AlertFeatureValidator>
|
||||
|
@ -43,7 +43,9 @@ namespace CFUValidator.Updates
|
||||
class AlternativeUrlDownloadUpdatesXmlSourceAction : DownloadUpdatesXmlAction, ICheckForUpdatesXMLSource
|
||||
{
|
||||
private readonly string newLocation;
|
||||
|
||||
public AlternativeUrlDownloadUpdatesXmlSourceAction(string url)
|
||||
: base(true, true, true)
|
||||
{
|
||||
newLocation = url;
|
||||
ErrorRaised = null;
|
||||
|
@ -40,6 +40,7 @@ namespace CFUValidator.Updates
|
||||
{
|
||||
private readonly string newLocation;
|
||||
public ReadFromFileUpdatesXmlSource(string location)
|
||||
: base(true, true, true)
|
||||
{
|
||||
newLocation = location;
|
||||
ErrorRaised = null;
|
||||
|
@ -48,9 +48,10 @@ namespace XenAdmin.Core
|
||||
public static event Action<bool, string> CheckForUpdatesCompleted;
|
||||
public static event Action CheckForUpdatesStarted;
|
||||
|
||||
|
||||
private static readonly object downloadedUpdatesLock = new object();
|
||||
private static List<XenServerVersion> XenServerVersions = new List<XenServerVersion>();
|
||||
private static List<XenServerPatch> XenServerPatches = new List<XenServerPatch>();
|
||||
private static List<XenCenterVersion> XenCenterVersions = new List<XenCenterVersion>();
|
||||
|
||||
private static readonly object updateAlertsLock = new object();
|
||||
private static readonly ChangeableList<Alert> updateAlerts = new ChangeableList<Alert>();
|
||||
@ -103,6 +104,36 @@ namespace XenAdmin.Core
|
||||
return updateAlerts.Find(predicate);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// If AutomaticCheck is enabled it checks for updates regardless the
|
||||
/// value of the parameter force. If AutomaticCheck is disabled it only
|
||||
/// checks if force is true.
|
||||
/// </summary>
|
||||
public static void CheckForUpdates(bool force)
|
||||
{
|
||||
if (Helpers.CommonCriteriaCertificationRelease)
|
||||
return;
|
||||
|
||||
if (Properties.Settings.Default.AllowXenCenterUpdates ||
|
||||
Properties.Settings.Default.AllowXenServerUpdates ||
|
||||
Properties.Settings.Default.AllowPatchesUpdates || force)
|
||||
{
|
||||
DownloadUpdatesXmlAction action = new DownloadUpdatesXmlAction(
|
||||
Properties.Settings.Default.AllowXenCenterUpdates || force,
|
||||
Properties.Settings.Default.AllowXenServerUpdates || force,
|
||||
Properties.Settings.Default.AllowPatchesUpdates || force);
|
||||
{
|
||||
action.Completed += actionCompleted;
|
||||
}
|
||||
|
||||
if (CheckForUpdatesStarted != null)
|
||||
CheckForUpdatesStarted();
|
||||
|
||||
action.RunAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private static void actionCompleted(ActionBase sender)
|
||||
{
|
||||
Program.AssertOffEventThread();
|
||||
@ -119,23 +150,29 @@ namespace XenAdmin.Core
|
||||
|
||||
if (succeeded)
|
||||
{
|
||||
XenServerVersions = action.XenServerVersions;
|
||||
XenServerPatches = action.XenServerPatches;
|
||||
lock (downloadedUpdatesLock)
|
||||
{
|
||||
var xcvs = action.XenCenterVersions.Where(v => !XenCenterVersions.Contains(v));
|
||||
XenCenterVersions.AddRange(xcvs);
|
||||
|
||||
var xenCenterAlert = NewXenCenterUpdateAlert(action.XenCenterVersions, Program.Version);
|
||||
var vers = action.XenServerVersions.Where(v => !XenServerVersions.Contains(v));
|
||||
XenServerVersions.AddRange(vers);
|
||||
|
||||
var patches = action.XenServerPatches.Where(p => !XenServerPatches.Contains(p));
|
||||
XenServerPatches.AddRange(patches);
|
||||
}
|
||||
|
||||
var xenCenterAlert = NewXenCenterUpdateAlert(XenCenterVersions, Program.Version);
|
||||
if (xenCenterAlert != null)
|
||||
updateAlerts.Add(xenCenterAlert);
|
||||
|
||||
var xenServerUpdateAlert = NewXenServerVersionAlert(action.XenServerVersions);
|
||||
if (xenServerUpdateAlert != null)
|
||||
var xenServerUpdateAlert = NewXenServerVersionAlert(XenServerVersions);
|
||||
if (xenServerUpdateAlert != null && !xenServerUpdateAlert.CanIgnore)
|
||||
updateAlerts.Add(xenServerUpdateAlert);
|
||||
|
||||
var xenServerPatchAlerts = NewXenServerPatchAlerts(action.XenServerVersions, action.XenServerPatches);
|
||||
var xenServerPatchAlerts = NewXenServerPatchAlerts(XenServerVersions, XenServerPatches);
|
||||
if (xenServerPatchAlerts != null)
|
||||
{
|
||||
foreach (var xenServerPatchAlert in xenServerPatchAlerts)
|
||||
updateAlerts.Add(xenServerPatchAlert);
|
||||
}
|
||||
updateAlerts.AddRange(xenServerPatchAlerts.Where(alert => !alert.CanIgnore));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -162,6 +199,7 @@ namespace XenAdmin.Core
|
||||
CheckForUpdatesCompleted(succeeded, errorMessage);
|
||||
}
|
||||
|
||||
|
||||
public static void RegisterCollectionChanged(CollectionChangeEventHandler handler)
|
||||
{
|
||||
updateAlerts.CollectionChanged += handler;
|
||||
@ -172,56 +210,20 @@ namespace XenAdmin.Core
|
||||
updateAlerts.CollectionChanged -= handler;
|
||||
}
|
||||
|
||||
private static bool AllowUpdates
|
||||
{
|
||||
get
|
||||
{
|
||||
return !Helpers.CommonCriteriaCertificationRelease &&
|
||||
(Properties.Settings.Default.AllowXenCenterUpdates ||
|
||||
Properties.Settings.Default.AllowXenServerUpdates ||
|
||||
Properties.Settings.Default.AllowPatchesUpdates);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If AutomaticCheck is enabled it checks for updates regardless the
|
||||
/// value of the parameter force. If AutomaticCheck is disabled it only
|
||||
/// checks if force is true.
|
||||
/// </summary>
|
||||
public static void CheckForUpdates(bool force)
|
||||
{
|
||||
if (!AllowUpdates && !force)
|
||||
return;
|
||||
|
||||
if (Helpers.CommonCriteriaCertificationRelease)
|
||||
return;
|
||||
|
||||
DownloadUpdatesXmlAction action = new DownloadUpdatesXmlAction();
|
||||
action.Completed += actionCompleted;
|
||||
|
||||
if (CheckForUpdatesStarted != null)
|
||||
CheckForUpdatesStarted();
|
||||
|
||||
action.RunAsync();
|
||||
}
|
||||
|
||||
private static XenCenterVersion GetLatestPublishedXenCenterVersion(List<XenCenterVersion> xenCenterVersions, Version programVersion)
|
||||
{
|
||||
if (xenCenterVersions.Count == 0 || programVersion == new Version(0, 0, 0, 0))
|
||||
return null;
|
||||
|
||||
var latest = from v in xenCenterVersions where v.IsLatest select v;
|
||||
|
||||
return latest.FirstOrDefault(xcv => xcv.Lang == Program.CurrentLanguage) ??
|
||||
latest.FirstOrDefault(xcv => string.IsNullOrEmpty(xcv.Lang));
|
||||
}
|
||||
|
||||
public static XenCenterUpdateAlert NewXenCenterUpdateAlert(List<XenCenterVersion> xenCenterVersions, Version currentProgramVersion)
|
||||
{
|
||||
if (Helpers.CommonCriteriaCertificationRelease)
|
||||
return null;
|
||||
|
||||
XenCenterVersion toUse = GetLatestPublishedXenCenterVersion(xenCenterVersions, currentProgramVersion);
|
||||
XenCenterVersion toUse = null;
|
||||
if (xenCenterVersions.Count != 0 && currentProgramVersion != new Version(0, 0, 0, 0))
|
||||
{
|
||||
var latest = from v in xenCenterVersions where v.IsLatest select v;
|
||||
|
||||
toUse = latest.FirstOrDefault(xcv => xcv.Lang == Program.CurrentLanguage) ??
|
||||
latest.FirstOrDefault(xcv => string.IsNullOrEmpty(xcv.Lang));
|
||||
}
|
||||
|
||||
if (toUse == null)
|
||||
return null;
|
||||
@ -244,26 +246,7 @@ namespace XenAdmin.Core
|
||||
if (Helpers.CommonCriteriaCertificationRelease)
|
||||
return null;
|
||||
|
||||
var alerts = GetServerPatchAlerts(xenServerVersions, xenServerPatches);
|
||||
return alerts.Where(alert => !alert.CanIgnore).ToList();
|
||||
}
|
||||
|
||||
private static XenServerPatchAlert GetServerPatchAlert(List<XenServerPatchAlert> alerts, XenServerPatch patch)
|
||||
{
|
||||
XenServerPatchAlert alert = new XenServerPatchAlert(patch);
|
||||
XenServerPatchAlert existingAlert = alerts.Find(al => al.Equals(alert));
|
||||
if (existingAlert != null)
|
||||
alert = existingAlert;
|
||||
else
|
||||
alerts.Add(alert);
|
||||
|
||||
return alert;
|
||||
}
|
||||
|
||||
private static List<XenServerPatchAlert> GetServerPatchAlerts(List<XenServerVersion> xenServerVersions,
|
||||
List<XenServerPatch> xenServerPatches)
|
||||
{
|
||||
List<XenServerPatchAlert> alerts = new List<XenServerPatchAlert>();
|
||||
var alerts = new List<XenServerPatchAlert>();
|
||||
|
||||
foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy)
|
||||
{
|
||||
@ -273,8 +256,7 @@ namespace XenAdmin.Core
|
||||
if (master == null || pool == null)
|
||||
continue;
|
||||
|
||||
List<XenServerVersion> serverVersions =
|
||||
xenServerVersions.FindAll(version =>
|
||||
var serverVersions = xenServerVersions.FindAll(version =>
|
||||
{
|
||||
if (version.BuildNumber != string.Empty)
|
||||
return (master.BuildNumberRaw == version.BuildNumber);
|
||||
@ -297,7 +279,17 @@ namespace XenAdmin.Core
|
||||
|
||||
foreach (XenServerPatch xenServerPatch in patches)
|
||||
{
|
||||
XenServerPatchAlert alert = GetServerPatchAlert(alerts, xenServerPatch);
|
||||
var alert = new XenServerPatchAlert(xenServerPatch);
|
||||
var existingAlert = alerts.Find(al => al.Equals(alert));
|
||||
|
||||
if (existingAlert != null)
|
||||
alert = existingAlert;
|
||||
else
|
||||
alerts.Add(alert);
|
||||
|
||||
if (!xenConnection.IsConnected)
|
||||
continue;
|
||||
|
||||
XenServerPatch serverPatch = xenServerPatch;
|
||||
var noPatchHosts = hosts.Where(host => !host.AppliedPatches().Any(patch => patch.uuid == serverPatch.Uuid));
|
||||
|
||||
@ -325,6 +317,9 @@ namespace XenAdmin.Core
|
||||
|
||||
foreach (IXenConnection xc in ConnectionsManager.XenConnectionsCopy)
|
||||
{
|
||||
if (!xc.IsConnected)
|
||||
continue;
|
||||
|
||||
Host master = Helpers.GetMaster(xc);
|
||||
Pool pool = Helpers.GetPoolOfOne(xc);
|
||||
List<Host> hosts = xc.Cache.Hosts.ToList();
|
||||
@ -339,49 +334,39 @@ namespace XenAdmin.Core
|
||||
alert.IncludeHosts(outOfDateHosts);
|
||||
}
|
||||
|
||||
if (alert.CanIgnore)
|
||||
return null;
|
||||
|
||||
return alert;
|
||||
}
|
||||
|
||||
|
||||
public static void CheckServerVersion()
|
||||
{
|
||||
if (!AllowUpdates || !Properties.Settings.Default.AllowXenServerUpdates)
|
||||
return;
|
||||
|
||||
var alert = NewXenServerVersionAlert(XenServerVersions);
|
||||
if (alert == null)
|
||||
return;
|
||||
|
||||
CheckUpdate(alert);
|
||||
}
|
||||
|
||||
public static void CheckServerPatches()
|
||||
{
|
||||
var alerts = NewXenServerPatchAlerts(XenServerVersions, XenServerPatches);
|
||||
if (alerts == null)
|
||||
return;
|
||||
|
||||
foreach (var alert in alerts)
|
||||
CheckUpdate(alert);
|
||||
}
|
||||
|
||||
private static void CheckUpdate(XenServerUpdateAlert alert)
|
||||
{
|
||||
var existingAlert = FindUpdate(alert);
|
||||
|
||||
if (existingAlert != null && alert.CanIgnore)
|
||||
RemoveUpdate(existingAlert);
|
||||
else if (existingAlert != null)
|
||||
((XenServerVersionAlert)existingAlert).CopyConnectionsAndHosts(alert);
|
||||
((XenServerUpdateAlert)existingAlert).CopyConnectionsAndHosts(alert);
|
||||
else if (!alert.CanIgnore)
|
||||
AddUpate(alert);
|
||||
}
|
||||
|
||||
public static void CheckServerPatches()
|
||||
{
|
||||
if (!AllowUpdates || !Properties.Settings.Default.AllowPatchesUpdates)
|
||||
return;
|
||||
|
||||
var alerts = GetServerPatchAlerts(XenServerVersions, XenServerPatches);
|
||||
|
||||
foreach (var alert in alerts)
|
||||
{
|
||||
var existingAlert = FindUpdate(alert);
|
||||
|
||||
if (existingAlert != null && alert.CanIgnore)
|
||||
RemoveUpdate(existingAlert);
|
||||
else if (existingAlert != null)
|
||||
((XenServerPatchAlert)existingAlert).CopyConnectionsAndHosts(alert);
|
||||
else if (!alert.CanIgnore)
|
||||
AddUpate(alert);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -781,6 +781,8 @@ namespace XenAdmin
|
||||
IXenConnection connection = (IXenConnection)sender;
|
||||
closeActiveWizards(connection);
|
||||
Alert.RemoveAlert(alert => alert.Connection != null && alert.Connection.Equals(connection));
|
||||
Updates.CheckServerPatches();
|
||||
Updates.CheckServerVersion();
|
||||
}
|
||||
|
||||
void connection_CachePopulated(object sender, EventArgs e)
|
||||
|
@ -49,6 +49,13 @@ namespace XenAdmin.Core
|
||||
OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Add, item));
|
||||
}
|
||||
|
||||
public new void AddRange(IEnumerable<T> collection)
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(collection != null, "Collection cannot be null");
|
||||
base.AddRange(collection);
|
||||
OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Add, collection));
|
||||
}
|
||||
|
||||
public new void Insert(int index, T item)
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(item != null, "Item cannot be null");
|
||||
|
@ -31,13 +31,12 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using XenAPI;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Net;
|
||||
using XenAdmin.Core;
|
||||
|
||||
|
||||
namespace XenAdmin.Actions
|
||||
{
|
||||
public class DownloadUpdatesXmlAction : AsyncAction
|
||||
@ -48,16 +47,23 @@ namespace XenAdmin.Actions
|
||||
private const string PatchesNode = "patches";
|
||||
private const string UpdateXmlUrl = @"http://updates.xensource.com/XenServer/updates.xml";
|
||||
|
||||
public List<XenCenterVersion> XenCenterVersions { get; set; }
|
||||
public List<XenServerVersion> XenServerVersions { get; set; }
|
||||
public List<XenServerPatch> XenServerPatches { get; set; }
|
||||
public List<XenCenterVersion> XenCenterVersions { get; private set; }
|
||||
public List<XenServerVersion> XenServerVersions { get; private set; }
|
||||
public List<XenServerPatch> XenServerPatches { get; private set; }
|
||||
private readonly bool _checkForXenCenter;
|
||||
private readonly bool _checkForServerVersion;
|
||||
private readonly bool _checkForPatches;
|
||||
|
||||
public DownloadUpdatesXmlAction()
|
||||
public DownloadUpdatesXmlAction(bool checkForXenCenter, bool checkForServerVersion, bool checkForPatches)
|
||||
: base(null, "_get_updates", "_get_updates", true)
|
||||
{
|
||||
XenServerPatches = new List<XenServerPatch>();
|
||||
XenServerVersions = new List<XenServerVersion>();
|
||||
XenCenterVersions = new List<XenCenterVersion>();
|
||||
|
||||
_checkForXenCenter = checkForXenCenter;
|
||||
_checkForServerVersion = checkForServerVersion;
|
||||
_checkForPatches = checkForPatches;
|
||||
}
|
||||
|
||||
protected override void Run()
|
||||
@ -66,7 +72,16 @@ namespace XenAdmin.Actions
|
||||
|
||||
XmlDocument xdoc = FetchCheckForUpdatesXml(UpdateXmlUrl);
|
||||
|
||||
// XenCenter Versions
|
||||
GetXenCenterVersions(xdoc);
|
||||
GetXenServerPatches(xdoc);
|
||||
GetXenServerVersions(xdoc);
|
||||
}
|
||||
|
||||
private void GetXenCenterVersions(XmlDocument xdoc)
|
||||
{
|
||||
if (!_checkForXenCenter)
|
||||
return;
|
||||
|
||||
foreach (XmlNode versions in xdoc.GetElementsByTagName(XenCenterVersionsNode))
|
||||
{
|
||||
foreach (XmlNode version in versions.ChildNodes)
|
||||
@ -94,8 +109,13 @@ namespace XenAdmin.Actions
|
||||
XenCenterVersions.Add(new XenCenterVersion(version_lang, name, is_latest, url, timestamp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GetXenServerPatches(XmlDocument xdoc)
|
||||
{
|
||||
if (!_checkForPatches)
|
||||
return;
|
||||
|
||||
// Patches
|
||||
foreach (XmlNode versions in xdoc.GetElementsByTagName(PatchesNode))
|
||||
{
|
||||
foreach (XmlNode version in versions.ChildNodes)
|
||||
@ -136,8 +156,13 @@ namespace XenAdmin.Actions
|
||||
patchUrl, timestamp, priority));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GetXenServerVersions(XmlDocument xdoc)
|
||||
{
|
||||
if (!_checkForServerVersion)
|
||||
return;
|
||||
|
||||
// XenServer Versions
|
||||
foreach (XmlNode versions in xdoc.GetElementsByTagName(XenServerVersionsNode))
|
||||
{
|
||||
foreach (XmlNode version in versions.ChildNodes)
|
||||
@ -171,7 +196,7 @@ namespace XenAdmin.Actions
|
||||
{
|
||||
if (childnode.Name != "patch")
|
||||
continue;
|
||||
XenServerPatch patch = XenServerPatches.Find(new Predicate<XenServerPatch>(delegate(XenServerPatch item) { return item.Uuid == childnode.Attributes["uuid"].Value; }));
|
||||
XenServerPatch patch = XenServerPatches.Find(item => item.Uuid == childnode.Attributes["uuid"].Value);
|
||||
if (patch == null)
|
||||
continue;
|
||||
patches.Add(patch);
|
||||
|
Loading…
Reference in New Issue
Block a user