summaryrefslogtreecommitdiff
path: root/opendc
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2020-02-21 15:47:33 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-02-21 15:56:25 +0100
commit49b673e26ebf9f6a1c96f083d3876b19027b2abc (patch)
tree9b9931ec263cd071e96617e339aa907af332f296 /opendc
parent04aea0d7b78516dc02388e66052f9c02879c40fd (diff)
feat: Simplify tagging of cloud resources
Diffstat (limited to 'opendc')
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/EmptyImage.kt3
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriver.kt3
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/HypervisorImage.kt5
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt3
-rw-r--r--opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriverTest.kt3
-rw-r--r--opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningServiceTest.kt3
-rw-r--r--opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagContainer.kt38
-rw-r--r--opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagContainerImpl.kt51
-rw-r--r--opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagKey.kt30
-rw-r--r--opendc/opendc-format/src/main/kotlin/com/atlarge/opendc/format/trace/gwf/GwfTraceReader.kt3
-rw-r--r--opendc/opendc-format/src/main/kotlin/com/atlarge/opendc/format/trace/vm/VmTraceReader.kt3
11 files changed, 15 insertions, 130 deletions
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 6e6b8100..8f6c4682 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
@@ -26,7 +26,6 @@ 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
/**
@@ -35,7 +34,7 @@ import java.util.UUID
object EmptyImage : Image {
override val uid: UUID = UUID.randomUUID()
override val name: String = "empty"
- override val tags: TagContainer = TagContainerImpl()
+ override val tags: TagContainer = emptyMap()
override suspend fun invoke(ctx: ServerContext) {}
}
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 a0bb82fe..827c1d38 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,7 +34,6 @@ 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
@@ -73,7 +72,7 @@ public class SimpleBareMetalDriver(
PowerState.POWER_OFF to PowerState.POWER_ON -> Server(
UUID.randomUUID(),
node.name,
- TagContainerImpl(),
+ emptyMap(),
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 8bc9dc0c..b66e04d2 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
@@ -31,7 +31,6 @@ 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
@@ -42,8 +41,8 @@ class HypervisorImage(
private val hypervisorMonitor: HypervisorMonitor
) : Image {
override val uid: UUID = UUID.randomUUID()
- override val name: String = "esxi"
- override val tags: TagContainer = TagContainerImpl()
+ override val name: String = "vmm"
+ override val tags: TagContainer = emptyMap()
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 4e7c4eb3..863626ad 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,7 +12,6 @@ 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
@@ -74,7 +73,7 @@ class SimpleVirtDriver(
}
override suspend fun spawn(image: Image, monitor: ServerMonitor, flavor: ServerFlavor): Server {
- val server = Server(UUID.randomUUID(), "<unnamed>", TagContainerImpl(), flavor, image, ServerState.BUILD)
+ val server = Server(UUID.randomUUID(), "<unnamed>", emptyMap(), flavor, image, ServerState.BUILD)
val context = VmServerContext(server, monitor, flavor, hostContext, Channel(Channel.CONFLATED))
serverContexts.add(context)
context.init()
diff --git a/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriverTest.kt b/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriverTest.kt
index 88212abf..05e943e2 100644
--- a/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriverTest.kt
+++ b/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriverTest.kt
@@ -32,7 +32,6 @@ import com.atlarge.opendc.compute.core.ServerState
import com.atlarge.opendc.compute.core.image.FlopsApplicationImage
import com.atlarge.opendc.compute.core.monitor.ServerMonitor
import com.atlarge.opendc.compute.metal.PowerState
-import com.atlarge.opendc.core.resource.TagContainerImpl
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
@@ -48,7 +47,7 @@ internal class SimpleBareMetalDriverTest {
val provider = ServiceLoader.load(SimulationEngineProvider::class.java).first()
val system = provider({ _ ->
val flavor = ServerFlavor(listOf(ProcessingUnit("Intel", "Xeon", "amd64", 2300.0, 4)))
- val image = FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", TagContainerImpl(), 1000, 2)
+ val image = FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", emptyMap(), 1000, 2)
val monitor = object : ServerMonitor {
override suspend fun onUpdate(server: Server, previousState: ServerState) {
println(server)
diff --git a/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningServiceTest.kt b/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningServiceTest.kt
index 63305cbd..a2112657 100644
--- a/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningServiceTest.kt
+++ b/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningServiceTest.kt
@@ -32,7 +32,6 @@ import com.atlarge.opendc.compute.core.ServerState
import com.atlarge.opendc.compute.core.image.FlopsApplicationImage
import com.atlarge.opendc.compute.core.monitor.ServerMonitor
import com.atlarge.opendc.compute.metal.driver.SimpleBareMetalDriver
-import com.atlarge.opendc.core.resource.TagContainerImpl
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
@@ -51,7 +50,7 @@ internal class SimpleProvisioningServiceTest {
val provider = ServiceLoader.load(SimulationEngineProvider::class.java).first()
val system = provider({ _ ->
val flavor = ServerFlavor(listOf(ProcessingUnit("Intel", "Xeon", "amd64", 2300.0, 4)))
- val image = FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", TagContainerImpl(), 1000, 2)
+ val image = FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", emptyMap(), 1000, 2)
val monitor = object : ServerMonitor {
override suspend fun onUpdate(server: Server, previousState: ServerState) {
println(server)
diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagContainer.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagContainer.kt
index 4167cd20..6ba1cf0b 100644
--- a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagContainer.kt
+++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagContainer.kt
@@ -27,36 +27,10 @@ package com.atlarge.opendc.core.resource
/**
* An immutable map containing the tags of some resource.
*/
-public interface TagContainer {
- /**
- * The keys in this container.
- */
- public val keys: Collection<TagKey<*>>
+typealias TagContainer = Map<String, Any>
- /**
- * Determine if this container contains a tag with the specified [TagKey].
- *
- * @param key The key of the tag to check for.
- * @return `true` if the tag is in the container, `false` otherwise.
- */
- public operator fun contains(key: TagKey<*>): Boolean
-
- /**
- * Obtain the tag with the specified [TagKey].
- *
- * @param key The key of the tag to obtain.
- * @return The value of the tag.
- * @throws IllegalArgumentException if the tag does not exists in the container.
- */
- public operator fun <T : Any> get(key: TagKey<T>): T
-
- /**
- * Return the result of associating the specified [value] with the specified [key] in this container.
- */
- public fun <T : Any> put(key: TagKey<T>, value: T): TagContainer
-
- /**
- * Return the result of removing the specified [key] and its corresponding value from this container.
- */
- public fun remove(key: TagKey<*>): TagContainer
-}
+/**
+ * Obtain the value of the tag with the specified [key] of type [T]. If the tag does not exist or the tag is of
+ * different type, `null` is returned.
+ */
+inline fun <reified T : Any> TagContainer.typed(key: String): T? = this[key] as? T
diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagContainerImpl.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagContainerImpl.kt
deleted file mode 100644
index 1acc7de4..00000000
--- a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagContainerImpl.kt
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.core.resource
-
-/**
- * Default implementation of [TagContainer] interface.
- *
- * @property map The internal map object to hold the tags.
- */
-public class TagContainerImpl private constructor(private val map: Map<TagKey<*>, Any>) : TagContainer {
- /**
- * Construct an empty [TagContainerImpl].
- */
- public constructor() : this(emptyMap())
-
- override val keys: Collection<TagKey<*>>
- get() = map.keys
-
- override fun contains(key: TagKey<*>): Boolean = map.contains(key)
-
- override fun <T : Any> get(key: TagKey<T>): T {
- @Suppress("UNCHECKED_CAST")
- return map.getValue(key) as T
- }
-
- override fun <T : Any> put(key: TagKey<T>, value: T): TagContainer = TagContainerImpl(map.plus(key to value))
-
- override fun remove(key: TagKey<*>): TagContainer = TagContainerImpl(map.minus(key))
-}
diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagKey.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagKey.kt
deleted file mode 100644
index 759f4461..00000000
--- a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagKey.kt
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.core.resource
-
-/**
- * Represents a typed key for a resource tag with a unique name.
- */
-public data class TagKey<T : Any>(val name: String)
diff --git a/opendc/opendc-format/src/main/kotlin/com/atlarge/opendc/format/trace/gwf/GwfTraceReader.kt b/opendc/opendc-format/src/main/kotlin/com/atlarge/opendc/format/trace/gwf/GwfTraceReader.kt
index 6b721212..498e2d1d 100644
--- a/opendc/opendc-format/src/main/kotlin/com/atlarge/opendc/format/trace/gwf/GwfTraceReader.kt
+++ b/opendc/opendc-format/src/main/kotlin/com/atlarge/opendc/format/trace/gwf/GwfTraceReader.kt
@@ -26,7 +26,6 @@ package com.atlarge.opendc.format.trace.gwf
import com.atlarge.opendc.compute.core.image.FlopsApplicationImage
import com.atlarge.opendc.core.User
-import com.atlarge.opendc.core.resource.TagContainerImpl
import com.atlarge.opendc.format.trace.TraceEntry
import com.atlarge.opendc.format.trace.TraceReader
import com.atlarge.opendc.workflows.workload.Job
@@ -121,7 +120,7 @@ class GwfTraceReader(reader: BufferedReader) : TraceReader<Job> {
val workflow = entry.workload
val task = Task(
UUID(0L, taskId), "<unnamed>",
- FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", TagContainerImpl(), flops, cores),
+ FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", emptyMap(), flops, cores),
HashSet()
)
entry.submissionTime = min(entry.submissionTime, submitTime)
diff --git a/opendc/opendc-format/src/main/kotlin/com/atlarge/opendc/format/trace/vm/VmTraceReader.kt b/opendc/opendc-format/src/main/kotlin/com/atlarge/opendc/format/trace/vm/VmTraceReader.kt
index e8c8ac88..f4ed0f57 100644
--- a/opendc/opendc-format/src/main/kotlin/com/atlarge/opendc/format/trace/vm/VmTraceReader.kt
+++ b/opendc/opendc-format/src/main/kotlin/com/atlarge/opendc/format/trace/vm/VmTraceReader.kt
@@ -28,7 +28,6 @@ import com.atlarge.opendc.compute.core.image.FlopsHistoryFragment
import com.atlarge.opendc.compute.core.image.VmImage
import com.atlarge.opendc.compute.core.workload.VmWorkload
import com.atlarge.opendc.core.User
-import com.atlarge.opendc.core.resource.TagContainerImpl
import com.atlarge.opendc.format.trace.TraceEntry
import com.atlarge.opendc.format.trace.TraceReader
import java.io.BufferedReader
@@ -112,7 +111,7 @@ class VmTraceReader(traceDirectory: File) : TraceReader<VmWorkload> {
val uuid = UUID(0L, vmId)
val vmWorkload = VmWorkload(
uuid, "<unnamed>", UnnamedUser,
- VmImage(uuid, "<unnamed>", TagContainerImpl(), flopsHistory, cores)
+ VmImage(uuid, "<unnamed>", emptyMap(), flopsHistory, cores)
)
entries[vmId] = TraceEntryImpl(
flopsHistory.firstOrNull()?.tick ?: -1,