summaryrefslogtreecommitdiff
path: root/opendc/opendc-compute/src
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2020-05-05 22:37:38 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-05-05 22:37:38 +0200
commit9d17c77a85d7d88287b06a521b0c6358f589ca9a (patch)
treefe2d62da9b4fb0aa12c8bc3a1606924bafae3fa3 /opendc/opendc-compute/src
parent6981d5581e2ce5c6df42dfbf133c350bd9c35a0f (diff)
parentc4ba00bdb3a777dea866a043820e2df89ff81f86 (diff)
Merge branch '2.x-vm-placement' into '2.x'
VM Placement mimicing policy Closes #58 and #61 See merge request opendc/opendc-simulator!62
Diffstat (limited to 'opendc/opendc-compute/src')
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ReplayAllocationPolicy.kt25
1 files changed, 25 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..f88eaed8
--- /dev/null
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ReplayAllocationPolicy.kt
@@ -0,0 +1,25 @@
+package com.atlarge.opendc.compute.virt.service.allocation
+
+import com.atlarge.opendc.compute.virt.service.HypervisorView
+import com.atlarge.opendc.compute.virt.service.SimpleVirtProvisioningService
+
+/**
+ * Policy replaying VM-cluster assignnment.
+ *
+ * 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 {
+ override fun invoke(): AllocationPolicy.Logic = object : AllocationPolicy.Logic {
+ override fun select(
+ hypervisors: Set<HypervisorView>,
+ image: SimpleVirtProvisioningService.ImageView
+ ): HypervisorView? {
+ 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) }
+ return machinesInCluster.maxBy { it.availableMemory }
+ ?: throw IllegalStateException("Cloud not find any machines belonging to cluster $clusterName for image ${image.name}")
+ }
+ }
+}