From 7a2005c20c14facbc58a04124156b5a3e69763ee Mon Sep 17 00:00:00 2001 From: Mathieu <70369997+MathieuRA@users.noreply.github.com> Date: Tue, 31 May 2022 11:59:52 +0200 Subject: [PATCH] feat(xo-server/pool): disable scheduled job when starting RPU (#6244) See zammad#5377, zammad#5333 --- CHANGELOG.unreleased.md | 1 + packages/xo-server/src/api/pool.mjs | 40 +++++++++++++++++++++ packages/xo-web/src/common/intl/messages.js | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 5ffb6eacf..45c7a148d 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -8,6 +8,7 @@ > Users must be able to say: “Nice enhancement, I'm eager to test it” - Created SRs will now have auto-scan enabled similarly to what XenCenter does (PR [#6246](https://github.com/vatesfr/xen-orchestra/pull/6246)) +- [RPU] Disable scheduled backup jobs during RPU (PR [#6244](https://github.com/vatesfr/xen-orchestra/pull/6244)) ### Bug fixes diff --git a/packages/xo-server/src/api/pool.mjs b/packages/xo-server/src/api/pool.mjs index d5408b149..f100aed8c 100644 --- a/packages/xo-server/src/api/pool.mjs +++ b/packages/xo-server/src/api/pool.mjs @@ -1,6 +1,8 @@ import { asyncMap } from '@xen-orchestra/async-map' import { createLogger } from '@xen-orchestra/log' +import { createPredicate } from 'value-matcher' import { defer as deferrable } from 'golike-defer' +import { extractIdsFromSimplePattern } from '@xen-orchestra/backups/extractIdsFromSimplePattern.js' import { format } from 'json-rpc-peer' import { Ref } from 'xen-api' import { incorrectState } from 'xo-common/api-errors.js' @@ -175,6 +177,44 @@ export const rollingUpdate = deferrable(async function ($defer, { bypassBackupCh await backupGuard.call(this, poolId) } + const poolId = pool.id + const [schedules, jobs] = await Promise.all([this.getAllSchedules(), this.getAllJobs('backup')]) + + const jobsOfthePool = [] + jobs.forEach(({ id: jobId, vms }) => { + if (vms.id !== undefined) { + for (const vmId of extractIdsFromSimplePattern(vms)) { + // try/catch to avoid `no such object` + try { + if (this.getObject(vmId).$poolId === poolId) { + jobsOfthePool.push(jobId) + break + } + } catch {} + } + } else { + // Smart mode + // For smart mode, we take a simplified approach: + // - if smart mode is explicitly 'resident' or 'not resident' on pools, we + // check if it concerns this pool + // - if not, the job may concern this pool so we add it to `jobsOfThePool` + if (vms.$pool === undefined || createPredicate(vms.$pool)(poolId)) { + jobsOfthePool.push(jobId) + } + } + }) + + // Disable schedules + await Promise.all( + schedules + .filter(schedule => jobsOfthePool.includes(schedule.jobId) && schedule.enabled) + .map(async schedule => { + await this.updateSchedule({ ...schedule, enabled: false }) + $defer(() => this.updateSchedule({ ...schedule, enabled: true })) + }) + ) + + // Disable load balancer if ((await this.getOptionalPlugin('load-balancer'))?.loaded) { await this.unloadPlugin('load-balancer') $defer(() => this.loadPlugin('load-balancer')) diff --git a/packages/xo-web/src/common/intl/messages.js b/packages/xo-web/src/common/intl/messages.js index 6a028464a..9c38a1b3a 100644 --- a/packages/xo-web/src/common/intl/messages.js +++ b/packages/xo-web/src/common/intl/messages.js @@ -1011,7 +1011,7 @@ const messages = { 'This will automatically restart the toolstack on every host. Running VMs will not be affected. Are you sure you want to continue and install all the patches on this pool?', rollingPoolUpdate: 'Rolling pool update', rollingPoolUpdateMessage: - 'Are you sure you want to start a rolling pool update? Running VMs will be migrated back and forth and this can take a while.', + 'Are you sure you want to start a rolling pool update? Running VMs will be migrated back and forth and this can take a while. Scheduled backups that may concern this pool will be disabled.', rollingPoolUpdateHaWarning: 'High Availability is enabled. This will automatically disable it during the update.', rollingPoolUpdateLoadBalancerWarning: 'Load Balancer plugin is running. This will automatically pause it during the update.',