summaryrefslogtreecommitdiff
path: root/opendc-compute
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-10-18 11:01:37 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-10-28 15:02:33 +0200
commitc6f2d16a20bfac466480c0e98341b08b12fc0772 (patch)
tree0cb0b456fbff089ae14af684d6f8b95d3f6a7141 /opendc-compute
parentd5aed4b1e6e5548728c5978e3b46d1472b62e791 (diff)
feat(compute/sim): Model host boot time
This change updates `SimHost` to support modeling the time and resource consumption it takes to boot the host. The boot procedure is modeled as a `SimWorkload`.
Diffstat (limited to 'opendc-compute')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt57
-rw-r--r--opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt6
2 files changed, 46 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 660c1ccc..ee607066 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
@@ -44,28 +44,38 @@ import org.opendc.simulator.compute.model.MachineModel
import org.opendc.simulator.compute.model.MemoryUnit
import org.opendc.simulator.compute.model.ProcessingNode
import org.opendc.simulator.compute.model.ProcessingUnit
-import org.opendc.simulator.flow2.FlowGraph
+import org.opendc.simulator.compute.workload.SimWorkload
+import org.opendc.simulator.compute.workload.SimWorkloads
+import java.time.Clock
import java.time.Duration
import java.time.Instant
import java.util.UUID
+import java.util.function.Supplier
/**
- * A [Host] that is simulates virtual machines on a physical machine using [SimHypervisor].
+ * A [Host] implementation that simulates virtual machines on a physical machine using [SimHypervisor].
+ *
+ * @param uid The unique identifier of the host.
+ * @param name The name of the host.
+ * @param meta The metadata of the host.
+ * @param clock The (virtual) clock used to track time.
+ * @param machine The [SimBareMetalMachine] on which the host runs.
+ * @param hypervisor The [SimHypervisor] to run on top of the machine.
+ * @param mapper A [SimWorkloadMapper] to map a [Server] to a [SimWorkload].
+ * @param bootModel A [Supplier] providing the [SimWorkload] to execute during the boot procedure of the hypervisor.
+ * @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>,
- graph: FlowGraph,
+ private val clock: Clock,
private val machine: SimBareMetalMachine,
private val hypervisor: SimHypervisor,
private val mapper: SimWorkloadMapper = DefaultWorkloadMapper,
+ private val bootModel: Supplier<SimWorkload?> = Supplier { null },
private val optimize: Boolean = false
) : Host, AutoCloseable {
- /**
- * The clock instance used by the host.
- */
- private val clock = graph.engine.clock
/**
* The event listeners registered with this host.
@@ -272,20 +282,39 @@ public class SimHost(
/**
* The [SimMachineContext] that represents the machine running the hypervisor.
*/
- private var _ctx: SimMachineContext? = null
+ private var ctx: SimMachineContext? = null
/**
* Launch the hypervisor.
*/
private fun launch() {
- check(_ctx == null) { "Concurrent hypervisor running" }
+ check(ctx == null) { "Concurrent hypervisor running" }
+
+ val bootWorkload = bootModel.get()
+ val hypervisor = hypervisor
+ val hypervisorWorkload = object : SimWorkload {
+ override fun onStart(ctx: SimMachineContext) {
+ try {
+ _bootTime = clock.instant()
+ _state = HostState.UP
+ hypervisor.onStart(ctx)
+ } catch (cause: Throwable) {
+ _state = HostState.ERROR
+ throw cause
+ }
+ }
+
+ override fun onStop(ctx: SimMachineContext) {
+ hypervisor.onStop(ctx)
+ }
+ }
+
+ val workload = if (bootWorkload != null) SimWorkloads.chain(bootWorkload, hypervisorWorkload) else hypervisorWorkload
// Launch hypervisor onto machine
- _bootTime = clock.instant()
- _state = HostState.UP
- _ctx = machine.startWorkload(hypervisor, emptyMap()) { cause ->
+ ctx = machine.startWorkload(workload, emptyMap()) { cause ->
_state = if (cause != null) HostState.ERROR else HostState.DOWN
- _ctx = null
+ ctx = null
}
}
@@ -296,7 +325,7 @@ public class SimHost(
updateUptime()
// Stop the hypervisor
- _ctx?.shutdown()
+ ctx?.shutdown()
_state = state
}
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 02be3f28..27151422 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
@@ -86,7 +86,7 @@ internal class SimHostTest {
uid = UUID.randomUUID(),
name = "test",
meta = emptyMap(),
- graph,
+ clock,
machine,
hypervisor
)
@@ -154,7 +154,7 @@ internal class SimHostTest {
uid = UUID.randomUUID(),
name = "test",
meta = emptyMap(),
- graph,
+ clock,
machine,
hypervisor
)
@@ -236,7 +236,7 @@ internal class SimHostTest {
uid = UUID.randomUUID(),
name = "test",
meta = emptyMap(),
- graph,
+ clock,
machine,
hypervisor
)