2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
*
|
|
|
|
|
* 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.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Diagnostics.Checks;
|
|
|
|
|
using XenAdmin.Diagnostics.Checks.DR;
|
|
|
|
|
using XenAdmin.Diagnostics.Problems;
|
|
|
|
|
using XenAdmin.Dialogs;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
|
|
|
|
using XenAdmin.Actions.DR;
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.DRWizards
|
|
|
|
|
{
|
|
|
|
|
public partial class DRFailoverWizardPrecheckPage : XenTabPage
|
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2022-03-09 00:10:13 +01:00
|
|
|
|
private readonly BackgroundWorker _worker;
|
|
|
|
|
private int _numberChecks;
|
|
|
|
|
private readonly object _lock = new object();
|
|
|
|
|
private bool _enableNext;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public event Action<string> NewDrTaskIntroduced;
|
|
|
|
|
public event Action<XenRef<SR>> SrIntroduced;
|
|
|
|
|
|
|
|
|
|
private Pool _pool;
|
|
|
|
|
public Pool Pool { set { _pool = value; } }
|
|
|
|
|
|
|
|
|
|
private Dictionary<XenRef<VDI>, PoolMetadata> selectedPoolMetadata;
|
|
|
|
|
public Dictionary<XenRef<VDI>, PoolMetadata> SelectedPoolMetadata {set { selectedPoolMetadata = value; }}
|
|
|
|
|
|
|
|
|
|
public List<AsyncAction> RevertActions = new List<AsyncAction>();
|
|
|
|
|
|
|
|
|
|
private string _nextButtonText = Messages.WIZARD_BUTTON_NEXT;
|
|
|
|
|
|
|
|
|
|
public override string NextText(bool isLastPage)
|
|
|
|
|
{
|
|
|
|
|
return _nextButtonText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DRFailoverWizardPrecheckPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
dataGridView1.BackgroundColor = dataGridView1.DefaultCellStyle.BackColor;
|
2022-03-09 00:10:13 +01:00
|
|
|
|
|
|
|
|
|
_worker = new BackgroundWorker
|
|
|
|
|
{
|
|
|
|
|
WorkerReportsProgress = true,
|
|
|
|
|
WorkerSupportsCancellation = true
|
|
|
|
|
};
|
|
|
|
|
_worker.DoWork += worker_DoWork;
|
|
|
|
|
_worker.ProgressChanged += worker_ProgressChanged;
|
|
|
|
|
_worker.RunWorkerCompleted += _worker_RunWorkerCompleted;
|
|
|
|
|
|
|
|
|
|
panelErrorsFound.Visible = false;
|
|
|
|
|
labelPrecheckStatus.Visible = false;
|
|
|
|
|
checkBoxHideSuccessful.Checked = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string PageTitle
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
switch (WizardType)
|
|
|
|
|
{
|
|
|
|
|
case DRWizardType.Failback:
|
|
|
|
|
return Messages.DR_WIZARD_PRECHECKPAGE_TITLE_FAILBACK;
|
|
|
|
|
default:
|
|
|
|
|
return Messages.DR_WIZARD_PRECHECKPAGE_TITLE_FAILOVER;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 00:10:13 +01:00
|
|
|
|
public override string Text => Messages.DR_WIZARD_PRECHECKPAGE_TEXT;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public override string HelpID
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
switch (WizardType)
|
|
|
|
|
{
|
|
|
|
|
case DRWizardType.Failback:
|
|
|
|
|
return "Failback_Prechecks";
|
|
|
|
|
case DRWizardType.Dryrun:
|
|
|
|
|
return "Dryrun_Prechecks";
|
|
|
|
|
default:
|
|
|
|
|
return "Failover_Prechecks";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool EnablePrevious()
|
|
|
|
|
{
|
|
|
|
|
return _worker != null && !_worker.IsBusy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int PercentageSelectedObjects(int i)
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
foreach (var poolMetadata in selectedPoolMetadata.Values)
|
|
|
|
|
{
|
|
|
|
|
count += (poolMetadata.VmAppliances.Count + poolMetadata.Vms.Count);
|
|
|
|
|
}
|
|
|
|
|
return (int)(((float)i / (float)(count)) * 100);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-09 01:31:46 +01:00
|
|
|
|
protected override void PageLoadedCore(PageLoadedDirection direction)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
SetupLabels();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (direction == PageLoadedDirection.Back)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
RefreshRechecks();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.Error(e, e);
|
|
|
|
|
throw;//better throw an exception rather than closing the wizard suddenly and silently
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DRWizardType WizardType { private get; set; }
|
|
|
|
|
|
|
|
|
|
private void SetupLabels()
|
|
|
|
|
{
|
|
|
|
|
switch (WizardType)
|
|
|
|
|
{
|
|
|
|
|
case DRWizardType.Failback:
|
|
|
|
|
labelContinue.Text = Messages.DR_WIZARD_PRECHECKPAGE_CONTINUE_FAILBACK;
|
|
|
|
|
_nextButtonText = Messages.DR_WIZARD_PRECHECKPAGE_NEXT_FAILBACK;
|
|
|
|
|
break;
|
|
|
|
|
case DRWizardType.Dryrun:
|
|
|
|
|
labelContinue.Text = Messages.DR_WIZARD_PRECHECKPAGE_CONTINUE_DRYRUN;
|
|
|
|
|
_nextButtonText = Messages.DR_WIZARD_PRECHECKPAGE_NEXT_FAILOVER;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
labelContinue.Text = Messages.DR_WIZARD_PRECHECKPAGE_CONTINUE_FAILOVER;
|
|
|
|
|
_nextButtonText = Messages.DR_WIZARD_PRECHECKPAGE_NEXT_FAILOVER;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 00:10:13 +01:00
|
|
|
|
private void RefreshRechecks()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
buttonResolveAll.Enabled = buttonReCheckProblems.Enabled = false;
|
2022-03-09 00:10:13 +01:00
|
|
|
|
panelErrorsFound.Visible = false;
|
|
|
|
|
labelPrecheckStatus.Visible = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
_worker.RunWorkerAsync();
|
2022-03-09 00:10:13 +01:00
|
|
|
|
OnPageUpdated();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 00:10:13 +01:00
|
|
|
|
private void _worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2022-03-09 00:10:13 +01:00
|
|
|
|
if (e.Cancelled)
|
|
|
|
|
{
|
2013-06-24 13:41:48 +02:00
|
|
|
|
OnPageUpdated();
|
2022-03-09 00:10:13 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
progressBar1.Value = 100;
|
2022-03-09 00:10:13 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
bool problemsFound = false;
|
2022-03-09 00:10:13 +01:00
|
|
|
|
bool allFixable = true;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
foreach (PreCheckGridRow row in dataGridView1.Rows)
|
|
|
|
|
{
|
2022-03-09 00:10:13 +01:00
|
|
|
|
if (row is PreCheckItemRow preCheckRow && preCheckRow.Problem != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
problemsFound = true;
|
2022-03-09 00:10:13 +01:00
|
|
|
|
|
|
|
|
|
if (!preCheckRow.IsFixable)
|
|
|
|
|
{
|
|
|
|
|
allFixable = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-09 00:10:13 +01:00
|
|
|
|
|
|
|
|
|
labelPrecheckStatus.Visible = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
buttonReCheckProblems.Enabled = true;
|
2022-03-09 00:10:13 +01:00
|
|
|
|
panelErrorsFound.Visible = problemsFound;
|
|
|
|
|
buttonResolveAll.Enabled = problemsFound && allFixable;
|
|
|
|
|
_enableNext = !problemsFound;
|
|
|
|
|
OnPageUpdated();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 00:10:13 +01:00
|
|
|
|
private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-03-09 00:10:13 +01:00
|
|
|
|
if (e.UserState is DataGridViewRow row && !dataGridView1.Rows.Contains(row))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2022-03-09 00:10:13 +01:00
|
|
|
|
if (row is PreCheckHeaderRow headerRow)
|
|
|
|
|
headerRow.Visible = true;
|
|
|
|
|
else if (row is PreCheckItemRow preCheckRow && preCheckRow.IsProblem)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
preCheckRow.Visible = true;
|
|
|
|
|
else
|
2022-03-09 00:10:13 +01:00
|
|
|
|
row.Visible = !checkBoxHideSuccessful.Checked;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
dataGridView1.Rows.Add(row);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 00:10:13 +01:00
|
|
|
|
int step = (int)(1.0 / ((float)_numberChecks) * e.ProgressPercentage);
|
|
|
|
|
progressBar1.Value += step + progressBar1.Value > 100 ? 0 : step;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2021-09-10 15:19:08 +02:00
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private DataGridViewRow RunCheck(Check check)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2016-06-07 18:40:59 +02:00
|
|
|
|
var problems = check.RunAllChecks();
|
|
|
|
|
if (problems.Count != 0)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2016-06-07 18:40:59 +02:00
|
|
|
|
// None of the checks used in the DR wizard returns more than one problem, so we just take the first.
|
|
|
|
|
// (Even if they did, we would only suffer the usability problem described in CA-77990).
|
|
|
|
|
return new PreCheckItemRow(problems[0]);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
return new PreCheckItemRow(check);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 00:10:13 +01:00
|
|
|
|
private void worker_DoWork(object sender, DoWorkEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
lock (_lock)
|
|
|
|
|
{
|
2015-04-16 15:17:02 +02:00
|
|
|
|
Program.Invoke(this, () =>
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
dataGridView1.Rows.Clear();
|
|
|
|
|
progressBar1.Value = 0;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
RevertActions.Clear();
|
|
|
|
|
List<KeyValuePair<string, List<Check>>> checks = GenerateChecks();
|
|
|
|
|
_numberChecks = checks.Count;
|
|
|
|
|
for (int i = 0; i < checks.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
List<Check> checkGroup = checks[i].Value;
|
|
|
|
|
DataGridViewRow row =
|
|
|
|
|
new PreCheckHeaderRow(string.Format(Messages.DR_WIZARD_PRECHECKPAGE_HEADER, i + 1,
|
|
|
|
|
checks.Count, checks[i].Key));
|
|
|
|
|
_worker.ReportProgress(5, row);
|
|
|
|
|
|
|
|
|
|
Session metadataSession = null;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
// run checks
|
2013-06-24 13:41:48 +02:00
|
|
|
|
for (int j = 0; j < checkGroup.Count; j++)
|
|
|
|
|
{
|
|
|
|
|
if (_worker.CancellationPending)
|
|
|
|
|
{
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Check check = checkGroup[j];
|
|
|
|
|
|
|
|
|
|
// special case - AssertCanBeRecoveredCheck - we need to open the metadata database
|
|
|
|
|
if (check is AssertCanBeRecoveredCheck)
|
|
|
|
|
{
|
|
|
|
|
AssertCanBeRecoveredCheck thisCheck = check as AssertCanBeRecoveredCheck;
|
|
|
|
|
AssertCanBeRecoveredCheck prevCheck = j > 0
|
|
|
|
|
? checkGroup[j - 1] as
|
|
|
|
|
AssertCanBeRecoveredCheck
|
|
|
|
|
: null;
|
|
|
|
|
if (prevCheck == null || prevCheck.Vdi.uuid != thisCheck.Vdi.uuid)
|
|
|
|
|
{
|
|
|
|
|
// close previous metadata session
|
|
|
|
|
if (metadataSession != null)
|
|
|
|
|
metadataSession.logout();
|
|
|
|
|
|
|
|
|
|
// open metadata database
|
|
|
|
|
VdiOpenDatabaseAction action = new VdiOpenDatabaseAction(Connection,
|
|
|
|
|
((AssertCanBeRecoveredCheck
|
|
|
|
|
)checkGroup[0]).Vdi);
|
2022-04-05 12:52:32 +02:00
|
|
|
|
action.RunSync(action.Session);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (action.Succeeded && action.MetadataSession != null)
|
|
|
|
|
metadataSession = action.MetadataSession;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// run check
|
|
|
|
|
if (metadataSession != null)
|
|
|
|
|
{
|
|
|
|
|
thisCheck.MetadataSession = metadataSession;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
row = RunCheck(thisCheck);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
_worker.ReportProgress(PercentageSelectedObjects(j + 1), row);
|
|
|
|
|
|
|
|
|
|
// close metadata session if this is the last check
|
|
|
|
|
if (j == checkGroup.Count - 1)
|
|
|
|
|
metadataSession.logout();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
row = RunCheck(check);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
_worker.ReportProgress(PercentageSelectedObjects(j + 1), row);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<KeyValuePair<string, List<Check>>> GenerateChecks()
|
|
|
|
|
{
|
|
|
|
|
List<KeyValuePair<string, List<Check>>> checks = new List<KeyValuePair<string, List<Check>>>();
|
|
|
|
|
List<Check> checkGroup;
|
|
|
|
|
|
|
|
|
|
//HA checks
|
|
|
|
|
if (WizardType == DRWizardType.Dryrun)
|
|
|
|
|
{
|
|
|
|
|
checks.Add(new KeyValuePair<string, List<Check>>(Messages.DR_WIZARD_CHECKING_HA_STATUS,
|
|
|
|
|
new List<Check>()));
|
|
|
|
|
checkGroup = checks[checks.Count - 1].Value;
|
|
|
|
|
checkGroup.Add(new DrHAEnabledCheck(_pool));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check if selected VMs and appliances are still running in the source pool
|
|
|
|
|
if (WizardType != DRWizardType.Dryrun)
|
|
|
|
|
{
|
|
|
|
|
checkGroup = new List<Check>();
|
|
|
|
|
foreach (PoolMetadata poolMetadata in selectedPoolMetadata.Values)
|
|
|
|
|
{
|
|
|
|
|
// is source pool connected?
|
|
|
|
|
PoolMetadata metadata = poolMetadata;
|
|
|
|
|
Pool sourcePool = ConnectionsManager.XenConnectionsCopy.Select
|
|
|
|
|
(connection => Helpers.GetPoolOfOne(connection)).FirstOrDefault
|
|
|
|
|
(pool => pool != null && pool.uuid == metadata.Pool.uuid);
|
|
|
|
|
if (sourcePool != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (VM_appliance vmAppliance in poolMetadata.VmAppliances.Values)
|
|
|
|
|
{
|
|
|
|
|
checkGroup.Add(new RunningVmApplianceCheck(vmAppliance, sourcePool));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (VM vm in poolMetadata.Vms.Values)
|
|
|
|
|
{
|
2019-05-14 17:28:23 +02:00
|
|
|
|
if (vm.IsAssignedToVapp())
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
//VM included in an appliance
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
checkGroup.Add(new RunningVmCheck(vm, sourcePool));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (checkGroup.Count > 0)
|
|
|
|
|
checks.Add(
|
|
|
|
|
new KeyValuePair<string, List<Check>>(
|
|
|
|
|
Messages.DR_WIZARD_CHECKING_POWER_STATE_IN_SOURCE_POOLS, checkGroup));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Existing VMs and appliances checks
|
|
|
|
|
checkGroup = new List<Check>();
|
|
|
|
|
foreach (PoolMetadata poolMetadata in selectedPoolMetadata.Values)
|
|
|
|
|
{
|
|
|
|
|
foreach (VM_appliance vmAppliance in poolMetadata.VmAppliances.Values)
|
|
|
|
|
{
|
|
|
|
|
PoolMetadata metadata = poolMetadata;
|
|
|
|
|
List<VM> vms = (from vmRef in vmAppliance.VMs
|
|
|
|
|
where metadata.Vms.ContainsKey(vmRef)
|
|
|
|
|
select metadata.Vms[vmRef]).ToList();
|
|
|
|
|
checkGroup.Add(new ExistingVmApplianceCheck(vmAppliance, vms, _pool));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (VM vm in poolMetadata.Vms.Values)
|
|
|
|
|
{
|
2019-05-14 17:28:23 +02:00
|
|
|
|
if (vm.IsAssignedToVapp())
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
//VM included in an appliance
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
checkGroup.Add(new ExistingVmCheck(vm, _pool));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (checkGroup.Count > 0)
|
2017-09-03 04:33:29 +02:00
|
|
|
|
checks.Add(new KeyValuePair<string, List<Check>>(String.Format(Messages.DR_WIZARD_CHECKING_EXISTING_APPLIANCES_AND_VMS, _pool.Name()), checkGroup));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//VM and appliance can be recovered checks
|
2017-09-03 04:33:29 +02:00
|
|
|
|
checks.Add(new KeyValuePair<string, List<Check>>(String.Format(Messages.DR_WIZARD_CHECKING_VMS_CAN_BE_RECOVERED, _pool.Name()), new List<Check>()));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
checkGroup = checks[checks.Count - 1].Value;
|
|
|
|
|
foreach (PoolMetadata poolMetadata in selectedPoolMetadata.Values)
|
|
|
|
|
{
|
|
|
|
|
foreach (VM_appliance vmAppliance in poolMetadata.VmAppliances.Values)
|
|
|
|
|
{
|
|
|
|
|
checkGroup.Add(new AssertCanBeRecoveredCheck(vmAppliance, _pool, poolMetadata.Vdi));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (VM vm in poolMetadata.Vms.Values)
|
|
|
|
|
{
|
2019-05-14 17:28:23 +02:00
|
|
|
|
if (vm.IsAssignedToVapp())
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
//VM included in an appliance
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
checkGroup.Add(new AssertCanBeRecoveredCheck(vm, _pool, poolMetadata.Vdi));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return checks;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-09 00:55:50 +01:00
|
|
|
|
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (direction == PageLoadedDirection.Back)
|
|
|
|
|
_worker.CancelAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool EnableNext()
|
|
|
|
|
{
|
2022-03-09 00:10:13 +01:00
|
|
|
|
return _enableNext;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 13:33:26 +01:00
|
|
|
|
public override void PageCancelled(ref bool cancel)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2022-03-09 00:10:13 +01:00
|
|
|
|
_worker.CancelAsync();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal List<string> GetWarnings()
|
|
|
|
|
{
|
|
|
|
|
var warnings = new List<string>();
|
|
|
|
|
foreach (DataGridViewRow row in dataGridView1.Rows)
|
|
|
|
|
{
|
|
|
|
|
var preCheckRow = row as PreCheckItemRow;
|
|
|
|
|
if (preCheckRow != null && preCheckRow.IsWarning)
|
|
|
|
|
{
|
|
|
|
|
warnings.Add(preCheckRow.Description);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return warnings;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private void RunSolution(PreCheckItemRow preCheckRow)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
bool cancelled;
|
2018-06-29 15:48:49 +02:00
|
|
|
|
AsyncAction action = preCheckRow.Problem.GetSolutionAction(out cancelled);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (action != null)
|
|
|
|
|
{
|
|
|
|
|
action.Completed += action_Completed;
|
2018-06-29 15:48:49 +02:00
|
|
|
|
using (var progressDialog = new ActionProgressDialog(action, ProgressBarStyle.Blocks))
|
|
|
|
|
progressDialog.ShowDialog(this);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (action.Succeeded)
|
|
|
|
|
{
|
2018-07-02 14:08:46 +02:00
|
|
|
|
var revertAction = preCheckRow.Problem.CreateUnwindChangesAction();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (revertAction != null)
|
|
|
|
|
RevertActions.Add(revertAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-05 15:28:21 +02:00
|
|
|
|
|
|
|
|
|
private void action_Completed(ActionBase sender)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
Program.Invoke(Program.MainWindow, RefreshRechecks);
|
|
|
|
|
|
2023-04-28 11:06:18 +02:00
|
|
|
|
if (sender is DrTaskCreateAction drTaskCreateAction && drTaskCreateAction.Succeeded)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-04-28 11:06:18 +02:00
|
|
|
|
NewDrTaskIntroduced?.Invoke(drTaskCreateAction.Result);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-28 11:06:18 +02:00
|
|
|
|
if (sender is SrIntroduceAction srIntroduceAction && srIntroduceAction.Succeeded)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-04-28 11:06:18 +02:00
|
|
|
|
SrIntroduced?.Invoke(new XenRef<SR>(srIntroduceAction.Result));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonReCheckProblems_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
RefreshRechecks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonResolveAll_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Dictionary<AsyncAction, AsyncAction> actions = new Dictionary<AsyncAction, AsyncAction>();
|
|
|
|
|
foreach (DataGridViewRow row in dataGridView1.Rows)
|
|
|
|
|
{
|
|
|
|
|
PreCheckItemRow preCheckRow = row as PreCheckItemRow;
|
|
|
|
|
if (preCheckRow != null && preCheckRow.Problem != null)
|
|
|
|
|
{
|
|
|
|
|
bool cancelled;
|
2018-06-29 15:48:49 +02:00
|
|
|
|
AsyncAction action = preCheckRow.Problem.GetSolutionAction(out cancelled);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (action != null)
|
|
|
|
|
{
|
2018-07-02 14:08:46 +02:00
|
|
|
|
actions.Add(action, preCheckRow.Problem.CreateUnwindChangesAction());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach (var asyncAction in actions.Keys)
|
|
|
|
|
{
|
2018-06-29 15:48:49 +02:00
|
|
|
|
using (var progressDialog = new ActionProgressDialog(asyncAction, ProgressBarStyle.Blocks))
|
|
|
|
|
progressDialog.ShowDialog(this);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
if (asyncAction.Succeeded && actions[asyncAction] != null)
|
|
|
|
|
RevertActions.Add(actions[asyncAction]);
|
|
|
|
|
Program.Invoke(Program.MainWindow, RefreshRechecks);
|
|
|
|
|
}
|
|
|
|
|
Program.Invoke(Program.MainWindow, RefreshRechecks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkBoxViewPrecheckFailuresOnly_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
foreach (DataGridViewRow row in dataGridView1.Rows)
|
|
|
|
|
{
|
2022-03-09 00:10:13 +01:00
|
|
|
|
if (row is PreCheckHeaderRow headerRow)
|
|
|
|
|
headerRow.Visible = true;
|
|
|
|
|
else if (row is PreCheckItemRow preCheckRow && preCheckRow.IsProblem)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
preCheckRow.Visible = true;
|
|
|
|
|
else
|
2022-03-09 00:10:13 +01:00
|
|
|
|
row.Visible = !checkBoxHideSuccessful.Checked;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
2022-03-09 00:10:13 +01:00
|
|
|
|
if (dataGridView1.Rows[e.RowIndex] is PreCheckItemRow preCheckRow && e.ColumnIndex == 2)
|
|
|
|
|
RunSolution(preCheckRow);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region PreCheckGridRow
|
2022-03-09 00:10:13 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private abstract class PreCheckGridRow : DataGridViewRow
|
|
|
|
|
{
|
|
|
|
|
protected DataGridViewImageCell _iconCell = new DataGridViewImageCell();
|
|
|
|
|
protected DataGridViewTextBoxCell _descriptionCell = new DataGridViewTextBoxCell();
|
|
|
|
|
protected DataGridViewCell _solutionCell = new DataGridViewLinkCell();
|
|
|
|
|
|
|
|
|
|
protected PreCheckGridRow()
|
|
|
|
|
{
|
|
|
|
|
Cells.Add(_iconCell);
|
|
|
|
|
Cells.Add(_descriptionCell);
|
|
|
|
|
Cells.Add(_solutionCell);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class PreCheckHeaderRow : PreCheckGridRow
|
|
|
|
|
{
|
|
|
|
|
public PreCheckHeaderRow(string text)
|
|
|
|
|
{
|
|
|
|
|
_iconCell.Value = new Bitmap(1, 1);
|
|
|
|
|
_descriptionCell.Value = text;
|
|
|
|
|
_descriptionCell.Style.Font = new Font(Program.DefaultFont, FontStyle.Bold);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class PreCheckItemRow : PreCheckGridRow
|
|
|
|
|
{
|
2021-10-05 12:33:53 +02:00
|
|
|
|
private readonly Check _check;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public PreCheckItemRow(Problem problem)
|
|
|
|
|
{
|
2022-03-09 00:10:13 +01:00
|
|
|
|
Problem = problem;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
_check = problem.Check;
|
|
|
|
|
UpdateRowFields();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PreCheckItemRow(Check check)
|
|
|
|
|
{
|
|
|
|
|
_check = check;
|
|
|
|
|
UpdateRowFields();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateRowFields()
|
|
|
|
|
{
|
|
|
|
|
_iconCell.Value = Problem == null
|
2016-10-20 14:09:48 +02:00
|
|
|
|
? Images.GetImage16For(Icons.Ok)
|
|
|
|
|
: Problem.Image;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
if (Problem != null)
|
2021-09-19 16:48:29 +02:00
|
|
|
|
_descriptionCell.Value = String.Format(Messages.STRING_COLON_SPACE_STRING, _check.Description, Problem.Description);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
else if (_check != null)
|
|
|
|
|
{
|
|
|
|
|
_descriptionCell.Value = String.Format(Messages.DR_WIZARD_PRECHECKPAGE_OK, _check.Description);
|
|
|
|
|
}
|
|
|
|
|
_solutionCell.Value = Problem == null ? string.Empty : Problem.HelpMessage;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 00:10:13 +01:00
|
|
|
|
public Problem Problem { get; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public string Description
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _descriptionCell.Value as string;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 00:10:13 +01:00
|
|
|
|
public bool IsProblem => Problem != null && !(Problem is Warning);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2022-03-09 00:10:13 +01:00
|
|
|
|
public bool IsFixable => Problem != null && Problem.IsFixable && !string.IsNullOrEmpty(Problem.HelpMessage);
|
|
|
|
|
|
|
|
|
|
public bool IsWarning => Problem != null && Problem is Warning;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
2022-03-09 00:10:13 +01:00
|
|
|
|
if (obj is PreCheckItemRow other && other.Problem != null && Problem != null)
|
|
|
|
|
return Problem.CompareTo(other.Problem) == 0;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
2022-03-09 00:10:13 +01:00
|
|
|
|
return Problem != null ? Problem.GetHashCode() : 0;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-09 00:10:13 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|