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,
scheduleId: string,
srId: string,
vmUuid?: string,
vmUuid?: string
): Vm[] => {
const { all } = xapi.objects
const vms = {}
@ -147,11 +147,9 @@ const listReplicatedVms = (
object.$type === 'vm' &&
oc['xo:backup:schedule'] === scheduleId &&
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
oc['xo:backup:vm'] === undefined
)
oc['xo:backup:vm'] === undefined)
) {
vms[object.$id] = object
}
@ -716,79 +714,75 @@ export default class BackupNg {
const errors = []
await waitAll(
[
...remotes.map(
defer(async ($defer, remoteId) => {
const fork = xva.pipe(new PassThrough())
...remotes.map(async remoteId => {
const fork = xva.pipe(new PassThrough())
const handler = await app.getRemoteHandler(remoteId)
const handler = await app.getRemoteHandler(remoteId)
const oldBackups: MetadataFull[] = (getOldEntries(
exportRetention,
await this._listVmBackups(
handler,
vm,
_ => _.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)
const oldBackups: MetadataFull[] = (getOldEntries(
exportRetention,
await this._listVmBackups(
handler,
vm,
_ => _.mode === 'full' && _.scheduleId === scheduleId
)
): any)
const deleteFirst = getSetting(settings, 'deleteFirst', srId)
if (deleteFirst) {
await this._deleteVms(xapi, oldVms)
}
const deleteFirst = getSetting(settings, 'deleteFirst', remoteId)
if (deleteFirst) {
await this._deleteFullVmBackups(handler, oldBackups)
}
const vm = await xapi.barrier(
await xapi._importVm($cancelToken, fork, sr, vm =>
xapi._setObjectProperties(vm, {
nameLabel: `${metadata.vm.name_label} (${safeDateFormat(
metadata.timestamp
)})`,
})
)
await writeStream(fork, handler, dataFilename)
await handler.outputFile(metadataFilename, jsonMetadata)
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([
xapi.addTag(vm.$ref, 'Disaster Recovery'),
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,
}),
])
await Promise.all([
xapi.addTag(vm.$ref, 'Disaster Recovery'),
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)
}
})
),
if (!deleteFirst) {
await this._deleteVms(xapi, oldVms)
}
}),
],
error => {
console.warn(error)
@ -898,112 +892,103 @@ export default class BackupNg {
const errors = []
await waitAll(
[
...remotes.map(
defer(async ($defer, remoteId) => {
const fork = forkExport()
...remotes.map(async remoteId => {
const fork = forkExport()
const handler = await app.getRemoteHandler(remoteId)
const handler = await app.getRemoteHandler(remoteId)
const oldBackups: MetadataDelta[] = (getOldEntries(
exportRetention,
await this._listVmBackups(
handler,
vm,
_ => _.mode === 'delta' && _.scheduleId === scheduleId
)
): any)
const oldBackups: MetadataDelta[] = (getOldEntries(
exportRetention,
await this._listVmBackups(
handler,
vm,
_ => _.mode === 'delta' && _.scheduleId === scheduleId
)
): any)
const deleteFirst = getSetting(settings, 'deleteFirst', remoteId)
if (deleteFirst) {
this._deleteDeltaVmBackups(handler, oldBackups)
}
const deleteFirst = getSetting(settings, 'deleteFirst', remoteId)
if (deleteFirst) {
this._deleteDeltaVmBackups(handler, oldBackups)
}
await asyncMap(
fork.vdis,
defer(async ($defer, vdi, id) => {
const path = `${vmDir}/${metadata.vhds[id]}`
await asyncMap(
fork.vdis,
defer(async ($defer, vdi, id) => {
const path = `${vmDir}/${metadata.vhds[id]}`
const isDelta = 'xo:base_delta' in vdi.other_config
let parentPath
if (isDelta) {
const vdiDir = dirname(path)
const parent = (await handler.list(vdiDir))
.filter(isVhd)
.sort()
.pop()
parentPath = `${vdiDir}/${parent}`
}
const isDelta = 'xo:base_delta' in vdi.other_config
let parentPath
if (isDelta) {
const vdiDir = dirname(path)
const parent = (await handler.list(vdiDir))
.filter(isVhd)
.sort()
.pop()
parentPath = `${vdiDir}/${parent}`
}
await writeStream(
fork.streams[`${id}.vhd`](),
handler,
path,
{
// 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)
}
await writeStream(fork.streams[`${id}.vhd`](), handler, path, {
// no checksum for VHDs, because they will be invalidated by
// merges and chainings
checksum: false,
})
)
$defer.onFailure.call(handler, 'unlink', path)
await handler.outputFile(metadataFilename, jsonMetadata)
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,
if (isDelta) {
await chainVhd(handler, parentPath, handler, path)
}
})
)
transferEnd = Math.max(transferEnd, Date.now())
await handler.outputFile(metadataFilename, jsonMetadata)
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) {
this._deleteDeltaVmBackups(handler, oldBackups)
}
}),
...srs.map(async srId => {
const fork = forkExport()
if (!deleteFirst) {
await this._deleteVms(xapi, oldVms)
}
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 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 => {
console.warn(error)