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/src') 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