From 6bbfbd7aeb99475308a140222316f3e9006aeec3 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 1 Nov 2022 10:38:26 +0100 Subject: refactor(compute/api): Do not suspend in compute API This change updates the API interface of the OpenDC Compute service to not suspend execution using Kotlin Coroutines. The suspending modifiers were introduced in case the ComputeClient would communicate with the service over a network connection. However, the main use-case has been together with the ComputeService, where the suspending modifiers only frustrate the user experience when writing experiments. Furthermore, with the advent of Project Loom, it is not necessarily a problem to block the (virtual) thread during network communications. --- .../kotlin/org/opendc/compute/simulator/SimHostTest.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'opendc-compute/opendc-compute-simulator') diff --git a/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt b/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt index a496cc99..1734daf5 100644 --- a/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt +++ b/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt @@ -305,11 +305,11 @@ internal class SimHostTest { override val labels: Map = emptyMap() override val meta: Map = emptyMap() - override suspend fun delete() { + override fun delete() { throw NotImplementedError() } - override suspend fun refresh() { + override fun reload() { throw NotImplementedError() } } @@ -320,11 +320,11 @@ internal class SimHostTest { override val labels: Map, override val meta: Map ) : Image { - override suspend fun delete() { + override fun delete() { throw NotImplementedError() } - override suspend fun refresh() { + override fun reload() { throw NotImplementedError() } } @@ -343,16 +343,16 @@ internal class SimHostTest { override val launchedAt: Instant? = null - override suspend fun start() {} + override fun start() {} - override suspend fun stop() {} + override fun stop() {} - override suspend fun delete() {} + override fun delete() {} override fun watch(watcher: ServerWatcher) {} override fun unwatch(watcher: ServerWatcher) {} - override suspend fun refresh() {} + override fun reload() {} } } -- cgit v1.2.3 From 4dfae28c5bd656806a7baf7855c95770f4ad0ed8 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 2 Nov 2022 17:20:00 +0100 Subject: refactor(compute/service): Do not split interface and implementation This change inlines the implementation of the compute service into the `ComputeService` interface. We do not intend to provide multiple implementations of the service. In addition, this approach makes more sense for a Java implementation. --- .../kotlin/org/opendc/compute/simulator/SimHost.kt | 37 ++++++++++++++++------ 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'opendc-compute/opendc-compute-simulator') diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt index a44ccc27..ec71f095 100644 --- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt +++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt @@ -65,9 +65,9 @@ import java.util.function.Supplier * @param optimize A flag to indicate to optimize the machine models of the virtual machines. */ public class SimHost( - override val uid: UUID, - override val name: String, - override val meta: Map, + private val uid: UUID, + private val name: String, + private val meta: Map, private val clock: InstantSource, private val machine: SimBareMetalMachine, private val hypervisor: SimHypervisor, @@ -87,11 +87,6 @@ public class SimHost( private val guests = HashMap() private val _guests = mutableListOf() - override val instances: Set - get() = guests.keys - - override val state: HostState - get() = _state private var _state: HostState = HostState.DOWN set(value) { if (value != field) { @@ -100,7 +95,7 @@ public class SimHost( field = value } - override val model: HostModel = HostModel( + private val model: HostModel = HostModel( machine.model.cpus.sumOf { it.frequency }, machine.model.cpus.size, machine.model.memory.sumOf { it.size } @@ -123,6 +118,30 @@ public class SimHost( launch() } + override fun getUid(): UUID { + return uid + } + + override fun getName(): String { + return name + } + + override fun getModel(): HostModel { + return model + } + + override fun getMeta(): Map { + return meta + } + + override fun getState(): HostState { + return _state + } + + override fun getInstances(): Set { + return guests.keys + } + override fun canFit(server: Server): Boolean { val sufficientMemory = model.memoryCapacity >= server.flavor.memorySize val enoughCpus = model.cpuCount >= server.flavor.cpuCount -- cgit v1.2.3