private void StartUploading()
        {
            // reset progress bar and action progress description
            UpdateActionProgress(null);

            // start the upload
            var actions = uploadActions.Values.Where(a => a != null).ToList();
            if (actions.Count == 0)
                return;

            using (var multipleAction = new MultipleAction(Connection, Messages.UPLOAD_PATCH_TITLE, Messages.UPLOAD_PATCH_DESCRIPTION, Messages.UPLOAD_PATCH_END_DESCRIPTION, actions, true, true, true))
            {
                multipleAction.Completed += multipleAction_Completed;
                multipleAction.RunAsync();
            }
        }
        private void TryUploading()
        {
            // reset progress bar and action progress description
            UpdateActionProgress(null);

            // Check if we can upload the patches to the masters if it is necessary.
            // This check is only available for Cream or greater hosts.
            // If we can upload (i.e. there is enough disk space) then start the upload.
            // Otherwise display error.
            canUpload = true;
            diskSpaceRequirements = null;
            var diskSpaceActions = new List<AsyncAction>();
            foreach (Host master in SelectedMasters.Where(master => Helpers.CreamOrGreater(master.Connection)))
            {
                AsyncAction action = null;
                switch (SelectedUpdateType)
                {
                    case UpdateType.NewRetail:
                        if (CanUploadUpdateOnHost(SelectedNewPatchPath, master))
                            action = new CheckDiskSpaceForPatchUploadAction(master, SelectedNewPatchPath, true);
                        break;
                    case UpdateType.Existing:
                        if (SelectedExistingPatch != null && !PatchExistsOnPool(SelectedExistingPatch, master))
                            action = new CheckDiskSpaceForPatchUploadAction(master, SelectedExistingPatch, true);
                        break;
                }

                if (action != null)
                {
                    action.Changed += delegate
                    {
                        Program.Invoke(Program.MainWindow, () => UpdateActionDescription(action));
                    };
                    diskSpaceActions.Add(action);
                }
            }

            if (diskSpaceActions.Count == 0)
            {
                StartUploading();
                return;
            }

            using (var multipleAction = new MultipleAction(Connection, "", "", "", diskSpaceActions, true, true, true))
            {
                multipleAction.Completed += delegate
                {
                    Program.Invoke(Program.MainWindow, () =>
                    {
                        if (multipleAction.Exception is NotEnoughSpaceException)
                        {
                            canUpload = false;
                            diskSpaceRequirements = (multipleAction.Exception as NotEnoughSpaceException).DiskSpaceRequirements;
                        }
                        UpdateButtons();
                        OnPageUpdated();
                        if (canUpload)
                            StartUploading();
                    });
                };
                multipleAction.RunAsync();
            }
        }
        public override void PageLoaded(PageLoadedDirection direction)
        {
            base.PageLoaded(direction);

            if (_thisPageHasBeenCompleted)
            {
                actionManualMode = null;
                actionsWorker = null;
                return;
            }
          
            if (!IsAutomaticMode)
            {
                textBoxLog.Text = ManualTextInstructions;
                
                List<AsyncAction> actions = new List<AsyncAction>();
                if (SelectedUpdateType != UpdateType.NewSuppPack)
                    actionManualMode = new ApplyPatchAction(new List<Pool_patch> { Patch }, SelectedServers);
                else
                    actionManualMode = new InstallSupplementalPackAction(SuppPackVdis, false);

                actions.Add(actionManualMode);
                if (RemoveUpdateFile && SelectedUpdateType != UpdateType.NewSuppPack)
                {
                    foreach (Pool pool in SelectedPools)
                    {
                        actions.Add(new PoolPatchCleanAction(pool, Patch, false));
                    }
                }

                using (var multipleAction = new MultipleAction(Connection, "", "", "", actions, true, true, true))
                {
                    multipleAction.Changed += action_Changed;
                    multipleAction.Completed += action_Completed;
                    multipleAction.RunAsync();
                }
                return;
            }

            _nextEnabled = false;
            OnPageUpdated();

            List<PlanAction> planActions = new List<PlanAction>();

            foreach (Pool pool in SelectedPools)
            {
                Pool_patch poolPatch = null;
                if (SelectedUpdateType != UpdateType.NewSuppPack)
                {
                    List<Pool_patch> poolPatches = new List<Pool_patch>(pool.Connection.Cache.Pool_patches);
                    poolPatch = poolPatches.Find(delegate(Pool_patch otherPatch)
                                                     {
                                                         if (Patch != null)
                                                             return string.Equals(otherPatch.uuid, Patch.uuid, StringComparison.OrdinalIgnoreCase);
                                                         return false;
                                                     });
                }

                List<Host> poolHosts = new List<Host>(pool.Connection.Cache.Hosts);
                Host master = SelectedServers.Find(host => host.IsMaster() && poolHosts.Contains(host));
                if (master != null)
                    planActions.AddRange(CompileActionList(master, poolPatch));
                foreach (Host server in SelectedServers)
                {
                    if (poolHosts.Contains(server))
                    {
                        if (!server.IsMaster())
                        {   
                            // check patch isn't already applied here
                            if (poolPatch == null || poolPatch.AppliedOn(server) == DateTime.MaxValue)
                                planActions.AddRange(CompileActionList(server, poolPatch));
                        }
                    }
                }
                if (RemoveUpdateFile)
                {
                    planActions.Add(new RemoveUpdateFile(pool, poolPatch));
                }
            }
            planActions.Add(new UnwindProblemsAction(ProblemsResolvedPreCheck));

            actionsWorker = new BackgroundWorker();
            actionsWorker.DoWork += new DoWorkEventHandler(PatchingWizardAutomaticPatchWork);
            actionsWorker.WorkerReportsProgress = true;
            actionsWorker.ProgressChanged += new ProgressChangedEventHandler(actionsWorker_ProgressChanged);
            actionsWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(actionsWorker_RunWorkerCompleted);
            actionsWorker.WorkerSupportsCancellation = true;
            actionsWorker.RunWorkerAsync(planActions);
        }
Ejemplo n.º 4
0
        private void OpenDatabaseActionCompleted(ActionBase sender)
        {
            VdiOpenDatabaseAction senderAction = (VdiOpenDatabaseAction)sender;
            senderAction.Completed -= OpenDatabaseActionCompleted;

            log.DebugFormat("Metadata database open ({0}). Now start recovering", senderAction.Vdi.Name);

            metadataSession = senderAction.MetadataSession;
            if (metadataSession == null)
                return;

            // assign metadata session to all recover actions
            List<AsyncAction> recoverSubActions = new List<AsyncAction>();
            foreach (var action in actions[senderAction.Vdi])
            {
                if (action is DrRecoverAction)
                {
                    ((DrRecoverAction)action).MetadataSession = metadataSession;
                    recoverSubActions.Add(action);
                }
            }

            multipleRecoverAction = new MultipleAction(Connection,
                String.Format(Messages.DR_WIZARD_RECOVERPAGE_RECOVER_FROM, senderAction.Vdi.Name),
                String.Format(Messages.DR_WIZARD_RECOVERPAGE_RECOVERING_FROM, senderAction.Vdi.Name), 
                Messages.COMPLETED, 
                recoverSubActions);
            multipleRecoverAction.Completed += MultipleRecoverActionCompleted;
            multipleRecoverAction.RunAsync();
        }
        private bool SaveChanges()
        {
            if (!HasChanged())
                return false;

            var mem = memorySpinner.Value;

            DialogResult dialogResult;
            using (var dlg = new ThreeButtonDialog(
                    new ThreeButtonDialog.Details(SystemIcons.Warning, Messages.CONFIRM_CHANGE_CONTROL_DOMAIN_MEMORY, Messages.XENCENTER),
                    ThreeButtonDialog.ButtonYes,
                    ThreeButtonDialog.ButtonNo))
            {
                dialogResult = dlg.ShowDialog(this);
            }

            if (DialogResult.Yes != dialogResult)
                return false;

            var actions = new List<AsyncAction>();
            var action = new ChangeControlDomainMemoryAction(host, (long)mem, false);
            actions.Add(action);

            actions.Add(new RebootHostAction(host, AddHostToPoolCommand.NtolDialog));

            var multipleAction = new MultipleAction(connection,
                string.Format(Messages.ACTION_CHANGE_CONTROL_DOMAIN_MEMORY, host.Name),
                string.Format(Messages.ACTION_CHANGE_CONTROL_DOMAIN_MEMORY, host.Name),
                Messages.COMPLETED, actions, true, false, true);

            multipleAction.RunAsync();
            return true;
        }
        private void okButton_Click(object sender, EventArgs e)
        {
            List<AsyncAction> actions = GetActions();

            if (actions.Count == 0)
                return;

            var multipleAction = new MultipleAction(
                connection,
                string.Format(Messages.UPDATE_PROPERTIES, Helpers.GetName(connection).Ellipsise(50)),
                Messages.UPDATING_PROPERTIES,
                Messages.UPDATED_PROPERTIES,
                actions, true);

            multipleAction.RunAsync();
        }
        public override void PageLoaded(PageLoadedDirection direction)
        {
            base.PageLoaded(direction);

            if (_thisPageHasBeenCompleted)
            {
                actionManualMode = null;
                actionsWorker = null;
                return;
            }

            if (!IsAutomaticMode)
            {
                textBoxLog.Text = ManualTextInstructions;

                List<AsyncAction> actions = new List<AsyncAction>();

                if (SelectedUpdateType == UpdateType.ISO && PoolUpdate != null)
                {
                    //Ely or greater: iso update format
                    actionManualMode = new ApplyUpdateAction(new List<Pool_update>() { PoolUpdate }, SelectedServers);
                }
                else
                {
                    //legacy mode
                    if (SelectedUpdateType != UpdateType.ISO)
                        actionManualMode = new ApplyPatchAction(new List<Pool_patch> { Patch }, SelectedServers);
                    else
                        actionManualMode = new InstallSupplementalPackAction(SuppPackVdis, false);
                }

                actions.Add(actionManualMode);
                if (RemoveUpdateFile && SelectedUpdateType != UpdateType.ISO)
                {
                    foreach (Pool pool in SelectedPools)
                    {
                        actions.Add(new PoolPatchCleanAction(pool, Patch, false));
                    }
                }

                using (var multipleAction = new MultipleAction(Connection, "", "", "", actions, true, true, true))
                {
                    multipleAction.Changed += action_Changed;
                    multipleAction.Completed += action_Completed;
                    multipleAction.RunAsync();
                }
                return;
            }

            _nextEnabled = false;
            OnPageUpdated();

            List<PlanAction> planActions = new List<PlanAction>();

            foreach (Pool pool in SelectedPools)
            {
                var poolHosts = new List<Host>(pool.Connection.Cache.Hosts);
                Host master = SelectedServers.Find(host => host.IsMaster() && poolHosts.Contains(host));

                //For Ely or greater: ISO updates only
                if (SelectedUpdateType == UpdateType.ISO && Helpers.ElyOrGreater(pool.Connection)) //updates for Ely (or higher) are always ISO
                {
                    var poolUpdates = new List<Pool_update>(pool.Connection.Cache.Pool_updates);
                    var poolUpdate = poolUpdates.FirstOrDefault(u => u != null && string.Equals(u.uuid, PoolUpdate.uuid, StringComparison.OrdinalIgnoreCase));

                    //master first
                    if (master != null && !poolUpdate.AppliedOn(master))
                    {
                        planActions.AddRange(CompilePoolUpdateActionList(master, poolUpdate));
                    }

                    //other hosts
                    foreach (var host in SelectedServers.Where(s => poolHosts.Contains(s) && !s.IsMaster() && !poolUpdate.AppliedOn(s)).ToList())
                    {
                        planActions.AddRange(CompilePoolUpdateActionList(host, poolUpdate));
                    }
                }
                // Legacy (pre-Ely) case: either ISO for supplemental packs (Pool_patch == null) or patch (Pool_patch != null)
                else
                {
                    Pool_patch poolPatch = null;

                    if (SelectedUpdateType != UpdateType.ISO)
                    {
                        List<Pool_patch> poolPatches = new List<Pool_patch>(pool.Connection.Cache.Pool_patches);

                        poolPatch = poolPatches.Find(delegate(Pool_patch otherPatch)
                                                        {
                                                            if (Patch != null)
                                                                return string.Equals(otherPatch.uuid, Patch.uuid, StringComparison.OrdinalIgnoreCase);
                                                            return false;
                                                        });
                    }

                    //master first
                    if (master != null && (poolPatch == null || poolPatch.AppliedOn(master) == DateTime.MaxValue))
                        planActions.AddRange(CompileActionList(master, poolPatch));

                    foreach (Host server in SelectedServers)
                    {
                        if (poolHosts.Contains(server))
                        {
                            if (!server.IsMaster())
                            {
                                // check patch isn't already applied here
                                if (poolPatch == null || poolPatch.AppliedOn(server) == DateTime.MaxValue)
                                    planActions.AddRange(CompileActionList(server, poolPatch));
                            }
                        }
                    }

                    if (RemoveUpdateFile)
                    {
                        planActions.Add(new RemoveUpdateFile(pool, poolPatch));
                    }
                }
            } //end pool in foreach

            planActions.Add(new UnwindProblemsAction(ProblemsResolvedPreCheck));

            actionsWorker = new BackgroundWorker();
            actionsWorker.DoWork += new DoWorkEventHandler(PatchingWizardAutomaticPatchWork);
            actionsWorker.WorkerReportsProgress = true;
            actionsWorker.ProgressChanged += new ProgressChangedEventHandler(actionsWorker_ProgressChanged);
            actionsWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(actionsWorker_RunWorkerCompleted);
            actionsWorker.WorkerSupportsCancellation = true;
            actionsWorker.RunWorkerAsync(planActions);
        }