diff options
| author | Georgios Andreadis <info@gandreadis.com> | 2020-05-05 18:16:40 +0200 |
|---|---|---|
| committer | Georgios Andreadis <info@gandreadis.com> | 2020-05-05 18:16:40 +0200 |
| commit | c27c43fd0f34b8ae95ce2a0939d827530b9e2bf2 (patch) | |
| tree | 36df1b0ddc0d362983f66da78f389a122abdcdd3 /opendc/opendc-compute/src | |
| parent | 6981d5581e2ce5c6df42dfbf133c350bd9c35a0f (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.kt | 19 |
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}") + } + } +} |
