From 3b928a66d992ec32ff28bfd4c11b0c7b2ac631ca Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Thu, 23 Sep 2021 14:44:46 +0200 Subject: fix(compute): Do not recover guests in non-error state --- .../main/kotlin/org/opendc/compute/simulator/SimHost.kt | 4 ++-- .../kotlin/org/opendc/compute/simulator/internal/Guest.kt | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 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 ff55c585..fdb3f1dc 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 @@ -262,7 +262,7 @@ public class SimHost( } override suspend fun delete(server: Server) { - val guest = guests.remove(server) ?: return + val guest = guests[server] ?: return guest.terminate() } @@ -296,7 +296,7 @@ public class SimHost( _bootTime = clock.millis() for (guest in guests.values) { - guest.start() + guest.recover() } } diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt index 90562e2f..7f33154a 100644 --- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt +++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt @@ -96,8 +96,8 @@ internal class Guest( } ServerState.RUNNING -> return ServerState.DELETED -> { - logger.warn { "User tried to start terminated server" } - throw IllegalArgumentException("Server is terminated") + logger.warn { "User tried to start deleted server" } + throw IllegalArgumentException("Server is deleted") } else -> assert(false) { "Invalid state transition" } } @@ -143,6 +143,17 @@ internal class Guest( doStop(ServerState.ERROR) } + /** + * Recover the guest if it is in an error state. + */ + suspend fun recover() { + if (state != ServerState.ERROR) { + return + } + + doStart() + } + /** * The [Job] representing the current active virtual machine instance or `null` if no virtual machine is active. */ -- cgit v1.2.3