summaryrefslogtreecommitdiff
path: root/simulator/opendc-compute
diff options
context:
space:
mode:
Diffstat (limited to 'simulator/opendc-compute')
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/ComputeService.kt17
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/AllocationPolicy.kt49
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/AvailableCoreMemoryAllocationPolicy.kt38
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/AvailableMemoryAllocationPolicy.kt37
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ComparableAllocationPolicyLogic.kt49
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/LegacyScheduler.kt46
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/NumberOfActiveServersAllocationPolicy.kt37
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ProvisionedCoresAllocationPolicy.kt40
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/RandomAllocationPolicy.kt48
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ReplayAllocationPolicy.kt56
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/scheduler/AllocationPolicyTest.kt219
11 files changed, 0 insertions, 636 deletions
diff --git a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/ComputeService.kt b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/ComputeService.kt
index 045a2ed3..1873eb99 100644
--- a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/ComputeService.kt
+++ b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/ComputeService.kt
@@ -26,9 +26,7 @@ import io.opentelemetry.api.metrics.Meter
import org.opendc.compute.api.ComputeClient
import org.opendc.compute.service.driver.Host
import org.opendc.compute.service.internal.ComputeServiceImpl
-import org.opendc.compute.service.scheduler.AllocationPolicy
import org.opendc.compute.service.scheduler.ComputeScheduler
-import org.opendc.compute.service.scheduler.LegacyScheduler
import java.time.Clock
import kotlin.coroutines.CoroutineContext
@@ -72,21 +70,6 @@ public interface ComputeService : AutoCloseable {
*
* @param context The [CoroutineContext] to use in the service.
* @param clock The clock instance to use.
- * @param allocationPolicy The allocation policy to use.
- */
- public operator fun invoke(
- context: CoroutineContext,
- clock: Clock,
- meter: Meter,
- allocationPolicy: AllocationPolicy,
- schedulingQuantum: Long = 300000,
- ): ComputeService = invoke(context, clock, meter, LegacyScheduler(allocationPolicy), schedulingQuantum)
-
- /**
- * Construct a new [ComputeService] implementation.
- *
- * @param context The [CoroutineContext] to use in the service.
- * @param clock The clock instance to use.
* @param scheduler The scheduler implementation to use.
*/
public operator fun invoke(
diff --git a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/AllocationPolicy.kt b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/AllocationPolicy.kt
deleted file mode 100644
index 5ee4c70f..00000000
--- a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/AllocationPolicy.kt
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2020 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.compute.service.scheduler
-
-import org.opendc.compute.api.Server
-import org.opendc.compute.service.internal.HostView
-
-/**
- * A policy for selecting the [Node] an image should be deployed to,
- */
-public interface AllocationPolicy {
- /**
- * The logic of the allocation policy.
- */
- public interface Logic {
- /**
- * Select the node on which the server should be scheduled.
- */
- public fun select(
- hypervisors: Set<HostView>,
- server: Server
- ): HostView?
- }
-
- /**
- * Builds the logic of the policy.
- */
- public operator fun invoke(): Logic
-}
diff --git a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/AvailableCoreMemoryAllocationPolicy.kt b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/AvailableCoreMemoryAllocationPolicy.kt
deleted file mode 100644
index ad422415..00000000
--- a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/AvailableCoreMemoryAllocationPolicy.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2020 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.compute.service.scheduler
-
-import org.opendc.compute.service.internal.HostView
-
-/**
- * An [AllocationPolicy] that selects the machine with the highest/lowest amount of memory per core.
- *
- * @param reversed An option to reverse the order of the machines (lower amount of memory scores better).
- */
-public class AvailableCoreMemoryAllocationPolicy(private val reversed: Boolean = false) : AllocationPolicy {
- override fun invoke(): AllocationPolicy.Logic = object : ComparableAllocationPolicyLogic {
- override val comparator: Comparator<HostView> =
- compareBy<HostView> { -it.availableMemory / it.host.model.cpuCount }
- .run { if (reversed) reversed() else this }
- }
-}
diff --git a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/AvailableMemoryAllocationPolicy.kt b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/AvailableMemoryAllocationPolicy.kt
deleted file mode 100644
index 6712b8a2..00000000
--- a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/AvailableMemoryAllocationPolicy.kt
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2020 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.compute.service.scheduler
-
-import org.opendc.compute.service.internal.HostView
-
-/**
- * Allocation policy that selects the node with the most available memory.
- *
- * @param reversed A flag to reverse the order (least amount of memory scores the best).
- */
-public class AvailableMemoryAllocationPolicy(public val reversed: Boolean = false) : AllocationPolicy {
- override fun invoke(): AllocationPolicy.Logic = object : ComparableAllocationPolicyLogic {
- override val comparator: Comparator<HostView> = compareBy<HostView> { -it.availableMemory }
- .run { if (reversed) reversed() else this }
- }
-}
diff --git a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ComparableAllocationPolicyLogic.kt b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ComparableAllocationPolicyLogic.kt
deleted file mode 100644
index 265d514d..00000000
--- a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ComparableAllocationPolicyLogic.kt
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2020 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.compute.service.scheduler
-
-import org.opendc.compute.api.Server
-import org.opendc.compute.service.internal.HostView
-
-/**
- * The logic for an [AllocationPolicy] that uses a [Comparator] to select the appropriate node.
- */
-public interface ComparableAllocationPolicyLogic : AllocationPolicy.Logic {
- /**
- * The comparator to use.
- */
- public val comparator: Comparator<HostView>
-
- override fun select(
- hypervisors: Set<HostView>,
- server: Server
- ): HostView? {
- return hypervisors.asSequence()
- .filter { hv ->
- val fitsMemory = hv.availableMemory >= (server.flavor.memorySize)
- val fitsCpu = hv.host.model.cpuCount >= server.flavor.cpuCount
- fitsMemory && fitsCpu
- }
- .minWithOrNull(comparator.thenBy { it.host.uid })
- }
-}
diff --git a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/LegacyScheduler.kt b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/LegacyScheduler.kt
deleted file mode 100644
index 3ce3deb1..00000000
--- a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/LegacyScheduler.kt
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.compute.service.scheduler
-
-import org.opendc.compute.api.Server
-import org.opendc.compute.service.internal.HostView
-
-/**
- * A [ComputeScheduler] that supports the legacy [AllocationPolicy] instances.
- */
-public class LegacyScheduler(policy: AllocationPolicy) : ComputeScheduler {
- private val policy = policy.invoke()
- private val hosts = mutableSetOf<HostView>()
-
- override fun addHost(host: HostView) {
- hosts.add(host)
- }
-
- override fun removeHost(host: HostView) {
- hosts.remove(host)
- }
-
- override fun select(server: Server): HostView? {
- return policy.select(hosts, server)
- }
-}
diff --git a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/NumberOfActiveServersAllocationPolicy.kt b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/NumberOfActiveServersAllocationPolicy.kt
deleted file mode 100644
index fb161f14..00000000
--- a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/NumberOfActiveServersAllocationPolicy.kt
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2020 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.compute.service.scheduler
-
-import org.opendc.compute.service.internal.HostView
-
-/**
- * Allocation policy that selects the node with the least amount of active servers.
- *
- * @param reversed A flag to reverse the order, such that the node with the most active servers is selected.
- */
-public class NumberOfActiveServersAllocationPolicy(public val reversed: Boolean = false) : AllocationPolicy {
- override fun invoke(): AllocationPolicy.Logic = object : ComparableAllocationPolicyLogic {
- override val comparator: Comparator<HostView> = compareBy<HostView> { it.instanceCount }
- .run { if (reversed) reversed() else this }
- }
-}
diff --git a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ProvisionedCoresAllocationPolicy.kt b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ProvisionedCoresAllocationPolicy.kt
deleted file mode 100644
index 4c196953..00000000
--- a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ProvisionedCoresAllocationPolicy.kt
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2020 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.compute.service.scheduler
-
-import org.opendc.compute.service.internal.HostView
-
-/**
- * An [AllocationPolicy] that takes into account the number of vCPUs that have been provisioned on this machine
- * relative to its core count.
- *
- * @param reversed A flag to reverse the order of the policy, such that the machine with the most provisioned cores
- * is selected.
- */
-public class ProvisionedCoresAllocationPolicy(private val reversed: Boolean = false) : AllocationPolicy {
- override fun invoke(): AllocationPolicy.Logic = object : ComparableAllocationPolicyLogic {
- override val comparator: Comparator<HostView> =
- compareBy<HostView> { it.provisionedCores / it.host.model.cpuCount }
- .run { if (reversed) reversed() else this }
- }
-}
diff --git a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/RandomAllocationPolicy.kt b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/RandomAllocationPolicy.kt
deleted file mode 100644
index 006e0d1c..00000000
--- a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/RandomAllocationPolicy.kt
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2020 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.compute.service.scheduler
-
-import org.opendc.compute.api.Server
-import org.opendc.compute.service.internal.HostView
-import kotlin.random.Random
-
-/**
- * An [AllocationPolicy] that select a random node on which the server fits.
- */
-public class RandomAllocationPolicy(private val random: Random = Random(0)) : AllocationPolicy {
- @OptIn(ExperimentalStdlibApi::class)
- override fun invoke(): AllocationPolicy.Logic = object : AllocationPolicy.Logic {
- override fun select(
- hypervisors: Set<HostView>,
- server: Server
- ): HostView? {
- return hypervisors.asIterable()
- .filter { hv ->
- val fitsMemory = hv.availableMemory >= server.flavor.memorySize
- val fitsCpu = hv.host.model.cpuCount >= server.flavor.cpuCount
- fitsMemory && fitsCpu
- }
- .randomOrNull(random)
- }
- }
-}
diff --git a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ReplayAllocationPolicy.kt b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ReplayAllocationPolicy.kt
deleted file mode 100644
index 2c953f8b..00000000
--- a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ReplayAllocationPolicy.kt
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2020 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.compute.service.scheduler
-
-import mu.KotlinLogging
-import org.opendc.compute.api.Server
-import org.opendc.compute.service.internal.HostView
-
-/**
- * Policy replaying VM-cluster assignment.
- *
- * Within each cluster, the active servers on each node determine which node gets
- * assigned the VM image.
- */
-public class ReplayAllocationPolicy(private val vmPlacements: Map<String, String>) : AllocationPolicy {
- private val logger = KotlinLogging.logger {}
-
- override fun invoke(): AllocationPolicy.Logic = object : AllocationPolicy.Logic {
- override fun select(
- hypervisors: Set<HostView>,
- server: Server
- ): HostView? {
- val clusterName = vmPlacements[server.name]
- ?: throw IllegalStateException("Could not find placement data in VM placement file for VM ${server.name}")
- val machinesInCluster = hypervisors.filter { it.host.name.contains(clusterName) }
-
- if (machinesInCluster.isEmpty()) {
- logger.info { "Could not find any machines belonging to cluster $clusterName for image ${server.name}, assigning randomly." }
- return hypervisors.maxByOrNull { it.availableMemory }
- }
-
- return machinesInCluster.maxByOrNull { it.availableMemory }
- ?: throw IllegalStateException("Cloud not find any machine and could not randomly assign")
- }
- }
-}
diff --git a/simulator/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/scheduler/AllocationPolicyTest.kt b/simulator/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/scheduler/AllocationPolicyTest.kt
deleted file mode 100644
index 7227d225..00000000
--- a/simulator/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/scheduler/AllocationPolicyTest.kt
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.compute.service.scheduler
-
-import io.mockk.every
-import io.mockk.mockk
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.params.ParameterizedTest
-import org.junit.jupiter.params.provider.Arguments
-import org.junit.jupiter.params.provider.MethodSource
-import org.opendc.compute.api.Server
-import org.opendc.compute.service.internal.HostView
-import java.util.*
-import java.util.stream.Stream
-import kotlin.random.Random
-
-/**
- * Test suite for the [AllocationPolicy] interface.
- */
-internal class AllocationPolicyTest {
- @ParameterizedTest
- @MethodSource("activeServersArgs")
- fun testActiveServersPolicy(
- reversed: Boolean,
- hosts: Set<HostView>,
- server: Server,
- expectedHost: HostView?
- ) {
- val policy = NumberOfActiveServersAllocationPolicy(reversed)
- assertEquals(expectedHost, policy.invoke().select(hosts, server))
- }
-
- @ParameterizedTest
- @MethodSource("availableMemoryArgs")
- fun testAvailableMemoryPolicy(
- reversed: Boolean,
- hosts: Set<HostView>,
- server: Server,
- expectedHost: HostView?
- ) {
- val policy = AvailableMemoryAllocationPolicy(reversed)
- assertEquals(expectedHost, policy.invoke().select(hosts, server))
- }
-
- @ParameterizedTest
- @MethodSource("availableCoreMemoryArgs")
- fun testAvailableCoreMemoryPolicy(
- reversed: Boolean,
- hosts: Set<HostView>,
- server: Server,
- expectedHost: HostView?
- ) {
- val policy = AvailableMemoryAllocationPolicy(reversed)
- assertEquals(expectedHost, policy.invoke().select(hosts, server))
- }
-
- @ParameterizedTest
- @MethodSource("provisionedCoresArgs")
- fun testProvisionedPolicy(
- reversed: Boolean,
- hosts: Set<HostView>,
- server: Server,
- expectedHost: HostView?
- ) {
- val policy = ProvisionedCoresAllocationPolicy(reversed)
- assertEquals(expectedHost, policy.invoke().select(hosts, server))
- }
-
- @Suppress("unused")
- private companion object {
- /**
- * Test arguments for the [NumberOfActiveServersAllocationPolicy].
- */
- @JvmStatic
- fun activeServersArgs(): Stream<Arguments> {
- val random = Random(1)
- val hosts = List(4) { i ->
- val view = mockk<HostView>()
- every { view.host.uid } returns UUID(0, i.toLong())
- every { view.host.model.cpuCount } returns random.nextInt(1, 16)
- every { view.host.model.memorySize } returns random.nextLong(1024, 1024 * 1024)
- every { view.availableMemory } returns random.nextLong(0, view.host.model.memorySize)
- every { view.instanceCount } returns random.nextInt(0, 6)
- every { view.provisionedCores } returns random.nextInt(0, view.host.model.cpuCount)
- every { view.toString() } returns "HostView[$i,numberOfActiveServers=${view.instanceCount}]"
- view
- }
-
- val servers = List(2) {
- val server = mockk<Server>()
- every { server.flavor.cpuCount } returns random.nextInt(1, 8)
- every { server.flavor.memorySize } returns random.nextLong(1024, 1024 * 512)
- server
- }
-
- return Stream.of(
- Arguments.of(false, hosts.toSet(), servers[0], hosts[2]),
- Arguments.of(false, hosts.toSet(), servers[1], hosts[1]),
- Arguments.of(true, hosts.toSet(), servers[1], hosts[0]),
- )
- }
-
- /**
- * Test arguments for the [AvailableCoreMemoryAllocationPolicy].
- */
- @JvmStatic
- fun availableCoreMemoryArgs(): Stream<Arguments> {
- val random = Random(1)
- val hosts = List(4) { i ->
- val view = mockk<HostView>()
- every { view.host.uid } returns UUID(0, i.toLong())
- every { view.host.model.cpuCount } returns random.nextInt(1, 16)
- every { view.host.model.memorySize } returns random.nextLong(1024, 1024 * 1024)
- every { view.availableMemory } returns random.nextLong(0, view.host.model.memorySize)
- every { view.instanceCount } returns random.nextInt(0, 6)
- every { view.provisionedCores } returns random.nextInt(0, view.host.model.cpuCount)
- every { view.toString() } returns "HostView[$i,availableMemory=${view.availableMemory}]"
- view
- }
-
- val servers = List(2) {
- val server = mockk<Server>()
- every { server.flavor.cpuCount } returns random.nextInt(1, 8)
- every { server.flavor.memorySize } returns random.nextLong(1024, 1024 * 512)
- server
- }
-
- return Stream.of(
- Arguments.of(false, hosts.toSet(), servers[0], hosts[2]),
- Arguments.of(false, hosts.toSet(), servers[1], hosts[2]),
- Arguments.of(true, hosts.toSet(), servers[1], hosts[1]),
- )
- }
-
- /**
- * Test arguments for the [AvailableMemoryAllocationPolicy].
- */
- @JvmStatic
- fun availableMemoryArgs(): Stream<Arguments> {
- val random = Random(1)
- val hosts = List(4) { i ->
- val view = mockk<HostView>()
- every { view.host.uid } returns UUID(0, i.toLong())
- every { view.host.model.cpuCount } returns random.nextInt(1, 16)
- every { view.host.model.memorySize } returns random.nextLong(1024, 1024 * 1024)
- every { view.availableMemory } returns random.nextLong(0, view.host.model.memorySize)
- every { view.instanceCount } returns random.nextInt(0, 6)
- every { view.provisionedCores } returns random.nextInt(0, view.host.model.cpuCount)
- every { view.toString() } returns "HostView[$i,availableMemory=${view.availableMemory}]"
- view
- }
-
- val servers = List(2) {
- val server = mockk<Server>()
- every { server.flavor.cpuCount } returns random.nextInt(1, 8)
- every { server.flavor.memorySize } returns random.nextLong(1024, 1024 * 512)
- server
- }
-
- return Stream.of(
- Arguments.of(false, hosts.toSet(), servers[0], hosts[2]),
- Arguments.of(false, hosts.toSet(), servers[1], hosts[2]),
- Arguments.of(true, hosts.toSet(), servers[1], hosts[1]),
- )
- }
-
- /**
- * Test arguments for the [ProvisionedCoresAllocationPolicy].
- */
- @JvmStatic
- fun provisionedCoresArgs(): Stream<Arguments> {
- val random = Random(1)
- val hosts = List(4) { i ->
- val view = mockk<HostView>()
- every { view.host.uid } returns UUID(0, i.toLong())
- every { view.host.model.cpuCount } returns random.nextInt(1, 16)
- every { view.host.model.memorySize } returns random.nextLong(1024, 1024 * 1024)
- every { view.availableMemory } returns random.nextLong(0, view.host.model.memorySize)
- every { view.instanceCount } returns random.nextInt(0, 6)
- every { view.provisionedCores } returns random.nextInt(0, view.host.model.cpuCount)
- every { view.toString() } returns "HostView[$i,provisionedCores=${view.provisionedCores}]"
- view
- }
-
- val servers = List(2) {
- val server = mockk<Server>()
- every { server.flavor.cpuCount } returns random.nextInt(1, 8)
- every { server.flavor.memorySize } returns random.nextLong(1024, 1024 * 512)
- server
- }
-
- return Stream.of(
- Arguments.of(false, hosts.toSet(), servers[0], hosts[2]),
- Arguments.of(false, hosts.toSet(), servers[1], hosts[0]),
- Arguments.of(true, hosts.toSet(), servers[1], hosts[0]),
- )
- }
- }
-}