summaryrefslogtreecommitdiff
path: root/opendc
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-05-20 15:05:25 +0200
committerGeorgios Andreadis <info@gandreadis.com>2020-05-20 16:02:43 +0200
commit1e24e8934396bf2947c0d3bd244c29c0ecff98a1 (patch)
treed83d4eecb92dadecee2da32e13d5e59ececb6670 /opendc
parent077d9da22a7877b56e967ed41a8e2f8dcd210b0e (diff)
Add fallback for placement info
Diffstat (limited to 'opendc')
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ReplayAllocationPolicy.kt16
1 files changed, 13 insertions, 3 deletions
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ReplayAllocationPolicy.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ReplayAllocationPolicy.kt
index f88eaed8..9e675e80 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ReplayAllocationPolicy.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ReplayAllocationPolicy.kt
@@ -2,14 +2,18 @@ package com.atlarge.opendc.compute.virt.service.allocation
import com.atlarge.opendc.compute.virt.service.HypervisorView
import com.atlarge.opendc.compute.virt.service.SimpleVirtProvisioningService
+import mu.KotlinLogging
+import kotlin.random.Random
+
+private val logger = KotlinLogging.logger {}
/**
- * Policy replaying VM-cluster assignnment.
+ * Policy replaying VM-cluster assignment.
*
* Within each cluster, the active servers on each node determine which node gets
* assigned the VM image.
*/
-class ReplayAllocationPolicy(val vmPlacements: Map<String, String>) : AllocationPolicy {
+class ReplayAllocationPolicy(val vmPlacements: Map<String, String>, val random: Random = Random(0)) : AllocationPolicy {
override fun invoke(): AllocationPolicy.Logic = object : AllocationPolicy.Logic {
override fun select(
hypervisors: Set<HypervisorView>,
@@ -18,8 +22,14 @@ class ReplayAllocationPolicy(val vmPlacements: Map<String, String>) : Allocation
val clusterName = vmPlacements[image.name]
?: throw IllegalStateException("Could not find placement data in VM placement file for VM ${image.name}")
val machinesInCluster = hypervisors.filter { it.server.name.contains(clusterName) }
+
+ if (machinesInCluster.isEmpty()) {
+ logger.info { "Could not find any machines belonging to cluster $clusterName for image ${image.name}, assigning randomly." }
+ return hypervisors.random(random)
+ }
+
return machinesInCluster.maxBy { it.availableMemory }
- ?: throw IllegalStateException("Cloud not find any machines belonging to cluster $clusterName for image ${image.name}")
+ ?: throw IllegalStateException("Cloud not find any machine and could not randomly assign")
}
}
}