summaryrefslogtreecommitdiff
path: root/opendc/opendc-compute/src
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2020-03-30 15:27:31 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-03-30 15:29:50 +0200
commit1699ae13574dddb680dc8176386817fa05816820 (patch)
tree568d54bd76a189a1a46f5b392d26db39cd6b87c3 /opendc/opendc-compute/src
parent3777b8fa8126b53d7e049f971bf897c93fe787b1 (diff)
bug: Record start and power off events in SC20 experiments
Diffstat (limited to 'opendc/opendc-compute/src')
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriver.kt10
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/ProvisioningService.kt5
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningService.kt10
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorEvent.kt11
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorImage.kt1
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt13
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt9
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/VirtProvisioningService.kt12
8 files changed, 44 insertions, 27 deletions
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
@@ -55,6 +55,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.
*/
companion object Key : AbstractServiceKey<ProvisioningService>(UUID.randomUUID(), "provisioner")
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<Unit> {}
} 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<HypervisorEvent> = eventFlow
- init {
- eventFlow.emit(HypervisorEvent.StateChanged(this, server))
- }
-
override suspend fun spawn(
name: String,
image: Image,
@@ -243,13 +239,6 @@ class SimpleVirtDriver(
}
/**
- * 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.
*/
internal data class CpuRequest(
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<ImageView> = mutableSetOf()
+ override val hypervisorEvents: Flow<HypervisorEvent> = 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.
@@ -13,6 +15,11 @@ interface VirtProvisioningService {
val allocationPolicy: AllocationPolicy
/**
+ * The events emitted by the hypervisors.
+ */
+ public val hypervisorEvents: Flow<HypervisorEvent>
+
+ /**
* Obtain the active hypervisors for this provisioner.
*/
public suspend fun drivers(): Set<VirtDriver>
@@ -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()
}