From f781a1dba4e1309a2c637d7b47aeef9f55e079b5 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Thu, 26 Mar 2020 19:58:31 +0100 Subject: Monitor state changes, as well They're now stored in a RLE-fashion. --- .../kotlin/com/atlarge/opendc/compute/virt/HypervisorEvent.kt | 11 +++++++++++ .../kotlin/com/atlarge/opendc/compute/virt/HypervisorImage.kt | 1 + .../atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt | 11 +++++++++++ 3 files changed, 23 insertions(+) (limited to 'opendc/opendc-compute') diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorEvent.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorEvent.kt index 5c19b00d..76a73a57 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorEvent.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorEvent.kt @@ -64,4 +64,15 @@ public sealed class HypervisorEvent { public val numberOfDeployedImages: Int, public val hostServer: Server ) : HypervisorEvent() + + /** + * This event is emitted when the hypervisor state changes. + * + * @property driver The driver that emitted the event. + * @property server The current server instance. + */ + public data class StateChanged( + override val driver: VirtDriver, + public val server: Server + ) : HypervisorEvent() } diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorImage.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorImage.kt index c21b002d..657d5067 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorImage.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorImage.kt @@ -50,6 +50,7 @@ object HypervisorImage : Image { try { suspendCancellableCoroutine {} } finally { + driver.onShutOff() driver.eventFlow.close() } } diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt index 76368080..b6cf3ac8 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt @@ -87,6 +87,10 @@ class SimpleVirtDriver( override val events: Flow = eventFlow + init { + eventFlow.emit(HypervisorEvent.StateChanged(this, server)) + } + override suspend fun spawn( name: String, image: Image, @@ -238,6 +242,13 @@ class SimpleVirtDriver( this.call = null } + /** + * To be called on shut-off of the hypervisor. + */ + public fun onShutOff() { + eventFlow.emit(HypervisorEvent.StateChanged(this, server)) + } + /** * A request to schedule a virtual CPU on the host cpu. */ -- cgit v1.2.3 From 1699ae13574dddb680dc8176386817fa05816820 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Mon, 30 Mar 2020 15:27:31 +0200 Subject: bug: Record start and power off events in SC20 experiments --- .../opendc/compute/metal/driver/SimpleBareMetalDriver.kt | 10 +++++++--- .../opendc/compute/metal/service/ProvisioningService.kt | 5 +++++ .../compute/metal/service/SimpleProvisioningService.kt | 10 ++++++++++ .../com/atlarge/opendc/compute/virt/HypervisorEvent.kt | 11 ----------- .../com/atlarge/opendc/compute/virt/HypervisorImage.kt | 1 - .../atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt | 13 +------------ .../compute/virt/service/SimpleVirtProvisioningService.kt | 9 +++++++++ .../opendc/compute/virt/service/VirtProvisioningService.kt | 12 ++++++++++++ 8 files changed, 44 insertions(+), 27 deletions(-) (limited to 'opendc/opendc-compute') diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriver.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriver.kt index 4a40dc9f..9396699a 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriver.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriver.kt @@ -142,7 +142,7 @@ public class SimpleBareMetalDriver( override suspend fun stop(): Node = withContext(domain.coroutineContext) { val node = nodeState.value - if (node.state == NodeState.SHUTOFF) { + if (node.state == NodeState.SHUTOFF || node.state == NodeState.ERROR) { return@withContext node } @@ -298,8 +298,12 @@ public class SimpleBareMetalDriver( get() = domain override suspend fun fail() { - serverContext?.cancel(fail = true) - domain.cancel() + try { + serverContext?.cancel(fail = true) + domain.cancel() + } catch (_: CancellationException) { + // Ignore if the machine has already failed. + } } override fun toString(): String = "SimpleBareMetalDriver(node = ${nodeState.value.uid})" diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/ProvisioningService.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/ProvisioningService.kt index 105505f2..a54d8df4 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/ProvisioningService.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/ProvisioningService.kt @@ -54,6 +54,11 @@ public interface ProvisioningService { */ public suspend fun deploy(node: Node, image: Image): Node + /** + * Stop the specified [Node] . + */ + public suspend fun stop(node: Node): Node + /** * The service key of this service. */ diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningService.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningService.kt index a7e143aa..f6b236ae 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningService.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningService.kt @@ -28,6 +28,7 @@ import com.atlarge.odcsim.Domain import com.atlarge.opendc.compute.core.image.Image import com.atlarge.opendc.compute.metal.Node import com.atlarge.opendc.compute.metal.driver.BareMetalDriver +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.withContext /** @@ -57,4 +58,13 @@ public class SimpleProvisioningService(val domain: Domain) : ProvisioningService val newNode = driver.reboot() return@withContext newNode } + + override suspend fun stop(node: Node): Node = withContext(domain.coroutineContext) { + val driver = nodes[node]!! + try { + driver.stop() + } catch (e: CancellationException) { + node + } + } } diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorEvent.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorEvent.kt index 76a73a57..5c19b00d 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorEvent.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorEvent.kt @@ -64,15 +64,4 @@ public sealed class HypervisorEvent { public val numberOfDeployedImages: Int, public val hostServer: Server ) : HypervisorEvent() - - /** - * This event is emitted when the hypervisor state changes. - * - * @property driver The driver that emitted the event. - * @property server The current server instance. - */ - public data class StateChanged( - override val driver: VirtDriver, - public val server: Server - ) : HypervisorEvent() } diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorImage.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorImage.kt index 657d5067..c21b002d 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorImage.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorImage.kt @@ -50,7 +50,6 @@ object HypervisorImage : Image { try { suspendCancellableCoroutine {} } finally { - driver.onShutOff() driver.eventFlow.close() } } diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt index b6cf3ac8..3086f4e6 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt @@ -67,7 +67,7 @@ class SimpleVirtDriver( /** * The [Server] on which this hypervisor runs. */ - private val server: Server + val server: Server get() = hostContext.server /** @@ -87,10 +87,6 @@ class SimpleVirtDriver( override val events: Flow = eventFlow - init { - eventFlow.emit(HypervisorEvent.StateChanged(this, server)) - } - override suspend fun spawn( name: String, image: Image, @@ -242,13 +238,6 @@ class SimpleVirtDriver( this.call = null } - /** - * To be called on shut-off of the hypervisor. - */ - public fun onShutOff() { - eventFlow.emit(HypervisorEvent.StateChanged(this, server)) - } - /** * A request to schedule a virtual CPU on the host cpu. */ diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt index 156521db..b8966275 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt @@ -1,6 +1,7 @@ package com.atlarge.opendc.compute.virt.service import com.atlarge.odcsim.SimulationContext +import com.atlarge.odcsim.flow.EventFlow import com.atlarge.opendc.compute.core.Flavor import com.atlarge.opendc.compute.core.Server import com.atlarge.opendc.compute.core.ServerEvent @@ -18,6 +19,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.Job import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch @@ -52,6 +54,8 @@ class SimpleVirtProvisioningService( */ private val activeImages: MutableSet = mutableSetOf() + override val hypervisorEvents: Flow = EventFlow() + init { launch { val provisionedNodes = provisioningService.nodes() @@ -84,6 +88,11 @@ class SimpleVirtProvisioningService( } } + override suspend fun terminate() { + val provisionedNodes = provisioningService.nodes() + provisionedNodes.forEach { node -> provisioningService.stop(node) } + } + private var call: Job? = null private fun requestCycle() { diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/VirtProvisioningService.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/VirtProvisioningService.kt index a3ade2fb..fb200f88 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/VirtProvisioningService.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/VirtProvisioningService.kt @@ -3,8 +3,10 @@ package com.atlarge.opendc.compute.virt.service import com.atlarge.opendc.compute.core.Flavor import com.atlarge.opendc.compute.core.Server import com.atlarge.opendc.compute.core.image.Image +import com.atlarge.opendc.compute.virt.HypervisorEvent import com.atlarge.opendc.compute.virt.driver.VirtDriver import com.atlarge.opendc.compute.virt.service.allocation.AllocationPolicy +import kotlinx.coroutines.flow.Flow /** * A service for VM provisioning on a cloud. @@ -12,6 +14,11 @@ import com.atlarge.opendc.compute.virt.service.allocation.AllocationPolicy interface VirtProvisioningService { val allocationPolicy: AllocationPolicy + /** + * The events emitted by the hypervisors. + */ + public val hypervisorEvents: Flow + /** * Obtain the active hypervisors for this provisioner. */ @@ -25,4 +32,9 @@ interface VirtProvisioningService { * @param flavor The flavor of the machine instance to run this [image] on. */ public suspend fun deploy(name: String, image: Image, flavor: Flavor): Server + + /** + * Terminate the provisioning service releasing all the leased bare-metal machines. + */ + public suspend fun terminate() } -- cgit v1.2.3