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) --- .../experiments/base/models/scenario/Scenario.kt | 55 -------- .../base/models/scenario/ScenarioFactories.kt | 146 --------------------- .../base/models/scenario/ScenarioReader.kt | 49 ------- .../models/scenario/specs/AllocationPolicySpec.kt | 38 ------ .../base/models/scenario/specs/ExportModelSpec.kt | 37 ------ .../base/models/scenario/specs/FailureModelSpec.kt | 37 ------ .../base/models/scenario/specs/PowerModelSpec.kt | 30 ----- .../base/models/scenario/specs/ScenarioSpec.kt | 67 ---------- .../base/models/scenario/specs/TopologySpec.kt | 40 ------ .../base/models/scenario/specs/WorkloadSpec.kt | 70 ---------- .../experiments/base/runner/ScenarioHelpers.kt | 20 +-- .../experiments/base/runner/ScenarioRunner.kt | 45 ++----- .../opendc/experiments/base/scenario/Scenario.kt | 55 ++++++++ .../experiments/base/scenario/ScenarioFactories.kt | 112 ++++++++++++++++ .../experiments/base/scenario/ScenarioReader.kt | 49 +++++++ .../base/scenario/specs/AllocationPolicySpec.kt | 38 ++++++ .../base/scenario/specs/ExportModelSpec.kt | 37 ++++++ .../base/scenario/specs/FailureModelSpec.kt | 37 ++++++ .../base/scenario/specs/PowerModelSpec.kt | 30 +++++ .../base/scenario/specs/ScenarioSpec.kt | 67 ++++++++++ .../base/scenario/specs/ScenarioTopologySpec.kt | 40 ++++++ .../base/scenario/specs/WorkloadSpec.kt | 70 ++++++++++ 22 files changed, 550 insertions(+), 619 deletions(-) delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/Scenario.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/ScenarioFactories.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/ScenarioReader.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/AllocationPolicySpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/ExportModelSpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/FailureModelSpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/PowerModelSpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/ScenarioSpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/TopologySpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/WorkloadSpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/Scenario.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ScenarioFactories.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ScenarioReader.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/AllocationPolicySpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ExportModelSpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/FailureModelSpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/PowerModelSpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ScenarioSpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ScenarioTopologySpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/WorkloadSpec.kt (limited to 'opendc-experiments/opendc-experiments-base/src/main') diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/Scenario.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/Scenario.kt deleted file mode 100644 index bd4b5cc9..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/Scenario.kt +++ /dev/null @@ -1,55 +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.experiments.base.models.scenario - -import AllocationPolicySpec -import ExportModelSpec -import WorkloadSpec -import org.opendc.compute.simulator.failure.FailureModel -import org.opendc.compute.topology.specs.HostSpec - -/** - * A data class representing a scenario for a set of experiments. - * - * @property topology The list of HostSpec representing the topology of the scenario. - * @property workload The WorkloadSpec representing the workload of the scenario. - * @property allocationPolicy The AllocationPolicySpec representing the allocation policy of the scenario. - * @property failureModel The FailureModel representing the failure model of the scenario. It can be null. - * @property exportModel The ExportSpec representing the export model of the scenario. It defaults to an instance of ExportSpec. - * @property outputFolder The String representing the output folder of the scenario. It defaults to "output". - * @property name The String representing the name of the scenario. It defaults to an empty string. - * @property runs The Int representing the number of runs of the scenario. It defaults to 1. - * @property initialSeed The Int representing the initial seed of the scenario. It defaults to 0. - */ -public data class Scenario( - val topology: List, - val workload: WorkloadSpec, - val allocationPolicy: AllocationPolicySpec, - val failureModel: FailureModel?, - val carbonTracePath: String? = null, - val exportModel: ExportModelSpec = ExportModelSpec(), - val outputFolder: String = "output", - val name: String = "", - val runs: Int = 1, - val initialSeed: Int = 0, -) diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/ScenarioFactories.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/ScenarioFactories.kt deleted file mode 100644 index 05fa762e..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/ScenarioFactories.kt +++ /dev/null @@ -1,146 +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.experiments.base.models.scenario - -import AllocationPolicySpec -import TopologySpec -import WorkloadSpec -import org.opendc.compute.simulator.failure.getFailureModel -import org.opendc.compute.topology.TopologyReader -import org.opendc.compute.topology.clusterTopology -import org.opendc.compute.topology.specs.TopologyJSONSpec -import org.opendc.experiments.base.models.scenario.specs.ScenarioSpec -import java.io.File - -private val scenarioReader = ScenarioReader() - -/** - * Returns a list of Scenarios from a given file path (input). - * - * @param filePath The path to the file containing the scenario specifications. - * @return A list of Scenarios. - */ -public fun getScenario(filePath: String): List { - return getScenario(File(filePath)) -} - -/** - * Returns a list of Scenarios from a given file. Reads and decodes the contents of the (JSON) file. - * - * @param file The file containing the scenario specifications. - * @return A list of Scenarios. - */ -public fun getScenario(file: File): List { - return getScenario(scenarioReader.read(file)) -} - -/** - * Returns a list of Scenarios from a given ScenarioSpec. - * - * @param scenarioSpec The ScenarioSpec containing the scenario specifications. - * @return A list of Scenarios. - */ -public fun getScenario(scenarioSpec: ScenarioSpec): List { - return getScenarioCombinations(scenarioSpec) -} - -/** - * Returns a list of Scenarios from a given ScenarioSpec by generating all possible combinations of - * workloads, allocation policies, failure models, and export models within a topology. - * - * @param scenarioSpec The ScenarioSpec containing the scenario specifications. - * @return A list of Scenarios. - */ -public fun getScenarioCombinations(scenarioSpec: ScenarioSpec): List { - val topologiesSpec = scenarioSpec.topologies - val workloads = scenarioSpec.workloads - val allocationPolicies = scenarioSpec.allocationPolicies - val failureModels = scenarioSpec.failureModels - val exportModels = scenarioSpec.exportModels - val scenarios = mutableListOf() - - for (topology in topologiesSpec) { - for (workload in workloads) { - for (allocationPolicy in allocationPolicies) { - for (failureModel in failureModels) { - for (carbonTracePath in scenarioSpec.carbonTracePaths) { - for (exportModel in exportModels) { - val scenario = - Scenario( - topology = clusterTopology(File(topology.pathToFile)), - workload = workload, - allocationPolicy = allocationPolicy, - failureModel = getFailureModel(failureModel.failureInterval), - carbonTracePath = carbonTracePath, - exportModel = exportModel, - outputFolder = scenarioSpec.outputFolder, - name = getOutputFolderName(scenarioSpec, topology, workload, allocationPolicy), - runs = scenarioSpec.runs, - initialSeed = scenarioSpec.initialSeed, - ) - scenarios.add(scenario) - } - } - } - } - } - } - - return scenarios -} - -/** - * Returns a list of TopologyJSONSpec from a given list of TopologySpec. - * - * @param topologies The list of TopologySpec. - * @return A list of TopologyJSONSpec. - */ -public fun getTopologies(topologies: List): List { - val readTopologies = mutableListOf() - for (topology in topologies) { - readTopologies.add(TopologyReader().read(File(topology.pathToFile))) - } - - return readTopologies -} - -/** - * Returns a string representing the output folder name for a given ScenarioSpec, CpuPowerModel, AllocationPolicySpec, and topology path. - * - * @param scenarioSpec The ScenarioSpec. - * @param powerModel The CpuPowerModel. - * @param allocationPolicy The AllocationPolicySpec. - * @param topologyPath The path to the topology file. - * @return A string representing the output folder name. - */ -public fun getOutputFolderName( - scenarioSpec: ScenarioSpec, - topology: TopologySpec, - workload: WorkloadSpec, - allocationPolicy: AllocationPolicySpec, -): String { - return "scenario=${scenarioSpec.name}" + - "-topology=${topology.name}" + - "-workload=${workload.name}" + - "-scheduler=${allocationPolicy.name}" -} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/ScenarioReader.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/ScenarioReader.kt deleted file mode 100644 index ffbb3aa3..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/ScenarioReader.kt +++ /dev/null @@ -1,49 +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.experiments.base.models.scenario - -import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.decodeFromStream -import org.opendc.experiments.base.models.scenario.specs.ScenarioSpec -import java.io.File -import java.io.InputStream - -public class ScenarioReader { - @OptIn(ExperimentalSerializationApi::class) - public fun read(file: File): ScenarioSpec { - val input = file.inputStream() - val obj = Json.decodeFromStream(input) - - return obj - } - - /** - * Read the specified [input]. - */ - @OptIn(ExperimentalSerializationApi::class) - public fun read(input: InputStream): ScenarioSpec { - val obj = Json.decodeFromStream(input) - return obj - } -} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/AllocationPolicySpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/AllocationPolicySpec.kt deleted file mode 100644 index f7ae7e9f..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/AllocationPolicySpec.kt +++ /dev/null @@ -1,38 +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. - */ - -import kotlinx.serialization.Serializable -import org.opendc.compute.service.scheduler.ComputeSchedulerEnum - -/** - * specification describing how tasks are allocated - * - * @property policyType - * - * TODO: expand with more variables such as allowed over-subscription - */ -@Serializable -public data class AllocationPolicySpec( - val policyType: ComputeSchedulerEnum, -) { - public val name: String = policyType.toString() -} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/ExportModelSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/ExportModelSpec.kt deleted file mode 100644 index 9a23ad00..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/ExportModelSpec.kt +++ /dev/null @@ -1,37 +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. - */ - -import kotlinx.serialization.Serializable - -/** - * specification describing how the results should be exported - * - * @property exportInterval The interval of exporting results in s. Should be higher than 0.0 - */ -@Serializable -public data class ExportModelSpec( - val exportInterval: Long = 5 * 60, -) { - init { - require(exportInterval > 0) { "The Export interval has to be higher than 0" } - } -} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/FailureModelSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/FailureModelSpec.kt deleted file mode 100644 index 99620366..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/FailureModelSpec.kt +++ /dev/null @@ -1,37 +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. - */ - -import kotlinx.serialization.Serializable - -/** - * specification describing the failure model - * - * @property failureInterval The interval between failures in s. Should be 0.0 or higher - */ -@Serializable -public data class FailureModelSpec( - val failureInterval: Double = 0.0, -) { - init { - require(failureInterval >= 0.0) { "failure frequency cannot be lower than 0" } - } -} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/PowerModelSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/PowerModelSpec.kt deleted file mode 100644 index fc568925..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/PowerModelSpec.kt +++ /dev/null @@ -1,30 +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. - */ - -import kotlinx.serialization.Serializable - -@Serializable -public data class PowerModelSpec( - val type: String = "constant", - val idlePower: Double = 200.0, - val maxPower: Double = 350.0, -) diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/ScenarioSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/ScenarioSpec.kt deleted file mode 100644 index 15012461..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/ScenarioSpec.kt +++ /dev/null @@ -1,67 +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.experiments.base.models.scenario.specs - -import AllocationPolicySpec -import ExportModelSpec -import FailureModelSpec -import TopologySpec -import WorkloadSpec -import kotlinx.serialization.Serializable - -/** - * specification describing a scenario - * - * @property topologies - * @property workloads - * @property allocationPolicies - * @property failureModels - * @property exportModels - * @property outputFolder - * @property initialSeed - * @property runs - */ -@Serializable -public data class ScenarioSpec( - val topologies: List, - val workloads: List, - val allocationPolicies: List, - val failureModels: List = listOf(FailureModelSpec()), - val carbonTracePaths: List = listOf(null), - val exportModels: List = listOf(ExportModelSpec()), - val outputFolder: String = "output", - val initialSeed: Int = 0, - val runs: Int = 1, - var name: String = "", -) { - init { - require(runs > 0) { "The number of runs should always be positive" } - - // generate name if not provided - // TODO: improve this - if (name == "") { - name = - "workload=${workloads[0].name}_topology=${topologies[0].name}_allocationPolicy=${allocationPolicies[0].name}" - } - } -} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/TopologySpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/TopologySpec.kt deleted file mode 100644 index 392b9763..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/TopologySpec.kt +++ /dev/null @@ -1,40 +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. - */ - -import kotlinx.serialization.Serializable -import java.io.File - -/** - * specification describing a topology - * - * @property pathToFile - */ -@Serializable -public data class TopologySpec( - val pathToFile: String, -) { - public val name: String = File(pathToFile).nameWithoutExtension - - init { - require(File(pathToFile).exists()) { "The provided path to the topology: $pathToFile does not exist " } - } -} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/WorkloadSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/WorkloadSpec.kt deleted file mode 100644 index 819f633d..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/models/scenario/specs/WorkloadSpec.kt +++ /dev/null @@ -1,70 +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. - */ - -import kotlinx.serialization.Serializable -import org.opendc.compute.workload.ComputeWorkload -import org.opendc.compute.workload.sampleByLoad -import org.opendc.compute.workload.trace -import java.io.File - -/** - * specification describing a workload - * - * @property pathToFile - * @property type - */ -@Serializable -public data class WorkloadSpec( - val pathToFile: String, - val type: WorkloadTypes, -) { - public val name: String = File(pathToFile).nameWithoutExtension - - init { - require(File(pathToFile).exists()) { "The provided path to the workload: $pathToFile does not exist " } - } -} - -/** - * specification describing a workload type - * - * @constructor Create empty Workload types - */ -public enum class WorkloadTypes { - /** - * Compute workload - * - * @constructor Create empty Compute workload - */ - ComputeWorkload, -} - -/** - * - *TODO: move to separate file - * @param type - */ -public fun getWorkloadType(type: WorkloadTypes): ComputeWorkload { - return when (type) { - WorkloadTypes.ComputeWorkload -> trace("trace").sampleByLoad(1.0) - } -} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ScenarioHelpers.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ScenarioHelpers.kt index 97914556..e1305b3f 100644 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ScenarioHelpers.kt +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ScenarioHelpers.kt @@ -24,6 +24,7 @@ package org.opendc.experiments.base.runner +import FailureModelSpec import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch @@ -33,11 +34,8 @@ import org.opendc.compute.api.Server import org.opendc.compute.api.ServerState import org.opendc.compute.api.ServerWatcher import org.opendc.compute.service.ComputeService -import org.opendc.compute.simulator.failure.FailureModel import org.opendc.compute.workload.VirtualMachine import java.time.InstantSource -import java.util.Random -import kotlin.coroutines.coroutineContext import kotlin.math.max /** @@ -76,16 +74,16 @@ public class RunningServerWatcher : ServerWatcher { * @param trace The trace to simulate. * @param seed The seed to use for randomness. * @param submitImmediately A flag to indicate that the servers are scheduled immediately (so not at their start time). - * @param failureModel A failure model to use for injecting failures. + * @param failureModelSpec A failure model to use for injecting failures. */ public suspend fun ComputeService.replay( clock: InstantSource, trace: List, - seed: Long, + failureModelSpec: FailureModelSpec? = null, + seed: Long = 0, submitImmediately: Boolean = false, - failureModel: FailureModel? = null, ) { - val injector = failureModel?.createInjector(coroutineContext, clock, this, Random(seed)) + // TODO: add failureModel functionality val client = newClient() // Create new image for the virtual machine @@ -93,8 +91,7 @@ public suspend fun ComputeService.replay( try { coroutineScope { - // Start the fault injector - injector?.start() + // TODO: start failure model when implemented var simulationOffset = Long.MIN_VALUE @@ -107,9 +104,6 @@ public suspend fun ComputeService.replay( simulationOffset = start - now } - // Make sure the trace entries are ordered by submission time - // assert(start - simulationOffset >= 0) { "Invalid trace order" } - // Delay the server based on the startTime given by the trace. if (!submitImmediately) { delay(max(0, (start - now - simulationOffset))) @@ -146,7 +140,7 @@ public suspend fun ComputeService.replay( } yield() } finally { - injector?.close() + // TODO: close failure model when implemented client.close() } } diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ScenarioRunner.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ScenarioRunner.kt index 734cdacc..bf5188a2 100644 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ScenarioRunner.kt +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ScenarioRunner.kt @@ -35,8 +35,9 @@ import org.opendc.compute.simulator.provisioner.registerComputeMonitor import org.opendc.compute.simulator.provisioner.setupComputeService import org.opendc.compute.simulator.provisioner.setupHosts import org.opendc.compute.telemetry.export.parquet.ParquetComputeMonitor +import org.opendc.compute.topology.clusterTopology import org.opendc.compute.workload.ComputeWorkloadLoader -import org.opendc.experiments.base.models.scenario.Scenario +import org.opendc.experiments.base.scenario.Scenario import org.opendc.simulator.kotlin.runSimulation import java.io.File import java.time.Duration @@ -47,10 +48,10 @@ import java.util.stream.LongStream /** * Run scenario when no pool is available for parallel execution * - * @param scenario The scenario to run + * @param scenarios The scenarios to run * @param parallelism The number of scenarios that can be run in parallel */ -public fun runScenario( +public fun runScenarios( scenarios: List, parallelism: Int, ) { @@ -110,12 +111,14 @@ public fun runScenario( runSimulation { val serviceDomain = "compute.opendc.org" Provisioner(dispatcher, seed).use { provisioner -> + + val topology = clusterTopology(scenario.topology.pathToFile, Random(seed)) provisioner.runSteps( setupComputeService( serviceDomain, { createComputeScheduler(ComputeSchedulerEnum.Mem, Random(it.seeder.nextLong())) }, ), - setupHosts(serviceDomain, scenario.topology, optimize = true), + setupHosts(serviceDomain, topology, optimize = true), ) val workloadLoader = ComputeWorkloadLoader(File(scenario.workload.pathToFile)) @@ -126,42 +129,10 @@ public fun runScenario( saveInOutputFolder(provisioner, serviceDomain, scenario, seed, startTime, carbonTrace) val service = provisioner.registry.resolve(serviceDomain, ComputeService::class.java)!! - service.replay(timeSource, vms, seed, failureModel = scenario.failureModel) + service.replay(timeSource, vms, failureModelSpec = scenario.failureModel, seed = seed) } } -/** - * When the simulation is run, saves the simulation results into a seed folder. This is useful for debugging purposes. - * @param provisioner The provisioner used to setup and run the simulation. - * @param serviceDomain The domain of the compute service. - * @param scenario The scenario being run in the simulation. - * @param seed The seed used for randomness in the simulation. - * @param partition The partition name for the output data. - * @param startTime The start time of the simulation. - - */ -public fun saveInSeedFolder( - provisioner: Provisioner, - serviceDomain: String, - scenario: Scenario, - seed: Long, - partition: String, - startTime: Duration, -) { - provisioner.runStep( - registerComputeMonitor( - serviceDomain, - ParquetComputeMonitor( - File(scenario.outputFolder), - partition, - bufferSize = 4096, - ), - Duration.ofSeconds(scenario.exportModel.exportInterval), - startTime, - ), - ) -} - /** * Saves the simulation results into a specific output folder received from the input. * diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/Scenario.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/Scenario.kt new file mode 100644 index 00000000..4f3fcd4f --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/Scenario.kt @@ -0,0 +1,55 @@ +/* + * 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.experiments.base.scenario + +import AllocationPolicySpec +import ExportModelSpec +import FailureModelSpec +import ScenarioTopologySpec +import WorkloadSpec + +/** + * A data class representing a scenario for a set of experiments. + * + * @property topology The list of HostSpec representing the topology of the scenario. + * @property workload The WorkloadSpec representing the workload of the scenario. + * @property allocationPolicy The AllocationPolicySpec representing the allocation policy of the scenario. + * @property failureModel The FailureModel representing the failure model of the scenario. It can be null. + * @property exportModel The ExportSpec representing the export model of the scenario. It defaults to an instance of ExportSpec. + * @property outputFolder The String representing the output folder of the scenario. It defaults to "output". + * @property name The String representing the name of the scenario. It defaults to an empty string. + * @property runs The Int representing the number of runs of the scenario. It defaults to 1. + * @property initialSeed The Int representing the initial seed of the scenario. It defaults to 0. + */ +public data class Scenario( + val topology: ScenarioTopologySpec, + val workload: WorkloadSpec, + val allocationPolicy: AllocationPolicySpec, + val failureModel: FailureModelSpec?, + val carbonTracePath: String? = null, + val exportModel: ExportModelSpec = ExportModelSpec(), + val outputFolder: String = "output", + val name: String = "", + val runs: Int = 1, + val initialSeed: Int = 0, +) diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ScenarioFactories.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ScenarioFactories.kt new file mode 100644 index 00000000..010c8845 --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ScenarioFactories.kt @@ -0,0 +1,112 @@ +/* + * 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.experiments.base.scenario + +import AllocationPolicySpec +import ScenarioTopologySpec +import WorkloadSpec +import org.opendc.experiments.base.scenario.specs.ScenarioSpec +import java.io.File + +private val scenarioReader = ScenarioReader() + +/** + * Returns a list of Scenarios from a given file path (input). + * + * @param filePath The path to the file containing the scenario specifications. + * @return A list of Scenarios. + */ +public fun getScenarios(filePath: String): List { + return getScenarios(File(filePath)) +} + +/** + * Returns a list of Scenarios from a given file. Reads and decodes the contents of the (JSON) file. + * + * @param file The file containing the scenario specifications. + * @return A list of Scenarios. + */ +public fun getScenarios(file: File): List { + return getScenarios(scenarioReader.read(file)) +} + +/** + * Returns a list of Scenarios from a given ScenarioSpec by generating all possible combinations of + * workloads, allocation policies, failure models, and export models within a topology. + * + * @param scenarioSpec The ScenarioSpec containing the scenario specifications. + * @return A list of Scenarios. + */ +public fun getScenarios(scenarioSpec: ScenarioSpec): List { + val scenarios = mutableListOf() + + for (scenarioTopologySpec in scenarioSpec.topologies) { + for (workloadSpec in scenarioSpec.workloads) { + for (allocationPolicySpec in scenarioSpec.allocationPolicies) { + for (failureModelSpec in scenarioSpec.failureModels) { + for (carbonTracePath in scenarioSpec.carbonTracePaths) { + for (exportModelSpec in scenarioSpec.exportModels) { + val scenario = + Scenario( + topology = scenarioTopologySpec, + workload = workloadSpec, + allocationPolicy = allocationPolicySpec, + failureModel = failureModelSpec, + carbonTracePath = carbonTracePath, + exportModel = exportModelSpec, + outputFolder = scenarioSpec.outputFolder, + name = getOutputFolderName(scenarioSpec, scenarioTopologySpec, workloadSpec, allocationPolicySpec), + runs = scenarioSpec.runs, + initialSeed = scenarioSpec.initialSeed, + ) + scenarios.add(scenario) + } + } + } + } + } + } + + return scenarios +} + +/** + * Returns a string representing the output folder name for a given ScenarioSpec, CpuPowerModel, AllocationPolicySpec, and topology path. + * + * @param scenarioSpec The ScenarioSpec. + * @param topology The specification of the topology used + * @param workload The specification of the workload + * @param allocationPolicy The allocation policy used + * @return A string representing the output folder name. + */ +public fun getOutputFolderName( + scenarioSpec: ScenarioSpec, + topology: ScenarioTopologySpec, + workload: WorkloadSpec, + allocationPolicy: AllocationPolicySpec, +): String { + return "scenario=${scenarioSpec.name}" + + "-topology=${topology.name}" + + "-workload=${workload.name}" + + "-allocation=${allocationPolicy.name}" +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ScenarioReader.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ScenarioReader.kt new file mode 100644 index 00000000..19ce5a14 --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ScenarioReader.kt @@ -0,0 +1,49 @@ +/* + * 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.experiments.base.scenario + +import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.decodeFromStream +import org.opendc.experiments.base.scenario.specs.ScenarioSpec +import java.io.File +import java.io.InputStream + +public class ScenarioReader { + @OptIn(ExperimentalSerializationApi::class) + public fun read(file: File): ScenarioSpec { + val input = file.inputStream() + val obj = Json.decodeFromStream(input) + + return obj + } + + /** + * Read the specified [input]. + */ + @OptIn(ExperimentalSerializationApi::class) + public fun read(input: InputStream): ScenarioSpec { + val obj = Json.decodeFromStream(input) + return obj + } +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/AllocationPolicySpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/AllocationPolicySpec.kt new file mode 100644 index 00000000..f7ae7e9f --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/AllocationPolicySpec.kt @@ -0,0 +1,38 @@ +/* + * 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. + */ + +import kotlinx.serialization.Serializable +import org.opendc.compute.service.scheduler.ComputeSchedulerEnum + +/** + * specification describing how tasks are allocated + * + * @property policyType + * + * TODO: expand with more variables such as allowed over-subscription + */ +@Serializable +public data class AllocationPolicySpec( + val policyType: ComputeSchedulerEnum, +) { + public val name: String = policyType.toString() +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ExportModelSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ExportModelSpec.kt new file mode 100644 index 00000000..9a23ad00 --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ExportModelSpec.kt @@ -0,0 +1,37 @@ +/* + * 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. + */ + +import kotlinx.serialization.Serializable + +/** + * specification describing how the results should be exported + * + * @property exportInterval The interval of exporting results in s. Should be higher than 0.0 + */ +@Serializable +public data class ExportModelSpec( + val exportInterval: Long = 5 * 60, +) { + init { + require(exportInterval > 0) { "The Export interval has to be higher than 0" } + } +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/FailureModelSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/FailureModelSpec.kt new file mode 100644 index 00000000..99620366 --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/FailureModelSpec.kt @@ -0,0 +1,37 @@ +/* + * 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. + */ + +import kotlinx.serialization.Serializable + +/** + * specification describing the failure model + * + * @property failureInterval The interval between failures in s. Should be 0.0 or higher + */ +@Serializable +public data class FailureModelSpec( + val failureInterval: Double = 0.0, +) { + init { + require(failureInterval >= 0.0) { "failure frequency cannot be lower than 0" } + } +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/PowerModelSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/PowerModelSpec.kt new file mode 100644 index 00000000..fc568925 --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/PowerModelSpec.kt @@ -0,0 +1,30 @@ +/* + * 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. + */ + +import kotlinx.serialization.Serializable + +@Serializable +public data class PowerModelSpec( + val type: String = "constant", + val idlePower: Double = 200.0, + val maxPower: Double = 350.0, +) diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ScenarioSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ScenarioSpec.kt new file mode 100644 index 00000000..cfbb913c --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ScenarioSpec.kt @@ -0,0 +1,67 @@ +/* + * 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.experiments.base.scenario.specs + +import AllocationPolicySpec +import ExportModelSpec +import FailureModelSpec +import ScenarioTopologySpec +import WorkloadSpec +import kotlinx.serialization.Serializable + +/** + * specification describing a scenario + * + * @property topologies + * @property workloads + * @property allocationPolicies + * @property failureModels + * @property exportModels + * @property outputFolder + * @property initialSeed + * @property runs + */ +@Serializable +public data class ScenarioSpec( + val topologies: List, + val workloads: List, + val allocationPolicies: List, + val failureModels: List = listOf(FailureModelSpec()), + val carbonTracePaths: List = listOf(null), + val exportModels: List = listOf(ExportModelSpec()), + val outputFolder: String = "output", + val initialSeed: Int = 0, + val runs: Int = 1, + var name: String = "", +) { + init { + require(runs > 0) { "The number of runs should always be positive" } + + // generate name if not provided + // TODO: improve this + if (name == "") { + name = + "workload=${workloads[0].name}_topology=${topologies[0].name}_allocationPolicy=${allocationPolicies[0].name}" + } + } +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ScenarioTopologySpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ScenarioTopologySpec.kt new file mode 100644 index 00000000..47d3447f --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ScenarioTopologySpec.kt @@ -0,0 +1,40 @@ +/* + * 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. + */ + +import kotlinx.serialization.Serializable +import java.io.File + +/** + * specification describing a topology + * + * @property pathToFile + */ +@Serializable +public data class ScenarioTopologySpec( + val pathToFile: String, +) { + public val name: String = File(pathToFile).nameWithoutExtension + + init { + require(File(pathToFile).exists()) { "The provided path to the topology: $pathToFile does not exist " } + } +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/WorkloadSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/WorkloadSpec.kt new file mode 100644 index 00000000..819f633d --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/WorkloadSpec.kt @@ -0,0 +1,70 @@ +/* + * 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. + */ + +import kotlinx.serialization.Serializable +import org.opendc.compute.workload.ComputeWorkload +import org.opendc.compute.workload.sampleByLoad +import org.opendc.compute.workload.trace +import java.io.File + +/** + * specification describing a workload + * + * @property pathToFile + * @property type + */ +@Serializable +public data class WorkloadSpec( + val pathToFile: String, + val type: WorkloadTypes, +) { + public val name: String = File(pathToFile).nameWithoutExtension + + init { + require(File(pathToFile).exists()) { "The provided path to the workload: $pathToFile does not exist " } + } +} + +/** + * specification describing a workload type + * + * @constructor Create empty Workload types + */ +public enum class WorkloadTypes { + /** + * Compute workload + * + * @constructor Create empty Compute workload + */ + ComputeWorkload, +} + +/** + * + *TODO: move to separate file + * @param type + */ +public fun getWorkloadType(type: WorkloadTypes): ComputeWorkload { + return when (type) { + WorkloadTypes.ComputeWorkload -> trace("trace").sampleByLoad(1.0) + } +} -- cgit v1.2.3