diff options
| author | Dante Niewenhuis <d.niewenhuis@hotmail.com> | 2024-04-29 13:51:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-29 13:51:36 +0200 |
| commit | 1b8e81343f576b0a29cf94e02e0429f5011b1f52 (patch) | |
| tree | 3abefbc3fabe6d51dd34df0ffb2dd3a4daf2d5b0 /opendc-compute/opendc-compute-topology/src | |
| parent | 2dc44c7283200f4689cc1be15115a8b1cd37d456 (diff) | |
Reworked Scenario.kt to consist of only specifications. The Specs are turned into objects when the scenario is being executed by ScenarioRunner.kt (#227)
Diffstat (limited to 'opendc-compute/opendc-compute-topology/src')
| -rw-r--r-- | opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt | 22 | ||||
| -rw-r--r-- | opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyReader.kt | 10 | ||||
| -rw-r--r-- | opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt (renamed from opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/JSONSpecs.kt) | 18 |
3 files changed, 30 insertions, 20 deletions
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 @@ -46,6 +46,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<HostSpec> { + return clusterTopology(File(pathToFile), random) +} + +/** * Construct a topology from the specified [file]. */ public fun clusterTopology( @@ -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<HostSpec> { +private fun TopologySpec.toHostSpecs(random: RandomGenerator): List<HostSpec> { return clusters.flatMap { cluster -> List(cluster.count) { cluster.toHostSpecs(random) @@ -79,11 +89,11 @@ private fun TopologyJSONSpec.toHostSpecs(random: RandomGenerator): List<HostSpec } /** - * Helper method to convert a [ClusterJSONSpec] into a list of [HostSpec]s. + * Helper method to convert a [ClusterSpec] into a list of [HostSpec]s. */ private var clusterId = 0 -private fun ClusterJSONSpec.toHostSpecs(random: RandomGenerator): List<HostSpec> { +private fun ClusterSpec.toHostSpecs(random: RandomGenerator): List<HostSpec> { 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<TopologyJSONSpec>(input) + val obj = Json.decodeFromStream<TopologySpec>(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<TopologyJSONSpec>(input) + public fun read(input: InputStream): TopologySpec { + val obj = Json.decodeFromStream<TopologySpec>(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/TopologySpecs.kt index 2bfed502..f34bc855 100644 --- 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/TopologySpecs.kt @@ -30,8 +30,8 @@ import kotlinx.serialization.Serializable * @param clusters List of the clusters in this topology */ @Serializable -public data class TopologyJSONSpec( - val clusters: List<ClusterJSONSpec>, +public data class TopologySpec( + val clusters: List<ClusterSpec>, val schemaVersion: Int = 1, ) @@ -43,7 +43,7 @@ public data class TopologyJSONSpec( * @param location Location of the cluster. This can impact the carbon intensity */ @Serializable -public data class ClusterJSONSpec( +public data class ClusterSpec( val name: String = "Cluster", val count: Int = 1, val hosts: List<HostJSONSpec>, @@ -62,9 +62,9 @@ public data class ClusterJSONSpec( @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 cpu: CPUSpec, + val memory: MemorySpec, + val powerModel: PowerModelSpec = PowerModelSpec("linear", 350.0, 400.0, 200.0), val count: Int = 1, ) @@ -78,7 +78,7 @@ public data class HostJSONSpec( * @param coreSpeed The speed of the cores in Mhz */ @Serializable -public data class CPUJSONSpec( +public data class CPUSpec( val vendor: String = "unknown", val modelName: String = "unknown", val arch: String = "unknown", @@ -97,7 +97,7 @@ public data class CPUJSONSpec( * @param memorySize The size of the memory Unit in MiB */ @Serializable -public data class MemoryJSONSpec( +public data class MemorySpec( val vendor: String = "unknown", val modelName: String = "unknown", val arch: String = "unknown", @@ -106,7 +106,7 @@ public data class MemoryJSONSpec( ) @Serializable -public data class PowerModelJSONSpec( +public data class PowerModelSpec( val modelType: String, val power: Double = 400.0, val maxPower: Double, |
