chore: rename asyncMap → asyncMapSettled

To express more clearly this function's behavior.
This commit is contained in:
Julien Fontanet 2021-03-01 09:45:56 +01:00
parent 57612eeced
commit f858c196f4
15 changed files with 58 additions and 58 deletions

View File

@ -3,7 +3,7 @@
// $FlowFixMe
import getStream from 'get-stream'
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import limit from 'limit-concurrency-decorator'
import path, { basename } from 'path'
import synchronized from 'decorator-synchronized'
@ -522,7 +522,7 @@ export default class RemoteHandlerAbstract {
}
const files = await this._list(dir)
await asyncMap(files, file =>
await asyncMapSettled(files, file =>
this._unlink(`${dir}/${file}`).catch(error => {
if (error.code === 'EISDIR') {
return this._rmtree(`${dir}/${file}`)

View File

@ -1,4 +1,4 @@
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import createLogger from '@xen-orchestra/log'
import Handlebars from 'handlebars'
import humanFormat from 'human-format'
@ -334,7 +334,7 @@ async function getHostsStats({ runningHosts, xo }) {
async function getSrsStats({ xo, xoObjects }) {
return orderBy(
await asyncMap(
await asyncMapSettled(
filter(xoObjects, obj => obj.type === 'SR' && obj.size > 0 && obj.$PBDs.length > 0),
async sr => {
const totalSpace = sr.size / gibPower

View File

@ -1,4 +1,4 @@
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import { some } from 'lodash'
import ensureArray from '../_ensureArray'
@ -64,7 +64,7 @@ export async function destroy({ sr }) {
const config = xapi.xo.getData(sr, 'xosan_config')
// we simply forget because the hosted disks are being destroyed with the VMs
await xapi.forgetSr(sr._xapiId)
await asyncMap(config.nodes, node => xapi.deleteVm(node.vm.id))
await asyncMapSettled(config.nodes, node => xapi.deleteVm(node.vm.id))
await xapi.deleteNetwork(config.network)
if (sr.SR_type === 'xosan') {
await this.unbindXosanLicense({ srId: sr.id })

View File

@ -1,5 +1,5 @@
import * as multiparty from 'multiparty'
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import defer from 'golike-defer'
import getStream from 'get-stream'
import { createLogger } from '@xen-orchestra/log'
@ -377,7 +377,7 @@ const delete_ = defer(async function (
$defer.onFailure(() => this.setVmResourceSet(vm._xapiId, resourceSet, true)::ignoreErrors())
}
await asyncMap(vm.snapshots, async id => {
await asyncMapSettled(vm.snapshots, async id => {
const { resourceSet } = this.getObject(id)
if (resourceSet !== undefined) {
await this.setVmResourceSet(id, null)

View File

@ -1,5 +1,5 @@
import assert from 'assert'
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import createLogger from '@xen-orchestra/log'
import defer from 'golike-defer'
import execa from 'execa'
@ -146,7 +146,7 @@ function createVolumeInfoTypes() {
}
const topTypes = ['open', 'read', 'write', 'opendir', 'readdir']
return asyncMap(topTypes, async type => ({
return asyncMapSettled(topTypes, async type => ({
type,
result: await this::sshInfoType(`top xosan ${type}`, parseTop)(sr),
}))
@ -1119,11 +1119,11 @@ export const removeBricks = defer(async function ($defer, { xosansr, bricks }) {
const dict = _getIPToVMDict(xapi, xosansr.id)
const brickVMs = map(bricks, b => dict[b])
await glusterCmd(glusterEndpoint, `volume remove-brick xosan ${bricks.join(' ')} force`)
await asyncMap(ips, ip => glusterCmd(glusterEndpoint, 'peer detach ' + ip, true))
await asyncMapSettled(ips, ip => glusterCmd(glusterEndpoint, 'peer detach ' + ip, true))
remove(data.nodes, node => ips.includes(node.vm.ip))
await xapi.xo.setData(xosansr.id, 'xosan_config', data)
await xapi.callAsync('SR.scan', xapi.getObject(xosansr._xapiId).$ref)
await asyncMap(brickVMs, vm => xapi.deleteVm(vm.vm, true))
await asyncMapSettled(brickVMs, vm => xapi.deleteVm(vm.vm, true))
} finally {
delete CURRENT_POOL_OPERATIONS[xapi.pool.$id]
}

View File

@ -1,4 +1,4 @@
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import { createClient as createRedisClient } from 'redis'
import { difference, filter, forEach, isEmpty, keys as getKeys, map } from 'lodash'
import { ignoreErrors, promisifyAll } from 'promise-toolbox'
@ -63,14 +63,14 @@ export default class Redis extends Collection {
}
const idsIndex = `${prefix}_ids`
return asyncMap(indexes, index =>
return asyncMapSettled(indexes, index =>
redis.keys(`${prefix}_${index}:*`).then(keys => keys.length !== 0 && redis.del(keys))
).then(() =>
asyncMap(redis.smembers(idsIndex), id =>
asyncMapSettled(redis.smembers(idsIndex), id =>
redis.hgetall(`${prefix}:${id}`).then(values =>
values == null
? redis.srem(idsIndex, id) // entry no longer exists
: asyncMap(indexes, index => {
: asyncMapSettled(indexes, index => {
const value = values[index]
if (value !== undefined) {
return redis.sadd(`${prefix}_${index}:${String(value).toLowerCase()}`, id)
@ -127,7 +127,7 @@ export default class Redis extends Collection {
// remove the previous values from indexes
if (indexes.length !== 0) {
const previous = await redis.hgetall(`${prefix}:${id}`)
await asyncMap(indexes, index => {
await asyncMapSettled(indexes, index => {
const value = previous[index]
if (value !== undefined) {
return redis.srem(`${prefix}_${index}:${String(value).toLowerCase()}`, id)
@ -211,11 +211,11 @@ export default class Redis extends Collection {
if (indexes.length !== 0) {
promise = Promise.all([
promise,
asyncMap(ids, id =>
asyncMapSettled(ids, id =>
redis.hgetall(`${prefix}:${id}`).then(
values =>
values != null &&
asyncMap(indexes, index => {
asyncMapSettled(indexes, index => {
const value = values[index]
if (value !== undefined) {
return redis.srem(`${prefix}_${index}:${String(value).toLowerCase()}`, id)

View File

@ -1,6 +1,6 @@
/* eslint eslint-comments/disable-enable-pair: [error, {allowWholeFile: true}] */
/* eslint-disable camelcase */
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import concurrency from 'limit-concurrency-decorator'
import createLogger from '@xen-orchestra/log'
import deferrable from 'golike-defer'
@ -349,7 +349,7 @@ export default class Xapi extends XapiBase {
// from host to another. It only works when a shared SR is present
// in the host. For this reason we chose to show a warning instead.
const pluggedPbds = host.$PBDs.filter(pbd => pbd.currently_attached)
await asyncMap(pluggedPbds, async pbd => {
await asyncMapSettled(pluggedPbds, async pbd => {
const ref = pbd.$ref
await this.unplugPbd(ref)
$defer(() => this.plugPbd(ref))
@ -623,12 +623,12 @@ export default class Xapi extends XapiBase {
await this.callAsync('VM.destroy', $ref)
return Promise.all([
asyncMap(vm.$snapshots, snapshot => this._deleteVm(snapshot))::ignoreErrors(),
asyncMapSettled(vm.$snapshots, snapshot => this._deleteVm(snapshot))::ignoreErrors(),
vm.power_state === 'Suspended' && vm.suspend_VDI !== NULL_REF && this._deleteVdi(vm.suspend_VDI)::ignoreErrors(),
deleteDisks &&
asyncMap(disks, ({ $ref: vdiRef }) => {
asyncMapSettled(disks, ({ $ref: vdiRef }) => {
let onFailure = () => {
onFailure = vdi => {
log.error(`cannot delete VDI ${vdi.name_label} (from VM ${vm.name_label})`)
@ -975,7 +975,7 @@ export default class Xapi extends XapiBase {
$defer.onFailure(() => this._deleteVm(vm))
// 2. Delete all VBDs which may have been created by the import.
await asyncMap(vm.$VBDs, vbd => this._deleteVbd(vbd))::ignoreErrors()
await asyncMapSettled(vm.$VBDs, vbd => this._deleteVbd(vbd))::ignoreErrors()
// 3. Create VDIs & VBDs.
//
@ -1011,7 +1011,7 @@ export default class Xapi extends XapiBase {
$defer.onFailure(() => this._deleteVdi(newVdi.$ref))
}
await asyncMap(vbds[vdiRef], vbd =>
await asyncMapSettled(vbds[vdiRef], vbd =>
this.createVbd({
...vbd,
vdi: newVdi,
@ -1042,7 +1042,7 @@ export default class Xapi extends XapiBase {
await Promise.all([
// Import VDI contents.
asyncMap(newVdis, async (vdi, id) => {
asyncMapSettled(newVdis, async (vdi, id) => {
for (let stream of ensureArray(streams[`${id}.vhd`])) {
if (typeof stream === 'function') {
stream = await stream()
@ -1057,10 +1057,10 @@ export default class Xapi extends XapiBase {
}),
// Wait for VDI export tasks (if any) termination.
asyncMap(streams, stream => stream.task),
asyncMapSettled(streams, stream => stream.task),
// Create VIFs.
asyncMap(delta.vifs, vif => {
asyncMapSettled(delta.vifs, vif => {
let network = vif.$network$uuid && this.getObject(vif.$network$uuid, undefined)
if (network === undefined) {
@ -1741,7 +1741,7 @@ export default class Xapi extends XapiBase {
throw error
}
const newVdi = await this.barrier(await this.callAsync('VDI.copy', vdi.$ref, sr.$ref).then(extractOpaqueRef))
await asyncMap(vdi.$VBDs, async vbd => {
await asyncMapSettled(vdi.$VBDs, async vbd => {
await this.call('VBD.destroy', vbd.$ref)
await this.createVbd({
...vbd,
@ -2076,7 +2076,7 @@ export default class Xapi extends XapiBase {
})
})
await asyncMap(pifsByHost, pifs => this.call('Bond.create', network.$ref, pifs, '', bondMode))
await asyncMapSettled(pifsByHost, pifs => this.call('Bond.create', network.$ref, pifs, '', bondMode))
return network
}

View File

@ -2,7 +2,7 @@
// $FlowFixMe
import type RemoteHandler from '@xen-orchestra/fs'
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import createLogger from '@xen-orchestra/log'
import defer from 'golike-defer'
import limitConcurrency from 'limit-concurrency-decorator'
@ -1798,7 +1798,7 @@ export default class BackupNg {
}
async _deleteFullVmBackups(handler: RemoteHandler, backups: MetadataFull[]): Promise<void> {
await asyncMap(backups, ({ _filename, xva }) => {
await asyncMapSettled(backups, ({ _filename, xva }) => {
_filename = ((_filename: any): string)
return Promise.all([handler.unlink(_filename), handler.unlink(resolveRelativeFromFile(_filename, xva))])
})
@ -1839,7 +1839,7 @@ export default class BackupNg {
}
async _deleteVms(xapi: Xapi, vms: Vm[]): Promise<void> {
await asyncMap(vms, vm => xapi.deleteVm(vm))
await asyncMapSettled(vms, vm => xapi.deleteVm(vm))
}
async _listVmBackups(

View File

@ -1,4 +1,4 @@
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import createLogger from '@xen-orchestra/log'
import deferrable from 'golike-defer'
import execa from 'execa'
@ -303,12 +303,12 @@ export default class {
const backups = []
await asyncMap(handler.list('.'), entry => {
await asyncMapSettled(handler.list('.'), entry => {
if (entry.endsWith('.xva')) {
backups.push(parseVmBackupPath(entry))
} else if (entry.startsWith('vm_delta_')) {
return handler.list(entry).then(children =>
asyncMap(children, child => {
asyncMapSettled(children, child => {
if (child.endsWith('.json')) {
const path = `${entry}/${child}`
@ -407,7 +407,7 @@ export default class {
}
if (toRemove !== undefined) {
promise.then(() => asyncMap(toRemove, _ => targetXapi.deleteVm(_.$id)))::ignoreErrors()
promise.then(() => asyncMapSettled(toRemove, _ => targetXapi.deleteVm(_.$id)))::ignoreErrors()
}
// (Asynchronously) Identify snapshot as future base.
@ -435,7 +435,7 @@ export default class {
const getPath = (file, dir) => (dir ? `${dir}/${file}` : file)
await asyncMap(backups.slice(0, n), backup => handler.unlink(getPath(backup, dir)))
await asyncMapSettled(backups.slice(0, n), backup => handler.unlink(getPath(backup, dir)))
}
// -----------------------------------------------------------------
@ -489,7 +489,7 @@ export default class {
const fullBackupId = j
// Remove old backups before the most recent full.
await asyncMap(range(0, j), i => handler.unlink(`${dir}/${backups[i]}`))
await asyncMapSettled(range(0, j), i => handler.unlink(`${dir}/${backups[i]}`))
const parent = `${dir}/${backups[fullBackupId]}`
@ -572,7 +572,7 @@ export default class {
const nOldBackups = backups.length - retention
if (nOldBackups > 0) {
await asyncMap(backups.slice(0, nOldBackups), backup =>
await asyncMapSettled(backups.slice(0, nOldBackups), backup =>
// Remove json file.
handler.unlink(`${dir}/${backup}`)
)
@ -664,7 +664,7 @@ export default class {
}
$defer.onFailure(() =>
asyncMap(fulFilledVdiBackups, vdiBackup => handler.unlink(`${dir}/${vdiBackup.value()}`)::ignoreErrors())
asyncMapSettled(fulFilledVdiBackups, vdiBackup => handler.unlink(`${dir}/${vdiBackup.value()}`)::ignoreErrors())
)
if (error) {

View File

@ -1,4 +1,4 @@
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import { createPredicate } from 'value-matcher'
import { timeout } from 'promise-toolbox'
import { filter, isEmpty, map, mapValues } from 'lodash'
@ -55,7 +55,7 @@ export default async function executeJobCall({ app, job, logger, runJobId, sched
timezone: schedule !== undefined ? schedule.timezone : undefined,
}
await asyncMap(paramsFlatVector, params => {
await asyncMapSettled(paramsFlatVector, params => {
const runCallId = logger.notice(`Starting ${job.method} call. (${job.id})`, {
event: 'jobCall.start',
runJobId,

View File

@ -2,7 +2,7 @@
import type { Pattern } from 'value-matcher'
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import createLogger from '@xen-orchestra/log'
import emitAsync from '@xen-orchestra/emit-async'
@ -162,7 +162,7 @@ export default class Jobs {
})
// it sends a report for the interrupted backup jobs
xo.on('plugins:registered', () =>
asyncMap(this._jobs.get(), job => {
asyncMapSettled(this._jobs.get(), job => {
// only the interrupted backup jobs have the runId property
if (job.runId === undefined) {
return

View File

@ -1,5 +1,5 @@
// @flow
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import createLogger from '@xen-orchestra/log'
import { fromEvent, ignoreErrors, timeout, using } from 'promise-toolbox'
import { parseDuration } from '@vates/parse-duration'
@ -195,7 +195,7 @@ export default class metadataBackup {
)
const metaDataFileName = `${dir}/metadata.json`
await asyncMap(handlers, async (handler, remoteId) => {
await asyncMapSettled(handlers, async (handler, remoteId) => {
const subTaskId = logger.notice(`Starting XO metadata backup for the remote (${remoteId}). (${job.id})`, {
data: {
id: remoteId,
@ -308,7 +308,7 @@ export default class metadataBackup {
)
const metaDataFileName = `${dir}/metadata.json`
await asyncMap(handlers, async (handler, remoteId) => {
await asyncMapSettled(handlers, async (handler, remoteId) => {
const subTaskId = logger.notice(
`Starting metadata backup for the pool (${poolId}) for the remote (${remoteId}). (${job.id})`,
{
@ -459,7 +459,7 @@ export default class metadataBackup {
const remotes = {}
const xapis = {}
await waitAll([
asyncMap(remoteIds, async id => {
asyncMapSettled(remoteIds, async id => {
const remote = await app.getRemoteWithCredentials(id)
if (remote.proxy !== proxyId) {
throw new Error(`The remote ${remote.name} must be linked to the proxy ${proxyId}`)
@ -467,7 +467,7 @@ export default class metadataBackup {
remotes[id] = remote
}),
asyncMap([...servers], async id => {
asyncMapSettled([...servers], async id => {
const { allowUnauthorized, host, password, username } = await app.getXenServer(id)
xapis[id] = {
allowUnauthorized,
@ -634,7 +634,7 @@ export default class metadataBackup {
})
const { id: jobId, settings } = job
await asyncMap(schedules, async (schedule, tmpId) => {
await asyncMapSettled(schedules, async (schedule, tmpId) => {
const { id: scheduleId } = await app.createSchedule({
...schedule,
jobId,
@ -657,7 +657,7 @@ export default class metadataBackup {
await Promise.all([
app.removeJob(id),
asyncMap(schedules, schedule => {
asyncMapSettled(schedules, schedule => {
if (schedule.id === id) {
return app.deleteSchedule(id)
}

View File

@ -1,4 +1,4 @@
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import synchronized from 'decorator-synchronized'
import { format, parse } from 'xo-remote-parser'
import { getHandler } from '@xen-orchestra/fs'
@ -120,7 +120,7 @@ export default class {
async getAllRemotesInfo() {
const remotesInfo = this._remotesInfo
await asyncMap(this._remotes.get(), async remote => {
await asyncMapSettled(this._remotes.get(), async remote => {
if (!remote.enabled) {
return
}

View File

@ -1,4 +1,4 @@
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import deferrable from 'golike-defer'
import synchronized from 'decorator-synchronized'
import { difference, every, forEach, isObject, keyBy, map as mapToArray, remove, some } from 'lodash'
@ -414,6 +414,6 @@ export default class {
}
const { subjects } = await this.getResourceSet(resourceSetId)
await asyncMap(subjects, subject => this._xo.addAcl(subject, vmId, 'admin'))
await asyncMapSettled(subjects, subject => this._xo.addAcl(subject, vmId, 'admin'))
}
}

View File

@ -1,6 +1,6 @@
// @flow
import asyncMap from '@xen-orchestra/async-map'
import asyncMapSettled from '@xen-orchestra/async-map'
import { createSchedule } from '@xen-orchestra/cron'
import { ignoreErrors } from 'promise-toolbox'
import { keyBy } from 'lodash'
@ -75,7 +75,7 @@ export default class Scheduling {
'schedules',
() => db.get(),
schedules =>
asyncMap(schedules, async schedule => {
asyncMapSettled(schedules, async schedule => {
await db.update(normalize(schedule))
this._start(schedule.id)
}),