From c27c43fd0f34b8ae95ce2a0939d827530b9e2bf2 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Tue, 5 May 2020 18:16:40 +0200 Subject: Add basic replay policy --- .../virt/service/allocation/ReplayAllocationPolicy.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ReplayAllocationPolicy.kt (limited to 'opendc/opendc-compute/src') 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) : AllocationPolicy { + override fun invoke(): AllocationPolicy.Logic = object : AllocationPolicy.Logic { + override fun select( + hypervisors: Set, + 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}") + } + } +} -- cgit v1.2.3