From 1b8e81343f576b0a29cf94e02e0429f5011b1f52 Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Mon, 29 Apr 2024 13:51:36 +0200 Subject: Reworked Scenario.kt to consist of only specifications. The Specs are turned into objects when the scenario is being executed by ScenarioRunner.kt (#227) --- .../opendc/compute/topology/TopologyFactories.kt | 22 ++-- .../org/opendc/compute/topology/TopologyReader.kt | 10 +- .../org/opendc/compute/topology/specs/JSONSpecs.kt | 118 --------------------- .../opendc/compute/topology/specs/TopologySpecs.kt | 118 +++++++++++++++++++++ 4 files changed, 139 insertions(+), 129 deletions(-) delete mode 100644 opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/JSONSpecs.kt create mode 100644 opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt (limited to 'opendc-compute') diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt index 549086d4..bab886a4 100644 --- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt +++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt @@ -24,10 +24,10 @@ package org.opendc.compute.topology -import org.opendc.compute.topology.specs.ClusterJSONSpec +import org.opendc.compute.topology.specs.ClusterSpec import org.opendc.compute.topology.specs.HostJSONSpec import org.opendc.compute.topology.specs.HostSpec -import org.opendc.compute.topology.specs.TopologyJSONSpec +import org.opendc.compute.topology.specs.TopologySpec import org.opendc.simulator.compute.SimPsuFactories import org.opendc.simulator.compute.model.MachineModel import org.opendc.simulator.compute.model.MemoryUnit @@ -45,6 +45,16 @@ import java.util.random.RandomGenerator */ private val reader = TopologyReader() +/** + * Construct a topology from the specified [pathToFile]. + */ +public fun clusterTopology( + pathToFile: String, + random: RandomGenerator = SplittableRandom(0), +): List { + return clusterTopology(File(pathToFile), random) +} + /** * Construct a topology from the specified [file]. */ @@ -68,9 +78,9 @@ public fun clusterTopology( } /** - * Helper method to convert a [TopologyJSONSpec] into a list of [HostSpec]s. + * Helper method to convert a [TopologySpec] into a list of [HostSpec]s. */ -private fun TopologyJSONSpec.toHostSpecs(random: RandomGenerator): List { +private fun TopologySpec.toHostSpecs(random: RandomGenerator): List { return clusters.flatMap { cluster -> List(cluster.count) { cluster.toHostSpecs(random) @@ -79,11 +89,11 @@ private fun TopologyJSONSpec.toHostSpecs(random: RandomGenerator): List { +private fun ClusterSpec.toHostSpecs(random: RandomGenerator): List { val hostSpecs = hosts.flatMap { host -> ( diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyReader.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyReader.kt index 70e08e3b..63719c0a 100644 --- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyReader.kt +++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyReader.kt @@ -25,7 +25,7 @@ package org.opendc.compute.topology import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json import kotlinx.serialization.json.decodeFromStream -import org.opendc.compute.topology.specs.TopologyJSONSpec +import org.opendc.compute.topology.specs.TopologySpec import java.io.File import java.io.InputStream @@ -34,9 +34,9 @@ import java.io.InputStream */ public class TopologyReader { @OptIn(ExperimentalSerializationApi::class) - public fun read(file: File): TopologyJSONSpec { + public fun read(file: File): TopologySpec { val input = file.inputStream() - val obj = Json.decodeFromStream(input) + val obj = Json.decodeFromStream(input) return obj } @@ -45,8 +45,8 @@ public class TopologyReader { * Read the specified [input]. */ @OptIn(ExperimentalSerializationApi::class) - public fun read(input: InputStream): TopologyJSONSpec { - val obj = Json.decodeFromStream(input) + public fun read(input: InputStream): TopologySpec { + val obj = Json.decodeFromStream(input) return obj } } diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/JSONSpecs.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/JSONSpecs.kt deleted file mode 100644 index 2bfed502..00000000 --- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/JSONSpecs.kt +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2024 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 org.opendc.compute.topology.specs - -import kotlinx.serialization.Serializable - -/** - * Definition of a Topology modeled in the simulation. - * - * @param clusters List of the clusters in this topology - */ -@Serializable -public data class TopologyJSONSpec( - val clusters: List, - val schemaVersion: Int = 1, -) - -/** - * Definition of a compute cluster modeled in the simulation. - * - * @param name The name of the cluster. - * @param hosts List of the different hosts (nodes) available in this cluster - * @param location Location of the cluster. This can impact the carbon intensity - */ -@Serializable -public data class ClusterJSONSpec( - val name: String = "Cluster", - val count: Int = 1, - val hosts: List, - val location: String = "NL", -) - -/** - * Definition of a compute host modeled in the simulation. - * - * @param name The name of the host. - * @param cpu The CPU available in this cluster - * @param memory The amount of RAM memory available in Byte - * @param powerModel The power model used to determine the power draw of a host - * @param count The power model used to determine the power draw of a host - */ -@Serializable -public data class HostJSONSpec( - val name: String = "Host", - val cpu: CPUJSONSpec, - val memory: MemoryJSONSpec, - val powerModel: PowerModelJSONSpec = PowerModelJSONSpec("linear", 350.0, 400.0, 200.0), - val count: Int = 1, -) - -/** - * Definition of a compute CPU modeled in the simulation. - * - * @param vendor The vendor of the storage device. - * @param modelName The model name of the device. - * @param arch The micro-architecture of the processor node. - * @param coreCount The number of cores in the CPU - * @param coreSpeed The speed of the cores in Mhz - */ -@Serializable -public data class CPUJSONSpec( - val vendor: String = "unknown", - val modelName: String = "unknown", - val arch: String = "unknown", - val coreCount: Int, - val coreSpeed: Double, - val count: Int = 1, -) - -/** - * Definition of a compute Memory modeled in the simulation. - * - * @param vendor The vendor of the storage device. - * @param modelName The model name of the device. - * @param arch The micro-architecture of the processor node. - * @param memorySpeed The speed of the cores in ? - * @param memorySize The size of the memory Unit in MiB - */ -@Serializable -public data class MemoryJSONSpec( - val vendor: String = "unknown", - val modelName: String = "unknown", - val arch: String = "unknown", - val memorySpeed: Double = -1.0, - val memorySize: Long, -) - -@Serializable -public data class PowerModelJSONSpec( - val modelType: String, - val power: Double = 400.0, - val maxPower: Double, - val idlePower: Double, -) { - init { - require(maxPower >= idlePower) { "The max power of a power model can not be less than the idle power" } - } -} diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt new file mode 100644 index 00000000..f34bc855 --- /dev/null +++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2024 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 org.opendc.compute.topology.specs + +import kotlinx.serialization.Serializable + +/** + * Definition of a Topology modeled in the simulation. + * + * @param clusters List of the clusters in this topology + */ +@Serializable +public data class TopologySpec( + val clusters: List, + val schemaVersion: Int = 1, +) + +/** + * Definition of a compute cluster modeled in the simulation. + * + * @param name The name of the cluster. + * @param hosts List of the different hosts (nodes) available in this cluster + * @param location Location of the cluster. This can impact the carbon intensity + */ +@Serializable +public data class ClusterSpec( + val name: String = "Cluster", + val count: Int = 1, + val hosts: List, + val location: String = "NL", +) + +/** + * Definition of a compute host modeled in the simulation. + * + * @param name The name of the host. + * @param cpu The CPU available in this cluster + * @param memory The amount of RAM memory available in Byte + * @param powerModel The power model used to determine the power draw of a host + * @param count The power model used to determine the power draw of a host + */ +@Serializable +public data class HostJSONSpec( + val name: String = "Host", + val cpu: CPUSpec, + val memory: MemorySpec, + val powerModel: PowerModelSpec = PowerModelSpec("linear", 350.0, 400.0, 200.0), + val count: Int = 1, +) + +/** + * Definition of a compute CPU modeled in the simulation. + * + * @param vendor The vendor of the storage device. + * @param modelName The model name of the device. + * @param arch The micro-architecture of the processor node. + * @param coreCount The number of cores in the CPU + * @param coreSpeed The speed of the cores in Mhz + */ +@Serializable +public data class CPUSpec( + val vendor: String = "unknown", + val modelName: String = "unknown", + val arch: String = "unknown", + val coreCount: Int, + val coreSpeed: Double, + val count: Int = 1, +) + +/** + * Definition of a compute Memory modeled in the simulation. + * + * @param vendor The vendor of the storage device. + * @param modelName The model name of the device. + * @param arch The micro-architecture of the processor node. + * @param memorySpeed The speed of the cores in ? + * @param memorySize The size of the memory Unit in MiB + */ +@Serializable +public data class MemorySpec( + val vendor: String = "unknown", + val modelName: String = "unknown", + val arch: String = "unknown", + val memorySpeed: Double = -1.0, + val memorySize: Long, +) + +@Serializable +public data class PowerModelSpec( + val modelType: String, + val power: Double = 400.0, + val maxPower: Double, + val idlePower: Double, +) { + init { + require(maxPower >= idlePower) { "The max power of a power model can not be less than the idle power" } + } +} -- cgit v1.2.3