chore(xo-server/backups-ng): rm unneeded defer decorators

This commit is contained in:
Julien Fontanet 2018-03-30 12:05:30 +02:00
parent b3d8ce2041
commit 2ac1093543

View File

@ -136,7 +136,7 @@ const listReplicatedVms = (
xapi: Xapi, xapi: Xapi,
scheduleId: string, scheduleId: string,
srId: string, srId: string,
vmUuid?: string, vmUuid?: string
): Vm[] => { ): Vm[] => {
const { all } = xapi.objects const { all } = xapi.objects
const vms = {} const vms = {}
@ -147,11 +147,9 @@ const listReplicatedVms = (
object.$type === 'vm' && object.$type === 'vm' &&
oc['xo:backup:schedule'] === scheduleId && oc['xo:backup:schedule'] === scheduleId &&
oc['xo:backup:sr'] === srId && oc['xo:backup:sr'] === srId &&
( (oc['xo:backup:vm'] === vmUuid ||
oc['xo:backup:vm'] === vmUuid ||
// 2018-03-28, JFT: to catch VMs replicated before this fix // 2018-03-28, JFT: to catch VMs replicated before this fix
oc['xo:backup:vm'] === undefined oc['xo:backup:vm'] === undefined)
)
) { ) {
vms[object.$id] = object vms[object.$id] = object
} }
@ -716,79 +714,75 @@ export default class BackupNg {
const errors = [] const errors = []
await waitAll( await waitAll(
[ [
...remotes.map( ...remotes.map(async remoteId => {
defer(async ($defer, remoteId) => { const fork = xva.pipe(new PassThrough())
const fork = xva.pipe(new PassThrough())
const handler = await app.getRemoteHandler(remoteId) const handler = await app.getRemoteHandler(remoteId)
const oldBackups: MetadataFull[] = (getOldEntries( const oldBackups: MetadataFull[] = (getOldEntries(
exportRetention, exportRetention,
await this._listVmBackups( await this._listVmBackups(
handler, handler,
vm, vm,
_ => _.mode === 'full' && _.scheduleId === scheduleId _ => _.mode === 'full' && _.scheduleId === scheduleId
)
): any)
const deleteFirst = getSetting(settings, 'deleteFirst', remoteId)
if (deleteFirst) {
await this._deleteFullVmBackups(handler, oldBackups)
}
await writeStream(fork, handler, dataFilename)
await handler.outputFile(metadataFilename, jsonMetadata)
if (!deleteFirst) {
await this._deleteFullVmBackups(handler, oldBackups)
}
})
),
...srs.map(
defer(async ($defer, srId) => {
const fork = xva.pipe(new PassThrough())
fork.task = exportTask
const xapi = app.getXapi(srId)
const sr = xapi.getObject(srId)
const oldVms = getOldEntries(
exportRetention,
listReplicatedVms(xapi, scheduleId, srId, vmUuid)
) )
): any)
const deleteFirst = getSetting(settings, 'deleteFirst', srId) const deleteFirst = getSetting(settings, 'deleteFirst', remoteId)
if (deleteFirst) { if (deleteFirst) {
await this._deleteVms(xapi, oldVms) await this._deleteFullVmBackups(handler, oldBackups)
} }
const vm = await xapi.barrier( await writeStream(fork, handler, dataFilename)
await xapi._importVm($cancelToken, fork, sr, vm =>
xapi._setObjectProperties(vm, { await handler.outputFile(metadataFilename, jsonMetadata)
nameLabel: `${metadata.vm.name_label} (${safeDateFormat(
metadata.timestamp if (!deleteFirst) {
)})`, await this._deleteFullVmBackups(handler, oldBackups)
}) }
) }),
...srs.map(async srId => {
const fork = xva.pipe(new PassThrough())
fork.task = exportTask
const xapi = app.getXapi(srId)
const sr = xapi.getObject(srId)
const oldVms = getOldEntries(
exportRetention,
listReplicatedVms(xapi, scheduleId, srId, vmUuid)
)
const deleteFirst = getSetting(settings, 'deleteFirst', srId)
if (deleteFirst) {
await this._deleteVms(xapi, oldVms)
}
const vm = await xapi.barrier(
await xapi._importVm($cancelToken, fork, sr, vm =>
xapi._setObjectProperties(vm, {
nameLabel: `${metadata.vm.name_label} (${safeDateFormat(
metadata.timestamp
)})`,
})
) )
)
await Promise.all([ await Promise.all([
xapi.addTag(vm.$ref, 'Disaster Recovery'), xapi.addTag(vm.$ref, 'Disaster Recovery'),
xapi._updateObjectMapProperty(vm, 'blocked_operations', { xapi._updateObjectMapProperty(vm, 'blocked_operations', {
start: start:
'Start operation for this vm is blocked, clone it if you want to use it.', 'Start operation for this vm is blocked, clone it if you want to use it.',
}), }),
xapi._updateObjectMapProperty(vm, 'other_config', { xapi._updateObjectMapProperty(vm, 'other_config', {
'xo:backup:sr': srId, 'xo:backup:sr': srId,
}), }),
]) ])
if (!deleteFirst) { if (!deleteFirst) {
await this._deleteVms(xapi, oldVms) await this._deleteVms(xapi, oldVms)
} }
}) }),
),
], ],
error => { error => {
console.warn(error) console.warn(error)
@ -898,112 +892,103 @@ export default class BackupNg {
const errors = [] const errors = []
await waitAll( await waitAll(
[ [
...remotes.map( ...remotes.map(async remoteId => {
defer(async ($defer, remoteId) => { const fork = forkExport()
const fork = forkExport()
const handler = await app.getRemoteHandler(remoteId) const handler = await app.getRemoteHandler(remoteId)
const oldBackups: MetadataDelta[] = (getOldEntries( const oldBackups: MetadataDelta[] = (getOldEntries(
exportRetention, exportRetention,
await this._listVmBackups( await this._listVmBackups(
handler, handler,
vm, vm,
_ => _.mode === 'delta' && _.scheduleId === scheduleId _ => _.mode === 'delta' && _.scheduleId === scheduleId
) )
): any) ): any)
const deleteFirst = getSetting(settings, 'deleteFirst', remoteId) const deleteFirst = getSetting(settings, 'deleteFirst', remoteId)
if (deleteFirst) { if (deleteFirst) {
this._deleteDeltaVmBackups(handler, oldBackups) this._deleteDeltaVmBackups(handler, oldBackups)
} }
await asyncMap( await asyncMap(
fork.vdis, fork.vdis,
defer(async ($defer, vdi, id) => { defer(async ($defer, vdi, id) => {
const path = `${vmDir}/${metadata.vhds[id]}` const path = `${vmDir}/${metadata.vhds[id]}`
const isDelta = 'xo:base_delta' in vdi.other_config const isDelta = 'xo:base_delta' in vdi.other_config
let parentPath let parentPath
if (isDelta) { if (isDelta) {
const vdiDir = dirname(path) const vdiDir = dirname(path)
const parent = (await handler.list(vdiDir)) const parent = (await handler.list(vdiDir))
.filter(isVhd) .filter(isVhd)
.sort() .sort()
.pop() .pop()
parentPath = `${vdiDir}/${parent}` parentPath = `${vdiDir}/${parent}`
} }
await writeStream( await writeStream(fork.streams[`${id}.vhd`](), handler, path, {
fork.streams[`${id}.vhd`](), // no checksum for VHDs, because they will be invalidated by
handler, // merges and chainings
path, checksum: false,
{
// no checksum for VHDs, because they will be invalidated by
// merges and chainings
checksum: false,
}
)
$defer.onFailure.call(handler, 'unlink', path)
if (isDelta) {
await chainVhd(handler, parentPath, handler, path)
}
}) })
) $defer.onFailure.call(handler, 'unlink', path)
await handler.outputFile(metadataFilename, jsonMetadata) if (isDelta) {
await chainVhd(handler, parentPath, handler, path)
if (!deleteFirst) { }
this._deleteDeltaVmBackups(handler, oldBackups)
}
})
),
...srs.map(
defer(async ($defer, srId) => {
const fork = forkExport()
const xapi = app.getXapi(srId)
const sr = xapi.getObject(srId)
const oldVms = getOldEntries(
exportRetention,
listReplicatedVms(xapi, scheduleId, srId, vmUuid)
)
const deleteFirst = getSetting(settings, 'deleteFirst', srId)
if (deleteFirst) {
await this._deleteVms(xapi, oldVms)
}
transferStart = Math.min(transferStart, Date.now())
const { vm } = await xapi.importDeltaVm(fork, {
disableStartAfterImport: false, // we'll take care of that
name_label: `${metadata.vm.name_label} (${safeDateFormat(
metadata.timestamp
)})`,
srId: sr.$id,
}) })
)
transferEnd = Math.max(transferEnd, Date.now()) await handler.outputFile(metadataFilename, jsonMetadata)
await Promise.all([ if (!deleteFirst) {
xapi.addTag(vm.$ref, 'Continuous Replication'), this._deleteDeltaVmBackups(handler, oldBackups)
xapi._updateObjectMapProperty(vm, 'blocked_operations', { }
start: }),
'Start operation for this vm is blocked, clone it if you want to use it.', ...srs.map(async srId => {
}), const fork = forkExport()
xapi._updateObjectMapProperty(vm, 'other_config', {
'xo:backup:sr': srId,
}),
])
if (!deleteFirst) { const xapi = app.getXapi(srId)
await this._deleteVms(xapi, oldVms) const sr = xapi.getObject(srId)
}
const oldVms = getOldEntries(
exportRetention,
listReplicatedVms(xapi, scheduleId, srId, vmUuid)
)
const deleteFirst = getSetting(settings, 'deleteFirst', srId)
if (deleteFirst) {
await this._deleteVms(xapi, oldVms)
}
transferStart = Math.min(transferStart, Date.now())
const { vm } = await xapi.importDeltaVm(fork, {
disableStartAfterImport: false, // we'll take care of that
name_label: `${metadata.vm.name_label} (${safeDateFormat(
metadata.timestamp
)})`,
srId: sr.$id,
}) })
),
transferEnd = Math.max(transferEnd, Date.now())
await Promise.all([
xapi.addTag(vm.$ref, 'Continuous Replication'),
xapi._updateObjectMapProperty(vm, 'blocked_operations', {
start:
'Start operation for this vm is blocked, clone it if you want to use it.',
}),
xapi._updateObjectMapProperty(vm, 'other_config', {
'xo:backup:sr': srId,
}),
])
if (!deleteFirst) {
await this._deleteVms(xapi, oldVms)
}
}),
], ],
error => { error => {
console.warn(error) console.warn(error)