feat(xo-server/listBackupNgDiskPartitions): use @xen-orchestra/backups lib (#5599)
This commit is contained in:
parent
624f328269
commit
d9531e24a3
@ -44,6 +44,7 @@
|
||||
>
|
||||
> In case of conflict, the highest (lowest in previous list) `$version` wins.
|
||||
|
||||
- @vates/disposable minor
|
||||
- @xen-orchestra/fs minor
|
||||
- @xen-orchestra/backups minor
|
||||
- xen-api patch
|
||||
|
@ -4,6 +4,9 @@
|
||||
|
||||
datadir = '/var/lib/xo-server/data'
|
||||
|
||||
# Delay for which a resource is cached
|
||||
resourceCacheDelay = '5m'
|
||||
|
||||
# Should users be created on first sign in?
|
||||
#
|
||||
# Necessary for external authentication providers.
|
||||
|
@ -33,7 +33,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@iarna/toml": "^2.2.1",
|
||||
"@vates/compose": "^2.0.0",
|
||||
"@vates/decorate-with": "^0.0.1",
|
||||
"@vates/disposable": "^0.0.0",
|
||||
"@vates/multi-key-map": "^0.1.0",
|
||||
"@vates/parse-duration": "0.1.0",
|
||||
"@xen-orchestra/async-map": "^0.0.0",
|
||||
|
27
packages/xo-server/src/xo-mixins/backups-remote-adapter.js
Normal file
27
packages/xo-server/src/xo-mixins/backups-remote-adapter.js
Normal file
@ -0,0 +1,27 @@
|
||||
import Disposable from 'promise-toolbox/Disposable'
|
||||
|
||||
import { compose } from '@vates/compose'
|
||||
import { decorateWith } from '@vates/decorate-with'
|
||||
import { deduped } from '@vates/disposable/deduped'
|
||||
import { RemoteAdapter } from '@xen-orchestra/backups/RemoteAdapter'
|
||||
|
||||
export default class BackupsRemoteAdapter {
|
||||
constructor(app, { backup }) {
|
||||
this._app = app
|
||||
this._config = backup
|
||||
}
|
||||
|
||||
// FIXME: invalidate cache on remote option change
|
||||
@decorateWith(compose, function (resource) {
|
||||
return this._app.debounceResource(resource)
|
||||
})
|
||||
@decorateWith(deduped, remote => [remote.url])
|
||||
@decorateWith(Disposable.factory)
|
||||
async *getBackupsRemoteAdapter(remote) {
|
||||
const app = this._app
|
||||
return new RemoteAdapter(await app.getRemoteHandler(remote), {
|
||||
debounceResource: app.debounceResource.bind(app),
|
||||
dirMode: this._config.dirMode,
|
||||
})
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import { createParser as createPairsParser } from 'parse-pairs'
|
||||
import { decorateWith } from '@vates/decorate-with'
|
||||
import { normalize } from 'path'
|
||||
import { readdir, rmdir, stat } from 'fs-extra'
|
||||
import { using } from 'promise-toolbox'
|
||||
import { ZipFile } from 'yazl'
|
||||
|
||||
import { dedupeUnmount } from '../_dedupeUnmount'
|
||||
@ -200,19 +201,18 @@ export default class BackupNgFileRestore {
|
||||
return zip.outputStream.on('end', () => partition.unmount().then(disk.unmount))
|
||||
}
|
||||
|
||||
@defer
|
||||
async listBackupNgDiskPartitions($defer, remoteId, diskId) {
|
||||
async listBackupNgDiskPartitions(remoteId, diskId) {
|
||||
const app = this._app
|
||||
const { proxy, url, options } = await app.getRemoteWithCredentials(remoteId)
|
||||
if (proxy !== undefined) {
|
||||
const remote = await app.getRemoteWithCredentials(remoteId)
|
||||
if (remote.proxy !== undefined) {
|
||||
const stream = await app.callProxyMethod(
|
||||
proxy,
|
||||
remote.proxy,
|
||||
'backup.listDiskPartitions',
|
||||
{
|
||||
disk: diskId,
|
||||
remote: {
|
||||
url,
|
||||
options,
|
||||
url: remote.url,
|
||||
options: remote.options,
|
||||
},
|
||||
},
|
||||
{ assertType: 'iterator' }
|
||||
@ -223,11 +223,9 @@ export default class BackupNgFileRestore {
|
||||
partitions.push(partition)
|
||||
}
|
||||
return partitions
|
||||
} else {
|
||||
return using(app.getBackupsRemoteAdapter(remote), adapter => adapter.listPartitions(diskId))
|
||||
}
|
||||
|
||||
const disk = await this._mountDisk(remoteId, diskId)
|
||||
$defer(disk.unmount)
|
||||
return this._listPartitions(disk.path)
|
||||
}
|
||||
|
||||
@defer
|
||||
|
@ -3,9 +3,11 @@ import XoCollection from 'xo-collection'
|
||||
import XoUniqueIndex from 'xo-collection/unique-index'
|
||||
import mixin from '@xen-orchestra/mixin'
|
||||
import { createClient as createRedisClient } from 'redis'
|
||||
import { createDebounceResource } from '@vates/disposable/debounceResource'
|
||||
import { EventEmitter } from 'events'
|
||||
import { noSuchObject } from 'xo-common/api-errors'
|
||||
import { forEach, includes, isEmpty, iteratee, map as mapToArray, stubTrue } from 'lodash'
|
||||
import { parseDuration } from '@vates/parse-duration'
|
||||
|
||||
import mixins from './xo-mixins'
|
||||
import Connection from './connection'
|
||||
@ -46,6 +48,12 @@ export default class Xo extends EventEmitter {
|
||||
}
|
||||
|
||||
this.on('start', () => this._watchObjects())
|
||||
|
||||
const debounceResource = createDebounceResource()
|
||||
debounceResource.defaultDelay = parseDuration(config.resourceCacheDelay)
|
||||
this.once('stop', debounceResource.flushAll)
|
||||
|
||||
this.debounceResource = debounceResource
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user