summaryrefslogtreecommitdiff
path: root/opendc/opendc-compute/src/main
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2020-02-26 20:36:39 +0100
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2020-02-26 20:36:39 +0100
commit9aed76152a03eaf76256691708c70508d12722c4 (patch)
tree00e79ed9af36fbab83c0056698468df8a9efffaf /opendc/opendc-compute/src/main
parentc44e9dce4da5deb900df11109dac51c1926cfabd (diff)
Model memory usage in VMs
Diffstat (limited to 'opendc/opendc-compute/src/main')
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/Flavor.kt (renamed from opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/ServerFlavor.kt)15
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/MemoryUnit.kt40
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/Server.kt2
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/FlopsApplicationImage.kt2
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt5
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriver.kt15
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/VirtDriver.kt4
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorImage.kt2
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorVirtDriver.kt27
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/InsufficientMemoryOnServerException.kt3
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/VmScheduler.kt4
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/VmSchedulerImpl.kt7
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/monitor/HypervisorMonitor.kt8
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt29
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/VirtProvisioningService.kt7
15 files changed, 124 insertions, 46 deletions
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/ServerFlavor.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/Flavor.kt
index d57dadf9..ff5060de 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/ServerFlavor.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/Flavor.kt
@@ -25,18 +25,17 @@
package com.atlarge.opendc.compute.core
/**
- * (Virtual) hardware configuration of a server.
+ * Flavors define the compute and memory capacity of [Server] instance. o put it simply, a flavor is an available
+ * hardware configuration for a server. It defines the size of a virtual server that can be launched.
*/
-public data class ServerFlavor(
+public data class Flavor(
/**
- * The processing units of this machine.
+ * The number of (virtual) processing cores to use.
*/
- public val cpus: List<ProcessingUnit>,
+ public val cpuCount: Int,
/**
- * Key and value pairs that can be used to describe the specification of the server which is more than just about
- * CPU, disk and RAM. For example, it can be used to indicate that the server created by this flavor has PCI
- * devices, etc.
+ * The amount of RAM available to the server (in MB).
*/
- public val details: Map<String, Any> = emptyMap()
+ public val memorySize: Long
)
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/MemoryUnit.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/MemoryUnit.kt
new file mode 100644
index 00000000..ce57fc72
--- /dev/null
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/MemoryUnit.kt
@@ -0,0 +1,40 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2020 atlarge-research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.atlarge.opendc.compute.core
+
+/**
+ * A memory unit of a compute resource, either virtual or physical.
+ *
+ * @property vendor The vendor string of the memory.
+ * @property modelName The name of the memory model.
+ * @property speed The access speed of the memory in MHz.
+ * @property size The size of the memory unit in MBs.
+ */
+public data class MemoryUnit(
+ public val vendor: String,
+ public val modelName: String,
+ public val speed: Double,
+ public val size: Long
+)
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/Server.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/Server.kt
index cb11cfc7..86ec9a5b 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/Server.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/Server.kt
@@ -53,7 +53,7 @@ public data class Server(
/**
* The hardware configuration of the server.
*/
- public val flavor: ServerFlavor,
+ public val flavor: Flavor,
/**
* The image running on the server.
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/FlopsApplicationImage.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/FlopsApplicationImage.kt
index f09adc84..3576b488 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/FlopsApplicationImage.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/FlopsApplicationImage.kt
@@ -60,7 +60,7 @@ class FlopsApplicationImage(
* Execute the runtime behavior based on a number of floating point operations to execute.
*/
override suspend fun invoke(ctx: ServerContext) {
- val cores = min(this.cores, ctx.server.flavor.cpus.sumBy { it.cores })
+ val cores = min(this.cores, ctx.server.flavor.cpuCount)
val req = flops / cores
coroutineScope {
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt
index b7eacd88..257b6149 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt
@@ -13,7 +13,8 @@ class VmImage(
public override val name: String,
public override val tags: TagContainer,
public val flopsHistory: List<FlopsHistoryFragment>,
- public val cores: Int
+ public val cores: Int,
+ public val requiredMemory: Long
) : Image {
override suspend fun invoke(ctx: ServerContext) {
@@ -21,7 +22,7 @@ class VmImage(
if (fragment.flops == 0L) {
delay(fragment.duration)
} else {
- val cores = min(this.cores, ctx.server.flavor.cpus.sumBy { it.cores })
+ val cores = min(this.cores, ctx.server.flavor.cpuCount)
val req = fragment.flops / cores
coroutineScope {
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 29573007..202c30e9 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
@@ -28,7 +28,8 @@ import com.atlarge.odcsim.ProcessContext
import com.atlarge.odcsim.processContext
import com.atlarge.opendc.compute.core.ProcessingUnit
import com.atlarge.opendc.compute.core.Server
-import com.atlarge.opendc.compute.core.ServerFlavor
+import com.atlarge.opendc.compute.core.Flavor
+import com.atlarge.opendc.compute.core.MemoryUnit
import com.atlarge.opendc.compute.core.ServerState
import com.atlarge.opendc.compute.core.execution.ProcessorContext
import com.atlarge.opendc.compute.core.execution.ServerManagementContext
@@ -49,12 +50,13 @@ import kotlin.math.min
*
* @param uid The unique identifier of the machine.
* @param name An optional name of the machine.
- * @param flavor The hardware configuration of the machine.
+ * @param cpuNodes The CPU nodes/packages available to the bare metal machine.
*/
public class SimpleBareMetalDriver(
uid: UUID,
name: String,
- private val flavor: ServerFlavor
+ val cpuNodes: List<ProcessingUnit>,
+ val memoryUnits: List<MemoryUnit>
) : BareMetalDriver {
/**
* The monitor to use.
@@ -66,6 +68,11 @@ public class SimpleBareMetalDriver(
*/
private var node: Node = Node(uid, name, PowerState.POWER_OFF, EmptyImage, null)
+ /**
+ * The flavor that corresponds to this machine.
+ */
+ private val flavor = Flavor(cpuNodes.sumBy { it.cores }, memoryUnits.map { it.size }.sum())
+
override suspend fun init(monitor: ServerMonitor): Node {
this.monitor = monitor
return node
@@ -141,7 +148,7 @@ public class SimpleBareMetalDriver(
private var initialized: Boolean = false
private lateinit var ctx: ProcessContext
- override val cpus: List<ProcessorContextImpl> = flavor.cpus
+ override val cpus: List<ProcessorContextImpl> = cpuNodes
.asSequence()
.flatMap { cpu ->
generateSequence { ProcessorContextImpl(cpu) }.take(cpu.cores)
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/VirtDriver.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/VirtDriver.kt
index 3541b414..68b8e541 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/VirtDriver.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/VirtDriver.kt
@@ -25,7 +25,7 @@
package com.atlarge.opendc.compute.virt.driver
import com.atlarge.opendc.compute.core.Server
-import com.atlarge.opendc.compute.core.ServerFlavor
+import com.atlarge.opendc.compute.core.Flavor
import com.atlarge.opendc.compute.core.image.Image
import com.atlarge.opendc.compute.core.monitor.ServerMonitor
import com.atlarge.opendc.core.services.AbstractServiceKey
@@ -44,7 +44,7 @@ public interface VirtDriver {
* @param flavor The flavor of the server which this driver is controlling.
* @return The virtual server spawned by this method.
*/
- public suspend fun spawn(image: Image, monitor: ServerMonitor, flavor: ServerFlavor): Server
+ public suspend fun spawn(image: Image, monitor: ServerMonitor, flavor: Flavor): Server
/**
* Returns the number of spawned images on the server managed by this driver.
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorImage.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorImage.kt
index fc7322db..b7848cf3 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorImage.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorImage.kt
@@ -43,7 +43,7 @@ class HypervisorImage(
override val tags: TagContainer = emptyMap()
override suspend fun invoke(ctx: ServerContext) {
- val driver = HypervisorVirtDriver(VmSchedulerImpl(ctx, hypervisorMonitor))
+ val driver = HypervisorVirtDriver(ctx, VmSchedulerImpl(ctx, hypervisorMonitor))
ctx.publishService(VirtDriver.Key, driver)
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorVirtDriver.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorVirtDriver.kt
index 9ae71f14..65ec75a2 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorVirtDriver.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorVirtDriver.kt
@@ -27,9 +27,10 @@ package com.atlarge.opendc.compute.virt.driver.hypervisor
import com.atlarge.odcsim.ProcessContext
import com.atlarge.odcsim.processContext
import com.atlarge.opendc.compute.core.Server
-import com.atlarge.opendc.compute.core.ServerFlavor
+import com.atlarge.opendc.compute.core.Flavor
import com.atlarge.opendc.compute.core.ServerState
import com.atlarge.opendc.compute.core.execution.ProcessorContext
+import com.atlarge.opendc.compute.core.execution.ServerContext
import com.atlarge.opendc.compute.core.execution.ServerManagementContext
import com.atlarge.opendc.compute.core.image.Image
import com.atlarge.opendc.compute.core.monitor.ServerMonitor
@@ -41,15 +42,29 @@ import java.util.UUID
/**
* A [VirtDriver] that is backed by a simple hypervisor implementation.
*/
-class HypervisorVirtDriver(private val scheduler: VmScheduler) : VirtDriver {
+class HypervisorVirtDriver(
+ private val hostContext: ServerContext,
+ private val scheduler: VmScheduler
+) : VirtDriver {
/**
* A set for tracking the VM context objects.
*/
internal val vms: MutableSet<VmServerContext> = mutableSetOf()
- override suspend fun spawn(image: Image, monitor: ServerMonitor, flavor: ServerFlavor): Server {
+ /**
+ * Current total memory use of the images on this hypervisor.
+ */
+ private var memoryAvailable: Long = hostContext.server.flavor.memorySize
+
+ override suspend fun spawn(image: Image, monitor: ServerMonitor, flavor: Flavor): Server {
+ val requiredMemory = flavor.memorySize
+ if (memoryAvailable - requiredMemory < 0) {
+ throw InsufficientMemoryOnServerException()
+ }
+
val server = Server(UUID.randomUUID(), "<unnamed>", emptyMap(), flavor, image, ServerState.BUILD)
- vms.add(VmServerContext(server, monitor, flavor, processContext))
+ memoryAvailable -= requiredMemory
+ vms.add(VmServerContext(server, monitor, processContext))
return server
}
@@ -60,7 +75,6 @@ class HypervisorVirtDriver(private val scheduler: VmScheduler) : VirtDriver {
internal inner class VmServerContext(
override var server: Server,
val monitor: ServerMonitor,
- flavor: ServerFlavor,
ctx: ProcessContext
) : ServerManagementContext {
private var initialized: Boolean = false
@@ -75,7 +89,7 @@ class HypervisorVirtDriver(private val scheduler: VmScheduler) : VirtDriver {
}
}
- override val cpus: List<ProcessorContext> = scheduler.createVirtualCpus(flavor)
+ override val cpus: List<ProcessorContext> = scheduler.createVirtualCpus(server.flavor)
override suspend fun init() {
if (initialized) {
@@ -92,6 +106,7 @@ class HypervisorVirtDriver(private val scheduler: VmScheduler) : VirtDriver {
val previousState = server.state
val state = if (cause == null) ServerState.SHUTOFF else ServerState.ERROR
server = server.copy(state = state)
+ memoryAvailable += server.flavor.memorySize
monitor.onUpdate(server, previousState)
initialized = false
}
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/InsufficientMemoryOnServerException.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/InsufficientMemoryOnServerException.kt
new file mode 100644
index 00000000..926234b5
--- /dev/null
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/InsufficientMemoryOnServerException.kt
@@ -0,0 +1,3 @@
+package com.atlarge.opendc.compute.virt.driver.hypervisor
+
+public class InsufficientMemoryOnServerException : IllegalStateException("Insufficient memory left on server.")
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/VmScheduler.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/VmScheduler.kt
index f02ac2b3..7b00d99c 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/VmScheduler.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/VmScheduler.kt
@@ -24,7 +24,7 @@
package com.atlarge.opendc.compute.virt.driver.hypervisor
-import com.atlarge.opendc.compute.core.ServerFlavor
+import com.atlarge.opendc.compute.core.Flavor
import com.atlarge.opendc.compute.core.execution.ProcessorContext
/**
@@ -34,5 +34,5 @@ public interface VmScheduler {
/**
* Create the virtual CPUs for the specified [flavor].
*/
- fun createVirtualCpus(flavor: ServerFlavor): List<ProcessorContext>
+ fun createVirtualCpus(flavor: Flavor): List<ProcessorContext>
}
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/VmSchedulerImpl.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/VmSchedulerImpl.kt
index b6be935e..dfed3d58 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/VmSchedulerImpl.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/VmSchedulerImpl.kt
@@ -26,7 +26,7 @@ package com.atlarge.opendc.compute.virt.driver.hypervisor
import com.atlarge.odcsim.processContext
import com.atlarge.opendc.compute.core.ProcessingUnit
-import com.atlarge.opendc.compute.core.ServerFlavor
+import com.atlarge.opendc.compute.core.Flavor
import com.atlarge.opendc.compute.core.execution.ProcessorContext
import com.atlarge.opendc.compute.core.execution.ServerContext
import com.atlarge.opendc.compute.virt.monitor.HypervisorMonitor
@@ -53,9 +53,10 @@ public class VmSchedulerImpl(
*/
private val cpus = hostContext.cpus.map { HostProcessorContext(it, hostContext, hypervisorMonitor) }
- override fun createVirtualCpus(flavor: ServerFlavor): List<ProcessorContext> {
+ override fun createVirtualCpus(flavor: Flavor): List<ProcessorContext> {
+ // TODO At the moment, the first N cores get filled the first. Distribute over all cores instead
return cpus.asSequence()
- .take(flavor.cpus.sumBy { it.cores })
+ .take(flavor.cpuCount)
.map { VirtualProcessorContext(it) }
.toList()
}
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/monitor/HypervisorMonitor.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/monitor/HypervisorMonitor.kt
index d4d71aaa..e259a3c0 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/monitor/HypervisorMonitor.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/monitor/HypervisorMonitor.kt
@@ -10,15 +10,15 @@ interface HypervisorMonitor {
* Invoked after a scheduling slice has finished processed.
*
* @param time The current time (in ms).
- * @param totalRequestedBurst The total requested CPU time (can be above capacity).
- * @param totalGrantedBurst The actual total granted capacity.
+ * @param requestedBurst The total requested CPU time (can be above capacity).
+ * @param grantedBurst The actual total granted capacity.
* @param numberOfDeployedImages The number of images deployed on this hypervisor.
* @param hostServer The server hosting this hypervisor.
*/
fun onSliceFinish(
time: Long,
- totalRequestedBurst: Long,
- totalGrantedBurst: Long,
+ requestedBurst: Long,
+ grantedBurst: Long,
numberOfDeployedImages: Int,
hostServer: Server
)
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 baf3f9ef..ef1528d9 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,14 +1,16 @@
package com.atlarge.opendc.compute.virt.service
import com.atlarge.odcsim.ProcessContext
+import com.atlarge.opendc.compute.core.Flavor
import com.atlarge.opendc.compute.core.Server
import com.atlarge.opendc.compute.core.ServerState
import com.atlarge.opendc.compute.core.image.Image
import com.atlarge.opendc.compute.core.monitor.ServerMonitor
import com.atlarge.opendc.compute.metal.Node
import com.atlarge.opendc.compute.metal.service.ProvisioningService
-import com.atlarge.opendc.compute.virt.driver.hypervisor.HypervisorImage
import com.atlarge.opendc.compute.virt.driver.VirtDriver
+import com.atlarge.opendc.compute.virt.driver.hypervisor.HypervisorImage
+import com.atlarge.opendc.compute.virt.driver.hypervisor.InsufficientMemoryOnServerException
import com.atlarge.opendc.compute.virt.monitor.HypervisorMonitor
import kotlinx.coroutines.launch
@@ -63,8 +65,8 @@ class SimpleVirtProvisioningService(
}
}
- override suspend fun deploy(image: Image, monitor: ServerMonitor) {
- val vmInstance = ImageView(image, monitor)
+ override suspend fun deploy(image: Image, monitor: ServerMonitor, flavor: Flavor) {
+ val vmInstance = ImageView(image, monitor, flavor)
incomingImages += vmInstance
requestCycle()
}
@@ -85,16 +87,20 @@ class SimpleVirtProvisioningService(
it.server!!.serviceRegistry[VirtDriver.Key].getNumberOfSpawnedImages()
}
- imageInstance.server = selectedNode?.server!!.serviceRegistry[VirtDriver.Key].spawn(
- imageInstance.image,
- imageInstance.monitor,
- nodes[0].server!!.flavor
- )
+ try {
+ imageInstance.server = selectedNode?.server!!.serviceRegistry[VirtDriver.Key].spawn(
+ imageInstance.image,
+ imageInstance.monitor,
+ imageInstance.flavor
+ )
+ activeImages += imageInstance
+ imagesByServer.putIfAbsent(imageInstance.server!!, mutableSetOf())
+ imagesByServer[imageInstance.server!!]!!.add(imageInstance)
+ } catch (e: InsufficientMemoryOnServerException) {
+ println("Unable to deploy image due to insufficient memory")
+ }
incomingImages -= imageInstance
- activeImages += imageInstance
- imagesByServer.putIfAbsent(imageInstance.server!!, mutableSetOf())
- imagesByServer[imageInstance.server!!]!!.add(imageInstance)
}
}
@@ -113,6 +119,7 @@ class SimpleVirtProvisioningService(
class ImageView(
val image: Image,
val monitor: ServerMonitor,
+ val flavor: Flavor,
var server: Server? = null
)
}
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 8e0e1137..fb087f9d 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
@@ -1,5 +1,6 @@
package com.atlarge.opendc.compute.virt.service
+import com.atlarge.opendc.compute.core.Flavor
import com.atlarge.opendc.compute.core.image.Image
import com.atlarge.opendc.compute.core.monitor.ServerMonitor
@@ -9,6 +10,10 @@ import com.atlarge.opendc.compute.core.monitor.ServerMonitor
interface VirtProvisioningService {
/**
* Submit the specified [Image] to the provisioning service.
+ *
+ * @param image The image to be deployed.
+ * @param monitor The monitor to inform on events.
+ * @param flavor The flavor of the machine instance to run this [image] on.
*/
- public suspend fun deploy(image: Image, monitor: ServerMonitor)
+ public suspend fun deploy(image: Image, monitor: ServerMonitor, flavor: Flavor)
}