Skip to content

Commit

Permalink
fix(xo-server/rest-api/dashboard): fix 'cannot get handler to proxy r…
Browse files Browse the repository at this point in the history
…emote' (#8021)
  • Loading branch information
MathieuRA authored Sep 30, 2024
1 parent ad8cd37 commit 68b1641
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
16 changes: 16 additions & 0 deletions @xen-orchestra/proxy/app/mixins/remotes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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' },
},
},
],
},
})
}
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
<!--packages-start-->

- @xen-orchestra/proxy minor
- @xen-orchestra/xapi patch
- xen-api patch
- xo-server minor

<!--packages-end-->
13 changes: 13 additions & 0 deletions packages/xo-server/src/xo-mixins/remotes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'

// ===================================================================

Expand Down Expand Up @@ -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())
}
}
6 changes: 2 additions & 4 deletions packages/xo-server/src/xo-mixins/rest-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 68b1641

Please sign in to comment.