chore: reformat with Prettier

This commit is contained in:
Julien Fontanet
2018-12-11 10:45:00 +01:00
parent 48727740c4
commit cc4ab94428
300 changed files with 1880 additions and 1728 deletions
@@ -6,7 +6,7 @@ import { debug } from './utils'
// ===================================================================
export default class DensityPlan extends Plan {
_checkRessourcesThresholds (objects, averages) {
_checkRessourcesThresholds(objects, averages) {
const { low } = this._thresholds.memoryFree
return filter(objects, object => {
const { memory, memoryFree = memory } = averages[object.id]
@@ -14,7 +14,7 @@ export default class DensityPlan extends Plan {
})
}
async execute () {
async execute() {
const results = await this._findHostsToOptimize()
if (!results) {
@@ -89,7 +89,7 @@ export default class DensityPlan extends Plan {
debug(`Density mode: ${optimizationsCount} optimizations.`)
}
async _simulate ({ host, destinations, hostsAverages }) {
async _simulate({ host, destinations, hostsAverages }) {
const { id: hostId } = host
debug(`Try to optimize Host (${hostId}).`)
@@ -145,7 +145,7 @@ export default class DensityPlan extends Plan {
}
// Test if a VM migration on a destination (of a destinations set) is possible.
_testMigration ({ vm, destinations, hostsAverages, vmsAverages }) {
_testMigration({ vm, destinations, hostsAverages, vmsAverages }) {
const {
_thresholds: { critical: criticalThreshold },
} = this
@@ -181,7 +181,7 @@ export default class DensityPlan extends Plan {
// Migrate the VMs of one host.
// Try to shutdown the VMs host.
async _migrate (hostId, moves) {
async _migrate(hostId, moves) {
const xapiSrc = this.xo.getXapi(hostId)
await Promise.all(
@@ -93,7 +93,7 @@ export const configurationSchema = {
// ===================================================================
class LoadBalancerPlugin {
constructor (xo) {
constructor(xo) {
this.xo = xo
this._job = createSchedule(`*/${EXECUTION_DELAY} * * * *`).createJob(
@@ -110,7 +110,7 @@ class LoadBalancerPlugin {
)
}
async configure ({ plans }) {
async configure({ plans }) {
this._plans = []
this._poolIds = [] // Used pools.
@@ -124,15 +124,15 @@ class LoadBalancerPlugin {
}
}
load () {
load() {
this._job.start()
}
unload () {
unload() {
this._job.stop()
}
_addPlan (mode, { name, pools, ...options }) {
_addPlan(mode, { name, pools, ...options }) {
pools = uniq(pools)
// Check already used pools.
@@ -148,7 +148,7 @@ class LoadBalancerPlugin {
)
}
_executePlans () {
_executePlans() {
debug('Execute plans!')
return Promise.all(mapToArray(this._plans, plan => plan.execute()))
@@ -4,7 +4,7 @@ import Plan from './plan'
import { debug } from './utils'
// Compare a list of objects and give the best.
function searchBestObject (objects, fun) {
function searchBestObject(objects, fun) {
let object = objects[0]
for (let i = 1; i < objects.length; i++) {
@@ -19,7 +19,7 @@ function searchBestObject (objects, fun) {
// ===================================================================
export default class PerformancePlan extends Plan {
_checkRessourcesThresholds (objects, averages) {
_checkRessourcesThresholds(objects, averages) {
return filter(objects, object => {
const objectAverages = averages[object.id]
@@ -30,7 +30,7 @@ export default class PerformancePlan extends Plan {
})
}
async execute () {
async execute() {
// Try to power on a hosts set.
try {
await Promise.all(
@@ -80,7 +80,7 @@ export default class PerformancePlan extends Plan {
}
}
async _optimize ({ exceededHost, hosts, hostsAverages }) {
async _optimize({ exceededHost, hosts, hostsAverages }) {
const vms = await this._getVms(exceededHost.id)
const vmsAverages = await this._getVmsAverages(vms, exceededHost)
+14 -14
View File
@@ -23,7 +23,7 @@ const numberOrDefault = (value, def) => (value >= 0 ? value : def)
// Averages.
// ===================================================================
function computeAverage (values, nPoints) {
function computeAverage(values, nPoints) {
if (values === undefined) {
return
}
@@ -47,7 +47,7 @@ function computeAverage (values, nPoints) {
return sum / tot
}
function computeRessourcesAverage (objects, objectsStats, nPoints) {
function computeRessourcesAverage(objects, objectsStats, nPoints) {
const averages = {}
for (const object of objects) {
@@ -67,7 +67,7 @@ function computeRessourcesAverage (objects, objectsStats, nPoints) {
return averages
}
function computeRessourcesAverageWithWeight (averages1, averages2, ratio) {
function computeRessourcesAverageWithWeight(averages1, averages2, ratio) {
const averages = {}
for (const id in averages1) {
@@ -87,7 +87,7 @@ function computeRessourcesAverageWithWeight (averages1, averages2, ratio) {
return averages
}
function setRealCpuAverageOfVms (vms, vmsAverages, nCpus) {
function setRealCpuAverageOfVms(vms, vmsAverages, nCpus) {
for (const vm of vms) {
const averages = vmsAverages[vm.id]
averages.cpu *= averages.nCpus / nCpus
@@ -97,7 +97,7 @@ function setRealCpuAverageOfVms (vms, vmsAverages, nCpus) {
// ===================================================================
export default class Plan {
constructor (xo, name, poolIds, { excludedHosts, thresholds } = {}) {
constructor(xo, name, poolIds, { excludedHosts, thresholds } = {}) {
this.xo = xo
this._name = name
this._poolIds = poolIds
@@ -132,7 +132,7 @@ export default class Plan {
}
}
execute () {
execute() {
throw new Error('Not implemented')
}
@@ -140,7 +140,7 @@ export default class Plan {
// Get hosts to optimize.
// ===================================================================
async _findHostsToOptimize () {
async _findHostsToOptimize() {
const hosts = this._getHosts()
const hostsStats = await this._getHostsStats(hosts, 'minutes')
@@ -181,7 +181,7 @@ export default class Plan {
}
}
_checkRessourcesThresholds () {
_checkRessourcesThresholds() {
throw new Error('Not implemented')
}
@@ -189,7 +189,7 @@ export default class Plan {
// Get objects.
// ===================================================================
_getPlanPools () {
_getPlanPools() {
const pools = {}
try {
@@ -204,7 +204,7 @@ export default class Plan {
}
// Compute hosts for each pool. They can change over time.
_getHosts ({ powerState = 'Running' } = {}) {
_getHosts({ powerState = 'Running' } = {}) {
return filter(
this.xo.getObjects(),
object =>
@@ -215,7 +215,7 @@ export default class Plan {
)
}
async _getVms (hostId) {
async _getVms(hostId) {
return filter(
this.xo.getObjects(),
object =>
@@ -229,7 +229,7 @@ export default class Plan {
// Get stats.
// ===================================================================
async _getHostsStats (hosts, granularity) {
async _getHostsStats(hosts, granularity) {
const hostsStats = {}
await Promise.all(
@@ -247,7 +247,7 @@ export default class Plan {
return hostsStats
}
async _getVmsStats (vms, granularity) {
async _getVmsStats(vms, granularity) {
const vmsStats = {}
await Promise.all(
@@ -265,7 +265,7 @@ export default class Plan {
return vmsStats
}
async _getVmsAverages (vms, host) {
async _getVmsAverages(vms, host) {
const vmsStats = await this._getVmsStats(vms, 'minutes')
const vmsAverages = computeRessourcesAverageWithWeight(
computeRessourcesAverage(vms, vmsStats, EXECUTION_DELAY),