diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-12-04 22:03:18 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-04 22:03:18 +0000 |
| commit | b88f07ebb056293b1a29f24e4f42203c09bcbcf8 (patch) | |
| tree | 52e2de58503714cc6510db614b4a654af2fdda3c /opendc-compute/opendc-compute-simulator/src | |
| parent | 2ca72c0b62e08efd244eba1723bc4fc65d30eed2 (diff) | |
| parent | 4dfae28c5bd656806a7baf7855c95770f4ad0ed8 (diff) | |
merge: Clean up compute service (v1)
This pull request is one in a series of changes that attempt to clean up the
warts of the OpenDC Compute Service. These changes should make the
API more robust for future developments.
## Implementation Notes :hammer_and_pick:
* Do not suspend in compute API
* Expose state directly to clients
* Do not split interface and implementation
## External Dependencies :four_leaf_clover:
* N/A
## Breaking API Changes :warning:
* The methods of `ComputeClient` do not have the suspend modifier anymore.
* Changes to the classes of `ComputeClient` are now immediately visible on the server side.
It is not necessary to call `refresh` anymore.
* `ComputeService` must be constructed via its builder class now.
Diffstat (limited to 'opendc-compute/opendc-compute-simulator/src')
2 files changed, 36 insertions, 17 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 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<String, String> = emptyMap() override val meta: Map<String, Any> = 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<String, String>, override val meta: Map<String, Any> ) : 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() {} } } |
