diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-08-24 12:55:49 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-08-24 12:55:49 +0200 |
| commit | 3721831204c2d350b93ea265731c0970cbd8fce4 (patch) | |
| tree | 7c8e5c6fe5081e1e6fcae934f69e2a7aba31a37c /opendc-compute/opendc-compute-simulator/src/main | |
| parent | 709cd4909ccc1305c7acfdf666156168d66646eb (diff) | |
feat(compute): Add support for SimHost failure
This change adds support for failures in the SimHost implementation.
Failing a host will now cause the virtual machine to enter an error
state.
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 | 26 |
1 files changed, 21 insertions, 5 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 5ea577f3..be771f6d 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 @@ -46,6 +46,7 @@ import org.opendc.simulator.resources.SimResourceInterpreter import java.util.* import kotlin.coroutines.CoroutineContext import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException /** * A [Host] that is simulates virtual machines on a physical machine using [SimHypervisor]. @@ -315,10 +316,16 @@ public class SimHost( override suspend fun fail() { _state = HostState.DOWN + for (guest in guests.values) { + guest.fail() + } } override suspend fun recover() { _state = HostState.UP + for (guest in guests.values) { + guest.start() + } } /** @@ -329,7 +336,7 @@ public class SimHost( suspend fun start() { when (state) { - ServerState.TERMINATED -> { + ServerState.TERMINATED, ServerState.ERROR -> { logger.info { "User requested to start server ${server.uid}" } launch() } @@ -356,9 +363,15 @@ public class SimHost( suspend fun terminate() { stop() + machine.close() state = ServerState.DELETED } + suspend fun fail() { + stop() + state = ServerState.ERROR + } + private var job: Job? = null private suspend fun launch() = suspendCancellableCoroutine<Unit> { cont -> @@ -366,16 +379,19 @@ public class SimHost( val workload = mapper.createWorkload(server) job = scope.launch { - delay(1) // TODO Introduce boot time - init() - cont.resume(Unit) + try { + delay(1) // TODO Introduce boot time + init() + cont.resume(Unit) + } catch (e: Throwable) { + cont.resumeWithException(e) + } try { machine.run(workload, mapOf("driver" to this@SimHost, "server" to server)) exit(null) } catch (cause: Throwable) { exit(cause) } finally { - machine.close() job = null } } |
