summaryrefslogtreecommitdiff
path: root/opendc-model-odc
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2018-02-14 12:32:57 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2018-02-14 12:32:57 +0100
commit157d30beb52c75831e29a1a22c199b95d6d30b42 (patch)
treec425bd9c5c6c76aa675634dd8c21590055f26f65 /opendc-model-odc
parent2e819d59934b5308bc58d6c69709112e2a6af402 (diff)
refactor(#18): Create distinction between kernel and simulation
This change creates a distinction between a kernel and a simulation. A single simulation is represented by a `Simulation` object which provides control over the simulation, while the `Kernel` interface allows users to create a new simulation using that kernel as backend.
Diffstat (limited to 'opendc-model-odc')
-rw-r--r--opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/JpaBootstrap.kt8
-rw-r--r--opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/platform/JpaExperiment.kt8
-rw-r--r--opendc-model-odc/setup/src/main/kotlin/com/atlarge/opendc/model/odc/platform/JpaPlatformRunner.kt5
3 files changed, 10 insertions, 11 deletions
diff --git a/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/JpaBootstrap.kt b/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/JpaBootstrap.kt
index 8c32c54d..0a0c792c 100644
--- a/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/JpaBootstrap.kt
+++ b/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/JpaBootstrap.kt
@@ -21,20 +21,20 @@ class JpaBootstrap(val experiment: Experiment) : Bootstrap<JpaModel> {
/**
* Bootstrap a model `M` for a kernel in the given context.
*
- * @param context The context to bootstrap to model in.
+ * @param context The context to apply to model in.
* @return The initialised model for the simulation.
*/
- override fun bootstrap(context: Bootstrap.Context<JpaModel>): JpaModel {
+ override fun apply(context: Bootstrap.Context<JpaModel>): JpaModel {
val section = experiment.path.sections.first()
- // TODO We should not modify parts of the experiment in a bootstrap as the bootstrap should be reproducible.
+ // TODO We should not modify parts of the experiment in a apply as the apply should be reproducible.
// Important: initialise the scheduler of the datacenter
section.datacenter.scheduler = experiment.scheduler
val topology = JpaTopologyFactory(section)
.create()
.bootstrap()
- .bootstrap(context)
+ .apply(context)
val trace = experiment.trace
val tasks = trace.jobs.flatMap { it.tasks }
diff --git a/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/platform/JpaExperiment.kt b/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/platform/JpaExperiment.kt
index 74f96ccb..4e88b3d4 100644
--- a/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/platform/JpaExperiment.kt
+++ b/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/platform/JpaExperiment.kt
@@ -34,7 +34,7 @@ import com.atlarge.opendc.model.odc.topology.container.Room
import com.atlarge.opendc.model.odc.topology.machine.Machine
import com.atlarge.opendc.model.topology.destinations
import com.atlarge.opendc.simulator.Duration
-import com.atlarge.opendc.simulator.kernel.KernelFactory
+import com.atlarge.opendc.simulator.kernel.Kernel
import com.atlarge.opendc.simulator.platform.Experiment
import mu.KotlinLogging
import java.io.Closeable
@@ -65,7 +65,7 @@ class JpaExperiment(private val manager: EntityManager,
* @param timeout The maximum duration of the experiment before returning to the caller.
* @return The result of the experiment or `null`.
*/
- override fun run(factory: KernelFactory, timeout: Duration): Unit? {
+ override fun run(factory: Kernel, timeout: Duration): Unit? {
if (experiment.state != ExperimentState.CLAIMED) {
throw IllegalStateException("The experiment is in illegal state ${experiment.state}")
}
@@ -136,7 +136,7 @@ class JpaExperiment(private val manager: EntityManager,
experiment.state = ExperimentState.FINISHED
}
- logger.info { "Kernel done" }
+ logger.info { "Simulation done" }
val waiting: Long = tasks.fold(0.toLong()) { acc, task ->
val finished = task.state as TaskState.Finished
acc + (finished.previous.at - finished.previous.previous.at)
@@ -165,7 +165,7 @@ class JpaExperiment(private val manager: EntityManager,
* @param factory The factory to create the simulation kernel with.
* @throws IllegalStateException if the simulation is already running or finished.
*/
- override fun run(factory: KernelFactory) = run(factory, -1)!!
+ override fun run(factory: Kernel) = run(factory, -1)!!
/**
* Closes this resource, relinquishing any underlying resources.
diff --git a/opendc-model-odc/setup/src/main/kotlin/com/atlarge/opendc/model/odc/platform/JpaPlatformRunner.kt b/opendc-model-odc/setup/src/main/kotlin/com/atlarge/opendc/model/odc/platform/JpaPlatformRunner.kt
index eb819a5b..13f322bc 100644
--- a/opendc-model-odc/setup/src/main/kotlin/com/atlarge/opendc/model/odc/platform/JpaPlatformRunner.kt
+++ b/opendc-model-odc/setup/src/main/kotlin/com/atlarge/opendc/model/odc/platform/JpaPlatformRunner.kt
@@ -24,8 +24,7 @@
package com.atlarge.opendc.model.odc.platform
-import com.atlarge.opendc.model.odc.platform.JpaExperimentManager
-import com.atlarge.opendc.omega.OmegaKernelFactory
+import com.atlarge.opendc.omega.OmegaKernel
import mu.KotlinLogging
import java.util.concurrent.Executors
import javax.persistence.Persistence
@@ -50,7 +49,7 @@ fun main(args: Array<String>) {
val threads = 4
val executorService = Executors.newFixedThreadPool(threads)
val experiments = JpaExperimentManager(factory)
- val kernel = OmegaKernelFactory
+ val kernel = OmegaKernel
logger.info { "Waiting for enqueued experiments..." }
while (true) {