diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-02-20 23:15:40 +0100 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-02-21 11:24:54 +0100 |
| commit | 04aea0d7b78516dc02388e66052f9c02879c40fd (patch) | |
| tree | 420bce5a334a4fe794e4c0262c03e670caeaf8fe /opendc/opendc-compute/src/main | |
| parent | 37a5902767bc787bcc470e42b5b078e340a67b18 (diff) | |
feat: Add support for resource tagging
Diffstat (limited to 'opendc/opendc-compute/src/main')
8 files changed, 43 insertions, 17 deletions
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 60340286..cb11cfc7 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 @@ -25,7 +25,8 @@ package com.atlarge.opendc.compute.core import com.atlarge.opendc.compute.core.image.Image -import com.atlarge.opendc.core.Identity +import com.atlarge.opendc.core.resource.Resource +import com.atlarge.opendc.core.resource.TagContainer import com.atlarge.opendc.core.services.ServiceRegistry import com.atlarge.opendc.core.services.ServiceRegistryImpl import java.util.UUID @@ -45,6 +46,11 @@ public data class Server( public override val name: String, /** + * The tags of this server. + */ + public override val tags: TagContainer, + + /** * The hardware configuration of the server. */ public val flavor: ServerFlavor, @@ -63,7 +69,7 @@ public data class Server( * The services published by this server. */ public val serviceRegistry: ServiceRegistry = ServiceRegistryImpl() -) : Identity { +) : Resource { override fun hashCode(): Int = uid.hashCode() override fun equals(other: Any?): Boolean = other is Server && uid == other.uid } diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/EmptyImage.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/EmptyImage.kt index a51e55f9..6e6b8100 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/EmptyImage.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/EmptyImage.kt @@ -25,12 +25,17 @@ package com.atlarge.opendc.compute.core.image import com.atlarge.opendc.compute.core.execution.ServerContext +import com.atlarge.opendc.core.resource.TagContainer +import com.atlarge.opendc.core.resource.TagContainerImpl +import java.util.UUID /** * An empty boot disk [Image] that exits immediately on start. */ object EmptyImage : Image { - override val details: Map<String, Any> = emptyMap() + override val uid: UUID = UUID.randomUUID() + override val name: String = "empty" + override val tags: TagContainer = TagContainerImpl() override suspend fun invoke(ctx: ServerContext) {} } 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 216a62a2..4af7c706 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 @@ -25,22 +25,28 @@ package com.atlarge.opendc.compute.core.image import com.atlarge.opendc.compute.core.execution.ServerContext +import com.atlarge.opendc.core.resource.TagContainer +import java.util.UUID import kotlin.math.min /** * An application [Image] that models applications performing a static number of floating point operations ([flops]) on * a compute resource. * + * @property uid The unique identifier of this image. + * @property name The name of this image. + * @property tags The tags attached to the image. * @property flops The number of floating point operations to perform for this task. * @property cores The number of cores that the image is able to utilize. * @property utilization A model of the CPU utilization of the application. - * @property details The details of this image. */ class FlopsApplicationImage( + public override val uid: UUID, + public override val name: String, + public override val tags: TagContainer, public val flops: Long, public val cores: Int, - public val utilization: Double = 0.8, - public override val details: Map<String, Any> = emptyMap() + public val utilization: Double = 0.8 ) : Image { init { require(flops >= 0) { "Negative number of flops" } diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/Image.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/Image.kt index ff922aa9..52d4d7b5 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/Image.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/Image.kt @@ -25,6 +25,7 @@ package com.atlarge.opendc.compute.core.image import com.atlarge.opendc.compute.core.execution.ServerContext +import com.atlarge.opendc.core.resource.Resource /** * An image containing a bootable operating system that can directly be executed by physical or virtual server. @@ -34,12 +35,7 @@ import com.atlarge.opendc.compute.core.execution.ServerContext * useful for backup purposes or for producing “gold” server images if you plan to deploy a particular server * configuration frequently. */ -public interface Image { - /** - * The details of the image in key/value pairs. - */ - public val details: Map<String, Any> - +public interface Image : Resource { /** * Launch the machine image in the specified [ServerContext]. * 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 82aa28e4..be24aa00 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 @@ -1,16 +1,20 @@ package com.atlarge.opendc.compute.core.image import com.atlarge.opendc.compute.core.execution.ServerContext +import com.atlarge.opendc.core.resource.TagContainer import kotlinx.coroutines.delay +import java.util.UUID import kotlin.math.ceil import kotlin.math.min public val VM_SCHEDULING_SLICE_DURATION = 5 * 60 * 1000L class VmImage( + public override val uid: UUID, + public override val name: String, + public override val tags: TagContainer, public val flopsHistory: List<FlopsHistoryFragment>, - public val cores: Int, - public override val details: Map<String, Any> = emptyMap() + public val cores: Int ) : Image { override suspend fun invoke(ctx: ServerContext) { flopsHistory.forEach { fragment -> 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 1dde8286..a0bb82fe 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 @@ -34,6 +34,7 @@ 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.PowerState +import com.atlarge.opendc.core.resource.TagContainerImpl import kotlinx.coroutines.delay import java.util.UUID import kotlin.math.max @@ -72,6 +73,7 @@ public class SimpleBareMetalDriver( PowerState.POWER_OFF to PowerState.POWER_ON -> Server( UUID.randomUUID(), node.name, + TagContainerImpl(), flavor, node.image, ServerState.BUILD 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 4f482ab7..8bc9dc0c 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 @@ -30,15 +30,21 @@ import com.atlarge.opendc.compute.core.image.Image import com.atlarge.opendc.compute.virt.driver.SimpleVirtDriver import com.atlarge.opendc.compute.virt.driver.VirtDriver import com.atlarge.opendc.compute.virt.monitor.HypervisorMonitor +import com.atlarge.opendc.core.resource.TagContainer +import com.atlarge.opendc.core.resource.TagContainerImpl import kotlinx.coroutines.suspendCancellableCoroutine +import java.util.UUID /** * A hypervisor managing the VMs of a node. */ class HypervisorImage( - private val hypervisorMonitor: HypervisorMonitor, - public override val details: Map<String, Any> = emptyMap() + private val hypervisorMonitor: HypervisorMonitor ) : Image { + override val uid: UUID = UUID.randomUUID() + override val name: String = "esxi" + override val tags: TagContainer = TagContainerImpl() + override suspend fun invoke(ctx: ServerContext) { val driver = SimpleVirtDriver(processContext, ctx, hypervisorMonitor) 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 cc24b49f..4e7c4eb3 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 @@ -12,6 +12,7 @@ import com.atlarge.opendc.compute.core.image.VM_SCHEDULING_SLICE_DURATION import com.atlarge.opendc.compute.core.monitor.ServerMonitor import com.atlarge.opendc.compute.virt.RunRequest import com.atlarge.opendc.compute.virt.monitor.HypervisorMonitor +import com.atlarge.opendc.core.resource.TagContainerImpl import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.channels.Channel @@ -73,7 +74,7 @@ class SimpleVirtDriver( } override suspend fun spawn(image: Image, monitor: ServerMonitor, flavor: ServerFlavor): Server { - val server = Server(UUID.randomUUID(), "<unnamed>", flavor, image, ServerState.BUILD) + val server = Server(UUID.randomUUID(), "<unnamed>", TagContainerImpl(), flavor, image, ServerState.BUILD) val context = VmServerContext(server, monitor, flavor, hostContext, Channel(Channel.CONFLATED)) serverContexts.add(context) context.init() |
