chore: change print width to 120 chars
This commit is contained in:
@@ -1,3 +1 @@
|
||||
module.exports = require('../../@xen-orchestra/babel-config')(
|
||||
require('./package.json')
|
||||
)
|
||||
module.exports = require('../../@xen-orchestra/babel-config')(require('./package.json'))
|
||||
|
||||
@@ -99,9 +99,7 @@ export default class DensityPlan extends Plan {
|
||||
|
||||
for (const vm of vms) {
|
||||
if (!vm.xenTools) {
|
||||
debug(
|
||||
`VM (${vm.id}) of Host (${hostId}) does not support pool migration.`
|
||||
)
|
||||
debug(`VM (${vm.id}) of Host (${hostId}) does not support pool migration.`)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -151,9 +149,7 @@ export default class DensityPlan extends Plan {
|
||||
} = this
|
||||
|
||||
// Sort the destinations by available memory. (- -> +)
|
||||
destinations.sort(
|
||||
(a, b) => hostsAverages[a.id].memoryFree - hostsAverages[b.id].memoryFree
|
||||
)
|
||||
destinations.sort((a, b) => hostsAverages[a.id].memoryFree - hostsAverages[b.id].memoryFree)
|
||||
|
||||
for (const destination of destinations) {
|
||||
const destinationAverages = hostsAverages[destination.id]
|
||||
@@ -188,14 +184,8 @@ export default class DensityPlan extends Plan {
|
||||
mapToArray(moves, move => {
|
||||
const { vm, destination } = move
|
||||
const xapiDest = this.xo.getXapi(destination)
|
||||
debug(
|
||||
`Migrate VM (${vm.id}) to Host (${destination.id}) from Host (${vm.$container}).`
|
||||
)
|
||||
return xapiDest.migrateVm(
|
||||
vm._xapiId,
|
||||
this.xo.getXapi(destination),
|
||||
destination._xapiId
|
||||
)
|
||||
debug(`Migrate VM (${vm.id}) to Host (${destination.id}) from Host (${vm.$container}).`)
|
||||
return xapiDest.migrateVm(vm._xapiId, this.xo.getXapi(destination), destination._xapiId)
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
@@ -3,10 +3,7 @@ import { intersection, map as mapToArray, uniq } from 'lodash'
|
||||
|
||||
import DensityPlan from './density-plan'
|
||||
import PerformancePlan from './performance-plan'
|
||||
import {
|
||||
DEFAULT_CRITICAL_THRESHOLD_CPU,
|
||||
DEFAULT_CRITICAL_THRESHOLD_MEMORY_FREE,
|
||||
} from './plan'
|
||||
import { DEFAULT_CRITICAL_THRESHOLD_CPU, DEFAULT_CRITICAL_THRESHOLD_MEMORY_FREE } from './plan'
|
||||
import { EXECUTION_DELAY, debug } from './utils'
|
||||
|
||||
// ===================================================================
|
||||
@@ -96,18 +93,13 @@ class LoadBalancerPlugin {
|
||||
constructor(xo) {
|
||||
this.xo = xo
|
||||
|
||||
this._job = createSchedule(`*/${EXECUTION_DELAY} * * * *`).createJob(
|
||||
async () => {
|
||||
try {
|
||||
await this._executePlans()
|
||||
} catch (error) {
|
||||
console.error(
|
||||
'[WARN] scheduled function:',
|
||||
(error && error.stack) || error
|
||||
)
|
||||
}
|
||||
this._job = createSchedule(`*/${EXECUTION_DELAY} * * * *`).createJob(async () => {
|
||||
try {
|
||||
await this._executePlans()
|
||||
} catch (error) {
|
||||
console.error('[WARN] scheduled function:', (error && error.stack) || error)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
async configure({ plans }) {
|
||||
@@ -116,10 +108,7 @@ class LoadBalancerPlugin {
|
||||
|
||||
if (plans) {
|
||||
for (const plan of plans) {
|
||||
this._addPlan(
|
||||
plan.mode === 'Performance mode' ? PERFORMANCE_MODE : DENSITY_MODE,
|
||||
plan
|
||||
)
|
||||
this._addPlan(plan.mode === 'Performance mode' ? PERFORMANCE_MODE : DENSITY_MODE, plan)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@ export default class PerformancePlan extends Plan {
|
||||
const objectAverages = averages[object.id]
|
||||
|
||||
return (
|
||||
objectAverages.cpu >= this._thresholds.cpu.high ||
|
||||
objectAverages.memoryFree <= this._thresholds.memoryFree.high
|
||||
objectAverages.cpu >= this._thresholds.cpu.high || objectAverages.memoryFree <= this._thresholds.memoryFree.high
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -35,10 +34,7 @@ export default class PerformancePlan extends Plan {
|
||||
try {
|
||||
await Promise.all(
|
||||
mapToArray(
|
||||
filter(
|
||||
this._getHosts({ powerState: 'Halted' }),
|
||||
host => host.powerOnMode !== ''
|
||||
),
|
||||
filter(this._getHosts({ powerState: 'Halted' }), host => host.powerOnMode !== ''),
|
||||
host => {
|
||||
const { id } = host
|
||||
return this.xo.getXapi(id).powerOnHost(id)
|
||||
@@ -94,8 +90,7 @@ export default class PerformancePlan extends Plan {
|
||||
const xapiSrc = this.xo.getXapi(exceededHost)
|
||||
let optimizationsCount = 0
|
||||
|
||||
const searchFunction = (a, b) =>
|
||||
hostsAverages[b.id].cpu - hostsAverages[a.id].cpu
|
||||
const searchFunction = (a, b) => hostsAverages[b.id].cpu - hostsAverages[a.id].cpu
|
||||
|
||||
for (const vm of vms) {
|
||||
debug(`Trying to migrate ${vm.id}...`)
|
||||
@@ -107,32 +102,25 @@ export default class PerformancePlan extends Plan {
|
||||
)
|
||||
|
||||
if (!destination) {
|
||||
debug(
|
||||
'No destination host found in the current VM pool. Trying in all pools.'
|
||||
)
|
||||
debug('No destination host found in the current VM pool. Trying in all pools.')
|
||||
destination = searchBestObject(hosts, searchFunction)
|
||||
}
|
||||
|
||||
const destinationAverages = hostsAverages[destination.id]
|
||||
const vmAverages = vmsAverages[vm.id]
|
||||
|
||||
debug(
|
||||
`Trying to migrate VM (${vm.id}) to Host (${destination.id}) from Host (${exceededHost.id})...`
|
||||
)
|
||||
debug(`Trying to migrate VM (${vm.id}) to Host (${destination.id}) from Host (${exceededHost.id})...`)
|
||||
|
||||
// Unable to move the vm.
|
||||
if (
|
||||
exceededAverages.cpu - vmAverages.cpu <
|
||||
destinationAverages.cpu + vmAverages.cpu ||
|
||||
exceededAverages.cpu - vmAverages.cpu < destinationAverages.cpu + vmAverages.cpu ||
|
||||
destinationAverages.memoryFree < vmAverages.memory
|
||||
) {
|
||||
debug(`Cannot migrate VM (${vm.id}) to Host (${destination.id}).`)
|
||||
debug(
|
||||
`Src Host CPU=${exceededAverages.cpu}, Dest Host CPU=${destinationAverages.cpu}, VM CPU=${vmAverages.cpu}`
|
||||
)
|
||||
debug(
|
||||
`Dest Host free RAM=${destinationAverages.memoryFree}, VM used RAM=${vmAverages.memory})`
|
||||
)
|
||||
debug(`Dest Host free RAM=${destinationAverages.memoryFree}, VM used RAM=${vmAverages.memory})`)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -142,23 +130,13 @@ export default class PerformancePlan extends Plan {
|
||||
exceededAverages.memoryFree += vmAverages.memory
|
||||
destinationAverages.memoryFree -= vmAverages.memory
|
||||
|
||||
debug(
|
||||
`Migrate VM (${vm.id}) to Host (${destination.id}) from Host (${exceededHost.id}).`
|
||||
)
|
||||
debug(`Migrate VM (${vm.id}) to Host (${destination.id}) from Host (${exceededHost.id}).`)
|
||||
optimizationsCount++
|
||||
|
||||
promises.push(
|
||||
xapiSrc.migrateVm(
|
||||
vm._xapiId,
|
||||
this.xo.getXapi(destination),
|
||||
destination._xapiId
|
||||
)
|
||||
)
|
||||
promises.push(xapiSrc.migrateVm(vm._xapiId, this.xo.getXapi(destination), destination._xapiId))
|
||||
}
|
||||
|
||||
await Promise.all(promises)
|
||||
debug(
|
||||
`Performance mode: ${optimizationsCount} optimizations for Host (${exceededHost.id}).`
|
||||
)
|
||||
debug(`Performance mode: ${optimizationsCount} optimizations for Host (${exceededHost.id}).`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,7 @@ function computeRessourcesAverage(objects, objectsStats, nPoints) {
|
||||
const { stats } = objectsStats[id]
|
||||
|
||||
averages[id] = {
|
||||
cpu: computeAverage(
|
||||
mapToArray(stats.cpus, cpu => computeAverage(cpu, nPoints))
|
||||
),
|
||||
cpu: computeAverage(mapToArray(stats.cpus, cpu => computeAverage(cpu, nPoints))),
|
||||
nCpus: size(stats.cpus),
|
||||
memoryFree: computeAverage(stats.memoryFree, nPoints),
|
||||
memory: computeAverage(stats.memory, nPoints),
|
||||
@@ -79,8 +77,7 @@ function computeRessourcesAverageWithWeight(averages1, averages2, ratio) {
|
||||
continue
|
||||
}
|
||||
|
||||
objectAverages[averageName] =
|
||||
average1 * ratio + averages2[id][averageName] * (1 - ratio)
|
||||
objectAverages[averageName] = average1 * ratio + averages2[id][averageName] * (1 - ratio)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,17 +101,10 @@ export default class Plan {
|
||||
this._excludedHosts = excludedHosts
|
||||
this._thresholds = {
|
||||
cpu: {
|
||||
critical: numberOrDefault(
|
||||
thresholds && thresholds.cpu,
|
||||
DEFAULT_CRITICAL_THRESHOLD_CPU
|
||||
),
|
||||
critical: numberOrDefault(thresholds && thresholds.cpu, DEFAULT_CRITICAL_THRESHOLD_CPU),
|
||||
},
|
||||
memoryFree: {
|
||||
critical:
|
||||
numberOrDefault(
|
||||
thresholds && thresholds.memoryFree,
|
||||
DEFAULT_CRITICAL_THRESHOLD_MEMORY_FREE
|
||||
) * 1024,
|
||||
critical: numberOrDefault(thresholds && thresholds.memoryFree, DEFAULT_CRITICAL_THRESHOLD_MEMORY_FREE) * 1024,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -155,16 +145,8 @@ export default class Plan {
|
||||
}
|
||||
|
||||
// Check in the last 30 min interval with ratio.
|
||||
const avgBefore = computeRessourcesAverage(
|
||||
hosts,
|
||||
hostsStats,
|
||||
MINUTES_OF_HISTORICAL_DATA
|
||||
)
|
||||
const avgWithRatio = computeRessourcesAverageWithWeight(
|
||||
avgNow,
|
||||
avgBefore,
|
||||
0.75
|
||||
)
|
||||
const avgBefore = computeRessourcesAverage(hosts, hostsStats, MINUTES_OF_HISTORICAL_DATA)
|
||||
const avgWithRatio = computeRessourcesAverageWithWeight(avgNow, avgBefore, 0.75)
|
||||
|
||||
toOptimize = this._checkRessourcesThresholds(toOptimize, avgWithRatio)
|
||||
|
||||
@@ -218,10 +200,7 @@ export default class Plan {
|
||||
async _getVms(hostId) {
|
||||
return filter(
|
||||
this.xo.getObjects(),
|
||||
object =>
|
||||
object.type === 'VM' &&
|
||||
object.power_state === 'Running' &&
|
||||
object.$container === hostId
|
||||
object => object.type === 'VM' && object.power_state === 'Running' && object.$container === hostId
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,4 @@ export const EXECUTION_DELAY = 1
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export const debug = LOAD_BALANCER_DEBUG
|
||||
? str => console.log(`[load-balancer]${str}`)
|
||||
: noop
|
||||
export const debug = LOAD_BALANCER_DEBUG ? str => console.log(`[load-balancer]${str}`) : noop
|
||||
|
||||
Reference in New Issue
Block a user