summaryrefslogtreecommitdiff
path: root/simulator/opendc-compute/opendc-compute-service/src
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-03-09 15:05:47 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-03-09 15:05:47 +0100
commitf5efde88ec95fc139e957303615c302d4aa2035d (patch)
treec9885811ba1843a2bf7d2f7350f626b1bcb37080 /simulator/opendc-compute/opendc-compute-service/src
parent970f5c6f653c8442ecd9b73b208a53a2dbb9a150 (diff)
compute: Introduce labels and meta-data for resources
This change adds the ability to define labels and meta-data for resources. This can be used in the future to identify servers and pass data between client and server.
Diffstat (limited to 'simulator/opendc-compute/opendc-compute-service/src')
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ClientServer.kt8
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ComputeServiceImpl.kt46
2 files changed, 24 insertions, 30 deletions
diff --git a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ClientServer.kt b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ClientServer.kt
index e65c5f1c..bca1ad44 100644
--- a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ClientServer.kt
+++ b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ClientServer.kt
@@ -46,7 +46,10 @@ internal class ClientServer(private val delegate: Server) : Server, ServerWatche
override var image: Image = delegate.image
private set
- override var tags: Map<String, String> = delegate.tags.toMap()
+ override var labels: Map<String, String> = delegate.labels.toMap()
+ private set
+
+ override var meta: Map<String, Any> = delegate.meta.toMap()
private set
override var state: ServerState = delegate.state
@@ -87,7 +90,8 @@ internal class ClientServer(private val delegate: Server) : Server, ServerWatche
name = delegate.name
flavor = delegate.flavor
image = delegate.image
- tags = delegate.tags
+ labels = delegate.labels
+ meta = delegate.meta
state = delegate.state
}
diff --git a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ComputeServiceImpl.kt b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ComputeServiceImpl.kt
index 453f5d65..0d4f379d 100644
--- a/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ComputeServiceImpl.kt
+++ b/simulator/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ComputeServiceImpl.kt
@@ -26,7 +26,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
-import kotlinx.coroutines.suspendCancellableCoroutine
import mu.KotlinLogging
import org.opendc.compute.api.*
import org.opendc.compute.service.ComputeService
@@ -41,9 +40,7 @@ import org.opendc.utils.TimerScheduler
import org.opendc.utils.flow.EventFlow
import java.time.Clock
import java.util.*
-import kotlin.coroutines.Continuation
import kotlin.coroutines.CoroutineContext
-import kotlin.coroutines.resume
import kotlin.math.max
/**
@@ -130,6 +127,8 @@ public class ComputeServiceImpl(
name: String,
image: Image,
flavor: Flavor,
+ labels: Map<String, String>,
+ meta: Map<String, Any>,
start: Boolean
): Server {
check(!isClosed) { "Client is closed" }
@@ -148,7 +147,14 @@ public class ComputeServiceImpl(
)
)
- val server = createServer(name, image, flavor)
+ val server = ServerImpl(
+ uid = UUID(random.nextLong(), random.nextLong()),
+ name,
+ flavor,
+ image,
+ labels.toMutableMap(),
+ meta.toMutableMap()
+ )
if (start) {
server.start()
}
@@ -189,19 +195,6 @@ public class ComputeServiceImpl(
scope.cancel()
}
- private fun createServer(
- name: String,
- image: Image,
- flavor: Flavor,
- ): ServerImpl {
- return ServerImpl(
- uid = UUID(random.nextLong(), random.nextLong()),
- name,
- flavor,
- image
- )
- }
-
private fun requestCycle() {
// Bail out in case we have already requested a new cycle.
if (scheduler.isTimerActive(Unit)) {
@@ -220,7 +213,7 @@ public class ComputeServiceImpl(
private fun schedule() {
while (queue.isNotEmpty()) {
- val (server, cont) = queue.peekFirst()
+ val (server) = queue.peekFirst()
val requiredMemory = server.flavor.memorySize
val selectedHv = allocationLogic.select(availableHosts, server)
@@ -265,7 +258,6 @@ public class ComputeServiceImpl(
scope.launch {
try {
selectedHv.host.spawn(server)
- cont.resume(Unit)
activeServers[server] = selectedHv.host
tracer.commit(VmScheduledEvent(server.name))
@@ -390,13 +382,15 @@ public class ComputeServiceImpl(
}
}
- private data class LaunchRequest(val server: ServerImpl, val cont: Continuation<Unit>)
+ private data class LaunchRequest(val server: ServerImpl)
private inner class ServerImpl(
override val uid: UUID,
override val name: String,
override val flavor: Flavor,
- override val image: Image
+ override val image: Image,
+ override val labels: MutableMap<String, String>,
+ override val meta: MutableMap<String, Any>
) : Server {
val watchers = mutableListOf<ServerWatcher>()
@@ -417,11 +411,9 @@ public class ComputeServiceImpl(
else -> {
logger.info { "User requested to start server $uid" }
state = ServerState.PROVISIONING
- suspendCancellableCoroutine<Unit> { cont ->
- val request = LaunchRequest(this, cont)
- queue += request
- requestCycle()
- }
+ val request = LaunchRequest(this)
+ queue += request
+ requestCycle()
}
}
}
@@ -463,8 +455,6 @@ public class ComputeServiceImpl(
// No-op: this object is the source-of-truth
}
- override val tags: Map<String, String> = emptyMap()
-
override var state: ServerState = ServerState.TERMINATED
set(value) {
if (value != field) {