2013-06-24 13:41:48 +02: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.Threading;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Wizards.PatchingWizard.PlanActions;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.RollingUpgradeWizard.PlanActions
|
|
|
|
|
{
|
2013-12-21 12:36:20 +01:00
|
|
|
|
class AutomaticBackgroundThread : BackgroundThreadBase
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
public AutomaticBackgroundThread(IEnumerable<Host> mastersToUpgrade, IDictionary<Host, List<PlanAction>> planActions, PlanAction revertAction)
|
|
|
|
|
{
|
|
|
|
|
_planActions = planActions;
|
|
|
|
|
_mastersToUpgrade = mastersToUpgrade;
|
|
|
|
|
_revertAction = revertAction;
|
|
|
|
|
_bw = new Thread(BworkerDoWork) { IsBackground = true };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BworkerDoWork()
|
|
|
|
|
{
|
|
|
|
|
Host currentHost = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (var selectedMaster in _mastersToUpgrade)
|
|
|
|
|
{
|
|
|
|
|
if (_cancel)
|
|
|
|
|
return;
|
2013-12-21 12:36:20 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Pool pool = Helpers.GetPoolOfOne(selectedMaster.Connection);
|
|
|
|
|
foreach (var host in pool.HostsToUpgrade)
|
|
|
|
|
{
|
2013-06-28 16:50:14 +02:00
|
|
|
|
log.InfoFormat("Host '{0}' upgrading from version '{1}'", host.Name, host.LongProductVersion);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
currentHost = host;
|
|
|
|
|
bool allactionsDone = true;
|
2013-12-21 12:36:20 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
foreach (var planAction in _planActions[host])
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-06-28 16:50:14 +02:00
|
|
|
|
string hostVersion = host.LongProductVersion;
|
2013-12-21 12:36:20 +01:00
|
|
|
|
OnReportRunning(planAction, host);
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
planAction.Run();
|
2013-12-21 12:36:20 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (_cancel)
|
|
|
|
|
return;
|
2013-12-21 12:36:20 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (planAction is UpgradeHostPlanAction)
|
|
|
|
|
{
|
2015-10-22 14:51:14 +02:00
|
|
|
|
Host hostAfterReboot = (planAction as UpgradeHostPlanAction).Host;
|
2015-04-17 15:56:40 +02:00
|
|
|
|
if (hostAfterReboot != null && Helpers.SameServerVersion(hostAfterReboot, hostVersion))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-06-28 16:50:14 +02:00
|
|
|
|
log.ErrorFormat("Host '{0}' rebooted with the same version '{1}'", hostAfterReboot.Name, hostAfterReboot.LongProductVersion);
|
2013-12-21 12:36:20 +01:00
|
|
|
|
OnReportException(new Exception(Messages.REBOOT_WITH_SAME_VERSION),
|
|
|
|
|
planAction, host);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
allactionsDone = false;
|
|
|
|
|
if (hostAfterReboot.IsMaster())
|
|
|
|
|
_cancel = true;
|
|
|
|
|
}
|
2015-04-17 15:56:40 +02:00
|
|
|
|
if (hostAfterReboot != null)
|
|
|
|
|
log.InfoFormat("Host '{0}' upgraded with version '{1}'", hostAfterReboot.Name, hostAfterReboot.LongProductVersion);
|
|
|
|
|
else
|
|
|
|
|
log.InfoFormat("Cannot check host's version after reboot because the host '{0}' cannot be resolved", host.Name);
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2013-12-21 12:36:20 +01:00
|
|
|
|
OnReportException(e, planAction, host);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
allactionsDone = false;
|
|
|
|
|
_cancel = true;
|
|
|
|
|
}
|
2013-12-21 12:36:20 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (_cancel)
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-12-21 12:36:20 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (allactionsDone)
|
2013-12-21 12:36:20 +01:00
|
|
|
|
OnReportHostDone(host);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception excep)
|
|
|
|
|
{
|
|
|
|
|
log.Error("Upgrade thread error: ", excep);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
//Revert resolved prechecks
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
log.Debug("Reverting prechecks");
|
2013-12-21 12:36:20 +01:00
|
|
|
|
OnReportRunning(_revertAction, currentHost);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
_revertAction.Run();
|
2013-12-21 12:36:20 +01:00
|
|
|
|
|
|
|
|
|
OnReportRevertDone();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception excep)
|
|
|
|
|
{
|
|
|
|
|
log.Error("Exception reverting prechecks", excep);
|
2013-12-21 12:36:20 +01:00
|
|
|
|
OnReportException(excep, _revertAction, currentHost);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-21 12:36:20 +01:00
|
|
|
|
OnCompleted();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|