summaryrefslogtreecommitdiff
path: root/opendc/opendc-compute/src
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-05-05 18:16:40 +0200
committerGeorgios Andreadis <info@gandreadis.com>2020-05-05 18:16:40 +0200
commitc27c43fd0f34b8ae95ce2a0939d827530b9e2bf2 (patch)
tree36df1b0ddc0d362983f66da78f389a122abdcdd3 /opendc/opendc-compute/src
parent6981d5581e2ce5c6df42dfbf133c350bd9c35a0f (diff)
Add basic replay policy
Diffstat (limited to 'opendc/opendc-compute/src')
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ReplayAllocationPolicy.kt19
1 files changed, 19 insertions, 0 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
new file mode 100644
index 00000000..31731256
--- /dev/null
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ReplayAllocationPolicy.kt
@@ -0,0 +1,19 @@
+package com.atlarge.opendc.compute.virt.service.allocation
+
+import com.atlarge.opendc.compute.virt.service.HypervisorView
+import com.atlarge.opendc.compute.virt.service.SimpleVirtProvisioningService
+
+class ReplayAllocationPolicy(val vmPlacements: Map<String, String>) : AllocationPolicy {
+ override fun invoke(): AllocationPolicy.Logic = object : AllocationPolicy.Logic {
+ override fun select(
+ hypervisors: Set<HypervisorView>,
+ image: SimpleVirtProvisioningService.ImageView
+ ): HypervisorView? {
+ val clusterName = vmPlacements[image.name]
+ ?: throw IllegalArgumentException("Could not find placement data in VM placement file for VM ${image.name}")
+ val machinesInCluster = hypervisors.filter { it.server.name.contains(clusterName) }
+ return machinesInCluster.minBy { it.numberOfActiveServers }
+ ?: throw IllegalArgumentException("Cloud not find any machines belonging to cluster $clusterName for image ${image.name}")
+ }
+ }
+}