2016-03-14 17:10:16 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems Inc.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using log4net;
|
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Diagnostics.Problems;
|
|
|
|
|
using XenAdmin.Dialogs;
|
|
|
|
|
using XenAdmin.Wizards.PatchingWizard.PlanActions;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
using XenAdmin.Actions;
|
2016-03-24 19:24:12 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Network;
|
2016-05-11 15:02:40 +02:00
|
|
|
|
using System.Text;
|
2016-11-16 13:26:26 +01:00
|
|
|
|
using System.Diagnostics;
|
2016-03-14 17:10:16 +01:00
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.PatchingWizard
|
|
|
|
|
{
|
|
|
|
|
public partial class PatchingWizard_AutoUpdatingPage : XenTabPage
|
|
|
|
|
{
|
|
|
|
|
protected static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2016-03-24 19:24:12 +01:00
|
|
|
|
public XenAdmin.Core.Updates.UpgradeSequence UpgradeSequences { get; set; }
|
2016-06-17 15:15:59 +02:00
|
|
|
|
private bool _thisPageIsCompleted = false;
|
2016-03-31 16:40:23 +02:00
|
|
|
|
|
|
|
|
|
public List<Problem> ProblemsResolvedPreCheck { private get; set; }
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-07-01 18:41:49 +02:00
|
|
|
|
public List<Pool> SelectedPools { private get; set; }
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
|
|
|
|
private List<PoolPatchMapping> patchMappings = new List<PoolPatchMapping>();
|
2016-06-17 15:15:59 +02:00
|
|
|
|
public Dictionary<XenServerPatch, string> AllDownloadedPatches = new Dictionary<XenServerPatch, string>();
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-06-17 15:15:59 +02:00
|
|
|
|
private List<UpdateProgressBackgroundWorker> backgroundWorkers = new List<UpdateProgressBackgroundWorker>();
|
2016-05-11 15:02:40 +02:00
|
|
|
|
|
2016-03-14 17:10:16 +01:00
|
|
|
|
public PatchingWizard_AutoUpdatingPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Text
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-03-16 14:22:23 +01:00
|
|
|
|
return Messages.PATCHINGWIZARD_AUTOUPDATINGPAGE_TEXT;
|
2016-03-14 17:10:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string PageTitle
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-03-16 14:22:23 +01:00
|
|
|
|
return Messages.PATCHINGWIZARD_AUTOUPDATINGPAGE_TITLE;
|
2016-03-14 17:10:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string HelpID
|
|
|
|
|
{
|
|
|
|
|
get { return ""; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool EnablePrevious()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _nextEnabled;
|
|
|
|
|
public override bool EnableNext()
|
|
|
|
|
{
|
|
|
|
|
return _nextEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _cancelEnabled;
|
|
|
|
|
public override bool EnableCancel()
|
|
|
|
|
{
|
|
|
|
|
return _cancelEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-17 15:15:59 +02:00
|
|
|
|
public override void PageCancelled()
|
|
|
|
|
{
|
|
|
|
|
if (!_thisPageIsCompleted)
|
|
|
|
|
{
|
|
|
|
|
backgroundWorkers.ForEach(bgw => bgw.CancelAsync());
|
|
|
|
|
backgroundWorkers.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.PageCancelled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
|
|
|
|
|
{
|
|
|
|
|
base.PageLeave(direction, ref cancel);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 17:10:16 +01:00
|
|
|
|
public override void PageLoaded(PageLoadedDirection direction)
|
|
|
|
|
{
|
|
|
|
|
base.PageLoaded(direction);
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-06-17 15:15:59 +02:00
|
|
|
|
if (_thisPageIsCompleted)
|
|
|
|
|
{
|
2016-03-31 16:40:23 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-07-01 18:41:49 +02:00
|
|
|
|
foreach (var pool in SelectedPools)
|
2016-03-24 19:24:12 +01:00
|
|
|
|
{
|
2016-07-01 18:41:49 +02:00
|
|
|
|
var master = Helpers.GetMaster(pool.Connection);
|
|
|
|
|
|
2016-07-05 15:35:31 +02:00
|
|
|
|
var planActions = new List<PlanAction>();
|
|
|
|
|
var delayedActionsByHost = new Dictionary<Host, List<PlanAction>>();
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-07-01 18:41:49 +02:00
|
|
|
|
foreach (var host in pool.Connection.Cache.Hosts)
|
2016-03-31 16:40:23 +02:00
|
|
|
|
{
|
2016-04-28 16:56:45 +02:00
|
|
|
|
delayedActionsByHost.Add(host, new List<PlanAction>());
|
2016-03-31 16:40:23 +02:00
|
|
|
|
}
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-07-01 18:41:49 +02:00
|
|
|
|
var hosts = pool.Connection.Cache.Hosts;
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-07-01 18:41:49 +02:00
|
|
|
|
var us = Updates.GetUpgradeSequence(pool.Connection);
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-11-16 13:26:26 +01:00
|
|
|
|
Debug.Assert(us != null, "Update sequence should not be null.");
|
|
|
|
|
|
|
|
|
|
if (us != null)
|
2016-03-24 19:24:12 +01:00
|
|
|
|
{
|
2016-11-16 13:26:26 +01:00
|
|
|
|
foreach (var patch in us.UniquePatches)
|
|
|
|
|
{
|
|
|
|
|
var hostsToApply = us.Where(u => u.Value.Contains(patch)).Select(u => u.Key).ToList();
|
|
|
|
|
hostsToApply.Sort();
|
2016-04-28 16:56:45 +02:00
|
|
|
|
|
2016-11-16 13:26:26 +01:00
|
|
|
|
planActions.Add(new DownloadPatchPlanAction(master.Connection, patch, AllDownloadedPatches));
|
|
|
|
|
planActions.Add(new UploadPatchToMasterPlanAction(master.Connection, patch, patchMappings, AllDownloadedPatches));
|
|
|
|
|
planActions.Add(new PatchPrechecksOnMultipleHostsInAPoolPlanAction(master.Connection, patch, hostsToApply, patchMappings));
|
2016-04-28 16:56:45 +02:00
|
|
|
|
|
2016-11-16 13:26:26 +01:00
|
|
|
|
foreach (var host in hostsToApply)
|
|
|
|
|
{
|
|
|
|
|
planActions.Add(new ApplyXenServerPatchPlanAction(host, patch, patchMappings));
|
|
|
|
|
planActions.AddRange(GetMandatoryActionListForPatch(delayedActionsByHost[host], host, patch));
|
|
|
|
|
UpdateDelayedAfterPatchGuidanceActionListForHost(delayedActionsByHost[host], host, patch);
|
|
|
|
|
}
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-11-16 13:26:26 +01:00
|
|
|
|
//clean up master at the end:
|
|
|
|
|
planActions.Add(new RemoveUpdateFileFromMasterPlanAction(master, patchMappings, patch));
|
2016-04-28 16:56:45 +02:00
|
|
|
|
|
2016-11-16 13:26:26 +01:00
|
|
|
|
}//patch
|
|
|
|
|
}
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-03-31 16:40:23 +02:00
|
|
|
|
//add all delayed actions to the end of the actions, per host
|
2016-07-05 15:35:31 +02:00
|
|
|
|
var delayedActions = new List<PlanAction>();
|
|
|
|
|
if (delayedActionsByHost.ContainsKey(master))
|
|
|
|
|
{
|
|
|
|
|
delayedActions.AddRange(delayedActionsByHost[master]);
|
|
|
|
|
}
|
2016-04-28 16:56:45 +02:00
|
|
|
|
foreach (var kvp in delayedActionsByHost)
|
2016-03-31 16:40:23 +02:00
|
|
|
|
{
|
2016-07-05 15:35:31 +02:00
|
|
|
|
if (kvp.Key != master)
|
|
|
|
|
{
|
|
|
|
|
delayedActions.AddRange(kvp.Value);
|
|
|
|
|
}
|
2016-03-31 16:40:23 +02:00
|
|
|
|
}
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-07-05 15:35:31 +02:00
|
|
|
|
if (planActions.Count > 0)
|
2016-05-18 14:43:34 +02:00
|
|
|
|
{
|
2016-07-05 15:35:31 +02:00
|
|
|
|
var bgw = new UpdateProgressBackgroundWorker(master, planActions, delayedActions);
|
2016-05-18 14:43:34 +02:00
|
|
|
|
backgroundWorkers.Add(bgw);
|
2016-05-11 15:02:40 +02:00
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
}
|
2016-03-31 16:40:23 +02:00
|
|
|
|
} //foreach in SelectedMasters
|
2016-04-28 16:56:45 +02:00
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
foreach (var bgw in backgroundWorkers)
|
2016-03-31 16:40:23 +02:00
|
|
|
|
{
|
2016-05-18 14:43:34 +02:00
|
|
|
|
bgw.DoWork += new DoWorkEventHandler(WorkerDoWork);
|
2016-05-11 15:02:40 +02:00
|
|
|
|
bgw.WorkerReportsProgress = true;
|
2016-05-18 14:43:34 +02:00
|
|
|
|
bgw.ProgressChanged += new ProgressChangedEventHandler(WorkerProgressChanged);
|
|
|
|
|
bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted);
|
2016-05-11 15:02:40 +02:00
|
|
|
|
bgw.WorkerSupportsCancellation = true;
|
2016-05-18 14:43:34 +02:00
|
|
|
|
bgw.RunWorkerAsync();
|
2016-03-31 16:40:23 +02:00
|
|
|
|
}
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
if (backgroundWorkers.Count == 0)
|
|
|
|
|
{
|
2016-06-17 15:15:59 +02:00
|
|
|
|
_thisPageIsCompleted = true;
|
2016-05-18 14:43:34 +02:00
|
|
|
|
_nextEnabled = true;
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
OnPageUpdated();
|
|
|
|
|
}
|
2016-03-31 16:40:23 +02:00
|
|
|
|
}
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
|
|
|
|
#region automatic_mode
|
|
|
|
|
|
2016-05-11 15:02:40 +02:00
|
|
|
|
private List<PlanAction> doneActions = new List<PlanAction>();
|
|
|
|
|
private List<PlanAction> inProgressActions = new List<PlanAction>();
|
2016-05-18 14:43:34 +02:00
|
|
|
|
private List<PlanAction> errorActions = new List<PlanAction>();
|
2016-05-11 15:02:40 +02:00
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
private void WorkerProgressChanged(object sender, ProgressChangedEventArgs e)
|
2016-03-24 19:24:12 +01:00
|
|
|
|
{
|
2016-05-11 15:02:40 +02:00
|
|
|
|
var actionsWorker = sender as BackgroundWorker;
|
|
|
|
|
|
2016-06-03 16:08:30 +02:00
|
|
|
|
Program.Invoke(Program.MainWindow, () =>
|
2016-03-24 19:24:12 +01:00
|
|
|
|
{
|
2016-06-03 16:08:30 +02:00
|
|
|
|
if (!actionsWorker.CancellationPending)
|
|
|
|
|
{
|
|
|
|
|
PlanAction action = (PlanAction)e.UserState;
|
2016-06-17 15:15:59 +02:00
|
|
|
|
if (action != null)
|
2016-06-03 16:08:30 +02:00
|
|
|
|
{
|
2016-06-17 15:15:59 +02:00
|
|
|
|
if (e.ProgressPercentage == 0)
|
|
|
|
|
{
|
|
|
|
|
inProgressActions.Add(action);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
doneActions.Add(action);
|
|
|
|
|
inProgressActions.Remove(action);
|
|
|
|
|
|
|
|
|
|
progressBar.Value += (int)((float)e.ProgressPercentage / (float)backgroundWorkers.Count); //extend with error handling related numbers
|
|
|
|
|
}
|
2016-06-03 16:08:30 +02:00
|
|
|
|
}
|
2016-05-11 15:02:40 +02:00
|
|
|
|
|
2016-06-03 16:08:30 +02:00
|
|
|
|
UpdateStatusTextBox();
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-05-18 14:43:34 +02:00
|
|
|
|
}
|
2016-05-11 15:02:40 +02:00
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
private void UpdateStatusTextBox()
|
|
|
|
|
{
|
|
|
|
|
var sb = new StringBuilder();
|
2016-05-11 15:02:40 +02:00
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
foreach (var pa in doneActions)
|
|
|
|
|
{
|
2016-06-17 15:15:59 +02:00
|
|
|
|
if (pa.Visible)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(pa);
|
|
|
|
|
sb.AppendLine(Messages.DONE);
|
|
|
|
|
}
|
2016-05-18 14:43:34 +02:00
|
|
|
|
}
|
2016-05-11 15:02:40 +02:00
|
|
|
|
|
2016-06-03 16:08:30 +02:00
|
|
|
|
foreach (var pa in errorActions)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(pa);
|
|
|
|
|
sb.AppendLine(Messages.ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
foreach (var pa in inProgressActions)
|
|
|
|
|
{
|
2016-06-17 15:15:59 +02:00
|
|
|
|
if (pa.Visible)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(pa);
|
2016-06-22 12:07:12 +02:00
|
|
|
|
sb.AppendLine();
|
2016-06-17 15:15:59 +02:00
|
|
|
|
}
|
2016-03-24 19:24:12 +01:00
|
|
|
|
}
|
2016-05-18 14:43:34 +02:00
|
|
|
|
|
|
|
|
|
textBoxLog.Text = sb.ToString();
|
2016-07-01 18:41:49 +02:00
|
|
|
|
|
|
|
|
|
textBoxLog.SelectionStart = textBoxLog.Text.Length;
|
|
|
|
|
textBoxLog.ScrollToCaret();
|
2016-03-24 19:24:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
private void WorkerDoWork(object sender, DoWorkEventArgs doWorkEventArgs)
|
2016-03-24 19:24:12 +01:00
|
|
|
|
{
|
2016-05-18 14:43:34 +02:00
|
|
|
|
var bgw = sender as UpdateProgressBackgroundWorker;
|
2016-05-11 15:02:40 +02:00
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
foreach (PlanAction action in bgw.AllActions)
|
2016-03-24 19:24:12 +01:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-05-18 14:43:34 +02:00
|
|
|
|
if (bgw.CancellationPending)
|
2016-03-24 19:24:12 +01:00
|
|
|
|
{
|
|
|
|
|
doWorkEventArgs.Cancel = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-08-26 16:22:03 +02:00
|
|
|
|
|
|
|
|
|
InitializePlanAction(bgw, action);
|
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
bgw.ReportProgress(0, action);
|
2016-03-24 19:24:12 +01:00
|
|
|
|
action.Run();
|
2016-08-26 17:41:12 +02:00
|
|
|
|
|
2016-03-24 19:24:12 +01:00
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
bgw.doneActions.Add(action);
|
|
|
|
|
bgw.ReportProgress((int)((1.0 / (double)bgw.AllActions.Count) * 100), action);
|
2016-03-24 19:24:12 +01:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2016-05-18 14:43:34 +02:00
|
|
|
|
bgw.FailedWithExceptionAction = action;
|
|
|
|
|
errorActions.Add(action);
|
2016-06-03 16:08:30 +02:00
|
|
|
|
inProgressActions.Remove(action);
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
|
|
|
|
log.Error("Failed to carry out plan.", e);
|
2016-06-03 16:08:30 +02:00
|
|
|
|
log.Debug(action.Title);
|
|
|
|
|
|
2016-03-24 19:24:12 +01:00
|
|
|
|
doWorkEventArgs.Result = new Exception(action.Title, e);
|
2016-06-03 16:08:30 +02:00
|
|
|
|
|
2016-11-22 16:42:15 +01:00
|
|
|
|
//this pool failed, we will stop here, but try to remove update files at least
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var positionOfFailedAction = bgw.AllActions.IndexOf(action);
|
|
|
|
|
if (positionOfFailedAction < bgw.AllActions.Count && !(action is DownloadPatchPlanAction || action is UploadPatchToMasterPlanAction))
|
|
|
|
|
{
|
|
|
|
|
int pos = positionOfFailedAction;
|
|
|
|
|
|
|
|
|
|
if (!(bgw.AllActions[pos] is RemoveUpdateFileFromMasterPlanAction)) //can't do anything if the remove action has failed
|
|
|
|
|
{
|
|
|
|
|
while (++pos < bgw.AllActions.Count)
|
|
|
|
|
{
|
|
|
|
|
if (bgw.AllActions[pos] is RemoveUpdateFileFromMasterPlanAction) //find the next remove
|
|
|
|
|
{
|
|
|
|
|
bgw.AllActions[pos].Run();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
//already in an error case - best effort
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-03 16:08:30 +02:00
|
|
|
|
bgw.ReportProgress(0);
|
2016-03-24 19:24:12 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 16:22:03 +02:00
|
|
|
|
private static void InitializePlanAction(UpdateProgressBackgroundWorker bgw, PlanAction action)
|
|
|
|
|
{
|
|
|
|
|
if (action is IAvoidRestartHostsAware)
|
|
|
|
|
{
|
|
|
|
|
var avoidRestartAction = action as IAvoidRestartHostsAware;
|
|
|
|
|
avoidRestartAction.AvoidRestartHosts = bgw.AvoidRestartHosts;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
2016-03-24 19:24:12 +01:00
|
|
|
|
{
|
2016-05-18 14:43:34 +02:00
|
|
|
|
var bgw = (UpdateProgressBackgroundWorker)sender;
|
|
|
|
|
|
2016-06-03 16:08:30 +02:00
|
|
|
|
Program.Invoke(Program.MainWindow, () =>
|
2016-03-24 19:24:12 +01:00
|
|
|
|
{
|
2016-06-03 16:08:30 +02:00
|
|
|
|
if (!e.Cancelled)
|
|
|
|
|
{
|
|
|
|
|
Exception exception = e.Result as Exception;
|
|
|
|
|
if (exception != null)
|
|
|
|
|
{
|
|
|
|
|
//not showing exceptions in the meantime
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if all finished
|
|
|
|
|
if (backgroundWorkers.All(w => !w.IsBusy))
|
|
|
|
|
{
|
|
|
|
|
AllWorkersFinished();
|
|
|
|
|
ShowErrors();
|
|
|
|
|
|
2016-06-17 15:15:59 +02:00
|
|
|
|
_thisPageIsCompleted = true;
|
2016-07-19 10:25:17 +02:00
|
|
|
|
|
|
|
|
|
_cancelEnabled = false;
|
|
|
|
|
_nextEnabled = true;
|
2016-06-03 16:08:30 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
OnPageUpdated();
|
2016-03-24 19:24:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-28 16:56:45 +02:00
|
|
|
|
private void UpdateDelayedAfterPatchGuidanceActionListForHost(List<PlanAction> delayedGuidances, Host host, XenServerPatch patch)
|
2016-03-24 19:24:12 +01:00
|
|
|
|
{
|
2016-05-04 14:44:26 +02:00
|
|
|
|
List<PlanAction> actions = GetAfterApplyGuidanceActionsForPatch(host, patch);
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-07-05 15:35:31 +02:00
|
|
|
|
//if this is a restart, clean delayed list
|
|
|
|
|
if (patch.after_apply_guidance == after_apply_guidance.restartHost)
|
|
|
|
|
delayedGuidances.Clear();
|
|
|
|
|
|
2016-04-28 16:56:45 +02:00
|
|
|
|
if (!patch.GuidanceMandatory)
|
|
|
|
|
{
|
|
|
|
|
//not mandatory, so these actions will have to be run later
|
|
|
|
|
//add the ones that are not yet there
|
|
|
|
|
foreach (var ap in actions)
|
|
|
|
|
if (!delayedGuidances.Any(da => da.GetType() == ap.GetType()))
|
|
|
|
|
{
|
|
|
|
|
//special rules
|
|
|
|
|
//do not add restartXAPI if there is already a restartHost on the list
|
|
|
|
|
if (delayedGuidances.Any(da => da is RebootHostPlanAction) && ap is RestartAgentPlanAction)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
delayedGuidances.Add(ap);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//remove delayed action of the same kind for this host (because it is mandatory and will run immediately)
|
2016-07-05 15:35:31 +02:00
|
|
|
|
delayedGuidances.RemoveAll(dg => actions.Any(ma => ma.GetType() == dg.GetType()));
|
2016-04-28 16:56:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-04 14:44:26 +02:00
|
|
|
|
private static List<PlanAction> GetAfterApplyGuidanceActionsForPatch(Host host, XenServerPatch patch)
|
2016-04-28 16:56:45 +02:00
|
|
|
|
{
|
2016-05-04 14:44:26 +02:00
|
|
|
|
List<PlanAction> actions = new List<PlanAction>();
|
2016-04-28 16:56:45 +02:00
|
|
|
|
|
|
|
|
|
List<XenRef<VM>> runningVMs = RunningVMs(host);
|
|
|
|
|
|
2016-05-04 14:44:26 +02:00
|
|
|
|
if (patch.after_apply_guidance == after_apply_guidance.restartHost)
|
2016-04-28 16:56:45 +02:00
|
|
|
|
{
|
|
|
|
|
actions.Add(new EvacuateHostPlanAction(host));
|
|
|
|
|
actions.Add(new RebootHostPlanAction(host));
|
|
|
|
|
actions.Add(new BringBabiesBackAction(runningVMs, host, false));
|
|
|
|
|
}
|
2016-05-04 14:44:26 +02:00
|
|
|
|
|
|
|
|
|
if (patch.after_apply_guidance == after_apply_guidance.restartXAPI)
|
2016-04-28 16:56:45 +02:00
|
|
|
|
{
|
|
|
|
|
actions.Add(new RestartAgentPlanAction(host));
|
2016-05-04 14:44:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (patch.after_apply_guidance == after_apply_guidance.restartHVM)
|
2016-04-28 16:56:45 +02:00
|
|
|
|
{
|
|
|
|
|
actions.Add(new RebootVMsPlanAction(host, RunningHvmVMs(host)));
|
|
|
|
|
}
|
2016-05-04 14:44:26 +02:00
|
|
|
|
|
|
|
|
|
if (patch.after_apply_guidance == after_apply_guidance.restartPV)
|
2016-04-28 16:56:45 +02:00
|
|
|
|
{
|
|
|
|
|
actions.Add(new RebootVMsPlanAction(host, RunningPvVMs(host)));
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-24 19:24:12 +01:00
|
|
|
|
return actions;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-04 14:44:26 +02:00
|
|
|
|
private List<PlanAction> GetMandatoryActionListForPatch(List<PlanAction> delayedGuidances, Host host, XenServerPatch patch)
|
2016-03-24 19:24:12 +01:00
|
|
|
|
{
|
2016-05-04 14:44:26 +02:00
|
|
|
|
var actions = new List<PlanAction>();
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-05-04 14:44:26 +02:00
|
|
|
|
if (!patch.GuidanceMandatory)
|
|
|
|
|
return actions;
|
|
|
|
|
|
|
|
|
|
actions = GetAfterApplyGuidanceActionsForPatch(host, patch);
|
|
|
|
|
|
|
|
|
|
return actions;
|
2016-03-24 19:24:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<XenRef<VM>> RunningHvmVMs(Host host)
|
|
|
|
|
{
|
|
|
|
|
List<XenRef<VM>> vms = new List<XenRef<VM>>();
|
|
|
|
|
foreach (VM vm in host.Connection.ResolveAll(host.resident_VMs))
|
|
|
|
|
{
|
|
|
|
|
if (!vm.IsHVM || !vm.is_a_real_vm)
|
|
|
|
|
continue;
|
|
|
|
|
vms.Add(new XenRef<VM>(vm.opaque_ref));
|
|
|
|
|
}
|
|
|
|
|
return vms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<XenRef<VM>> RunningPvVMs(Host host)
|
|
|
|
|
{
|
|
|
|
|
List<XenRef<VM>> vms = new List<XenRef<VM>>();
|
|
|
|
|
foreach (VM vm in host.Connection.ResolveAll(host.resident_VMs))
|
|
|
|
|
{
|
|
|
|
|
if (vm.IsHVM || !vm.is_a_real_vm)
|
|
|
|
|
continue;
|
|
|
|
|
vms.Add(new XenRef<VM>(vm.opaque_ref));
|
|
|
|
|
}
|
|
|
|
|
return vms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<XenRef<VM>> RunningVMs(Host host)
|
|
|
|
|
{
|
|
|
|
|
List<XenRef<VM>> vms = new List<XenRef<VM>>();
|
|
|
|
|
foreach (VM vm in host.Connection.ResolveAll(host.resident_VMs))
|
|
|
|
|
{
|
|
|
|
|
if (!vm.is_a_real_vm)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
vms.Add(new XenRef<VM>(vm.opaque_ref));
|
|
|
|
|
}
|
|
|
|
|
return vms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
private void ShowErrors()
|
2016-03-24 19:24:12 +01:00
|
|
|
|
{
|
2016-05-18 14:43:34 +02:00
|
|
|
|
if (ErrorMessages != null)
|
|
|
|
|
{
|
|
|
|
|
labelTitle.Text = Messages.PATCHINGWIZARD_AUTOUPDATINGPAGE_FAILED;
|
|
|
|
|
labelError.Text = Messages.PATCHINGWIZARD_AUTOUPDATINGPAGE_ERROR;
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
textBoxLog.Text += ErrorMessages;
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
log.ErrorFormat("Error message displayed: {0}", labelError.Text);
|
|
|
|
|
pictureBox1.Image = SystemIcons.Error.ToBitmap();
|
|
|
|
|
panel1.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string ErrorMessages
|
|
|
|
|
{
|
|
|
|
|
get
|
2016-03-24 19:24:12 +01:00
|
|
|
|
{
|
2016-05-18 14:43:34 +02:00
|
|
|
|
if (errorActions.Count == 0)
|
|
|
|
|
return null;
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
var sb = new StringBuilder();
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-06-03 16:08:30 +02:00
|
|
|
|
sb.AppendLine();
|
2016-06-22 15:43:22 +02:00
|
|
|
|
sb.AppendLine(errorActions.Count > 1 ? Messages.PATCHINGWIZARD_AUTOUPDATINGPAGE_ERRORS_OCCURRED : Messages.PATCHINGWIZARD_AUTOUPDATINGPAGE_ERROR_OCCURRED);
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
foreach (var action in errorActions)
|
|
|
|
|
{
|
|
|
|
|
var exception = action.Error;
|
|
|
|
|
if (exception == null)
|
|
|
|
|
{
|
|
|
|
|
log.ErrorFormat("An action has failed with an empty exception. Action: {0}", action.ToString());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2016-08-03 18:15:57 +02:00
|
|
|
|
log.Error(exception);
|
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
if (exception != null && exception.InnerException != null && exception.InnerException is Failure)
|
|
|
|
|
{
|
|
|
|
|
var innerEx = exception.InnerException as Failure;
|
2016-08-03 18:15:57 +02:00
|
|
|
|
log.Error(innerEx);
|
2016-05-18 14:43:34 +02:00
|
|
|
|
|
2016-08-03 18:15:57 +02:00
|
|
|
|
sb.AppendLine(innerEx.Message);
|
2016-05-18 14:43:34 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-08-03 18:15:57 +02:00
|
|
|
|
sb.AppendLine(exception.Message);
|
2016-05-18 14:43:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
2016-03-24 19:24:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-18 14:43:34 +02:00
|
|
|
|
private void AllWorkersFinished()
|
2016-03-24 19:24:12 +01:00
|
|
|
|
{
|
2016-03-31 16:40:23 +02:00
|
|
|
|
labelTitle.Text = Messages.PATCHINGWIZARD_UPDATES_DONE_AUTOMATIC_MODE;
|
2016-06-03 16:08:30 +02:00
|
|
|
|
progressBar.Value = 100;
|
2016-03-24 19:24:12 +01:00
|
|
|
|
pictureBox1.Image = null;
|
|
|
|
|
labelError.Text = Messages.CLOSE_WIZARD_CLICK_FINISH;
|
|
|
|
|
}
|
2016-03-14 17:10:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-31 16:40:23 +02:00
|
|
|
|
|