summaryrefslogtreecommitdiff
path: root/opendc/opendc-compute/src
diff options
context:
space:
mode:
Diffstat (limited to 'opendc/opendc-compute/src')
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt4
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ComparableAllocationPolicyLogic.kt6
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/RandomAllocationPolicy.kt6
3 files changed, 13 insertions, 3 deletions
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt
index 85bdc438..2e483db4 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt
@@ -28,6 +28,7 @@ import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import kotlin.coroutines.Continuation
import kotlin.coroutines.resume
+import kotlin.math.max
@OptIn(ExperimentalCoroutinesApi::class)
class SimpleVirtProvisioningService(
@@ -121,8 +122,9 @@ class SimpleVirtProvisioningService(
for (imageInstance in imagesToBeScheduled) {
val requiredMemory = (imageInstance.image as VmImage).requiredMemory
val selectedHv = allocationLogic.select(availableHypervisors, imageInstance) ?: break
+
try {
- log.info("Spawning ${imageInstance.image} on ${selectedHv.server} ${availableHypervisors.size}")
+ log.info("Spawning ${imageInstance.image} on ${selectedHv.server}")
incomingImages -= imageInstance
// Speculatively update the hypervisor view information to prevent other images in the queue from
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ComparableAllocationPolicyLogic.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ComparableAllocationPolicyLogic.kt
index 5e41bcef..79dd95f3 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ComparableAllocationPolicyLogic.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/ComparableAllocationPolicyLogic.kt
@@ -42,7 +42,11 @@ interface ComparableAllocationPolicyLogic : AllocationPolicy.Logic {
image: SimpleVirtProvisioningService.ImageView
): HypervisorView? {
return hypervisors.asSequence()
- .filter { it.availableMemory >= (image.image as VmImage).requiredMemory }
+ .filter { hv ->
+ val fitsMemory = hv.availableMemory >= (image.image as VmImage).requiredMemory
+ val fitsCpu = hv.server.flavor.cpuCount >= image.flavor.cpuCount
+ fitsMemory && fitsCpu
+ }
.minWith(comparator.thenBy { it.server.uid })
}
}
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/RandomAllocationPolicy.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/RandomAllocationPolicy.kt
index 142846ac..07dcf1c5 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/RandomAllocationPolicy.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/RandomAllocationPolicy.kt
@@ -40,7 +40,11 @@ public class RandomAllocationPolicy(val random: Random = Random(0)) : Allocation
image: SimpleVirtProvisioningService.ImageView
): HypervisorView? {
return hypervisors.asIterable()
- .filter { it.availableMemory >= (image.image as VmImage).requiredMemory }
+ .filter { hv ->
+ val fitsMemory = hv.availableMemory >= (image.image as VmImage).requiredMemory
+ val fitsCpu = hv.server.flavor.cpuCount >= image.flavor.cpuCount
+ fitsMemory && fitsCpu
+ }
.randomOrNull(random)
}
}