diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-11-02 17:20:00 +0100 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-11-27 20:50:13 +0000 |
| commit | 4dfae28c5bd656806a7baf7855c95770f4ad0ed8 (patch) | |
| tree | 52e2de58503714cc6510db614b4a654af2fdda3c /opendc-compute/opendc-compute-simulator/src/main | |
| parent | e0856b26c3e1961e7ff4bb3ca038adc4892bbc22 (diff) | |
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.
Diffstat (limited to 'opendc-compute/opendc-compute-simulator/src/main')
| -rw-r--r-- | opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt | 37 |
1 files changed, 28 insertions, 9 deletions
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<String, Any>, + private val uid: UUID, + private val name: String, + private val meta: Map<String, Any>, private val clock: InstantSource, private val machine: SimBareMetalMachine, private val hypervisor: SimHypervisor, @@ -87,11 +87,6 @@ public class SimHost( private val guests = HashMap<Server, Guest>() private val _guests = mutableListOf<Guest>() - override val instances: Set<Server> - 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<String, *> { + return meta + } + + override fun getState(): HostState { + return _state + } + + override fun getInstances(): Set<Server> { + return guests.keys + } + override fun canFit(server: Server): Boolean { val sufficientMemory = model.memoryCapacity >= server.flavor.memorySize val enoughCpus = model.cpuCount >= server.flavor.cpuCount |
