diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-10-28 16:46:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-28 16:46:47 +0200 |
| commit | b96acc687f59b698fbc4d4c984d77b008cd4051b (patch) | |
| tree | ff4d99454259b92ec4484433bb716acd6319faa1 /opendc-simulator/opendc-simulator-compute/src/main/kotlin | |
| parent | c4cfb6f6e0507f335fd88935857f20e88c34abd0 (diff) | |
| parent | 8bf940eb7b59b5e5e326cfc06d51bdb54393f33b (diff) | |
Support custom start-up and clean-up time for VMs (#112)
This pull request implements customizable startup and clean-up time for virtual machine.
We achieve this by implementing `SimWorkload` chaining and modelling start-up and
clean-up time using `SimWorkload` as well.
Implements #33
## Implementation Notes :hammer_and_pick:
* Store method parameters in class files
* Add completion parameter to startWorkload
* Provide workload constructors in SimWorkloads
* Add support for resetting machine context
* Add support for chaining workloads
* Use workload chaining for boot delay
* Model host boot time
* Do not suspend on guest start
* Use static logger field
## Breaking API Changes :warning:
* `SimMachine#startWorkload` now has a third parameter `completion` which is invoked when
the workload finishes executing (either due to failure or success).
* `SimFlopsWorkload` and `SimRuntimeWorkload` can be instantiated via `SimWorkloads`.
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute/src/main/kotlin')
| -rw-r--r-- | opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/Coroutines.kt | 29 |
1 files changed, 3 insertions, 26 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/Coroutines.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/Coroutines.kt index c23f48dc..b354caff 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/Coroutines.kt +++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/Coroutines.kt @@ -39,31 +39,8 @@ public suspend fun SimMachine.runWorkload(workload: SimWorkload, meta: Map<Strin return suspendCancellableCoroutine { cont -> cont.invokeOnCancellation { this@runWorkload.cancel() } - startWorkload( - object : SimWorkload { - override fun onStart(ctx: SimMachineContext) { - try { - workload.onStart(ctx) - } catch (cause: Throwable) { - cont.resumeWithException(cause) - throw cause - } - } - - override fun onStop(ctx: SimMachineContext) { - try { - workload.onStop(ctx) - - if (!cont.isCompleted) { - cont.resume(Unit) - } - } catch (cause: Throwable) { - cont.resumeWithException(cause) - throw cause - } - } - }, - meta - ) + startWorkload(workload, meta) { cause -> + if (cause != null) cont.resumeWithException(cause) else cont.resume(Unit) + } } } |
