From 68b1641e0714e1ae76c265aeaefa765e460af8a5 Mon Sep 17 00:00:00 2001 From: Mathieu <70369997+MathieuRA@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:59:26 +0200 Subject: [PATCH] fix(xo-server/rest-api/dashboard): fix 'cannot get handler to proxy remote' (#8021) --- @xen-orchestra/proxy/app/mixins/remotes.mjs | 16 ++++++++++++++++ CHANGELOG.unreleased.md | 2 ++ packages/xo-server/src/xo-mixins/remotes.mjs | 13 +++++++++++++ packages/xo-server/src/xo-mixins/rest-api.mjs | 6 ++---- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/@xen-orchestra/proxy/app/mixins/remotes.mjs b/@xen-orchestra/proxy/app/mixins/remotes.mjs index f806008fa77..816ae36c48b 100644 --- a/@xen-orchestra/proxy/app/mixins/remotes.mjs +++ b/@xen-orchestra/proxy/app/mixins/remotes.mjs @@ -3,6 +3,7 @@ import { compose } from '@vates/compose' import { decorateMethodsWith } from '@vates/decorate-with' import { deduped } from '@vates/disposable/deduped.js' import { getHandler } from '@xen-orchestra/fs' +import { RemoteAdapter } from '@xen-orchestra/backups/RemoteAdapter.mjs' export default class Remotes { constructor(app) { @@ -31,6 +32,21 @@ export default class Remotes { }, }, ], + + getTotalBackupSize: [ + ({ remote }) => + Disposable.use(this.getHandler(remote), handler => { + const remoteAdapter = new RemoteAdapter(handler, { + debounceResource: app.debounceResource.bind(app), + }) + return remoteAdapter.getTotalBackupSize() + }), + { + params: { + remote: { type: 'object' }, + }, + }, + ], }, }) } diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index c08bd94d95f..c5f7c96f89b 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -33,7 +33,9 @@ +- @xen-orchestra/proxy minor - @xen-orchestra/xapi patch - xen-api patch +- xo-server minor diff --git a/packages/xo-server/src/xo-mixins/remotes.mjs b/packages/xo-server/src/xo-mixins/remotes.mjs index 02988e53fa8..e2f08a75019 100644 --- a/packages/xo-server/src/xo-mixins/remotes.mjs +++ b/packages/xo-server/src/xo-mixins/remotes.mjs @@ -10,6 +10,7 @@ import { synchronized } from 'decorator-synchronized' import patch from '../patch.mjs' import { Remotes } from '../models/remote.mjs' +import Disposable from 'promise-toolbox/Disposable' // =================================================================== @@ -297,4 +298,16 @@ export default class { await this._remotes.remove(id) } + + async getTotalBackupSizeOnRemote(id) { + const remote = await this._getRemote(id) + + if (remote.proxy !== undefined) { + return this._app.callProxyMethod(remote.proxy, 'remote.getTotalBackupSize', { + remote, + }) + } + + return Disposable.use(this._app.getBackupsRemoteAdapter(remote), adapter => adapter.getTotalBackupSize()) + } } diff --git a/packages/xo-server/src/xo-mixins/rest-api.mjs b/packages/xo-server/src/xo-mixins/rest-api.mjs index 6e43f569378..589d21545b0 100644 --- a/packages/xo-server/src/xo-mixins/rest-api.mjs +++ b/packages/xo-server/src/xo-mixins/rest-api.mjs @@ -9,7 +9,6 @@ import { pipeline } from 'node:stream/promises' import { json, Router } from 'express' import { Readable } from 'node:stream' import cloneDeep from 'lodash/cloneDeep.js' -import Disposable from 'promise-toolbox/Disposable' import groupBy from 'lodash/groupBy.js' import path from 'node:path' import pDefer from 'promise-toolbox/defer' @@ -251,9 +250,8 @@ async function _getDashboardStats(app) { continue } - const totalBackupSize = await Disposable.use(app.getBackupsRemoteAdapter(backupRepository), adapter => - adapter.getTotalBackupSize() - ) + const totalBackupSize = await app.getTotalBackupSizeOnRemote(backupRepository.id) + const { available, size, used } = backupRepositoryInfo const isS3 = type === 's3'