Ejemplo n.º 1
0
        private void BworkerDoWork()
        {
            Host currentHost = null;

            try
            {
                foreach (var selectedMaster in _mastersToUpgrade)
                {
                    if (_cancel)
                    {
                        return;
                    }
                    Pool pool = Helpers.GetPoolOfOne(selectedMaster.Connection);
                    foreach (var host in pool.HostsToUpgrade)
                    {
                        log.InfoFormat("Host '{0}' upgrading from version '{1}'", host.Name, host.LongProductVersion);
                        currentHost = host;
                        bool allactionsDone = true;
                        foreach (var planAction in _planActions[host])
                        {
                            try
                            {
                                string hostVersion = host.LongProductVersion;
                                ReportRunning(this, new ReportRunningArgs(planAction, host));
                                planAction.Run();
                                if (_cancel)
                                {
                                    return;
                                }
                                if (planAction is UpgradeHostPlanAction)
                                {
                                    Host hostAfterReboot = host.Connection.Resolve(new XenRef <Host>(host.opaque_ref));
                                    if (Helpers.SameServerVersion(hostAfterReboot, hostVersion))
                                    {
                                        log.ErrorFormat("Host '{0}' rebooted with the same version '{1}'", hostAfterReboot.Name, hostAfterReboot.LongProductVersion);
                                        ReportException.Raise(this,
                                                              new ReportExceptionArgs(
                                                                  new Exception(Messages.REBOOT_WITH_SAME_VERSION),
                                                                  planAction, host));
                                        allactionsDone = false;
                                        if (hostAfterReboot.IsMaster())
                                        {
                                            _cancel = true;
                                        }
                                    }
                                    log.InfoFormat("Host '{0}' upgraded with version '{1}'", hostAfterReboot.Name, hostAfterReboot.LongProductVersion);
                                }
                            }
                            catch (Exception e)
                            {
                                ReportException.Raise(this, new ReportExceptionArgs(e, planAction, host));
                                allactionsDone = false;
                                _cancel        = true;
                            }
                            if (_cancel)
                            {
                                return;
                            }
                        }
                        if (allactionsDone)
                        {
                            ReportHostDone.Raise(this, new ReportHostDoneArgs(host));
                        }
                    }
                }
            }
            catch (Exception excep)
            {
                log.Error("Upgrade thread error: ", excep);
            }
            finally
            {
                //Revert resolved prechecks
                try
                {
                    log.Debug("Reverting prechecks");
                    ReportRunning.Raise(this, () => new ReportRunningArgs(_revertAction, currentHost));
                    _revertAction.Run();
                    ReportRevertDone.Raise(this, () => new ReportRevertDoneArgs(_revertAction));
                }
                catch (Exception excep)
                {
                    log.Error("Exception reverting prechecks", excep);
                    ReportException.Raise(this, () => new ReportExceptionArgs(excep, _revertAction, currentHost));
                }

                Completed.Raise(this);
            }


            Completed.Raise(this);
        }
        private void BworkerDoWork()
        {
            Host currentHost = null;

            try
            {
                List <Host> hosts = GetAllHosts(_mastersToUpgrade);

                bool   currentMasterFailed      = false;
                string poolHigherProductVersion = string.Empty;
                for (int i = 0; i < hosts.Count; i++)
                {
                    if (_cancel)
                    {
                        return;
                    }
                    //Skip hosts already upgraded
                    var host = currentHost = hosts[i];
                    if (host.IsMaster())
                    {
                        poolHigherProductVersion = host.LongProductVersion;
                        if (CheckMasterIsUpgraded(hosts, i))
                        {
                            log.Debug(string.Format("Skipping master '{0}' because it is upgraded", host.Name));
                            continue;
                        }
                    }
                    else if (host.LongProductVersion == poolHigherProductVersion)
                    {
                        log.Debug(string.Format("Skipping host '{0}' because it is upgraded", host.Name));
                        continue;
                    }
                    log.Debug(string.Format("Starting to upgrade host '{0}'", host.Name));
                    //Add subtasks for the current host
                    bool allActionsDone = true;
                    foreach (var planAction in _planActions[host])
                    {
                        //if the wizard has been cancelled, skip this action, unless it is a BringBabiesBackAction
                        if (_cancel && !(planAction is BringBabiesBackAction))
                        {
                            continue;
                        }

                        PlanAction action = planAction;
                        ReportRunning.Raise(this, () => new ReportRunningArgs(action, host));
                        try
                        {
                            if (planAction is UpgradeManualHostPlanAction)
                            {
                                var upgradeAction = (UpgradeManualHostPlanAction)planAction;
                                ManageSemiAutomaticPlanAction.Raise(this, () => new ManageSemiAutomaticPlanActionArgs(upgradeAction));
                                if (host.IsMaster())
                                {
                                    poolHigherProductVersion = upgradeAction.Host.LongProductVersion;
                                }
                            }
                            else
                            {
                                planAction.Run();
                            }
                        }
                        catch (Exception excep)
                        {
                            log.Error(string.Format("Exception in host '{0}' while it was upgraded", host.Name), excep);
                            PlanAction action1 = planAction;
                            ReportException.Raise(this, () => new ReportExceptionArgs(excep, action1, host));
                            if (host.IsMaster())
                            {
                                currentMasterFailed = true;
                            }
                            allActionsDone = false;
                            break;
                        }
                    }

                    if (allActionsDone)
                    {
                        ReportHostDone.Raise(this, () => new ReportHostDoneArgs(host));
                    }

                    //Skip slaves if master failed
                    if (currentMasterFailed)
                    {
                        i = SkipSlaves(hosts, i);
                    }
                }
            }
            catch (Exception excep)
            {
                log.Error("Upgrade thread error: ", excep);
            }
            finally
            {
                //Revert resolved prechecks
                try
                {
                    log.Debug("Reverting prechecks");
                    ReportRunning.Raise(this, () => new ReportRunningArgs(_revertAction, currentHost));
                    _revertAction.Run();
                    ReportRevertDone.Raise(this, () => new ReportRevertDoneArgs(_revertAction));
                }
                catch (Exception excep)
                {
                    log.Error("Exception reverting prechecks", excep);
                    ReportException.Raise(this, () => new ReportExceptionArgs(excep, _revertAction, currentHost));
                }

                Completed.Raise(this);
            }
        }