From 2e819d59934b5308bc58d6c69709112e2a6af402 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 13 Feb 2018 14:27:15 +0100 Subject: refactor(#18): Fix OpenDC model deployment This change fixes the deployment of the OpenDC simulation model. --- .../kotlin/com/atlarge/opendc/omega/OmegaKernel.kt | 4 +- .../model/odc/topology/container/Datacenter.kt | 5 ++ .../com/atlarge/opendc/model/odc/JpaBootstrap.kt | 7 +++ .../opendc/model/odc/platform/JpaExperiment.kt | 24 ++++---- opendc-model-odc/setup/Dockerfile | 5 +- opendc-model-odc/setup/build.gradle | 2 +- .../opendc/model/odc/platform/JpaPlatformRunner.kt | 66 ++++++++++++++++++++++ .../src/main/kotlin/platform/JpaPlatformRunner.kt | 66 ---------------------- 8 files changed, 94 insertions(+), 85 deletions(-) create mode 100644 opendc-model-odc/setup/src/main/kotlin/com/atlarge/opendc/model/odc/platform/JpaPlatformRunner.kt delete mode 100644 opendc-model-odc/setup/src/main/kotlin/platform/JpaPlatformRunner.kt diff --git a/opendc-kernel-omega/src/main/kotlin/com/atlarge/opendc/omega/OmegaKernel.kt b/opendc-kernel-omega/src/main/kotlin/com/atlarge/opendc/omega/OmegaKernel.kt index 91150078..6ece73aa 100644 --- a/opendc-kernel-omega/src/main/kotlin/com/atlarge/opendc/omega/OmegaKernel.kt +++ b/opendc-kernel-omega/src/main/kotlin/com/atlarge/opendc/omega/OmegaKernel.kt @@ -122,7 +122,7 @@ internal class OmegaKernel(bootstrap: Bootstrap) : Kernel, Bootstrap.Co break } else if (delivery < time) { // Tick has already occurred - logger.warn { "message processed out of order" } + logger.warn { "Message processed out of order" } } queue.poll() @@ -270,7 +270,7 @@ internal class OmegaKernel(bootstrap: Bootstrap) : Kernel, Bootstrap.Co override suspend fun Entity<*, *>.send(msg: Any, delay: Duration) = send(msg, process, delay) override suspend fun Entity<*, *>.send(msg: Any, sender: Entity<*, *>, delay: Duration) = - schedule(prepare(msg, sender, delay = delay)) + schedule(prepare(msg, this, sender, delay)) override suspend fun Entity<*, *>.interrupt() = send(Interrupt) diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Datacenter.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Datacenter.kt index b9b804d3..7293d9f7 100644 --- a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Datacenter.kt +++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Datacenter.kt @@ -26,6 +26,7 @@ package com.atlarge.opendc.model.odc.topology.container import com.atlarge.opendc.model.odc.platform.scheduler.Scheduler import com.atlarge.opendc.model.odc.platform.workload.Task +import com.atlarge.opendc.model.odc.platform.workload.TaskState import com.atlarge.opendc.model.odc.topology.machine.Machine import com.atlarge.opendc.model.topology.Topology import com.atlarge.opendc.model.topology.destinations @@ -88,6 +89,10 @@ interface Datacenter : Process { while (queue.isNotEmpty()) { val msg = queue.poll() if (msg is Task) { + if (msg.state != TaskState.Underway) { + logger.warn { "Received invalid task $msg"} + continue + } msg.arrive(time) scheduler.submit(msg) } 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 09d8f4b3..8c32c54d 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 @@ -5,6 +5,7 @@ import com.atlarge.opendc.model.odc.integration.jpa.schema.Task import com.atlarge.opendc.model.odc.topology.JpaTopologyFactory import com.atlarge.opendc.model.topology.bootstrap import com.atlarge.opendc.simulator.Bootstrap +import mu.KotlinLogging /** * A [Bootstrap] procedure for experiments retrieved from a JPA data store. @@ -12,6 +13,11 @@ import com.atlarge.opendc.simulator.Bootstrap * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ class JpaBootstrap(val experiment: Experiment) : Bootstrap { + /** + * The logging instance. + */ + private val logger = KotlinLogging.logger {} + /** * Bootstrap a model `M` for a kernel in the given context. * @@ -35,6 +41,7 @@ class JpaBootstrap(val experiment: Experiment) : Bootstrap { // Schedule all messages in the trace tasks.forEach { task -> if (task is Task) { + logger.info { "Scheduling $task" } context.schedule(task, section.datacenter, delay = task.startTime) } } 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 6c3ad5e8..74f96ccb 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 @@ -115,22 +115,20 @@ class JpaExperiment(private val manager: EntityManager, manager.persist(wrapped) } - trace.jobs.asSequence() - .flatMap { it.tasks.asSequence() } - .forEach { task -> - val state = InternalTaskState(0, - task as com.atlarge.opendc.model.odc.integration.jpa.schema.Task, - experiment, - simulation.time, - task.remaining.toInt(), - 1 - ) - manager.persist(state) - } + tasks.forEach { task -> + val state = InternalTaskState(0, + task as com.atlarge.opendc.model.odc.integration.jpa.schema.Task, + experiment, + simulation.time, + task.remaining.toInt(), + 1 + ) + manager.persist(state) + } } // Run next simulation cycle - simulation.run(simulation.time + 1) + simulation.step() } // Set the experiment state diff --git a/opendc-model-odc/setup/Dockerfile b/opendc-model-odc/setup/Dockerfile index 70e6fe11..bfebc044 100644 --- a/opendc-model-odc/setup/Dockerfile +++ b/opendc-model-odc/setup/Dockerfile @@ -17,7 +17,7 @@ USER root WORKDIR $APP_HOME # Build the application -RUN gradle --no-daemon :opendc-model-odc:setup:installDist +RUN gradle --no-daemon assemble installDist # Fix permissions RUN chown -R gradle:gradle $APP_HOME @@ -26,5 +26,4 @@ RUN chown -R gradle:gradle $APP_HOME USER gradle # Start the Gradle application on run -CMD opendc-odc-model/setup/build/install/setup/bin/setup - +CMD opendc-model-odc/setup/build/install/setup/bin/setup diff --git a/opendc-model-odc/setup/build.gradle b/opendc-model-odc/setup/build.gradle index ddb5860b..1cca2a6e 100644 --- a/opendc-model-odc/setup/build.gradle +++ b/opendc-model-odc/setup/build.gradle @@ -44,7 +44,7 @@ apply plugin: 'application' apply plugin: 'kotlin' apply plugin: 'org.jetbrains.dokka' -mainClassName = "nl.atlarge.opendc.model.odc.platform.JpaPlatformRunnerKt" +mainClassName = "com.atlarge.opendc.model.odc.platform.JpaPlatformRunnerKt" compileKotlin { kotlinOptions { 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 new file mode 100644 index 00000000..eb819a5b --- /dev/null +++ b/opendc-model-odc/setup/src/main/kotlin/com/atlarge/opendc/model/odc/platform/JpaPlatformRunner.kt @@ -0,0 +1,66 @@ +/* + * MIT License + * + * Copyright (c) 2017 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.model.odc.platform + +import com.atlarge.opendc.model.odc.platform.JpaExperimentManager +import com.atlarge.opendc.omega.OmegaKernelFactory +import mu.KotlinLogging +import java.util.concurrent.Executors +import javax.persistence.Persistence + +val logger = KotlinLogging.logger {} + +/** + * The main entry point of the program. This program polls experiments from a database and runs the + * simulation and reports the results back to the database. + * + * @param args The command line arguments of the program. + */ +fun main(args: Array) { + val properties = HashMap() + val env = System.getenv() + properties["javax.persistence.jdbc.url"] = env["PERSISTENCE_URL"] ?: "" + properties["javax.persistence.jdbc.user"] = env["PERSISTENCE_USER"] ?: "" + properties["javax.persistence.jdbc.password"] = env["PERSISTENCE_PASSWORD"] ?: "" + val factory = Persistence.createEntityManagerFactory("opendc-simulator", properties) + + val timeout = 10000L + val threads = 4 + val executorService = Executors.newFixedThreadPool(threads) + val experiments = JpaExperimentManager(factory) + val kernel = OmegaKernelFactory + + logger.info { "Waiting for enqueued experiments..." } + while (true) { + experiments.poll()?.let { experiment -> + logger.info { "Found experiment. Submitting for simulation now..." } + executorService.submit { + experiment.use { it.run(kernel, timeout) } + } + } + + Thread.sleep(500) + } +} diff --git a/opendc-model-odc/setup/src/main/kotlin/platform/JpaPlatformRunner.kt b/opendc-model-odc/setup/src/main/kotlin/platform/JpaPlatformRunner.kt deleted file mode 100644 index 8fe49844..00000000 --- a/opendc-model-odc/setup/src/main/kotlin/platform/JpaPlatformRunner.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 platform - -import com.atlarge.opendc.model.odc.platform.JpaExperimentManager -import com.atlarge.opendc.omega.OmegaKernelFactory -import mu.KotlinLogging -import java.util.concurrent.Executors -import javax.persistence.Persistence - -val logger = KotlinLogging.logger {} - -/** - * The main entry point of the program. This program polls experiments from a database and runs the - * simulation and reports the results back to the database. - * - * @param args The command line arguments of the program. - */ -fun main(args: Array) { - val properties = HashMap() - val env = System.getenv() - properties["javax.persistence.jdbc.url"] = env["PERSISTENCE_URL"] ?: "" - properties["javax.persistence.jdbc.user"] = env["PERSISTENCE_USER"] ?: "" - properties["javax.persistence.jdbc.password"] = env["PERSISTENCE_PASSWORD"] ?: "" - val factory = Persistence.createEntityManagerFactory("opendc-simulator", properties) - - val timeout = 10000L - val threads = 4 - val executorService = Executors.newFixedThreadPool(threads) - val experiments = JpaExperimentManager(factory) - val kernel = OmegaKernelFactory - - logger.info { "Waiting for enqueued experiments..." } - while (true) { - experiments.poll()?.let { experiment -> - logger.info { "Found experiment. Submitting for simulation now..." } - executorService.submit { - experiment.use { it.run(kernel, timeout) } - } - } - - Thread.sleep(500) - } -} -- cgit v1.2.3