summaryrefslogtreecommitdiff
path: root/simulator/opendc/opendc-runner-web
diff options
context:
space:
mode:
Diffstat (limited to 'simulator/opendc/opendc-runner-web')
-rw-r--r--simulator/opendc/opendc-runner-web/build.gradle.kts1
-rw-r--r--simulator/opendc/opendc-runner-web/src/main/kotlin/com/atlarge/opendc/runner/web/Main.kt27
-rw-r--r--simulator/opendc/opendc-runner-web/src/main/kotlin/com/atlarge/opendc/runner/web/TopologyParser.kt5
3 files changed, 17 insertions, 16 deletions
diff --git a/simulator/opendc/opendc-runner-web/build.gradle.kts b/simulator/opendc/opendc-runner-web/build.gradle.kts
index 6f725de1..1d263e75 100644
--- a/simulator/opendc/opendc-runner-web/build.gradle.kts
+++ b/simulator/opendc/opendc-runner-web/build.gradle.kts
@@ -39,6 +39,7 @@ dependencies {
implementation(project(":opendc:opendc-compute"))
implementation(project(":opendc:opendc-format"))
implementation(project(":opendc:opendc-experiments-sc20"))
+ implementation(project(":opendc:opendc-simulator"))
implementation("com.github.ajalt:clikt:2.8.0")
implementation("io.github.microutils:kotlin-logging:1.7.10")
diff --git a/simulator/opendc/opendc-runner-web/src/main/kotlin/com/atlarge/opendc/runner/web/Main.kt b/simulator/opendc/opendc-runner-web/src/main/kotlin/com/atlarge/opendc/runner/web/Main.kt
index 9cfe5531..ac4d9087 100644
--- a/simulator/opendc/opendc-runner-web/src/main/kotlin/com/atlarge/opendc/runner/web/Main.kt
+++ b/simulator/opendc/opendc-runner-web/src/main/kotlin/com/atlarge/opendc/runner/web/Main.kt
@@ -1,6 +1,5 @@
package com.atlarge.opendc.runner.web
-import com.atlarge.odcsim.SimulationEngineProvider
import com.atlarge.opendc.compute.virt.service.allocation.*
import com.atlarge.opendc.experiments.sc20.experiment.attachMonitor
import com.atlarge.opendc.experiments.sc20.experiment.createFailureDomain
@@ -24,8 +23,10 @@ import com.mongodb.client.MongoDatabase
import com.mongodb.client.model.Filters
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
+import kotlinx.coroutines.test.TestCoroutineScope
import mu.KotlinLogging
import org.bson.Document
+import org.opendc.simulator.utils.DelayControllerClockAdapter
import java.io.File
import java.util.*
import kotlin.random.Random
@@ -33,13 +34,9 @@ import kotlin.random.Random
private val logger = KotlinLogging.logger {}
/**
- * The provider for the simulation engine to use.
- */
-private val provider = ServiceLoader.load(SimulationEngineProvider::class.java).first()
-
-/**
* Represents the CLI command for starting the OpenDC web runner.
*/
+@OptIn(ExperimentalCoroutinesApi::class)
class RunnerCli : CliktCommand(name = "runner") {
/**
* The name of the database to use.
@@ -195,8 +192,8 @@ class RunnerCli : CliktCommand(name = "runner") {
val workloadFraction = traceDocument.get("loadSamplingFraction", Number::class.java).toDouble()
val seeder = Random(seed)
- val system = provider("experiment-$id")
- val root = system.newDomain("root")
+ val testScope = TestCoroutineScope()
+ val clock = DelayControllerClockAdapter(testScope)
val chan = Channel<Unit>(Channel.CONFLATED)
@@ -230,9 +227,10 @@ class RunnerCli : CliktCommand(name = "runner") {
4096
)
- root.launch {
+ testScope.launch {
val (bareMetalProvisioner, scheduler) = createProvisioner(
- root,
+ this,
+ clock,
environment,
allocationPolicy
)
@@ -240,6 +238,8 @@ class RunnerCli : CliktCommand(name = "runner") {
val failureDomain = if (operational.getBoolean("failuresEnabled")) {
logger.debug("ENABLING failures")
createFailureDomain(
+ testScope,
+ clock,
seeder.nextInt(),
operational.get("failureFrequency", Number::class.java)?.toDouble() ?: 24.0 * 7,
bareMetalProvisioner,
@@ -249,8 +249,10 @@ class RunnerCli : CliktCommand(name = "runner") {
null
}
- attachMonitor(scheduler, monitor)
+ attachMonitor(this, clock, scheduler, monitor)
processTrace(
+ this,
+ clock,
trace,
scheduler,
chan,
@@ -269,9 +271,8 @@ class RunnerCli : CliktCommand(name = "runner") {
}
try {
- system.run()
+ testScope.advanceUntilIdle()
} finally {
- system.terminate()
monitor.close()
}
}
diff --git a/simulator/opendc/opendc-runner-web/src/main/kotlin/com/atlarge/opendc/runner/web/TopologyParser.kt b/simulator/opendc/opendc-runner-web/src/main/kotlin/com/atlarge/opendc/runner/web/TopologyParser.kt
index ab683985..f9b1c6c4 100644
--- a/simulator/opendc/opendc-runner-web/src/main/kotlin/com/atlarge/opendc/runner/web/TopologyParser.kt
+++ b/simulator/opendc/opendc-runner-web/src/main/kotlin/com/atlarge/opendc/runner/web/TopologyParser.kt
@@ -1,6 +1,5 @@
package com.atlarge.opendc.runner.web
-import com.atlarge.odcsim.simulationContext
import com.atlarge.opendc.compute.core.MemoryUnit
import com.atlarge.opendc.compute.core.ProcessingNode
import com.atlarge.opendc.compute.core.ProcessingUnit
@@ -23,6 +22,7 @@ import com.mongodb.client.model.Projections
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.bson.Document
+import java.time.Clock
import java.util.*
/**
@@ -32,8 +32,7 @@ class TopologyParser(private val collection: MongoCollection<Document>, private
/**
* Parse the topology with the specified [id].
*/
- override suspend fun construct(coroutineScope: CoroutineScope): Environment {
- val clock = simulationContext.clock
+ override suspend fun construct(coroutineScope: CoroutineScope, clock: Clock): Environment {
val nodes = mutableListOf<SimpleBareMetalDriver>()
val random = Random(0)