From 0f835d57b0e989e25aa0b71fe374a0fb1a94e86f Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Tue, 5 Nov 2024 14:17:08 +0100 Subject: Documentation update (#261) * Updated a lot of documentation, added a new get-started tutorial. * Applied Spotless * Applied Spotless Java * Added bitbrains workload to site --- .../opendc-experiments-base/build.gradle.kts | 6 +- .../base/experiment/ExperimentFactories.kt | 115 ++++++++ .../base/experiment/ExperimentReader.kt | 53 ++++ .../base/experiment/ExperimentWriter.kt | 67 +++++ .../opendc/experiments/base/experiment/Scenario.kt | 61 ++++ .../base/experiment/specs/AllocationPolicySpec.kt | 40 +++ .../base/experiment/specs/CheckpointModelSpec.kt | 32 +++ .../base/experiment/specs/ExperimentSpec.kt | 116 ++++++++ .../base/experiment/specs/ExportModelSpec.kt | 39 +++ .../base/experiment/specs/FailureModelSpec.kt | 320 +++++++++++++++++++++ .../base/experiment/specs/PowerModelSpec.kt | 32 +++ .../base/experiment/specs/ScenarioSpec.kt | 41 +++ .../base/experiment/specs/ScenarioTopologySpec.kt | 42 +++ .../base/experiment/specs/WorkloadSpec.kt | 72 +++++ .../experiments/base/runner/ExperimentCli.kt | 2 +- .../experiments/base/runner/ExperimentRunner.kt | 2 +- .../experiments/base/runner/ScenarioReplayer.kt | 4 +- .../experiments/base/runner/ScenarioRunner.kt | 4 +- .../base/scenario/ExperimentFactories.kt | 115 -------- .../experiments/base/scenario/ExperimentReader.kt | 53 ---- .../experiments/base/scenario/ExperimentWriter.kt | 67 ----- .../opendc/experiments/base/scenario/Scenario.kt | 61 ---- .../base/scenario/specs/AllocationPolicySpec.kt | 40 --- .../base/scenario/specs/CheckpointModelSpec.kt | 32 --- .../base/scenario/specs/ExperimentSpec.kt | 116 -------- .../base/scenario/specs/ExportModelSpec.kt | 39 --- .../base/scenario/specs/FailureModelSpec.kt | 320 --------------------- .../base/scenario/specs/PowerModelSpec.kt | 32 --- .../base/scenario/specs/ScenarioSpec.kt | 41 --- .../base/scenario/specs/ScenarioTopologySpec.kt | 42 --- .../base/scenario/specs/WorkloadSpec.kt | 72 ----- .../experiments/base/ScenarioIntegrationTest.kt | 2 +- .../org/opendc/experiments/m3sa/runner/M3SACli.kt | 2 +- .../opendc/experiments/m3sa/runner/M3SARunner.kt | 2 +- .../experiments/m3sa/scenario/M3SAFactories.kt | 2 +- 35 files changed, 1043 insertions(+), 1043 deletions(-) create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/ExperimentFactories.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/ExperimentReader.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/ExperimentWriter.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/Scenario.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/AllocationPolicySpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/CheckpointModelSpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ExperimentSpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ExportModelSpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/FailureModelSpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/PowerModelSpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ScenarioSpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ScenarioTopologySpec.kt create mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/WorkloadSpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ExperimentFactories.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ExperimentReader.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ExperimentWriter.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/Scenario.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/AllocationPolicySpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/CheckpointModelSpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ExperimentSpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ExportModelSpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/FailureModelSpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/PowerModelSpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ScenarioSpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ScenarioTopologySpec.kt delete mode 100644 opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/WorkloadSpec.kt (limited to 'opendc-experiments') diff --git a/opendc-experiments/opendc-experiments-base/build.gradle.kts b/opendc-experiments/opendc-experiments-base/build.gradle.kts index d8921ffb..36073418 100644 --- a/opendc-experiments/opendc-experiments-base/build.gradle.kts +++ b/opendc-experiments/opendc-experiments-base/build.gradle.kts @@ -52,8 +52,8 @@ dependencies { val createScenarioApp by tasks.creating(CreateStartScripts::class) { dependsOn(tasks.jar) - applicationName = "OpenDCScenarioRunner" - mainClass.set("org.opendc.experiments.base.runner.ScenarioCli") + applicationName = "OpenDCExperimentRunner" + mainClass.set("org.opendc.experiments.base.runner.ExperimentCli") classpath = tasks.jar.get().outputs.files + configurations["runtimeClasspath"] outputDir = project.buildDir.resolve("scripts") } @@ -61,7 +61,7 @@ val createScenarioApp by tasks.creating(CreateStartScripts::class) { // Create custom Scenario distribution distributions { main { - distributionBaseName.set("OpenDCScenarioRunner") + distributionBaseName.set("OpenDCExperimentRunner") contents { from("README.md") diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/ExperimentFactories.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/ExperimentFactories.kt new file mode 100644 index 00000000..5d158ea3 --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/ExperimentFactories.kt @@ -0,0 +1,115 @@ +/* + * 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.experiment + +import org.opendc.experiments.base.experiment.specs.ExperimentSpec +import org.opendc.experiments.base.experiment.specs.ScenarioSpec +import java.io.File + +private val experimentReader = ExperimentReader() +private val experimentWriter = ExperimentWriter() + +/** + * 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 getExperiment(filePath: String): List { + return getExperiment(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 getExperiment(file: File): List { + return getExperiment(experimentReader.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 experimentSpec The ScenarioSpec containing the scenario specifications. + * @return A list of Scenarios. + */ +public fun getExperiment(experimentSpec: ExperimentSpec): List { + val outputFolder = experimentSpec.outputFolder + "/" + experimentSpec.name + File(outputFolder).mkdirs() + + val trackrPath = "$outputFolder/trackr.json" + File(trackrPath).createNewFile() + + val scenarios = mutableListOf() + + val cartesianInput = experimentSpec.getCartesian() + + for ((scenarioID, scenarioSpec) in cartesianInput.withIndex()) { + val scenario = + Scenario( + id = scenarioID, + name = scenarioID.toString(), + outputFolder = outputFolder, + runs = experimentSpec.runs, + initialSeed = experimentSpec.initialSeed, + computeExportConfig = scenarioSpec.computeExportConfig, + topologySpec = scenarioSpec.topology, + workloadSpec = scenarioSpec.workload, + allocationPolicySpec = scenarioSpec.allocationPolicy, + exportModelSpec = scenarioSpec.exportModel, + failureModelSpec = scenarioSpec.failureModel, + checkpointModelSpec = scenarioSpec.checkpointModel, + maxNumFailures = scenarioSpec.maxNumFailures, + ) + trackScenario(scenarioSpec, outputFolder) + scenarios.add(scenario) + } + + return scenarios +} + +/** + * Writes a ScenarioSpec to a file. + * + * @param scenariosSpec The ScenarioSpec. + * @param outputFolder The output folder path. + * @param scenario The Scenario. + * @param topologySpec The TopologySpec. + + */ +public fun trackScenario( + scenarioSpec: ScenarioSpec, + outputFolder: String, +) { + val trackrPath = "$outputFolder/trackr.json" + experimentWriter.write( + scenarioSpec, + File(trackrPath), + ) + + // remove the last comma + File(trackrPath).writeText(File(trackrPath).readText().dropLast(3) + "]") +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/ExperimentReader.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/ExperimentReader.kt new file mode 100644 index 00000000..12127644 --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/ExperimentReader.kt @@ -0,0 +1,53 @@ +/* + * 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.experiment + +import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.decodeFromStream +import org.opendc.compute.simulator.telemetry.parquet.ComputeExportConfig +import org.opendc.experiments.base.experiment.specs.ExperimentSpec +import java.io.File +import java.io.InputStream +import java.nio.file.Path +import kotlin.io.path.inputStream + +public class ExperimentReader { + private val jsonReader = Json + + public fun read(file: File): ExperimentSpec = read(file.inputStream()) + + public fun read(path: Path): ExperimentSpec = read(path.inputStream()) + + /** + * Read the specified [input]. + */ + @OptIn(ExperimentalSerializationApi::class) + public fun read(input: InputStream): ExperimentSpec { + // Loads the default parquet output fields, + // so that they can be deserialized + ComputeExportConfig.loadDfltColumns() + + return jsonReader.decodeFromStream(input) + } +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/ExperimentWriter.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/ExperimentWriter.kt new file mode 100644 index 00000000..73331fe2 --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/ExperimentWriter.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.experiment + +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json +import org.opendc.experiments.base.experiment.specs.ScenarioSpec +import java.io.File + +/** + * A writer for writing scenarios to a file. + * @param jsonText The JSON text to write to the file, which is constantly updated during the writing process. + * @param json The JSON object used to encode the scenario specification. + */ +public class ExperimentWriter { + private var jsonText = "[" + private val json = Json { prettyPrint = true } + + /** + * Write the given [scenariosSpec] to the given [file]. + */ + public fun write( + scenarioSpec: ScenarioSpec, + file: File, + ) { + openArray(file) + val jsonString = json.encodeToString(scenarioSpec) + "," + jsonText += jsonString + "\n" + file.writeText(jsonText) + closeArray(file) + } + + /** + * Delete the last character of the file. + */ + private fun openArray(file: File) { + val text = file.readText() + file.writeText(text.dropLast(0)) + } + + /** + * Add the closing bracket to the file. + */ + private fun closeArray(file: File) { + file.appendText("]") + } +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/Scenario.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/Scenario.kt new file mode 100644 index 00000000..a99bd061 --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/Scenario.kt @@ -0,0 +1,61 @@ +/* + * 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.experiment + +import org.opendc.compute.simulator.telemetry.parquet.ComputeExportConfig +import org.opendc.experiments.base.experiment.specs.AllocationPolicySpec +import org.opendc.experiments.base.experiment.specs.CheckpointModelSpec +import org.opendc.experiments.base.experiment.specs.ExportModelSpec +import org.opendc.experiments.base.experiment.specs.FailureModelSpec +import org.opendc.experiments.base.experiment.specs.ScenarioTopologySpec +import org.opendc.experiments.base.experiment.specs.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. + * @property computeExportConfig configures which parquet columns are to be included in the output files. + */ +public data class Scenario( + var id: Int = -1, + val name: String = "", + val outputFolder: String = "output", + val runs: Int = 1, + val initialSeed: Int = 0, + val computeExportConfig: ComputeExportConfig, + val topologySpec: ScenarioTopologySpec, + val workloadSpec: WorkloadSpec, + val allocationPolicySpec: AllocationPolicySpec, + val exportModelSpec: ExportModelSpec = ExportModelSpec(), + val failureModelSpec: FailureModelSpec?, + val checkpointModelSpec: CheckpointModelSpec?, + val maxNumFailures: Int = 10, +) diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/AllocationPolicySpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/AllocationPolicySpec.kt new file mode 100644 index 00000000..0bd3d476 --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/AllocationPolicySpec.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. + */ + +package org.opendc.experiments.base.experiment.specs + +import kotlinx.serialization.Serializable +import org.opendc.compute.simulator.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 = ComputeSchedulerEnum.Mem, +) { + public val name: String = policyType.toString() +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/CheckpointModelSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/CheckpointModelSpec.kt new file mode 100644 index 00000000..47c3eb70 --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/CheckpointModelSpec.kt @@ -0,0 +1,32 @@ +/* + * 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.experiment.specs + +import kotlinx.serialization.Serializable + +@Serializable +public data class CheckpointModelSpec( + val checkpointInterval: Long = 60 * 60 * 1000, + val checkpointDuration: Long = 5 * 60 * 1000, + val checkpointIntervalScaling: Double = 1.0, +) diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ExperimentSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ExperimentSpec.kt new file mode 100644 index 00000000..6d8c8ebf --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ExperimentSpec.kt @@ -0,0 +1,116 @@ +/* + * 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.experiment.specs + +import kotlinx.serialization.Serializable +import org.opendc.common.logger.infoNewLine +import org.opendc.common.logger.logger +import org.opendc.compute.simulator.telemetry.parquet.ComputeExportConfig +import java.util.UUID + +/** + * specification describing a scenario + * + * @property topologies + * @property workloads + * @property allocationPolicies + * @property failureModels + * @property exportModels + * @property outputFolder + * @property initialSeed + * @property runs + * @property computeExportConfig configures which parquet columns are to + * be included in the output files. + */ + +@Serializable +public data class ExperimentSpec( + var id: Int = -1, + var name: String = "", + val outputFolder: String = "output", + val initialSeed: Int = 0, + val runs: Int = 1, + val exportModels: Set = setOf(ExportModelSpec()), + val computeExportConfig: ComputeExportConfig = ComputeExportConfig.ALL_COLUMNS, + val maxNumFailures: Set = setOf(10), + val topologies: Set, + val workloads: Set, + val allocationPolicies: Set = setOf(AllocationPolicySpec()), + val failureModels: Set = setOf(null), + val checkpointModels: Set = setOf(null), +) { + init { + require(runs > 0) { "The number of runs should always be positive" } + + // generate name if not provided + // TODO: improve this + if (name == "") { + name = "unnamed-simulation-${UUID.randomUUID().toString().substring(0, 4)}" +// "workload=${workloads[0].name}_topology=${topologies[0].name}_allocationPolicy=${allocationPolicies[0].name}" + } + + LOG.infoNewLine(computeExportConfig.fmt()) + } + + public fun getCartesian(): Sequence { + return sequence { + val checkpointDiv = maxNumFailures.size + val failureDiv = checkpointDiv * checkpointModels.size + val exportDiv = failureDiv * failureModels.size + val allocationDiv = exportDiv * exportModels.size + val workloadDiv = allocationDiv * allocationPolicies.size + val topologyDiv = workloadDiv * workloads.size + val numScenarios = topologyDiv * topologies.size + + val topologyList = topologies.toList() + val workloadList = workloads.toList() + val allocationPolicyList = allocationPolicies.toList() + val exportModelList = exportModels.toList() + val failureModelList = failureModels.toList() + val checkpointModelList = checkpointModels.toList() + val maxNumFailuresList = maxNumFailures.toList() + + for (i in 0 until numScenarios) { + yield( + ScenarioSpec( + id, + name, + outputFolder, + computeExportConfig = computeExportConfig, + topologyList[(i / topologyDiv) % topologyList.size], + workloadList[(i / workloadDiv) % workloadList.size], + allocationPolicyList[(i / allocationDiv) % allocationPolicyList.size], + exportModelList[(i / exportDiv) % exportModelList.size], + failureModelList[(i / failureDiv) % failureModelList.size], + checkpointModelList[(i / checkpointDiv) % checkpointModelList.size], + maxNumFailuresList[i % maxNumFailuresList.size], + ), + ) + } + } + } + + internal companion object { + private val LOG by logger() + } +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ExportModelSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ExportModelSpec.kt new file mode 100644 index 00000000..62f1ea4b --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ExportModelSpec.kt @@ -0,0 +1,39 @@ +/* + * 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.experiment.specs + +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/experiment/specs/FailureModelSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/FailureModelSpec.kt new file mode 100644 index 00000000..520d7e3d --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/FailureModelSpec.kt @@ -0,0 +1,320 @@ +/* + * 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.experiment.specs + +/* + * 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.SerialName +import kotlinx.serialization.Serializable +import org.apache.commons.math3.distribution.ConstantRealDistribution +import org.apache.commons.math3.distribution.ExponentialDistribution +import org.apache.commons.math3.distribution.GammaDistribution +import org.apache.commons.math3.distribution.LogNormalDistribution +import org.apache.commons.math3.distribution.NormalDistribution +import org.apache.commons.math3.distribution.ParetoDistribution +import org.apache.commons.math3.distribution.RealDistribution +import org.apache.commons.math3.distribution.UniformRealDistribution +import org.apache.commons.math3.distribution.WeibullDistribution +import org.apache.commons.math3.random.Well19937c +import org.opendc.compute.failure.models.FailureModel +import org.opendc.compute.failure.models.SampleBasedFailureModel +import org.opendc.compute.failure.models.TraceBasedFailureModel +import org.opendc.compute.failure.prefab.FailurePrefab +import org.opendc.compute.failure.prefab.createFailureModelPrefab +import org.opendc.compute.simulator.service.ComputeService +import java.io.File +import java.time.InstantSource +import kotlin.coroutines.CoroutineContext + +/** + * Specifications of the different Failure models + * There are three types of Specs that can be used by using their SerialName as the type. + * + * @constructor Create empty Failure model spec + */ + +@Serializable +public sealed interface FailureModelSpec { + public var name: String +} + +/** + * A failure model spec for failure models based on a failure trace. + * + * @property pathToFile Path to the parquet file that contains the failure trace + */ +@Serializable +@SerialName("trace-based") +public data class TraceBasedFailureModelSpec( + public val pathToFile: String, +) : FailureModelSpec { + override var name: String = File(pathToFile).nameWithoutExtension + + init { + require(File(pathToFile).exists()) { "Path to file $pathToFile does not exist" } + } +} + +/** + * A specification for a failure model that is already present in OpenDC. + * + * @property prefabName The name of the prefab. It needs to be valid [FailurePrefab] + */ +@Serializable +@SerialName("prefab") +public data class PrefabFailureModelSpec( + public val prefabName: FailurePrefab, +) : FailureModelSpec { + override var name: String = prefabName.toString() +} + +/** + * Specification of a custom failure model that is defined by three distributions to sample from. + * Distributions are defined using a [DistributionSpec]. + * + * @property iatSampler Sampler for the time between failures defined in hours + * @property durationSampler Sampler for the time of a failure defined in hours + * @property nohSampler Sampler for ratio of hosts that fail defined as a double between 0.0 and 1.0 + * @constructor Create empty Custom failure model spec + */ +@Serializable +@SerialName("custom") +public data class CustomFailureModelSpec( + public val iatSampler: DistributionSpec, + public val durationSampler: DistributionSpec, + public val nohSampler: DistributionSpec, +) : FailureModelSpec { + override var name: String = "custom" +} + +/** + * Specifications of the different Distributions that can used to create a [CustomFailureModelSpec] + * All [DistributionSpec]s have a different definition based on the variables they need to function. + * Available [DistributionSpec] are: + * - [ConstantDistributionSpec] + * - [ExponentialDistributionSpec] + * - [GammaDistributionSpec] + * - [LogNormalDistributionSpec] + * - [ParetoDistributionSpec] + * - [UniformDistributionSpec] + * - [WeibullDistributionSpec] +*/ + +@Serializable +public sealed interface DistributionSpec + +@Serializable +@SerialName("constant") +public data class ConstantDistributionSpec( + public val value: Double, +) : DistributionSpec { + init { + require(value > 0.0) { "Value must be greater than 0.0" } + } +} + +@Serializable +@SerialName("exponential") +public data class ExponentialDistributionSpec( + public val mean: Double, +) : DistributionSpec + +@Serializable +@SerialName("gamma") +public data class GammaDistributionSpec( + public val shape: Double, + public val scale: Double, +) : DistributionSpec + +@Serializable +@SerialName("log-normal") +public data class LogNormalDistributionSpec( + public val scale: Double, + public val shape: Double, +) : DistributionSpec + +@Serializable +@SerialName("normal") +public data class NormalDistributionSpec( + public val mean: Double, + public val std: Double, +) : DistributionSpec + +@Serializable +@SerialName("pareto") +public data class ParetoDistributionSpec( + public val scale: Double, + public val shape: Double, +) : DistributionSpec + +@Serializable +@SerialName("uniform") +public data class UniformDistributionSpec( + public val upper: Double, + public val lower: Double, +) : DistributionSpec { + init { + require(upper > lower) { "Upper bound must be greater than the lower bound" } + } +} + +@Serializable +@SerialName("weibull") +public data class WeibullDistributionSpec( + public val alpha: Double, + public val beta: Double, +) : DistributionSpec + +/** + * Create a [FailureModel] based on the provided [FailureModelSpec] + * + * @param context + * @param clock + * @param service + * @param random + * @param failureModelSpec + * @return + */ +public fun createFailureModel( + context: CoroutineContext, + clock: InstantSource, + service: ComputeService, + random: java.util.random.RandomGenerator, + failureModelSpec: FailureModelSpec?, +): FailureModel? { + return when (failureModelSpec) { + is PrefabFailureModelSpec -> createFailureModel(context, clock, service, random, failureModelSpec) + is CustomFailureModelSpec -> createFailureModel(context, clock, service, random, failureModelSpec) + is TraceBasedFailureModelSpec -> createFailureModel(context, clock, service, random, failureModelSpec) + else -> null + } +} + +/** + * Create [FailureModel] based on the provided [PrefabFailureModelSpec] + * + * @param context + * @param clock + * @param service + * @param random + * @param failureModel + * @return + */ +public fun createFailureModel( + context: CoroutineContext, + clock: InstantSource, + service: ComputeService, + random: java.util.random.RandomGenerator, + failureModel: PrefabFailureModelSpec, +): FailureModel { + return createFailureModelPrefab(context, clock, service, random, failureModel.prefabName) +} + +/** + * Create [FailureModel] based on the provided [TraceBasedFailureModel] + * + * @param context + * @param clock + * @param service + * @param random + * @param failureModel + * @return + */ +public fun createFailureModel( + context: CoroutineContext, + clock: InstantSource, + service: ComputeService, + random: java.util.random.RandomGenerator, + failureModel: TraceBasedFailureModelSpec, +): FailureModel { + return TraceBasedFailureModel(context, clock, service, random, failureModel.pathToFile) +} + +/** + * Create [FailureModel] based on the provided [CustomFailureModelSpec] + * + * @param context + * @param clock + * @param service + * @param random + * @param failureModel + * @return + */ +public fun createFailureModel( + context: CoroutineContext, + clock: InstantSource, + service: ComputeService, + random: java.util.random.RandomGenerator, + failureModel: CustomFailureModelSpec, +): FailureModel { + val rng: org.apache.commons.math3.random.RandomGenerator = Well19937c(random.nextLong()) + + val iatSampler = createSampler(rng, failureModel.iatSampler) + val durationSampler = createSampler(rng, failureModel.durationSampler) + val nohSampler = createSampler(rng, failureModel.nohSampler) + + return SampleBasedFailureModel(context, clock, service, random, iatSampler, durationSampler, nohSampler) +} + +/** + * Create a [RealDistribution] to sample from based on the provided [DistributionSpec] + * + * @param rng + * @param distributionSpec + * @return + */ +public fun createSampler( + rng: org.apache.commons.math3.random.RandomGenerator, + distributionSpec: DistributionSpec, +): RealDistribution { + return when (distributionSpec) { + is ConstantDistributionSpec -> ConstantRealDistribution(distributionSpec.value) + is ExponentialDistributionSpec -> ExponentialDistribution(rng, distributionSpec.mean) + is GammaDistributionSpec -> GammaDistribution(rng, distributionSpec.shape, distributionSpec.scale) + is LogNormalDistributionSpec -> LogNormalDistribution(rng, distributionSpec.scale, distributionSpec.shape) + is NormalDistributionSpec -> NormalDistribution(rng, distributionSpec.mean, distributionSpec.std) + is ParetoDistributionSpec -> ParetoDistribution(rng, distributionSpec.scale, distributionSpec.shape) + is UniformDistributionSpec -> UniformRealDistribution(rng, distributionSpec.lower, distributionSpec.upper) + is WeibullDistributionSpec -> WeibullDistribution(rng, distributionSpec.alpha, distributionSpec.beta) + } +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/PowerModelSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/PowerModelSpec.kt new file mode 100644 index 00000000..a508d8c1 --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/PowerModelSpec.kt @@ -0,0 +1,32 @@ +/* + * 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.experiment.specs + +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/experiment/specs/ScenarioSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ScenarioSpec.kt new file mode 100644 index 00000000..b41eb37b --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ScenarioSpec.kt @@ -0,0 +1,41 @@ +/* + * 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.experiment.specs + +import kotlinx.serialization.Serializable +import org.opendc.compute.simulator.telemetry.parquet.ComputeExportConfig + +@Serializable +public data class ScenarioSpec( + var id: Int = -1, + var name: String = "", + val outputFolder: String = "output", + val computeExportConfig: ComputeExportConfig, + val topology: ScenarioTopologySpec, + val workload: WorkloadSpec, + val allocationPolicy: AllocationPolicySpec = AllocationPolicySpec(), + val exportModel: ExportModelSpec = ExportModelSpec(), + val failureModel: FailureModelSpec? = null, + val checkpointModel: CheckpointModelSpec? = null, + val maxNumFailures: Int = 10, +) diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ScenarioTopologySpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ScenarioTopologySpec.kt new file mode 100644 index 00000000..02c40af4 --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ScenarioTopologySpec.kt @@ -0,0 +1,42 @@ +/* + * 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.experiment.specs + +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/experiment/specs/WorkloadSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/WorkloadSpec.kt new file mode 100644 index 00000000..7f34c508 --- /dev/null +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/WorkloadSpec.kt @@ -0,0 +1,72 @@ +/* + * 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.experiment.specs + +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().sampleByLoad(1.0) + } +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentCli.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentCli.kt index 28ebe45c..e067bf45 100644 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentCli.kt +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentCli.kt @@ -30,7 +30,7 @@ import com.github.ajalt.clikt.parameters.options.defaultLazy import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.types.file import com.github.ajalt.clikt.parameters.types.int -import org.opendc.experiments.base.scenario.getExperiment +import org.opendc.experiments.base.experiment.getExperiment import java.io.File /** diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentRunner.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentRunner.kt index 076cfb9f..0b45806b 100644 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentRunner.kt +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentRunner.kt @@ -22,7 +22,7 @@ package org.opendc.experiments.base.runner -import org.opendc.experiments.base.scenario.Scenario +import org.opendc.experiments.base.experiment.Scenario import java.util.concurrent.ForkJoinPool /** diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ScenarioReplayer.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ScenarioReplayer.kt index c82e2557..a0263e38 100644 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ScenarioReplayer.kt +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ScenarioReplayer.kt @@ -35,8 +35,8 @@ import org.opendc.compute.simulator.TaskWatcher import org.opendc.compute.simulator.service.ComputeService import org.opendc.compute.simulator.service.ServiceTask import org.opendc.compute.workload.Task -import org.opendc.experiments.base.scenario.specs.FailureModelSpec -import org.opendc.experiments.base.scenario.specs.createFailureModel +import org.opendc.experiments.base.experiment.specs.FailureModelSpec +import org.opendc.experiments.base.experiment.specs.createFailureModel import java.time.InstantSource import java.util.Random import kotlin.coroutines.coroutineContext 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 d525e066..4d6069e4 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 @@ -33,8 +33,8 @@ import org.opendc.compute.simulator.service.ComputeService import org.opendc.compute.simulator.telemetry.parquet.ParquetComputeMonitor import org.opendc.compute.topology.clusterTopology import org.opendc.compute.workload.ComputeWorkloadLoader -import org.opendc.experiments.base.scenario.Scenario -import org.opendc.experiments.base.scenario.specs.getWorkloadType +import org.opendc.experiments.base.experiment.Scenario +import org.opendc.experiments.base.experiment.specs.getWorkloadType import org.opendc.simulator.kotlin.runSimulation import java.io.File import java.time.Duration diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ExperimentFactories.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ExperimentFactories.kt deleted file mode 100644 index 524d4219..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ExperimentFactories.kt +++ /dev/null @@ -1,115 +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.scenario - -import org.opendc.experiments.base.scenario.specs.ExperimentSpec -import org.opendc.experiments.base.scenario.specs.ScenarioSpec -import java.io.File - -private val experimentReader = ExperimentReader() -private val experimentWriter = ExperimentWriter() - -/** - * 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 getExperiment(filePath: String): List { - return getExperiment(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 getExperiment(file: File): List { - return getExperiment(experimentReader.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 experimentSpec The ScenarioSpec containing the scenario specifications. - * @return A list of Scenarios. - */ -public fun getExperiment(experimentSpec: ExperimentSpec): List { - val outputFolder = experimentSpec.outputFolder + "/" + experimentSpec.name - File(outputFolder).mkdirs() - - val trackrPath = "$outputFolder/trackr.json" - File(trackrPath).createNewFile() - - val scenarios = mutableListOf() - - val cartesianInput = experimentSpec.getCartesian() - - for ((scenarioID, scenarioSpec) in cartesianInput.withIndex()) { - val scenario = - Scenario( - id = scenarioID, - name = scenarioID.toString(), - outputFolder = outputFolder, - runs = experimentSpec.runs, - initialSeed = experimentSpec.initialSeed, - computeExportConfig = scenarioSpec.computeExportConfig, - topologySpec = scenarioSpec.topology, - workloadSpec = scenarioSpec.workload, - allocationPolicySpec = scenarioSpec.allocationPolicy, - exportModelSpec = scenarioSpec.exportModel, - failureModelSpec = scenarioSpec.failureModel, - checkpointModelSpec = scenarioSpec.checkpointModel, - maxNumFailures = scenarioSpec.maxNumFailures, - ) - trackScenario(scenarioSpec, outputFolder) - scenarios.add(scenario) - } - - return scenarios -} - -/** - * Writes a ScenarioSpec to a file. - * - * @param scenariosSpec The ScenarioSpec. - * @param outputFolder The output folder path. - * @param scenario The Scenario. - * @param topologySpec The TopologySpec. - - */ -public fun trackScenario( - scenarioSpec: ScenarioSpec, - outputFolder: String, -) { - val trackrPath = "$outputFolder/trackr.json" - experimentWriter.write( - scenarioSpec, - File(trackrPath), - ) - - // remove the last comma - File(trackrPath).writeText(File(trackrPath).readText().dropLast(3) + "]") -} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ExperimentReader.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ExperimentReader.kt deleted file mode 100644 index 8ed60b08..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ExperimentReader.kt +++ /dev/null @@ -1,53 +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.scenario - -import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.decodeFromStream -import org.opendc.compute.simulator.telemetry.parquet.ComputeExportConfig -import org.opendc.experiments.base.scenario.specs.ExperimentSpec -import java.io.File -import java.io.InputStream -import java.nio.file.Path -import kotlin.io.path.inputStream - -public class ExperimentReader { - private val jsonReader = Json - - public fun read(file: File): ExperimentSpec = read(file.inputStream()) - - public fun read(path: Path): ExperimentSpec = read(path.inputStream()) - - /** - * Read the specified [input]. - */ - @OptIn(ExperimentalSerializationApi::class) - public fun read(input: InputStream): ExperimentSpec { - // Loads the default parquet output fields, - // so that they can be deserialized - ComputeExportConfig.loadDfltColumns() - - return jsonReader.decodeFromStream(input) - } -} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ExperimentWriter.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ExperimentWriter.kt deleted file mode 100644 index 6afe6031..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/ExperimentWriter.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.scenario - -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json -import org.opendc.experiments.base.scenario.specs.ScenarioSpec -import java.io.File - -/** - * A writer for writing scenarios to a file. - * @param jsonText The JSON text to write to the file, which is constantly updated during the writing process. - * @param json The JSON object used to encode the scenario specification. - */ -public class ExperimentWriter { - private var jsonText = "[" - private val json = Json { prettyPrint = true } - - /** - * Write the given [scenariosSpec] to the given [file]. - */ - public fun write( - scenarioSpec: ScenarioSpec, - file: File, - ) { - openArray(file) - val jsonString = json.encodeToString(scenarioSpec) + "," - jsonText += jsonString + "\n" - file.writeText(jsonText) - closeArray(file) - } - - /** - * Delete the last character of the file. - */ - private fun openArray(file: File) { - val text = file.readText() - file.writeText(text.dropLast(0)) - } - - /** - * Add the closing bracket to the file. - */ - private fun closeArray(file: File) { - file.appendText("]") - } -} 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 deleted file mode 100644 index e62669e4..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/Scenario.kt +++ /dev/null @@ -1,61 +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.scenario - -import org.opendc.compute.simulator.telemetry.parquet.ComputeExportConfig -import org.opendc.experiments.base.scenario.specs.AllocationPolicySpec -import org.opendc.experiments.base.scenario.specs.CheckpointModelSpec -import org.opendc.experiments.base.scenario.specs.ExportModelSpec -import org.opendc.experiments.base.scenario.specs.FailureModelSpec -import org.opendc.experiments.base.scenario.specs.ScenarioTopologySpec -import org.opendc.experiments.base.scenario.specs.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. - * @property computeExportConfig configures which parquet columns are to be included in the output files. - */ -public data class Scenario( - var id: Int = -1, - val name: String = "", - val outputFolder: String = "output", - val runs: Int = 1, - val initialSeed: Int = 0, - val computeExportConfig: ComputeExportConfig, - val topologySpec: ScenarioTopologySpec, - val workloadSpec: WorkloadSpec, - val allocationPolicySpec: AllocationPolicySpec, - val exportModelSpec: ExportModelSpec = ExportModelSpec(), - val failureModelSpec: FailureModelSpec?, - val checkpointModelSpec: CheckpointModelSpec?, - val maxNumFailures: Int = 10, -) 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 deleted file mode 100644 index ddc11a50..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/AllocationPolicySpec.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. - */ - -package org.opendc.experiments.base.scenario.specs - -import kotlinx.serialization.Serializable -import org.opendc.compute.simulator.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 = ComputeSchedulerEnum.Mem, -) { - public val name: String = policyType.toString() -} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/CheckpointModelSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/CheckpointModelSpec.kt deleted file mode 100644 index ad0fba1d..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/CheckpointModelSpec.kt +++ /dev/null @@ -1,32 +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.scenario.specs - -import kotlinx.serialization.Serializable - -@Serializable -public data class CheckpointModelSpec( - val checkpointInterval: Long = 60 * 60 * 1000, - val checkpointDuration: Long = 5 * 60 * 1000, - val checkpointIntervalScaling: Double = 1.0, -) diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ExperimentSpec.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ExperimentSpec.kt deleted file mode 100644 index 7805ed2b..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ExperimentSpec.kt +++ /dev/null @@ -1,116 +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.scenario.specs - -import kotlinx.serialization.Serializable -import org.opendc.common.logger.infoNewLine -import org.opendc.common.logger.logger -import org.opendc.compute.simulator.telemetry.parquet.ComputeExportConfig -import java.util.UUID - -/** - * specification describing a scenario - * - * @property topologies - * @property workloads - * @property allocationPolicies - * @property failureModels - * @property exportModels - * @property outputFolder - * @property initialSeed - * @property runs - * @property computeExportConfig configures which parquet columns are to - * be included in the output files. - */ - -@Serializable -public data class ExperimentSpec( - var id: Int = -1, - var name: String = "", - val outputFolder: String = "output", - val initialSeed: Int = 0, - val runs: Int = 1, - val topologies: Set, - val workloads: Set, - val allocationPolicies: Set = setOf(AllocationPolicySpec()), - val exportModels: Set = setOf(ExportModelSpec()), - val failureModels: Set = setOf(null), - val checkpointModels: Set = setOf(null), - val computeExportConfig: ComputeExportConfig = ComputeExportConfig.ALL_COLUMNS, - val maxNumFailures: Set = setOf(10), -) { - init { - require(runs > 0) { "The number of runs should always be positive" } - - // generate name if not provided - // TODO: improve this - if (name == "") { - name = "unnamed-simulation-${UUID.randomUUID().toString().substring(0, 4)}" -// "workload=${workloads[0].name}_topology=${topologies[0].name}_allocationPolicy=${allocationPolicies[0].name}" - } - - LOG.infoNewLine(computeExportConfig.fmt()) - } - - public fun getCartesian(): Sequence { - return sequence { - val checkpointDiv = maxNumFailures.size - val failureDiv = checkpointDiv * checkpointModels.size - val exportDiv = failureDiv * failureModels.size - val allocationDiv = exportDiv * exportModels.size - val workloadDiv = allocationDiv * allocationPolicies.size - val topologyDiv = workloadDiv * workloads.size - val numScenarios = topologyDiv * topologies.size - - val topologyList = topologies.toList() - val workloadList = workloads.toList() - val allocationPolicyList = allocationPolicies.toList() - val exportModelList = exportModels.toList() - val failureModelList = failureModels.toList() - val checkpointModelList = checkpointModels.toList() - val maxNumFailuresList = maxNumFailures.toList() - - for (i in 0 until numScenarios) { - yield( - ScenarioSpec( - id, - name, - outputFolder, - computeExportConfig = computeExportConfig, - topologyList[(i / topologyDiv) % topologyList.size], - workloadList[(i / workloadDiv) % workloadList.size], - allocationPolicyList[(i / allocationDiv) % allocationPolicyList.size], - exportModelList[(i / exportDiv) % exportModelList.size], - failureModelList[(i / failureDiv) % failureModelList.size], - checkpointModelList[(i / checkpointDiv) % checkpointModelList.size], - maxNumFailuresList[i % maxNumFailuresList.size], - ), - ) - } - } - } - - internal companion object { - private val LOG by logger() - } -} 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 deleted file mode 100644 index d51de27b..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ExportModelSpec.kt +++ /dev/null @@ -1,39 +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.scenario.specs - -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 deleted file mode 100644 index c20b4467..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/FailureModelSpec.kt +++ /dev/null @@ -1,320 +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.scenario.specs - -/* - * 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.SerialName -import kotlinx.serialization.Serializable -import org.apache.commons.math3.distribution.ConstantRealDistribution -import org.apache.commons.math3.distribution.ExponentialDistribution -import org.apache.commons.math3.distribution.GammaDistribution -import org.apache.commons.math3.distribution.LogNormalDistribution -import org.apache.commons.math3.distribution.NormalDistribution -import org.apache.commons.math3.distribution.ParetoDistribution -import org.apache.commons.math3.distribution.RealDistribution -import org.apache.commons.math3.distribution.UniformRealDistribution -import org.apache.commons.math3.distribution.WeibullDistribution -import org.apache.commons.math3.random.Well19937c -import org.opendc.compute.failure.models.FailureModel -import org.opendc.compute.failure.models.SampleBasedFailureModel -import org.opendc.compute.failure.models.TraceBasedFailureModel -import org.opendc.compute.failure.prefab.FailurePrefab -import org.opendc.compute.failure.prefab.createFailureModelPrefab -import org.opendc.compute.simulator.service.ComputeService -import java.io.File -import java.time.InstantSource -import kotlin.coroutines.CoroutineContext - -/** - * Specifications of the different Failure models - * There are three types of Specs that can be used by using their SerialName as the type. - * - * @constructor Create empty Failure model spec - */ - -@Serializable -public sealed interface FailureModelSpec { - public var name: String -} - -/** - * A failure model spec for failure models based on a failure trace. - * - * @property pathToFile Path to the parquet file that contains the failure trace - */ -@Serializable -@SerialName("trace-based") -public data class TraceBasedFailureModelSpec( - public val pathToFile: String, -) : FailureModelSpec { - override var name: String = File(pathToFile).nameWithoutExtension - - init { - require(File(pathToFile).exists()) { "Path to file $pathToFile does not exist" } - } -} - -/** - * A specification for a failure model that is already present in OpenDC. - * - * @property prefabName The name of the prefab. It needs to be valid [FailurePrefab] - */ -@Serializable -@SerialName("prefab") -public data class PrefabFailureModelSpec( - public val prefabName: FailurePrefab, -) : FailureModelSpec { - override var name: String = prefabName.toString() -} - -/** - * Specification of a custom failure model that is defined by three distributions to sample from. - * Distributions are defined using a [DistributionSpec]. - * - * @property iatSampler Sampler for the time between failures defined in hours - * @property durationSampler Sampler for the time of a failure defined in hours - * @property nohSampler Sampler for ratio of hosts that fail defined as a double between 0.0 and 1.0 - * @constructor Create empty Custom failure model spec - */ -@Serializable -@SerialName("custom") -public data class CustomFailureModelSpec( - public val iatSampler: DistributionSpec, - public val durationSampler: DistributionSpec, - public val nohSampler: DistributionSpec, -) : FailureModelSpec { - override var name: String = "custom" -} - -/** - * Specifications of the different Distributions that can used to create a [CustomFailureModelSpec] - * All [DistributionSpec]s have a different definition based on the variables they need to function. - * Available [DistributionSpec] are: - * - [ConstantDistributionSpec] - * - [ExponentialDistributionSpec] - * - [GammaDistributionSpec] - * - [LogNormalDistributionSpec] - * - [ParetoDistributionSpec] - * - [UniformDistributionSpec] - * - [WeibullDistributionSpec] -*/ - -@Serializable -public sealed interface DistributionSpec - -@Serializable -@SerialName("constant") -public data class ConstantDistributionSpec( - public val value: Double, -) : DistributionSpec { - init { - require(value > 0.0) { "Value must be greater than 0.0" } - } -} - -@Serializable -@SerialName("exponential") -public data class ExponentialDistributionSpec( - public val mean: Double, -) : DistributionSpec - -@Serializable -@SerialName("gamma") -public data class GammaDistributionSpec( - public val shape: Double, - public val scale: Double, -) : DistributionSpec - -@Serializable -@SerialName("log-normal") -public data class LogNormalDistributionSpec( - public val scale: Double, - public val shape: Double, -) : DistributionSpec - -@Serializable -@SerialName("normal") -public data class NormalDistributionSpec( - public val mean: Double, - public val std: Double, -) : DistributionSpec - -@Serializable -@SerialName("pareto") -public data class ParetoDistributionSpec( - public val scale: Double, - public val shape: Double, -) : DistributionSpec - -@Serializable -@SerialName("uniform") -public data class UniformDistributionSpec( - public val upper: Double, - public val lower: Double, -) : DistributionSpec { - init { - require(upper > lower) { "Upper bound must be greater than the lower bound" } - } -} - -@Serializable -@SerialName("weibull") -public data class WeibullDistributionSpec( - public val alpha: Double, - public val beta: Double, -) : DistributionSpec - -/** - * Create a [FailureModel] based on the provided [FailureModelSpec] - * - * @param context - * @param clock - * @param service - * @param random - * @param failureModelSpec - * @return - */ -public fun createFailureModel( - context: CoroutineContext, - clock: InstantSource, - service: ComputeService, - random: java.util.random.RandomGenerator, - failureModelSpec: FailureModelSpec?, -): FailureModel? { - return when (failureModelSpec) { - is PrefabFailureModelSpec -> createFailureModel(context, clock, service, random, failureModelSpec) - is CustomFailureModelSpec -> createFailureModel(context, clock, service, random, failureModelSpec) - is TraceBasedFailureModelSpec -> createFailureModel(context, clock, service, random, failureModelSpec) - else -> null - } -} - -/** - * Create [FailureModel] based on the provided [PrefabFailureModelSpec] - * - * @param context - * @param clock - * @param service - * @param random - * @param failureModel - * @return - */ -public fun createFailureModel( - context: CoroutineContext, - clock: InstantSource, - service: ComputeService, - random: java.util.random.RandomGenerator, - failureModel: PrefabFailureModelSpec, -): FailureModel { - return createFailureModelPrefab(context, clock, service, random, failureModel.prefabName) -} - -/** - * Create [FailureModel] based on the provided [TraceBasedFailureModel] - * - * @param context - * @param clock - * @param service - * @param random - * @param failureModel - * @return - */ -public fun createFailureModel( - context: CoroutineContext, - clock: InstantSource, - service: ComputeService, - random: java.util.random.RandomGenerator, - failureModel: TraceBasedFailureModelSpec, -): FailureModel { - return TraceBasedFailureModel(context, clock, service, random, failureModel.pathToFile) -} - -/** - * Create [FailureModel] based on the provided [CustomFailureModelSpec] - * - * @param context - * @param clock - * @param service - * @param random - * @param failureModel - * @return - */ -public fun createFailureModel( - context: CoroutineContext, - clock: InstantSource, - service: ComputeService, - random: java.util.random.RandomGenerator, - failureModel: CustomFailureModelSpec, -): FailureModel { - val rng: org.apache.commons.math3.random.RandomGenerator = Well19937c(random.nextLong()) - - val iatSampler = createSampler(rng, failureModel.iatSampler) - val durationSampler = createSampler(rng, failureModel.durationSampler) - val nohSampler = createSampler(rng, failureModel.nohSampler) - - return SampleBasedFailureModel(context, clock, service, random, iatSampler, durationSampler, nohSampler) -} - -/** - * Create a [RealDistribution] to sample from based on the provided [DistributionSpec] - * - * @param rng - * @param distributionSpec - * @return - */ -public fun createSampler( - rng: org.apache.commons.math3.random.RandomGenerator, - distributionSpec: DistributionSpec, -): RealDistribution { - return when (distributionSpec) { - is ConstantDistributionSpec -> ConstantRealDistribution(distributionSpec.value) - is ExponentialDistributionSpec -> ExponentialDistribution(rng, distributionSpec.mean) - is GammaDistributionSpec -> GammaDistribution(rng, distributionSpec.shape, distributionSpec.scale) - is LogNormalDistributionSpec -> LogNormalDistribution(rng, distributionSpec.scale, distributionSpec.shape) - is NormalDistributionSpec -> NormalDistribution(rng, distributionSpec.mean, distributionSpec.std) - is ParetoDistributionSpec -> ParetoDistribution(rng, distributionSpec.scale, distributionSpec.shape) - is UniformDistributionSpec -> UniformRealDistribution(rng, distributionSpec.lower, distributionSpec.upper) - is WeibullDistributionSpec -> WeibullDistribution(rng, distributionSpec.alpha, distributionSpec.beta) - } -} 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 deleted file mode 100644 index f9679b26..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/PowerModelSpec.kt +++ /dev/null @@ -1,32 +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.scenario.specs - -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 deleted file mode 100644 index b4f04c1c..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ScenarioSpec.kt +++ /dev/null @@ -1,41 +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.scenario.specs - -import kotlinx.serialization.Serializable -import org.opendc.compute.simulator.telemetry.parquet.ComputeExportConfig - -@Serializable -public data class ScenarioSpec( - var id: Int = -1, - var name: String = "", - val outputFolder: String = "output", - val computeExportConfig: ComputeExportConfig, - val topology: ScenarioTopologySpec, - val workload: WorkloadSpec, - val allocationPolicy: AllocationPolicySpec = AllocationPolicySpec(), - val exportModel: ExportModelSpec = ExportModelSpec(), - val failureModel: FailureModelSpec? = null, - val checkpointModel: CheckpointModelSpec? = null, - val maxNumFailures: Int = 10, -) 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 deleted file mode 100644 index feaca0c6..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/ScenarioTopologySpec.kt +++ /dev/null @@ -1,42 +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.scenario.specs - -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 deleted file mode 100644 index 956e97f1..00000000 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/scenario/specs/WorkloadSpec.kt +++ /dev/null @@ -1,72 +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.scenario.specs - -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().sampleByLoad(1.0) - } -} diff --git a/opendc-experiments/opendc-experiments-base/src/test/kotlin/org/opendc/experiments/base/ScenarioIntegrationTest.kt b/opendc-experiments/opendc-experiments-base/src/test/kotlin/org/opendc/experiments/base/ScenarioIntegrationTest.kt index 9fa1a09a..132ed7b5 100644 --- a/opendc-experiments/opendc-experiments-base/src/test/kotlin/org/opendc/experiments/base/ScenarioIntegrationTest.kt +++ b/opendc-experiments/opendc-experiments-base/src/test/kotlin/org/opendc/experiments/base/ScenarioIntegrationTest.kt @@ -45,8 +45,8 @@ import org.opendc.compute.workload.ComputeWorkloadLoader import org.opendc.compute.workload.Task import org.opendc.compute.workload.sampleByLoad import org.opendc.compute.workload.trace +import org.opendc.experiments.base.experiment.specs.TraceBasedFailureModelSpec import org.opendc.experiments.base.runner.replay -import org.opendc.experiments.base.scenario.specs.TraceBasedFailureModelSpec import org.opendc.simulator.kotlin.runSimulation import java.io.File import java.util.Random diff --git a/opendc-experiments/opendc-experiments-m3sa/src/main/kotlin/org/opendc/experiments/m3sa/runner/M3SACli.kt b/opendc-experiments/opendc-experiments-m3sa/src/main/kotlin/org/opendc/experiments/m3sa/runner/M3SACli.kt index 8036e5b7..4fe58d88 100644 --- a/opendc-experiments/opendc-experiments-m3sa/src/main/kotlin/org/opendc/experiments/m3sa/runner/M3SACli.kt +++ b/opendc-experiments/opendc-experiments-m3sa/src/main/kotlin/org/opendc/experiments/m3sa/runner/M3SACli.kt @@ -30,8 +30,8 @@ import com.github.ajalt.clikt.parameters.options.defaultLazy import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.types.file import com.github.ajalt.clikt.parameters.types.int +import org.opendc.experiments.base.experiment.getExperiment import org.opendc.experiments.base.runner.runExperiment -import org.opendc.experiments.base.scenario.getExperiment import org.opendc.experiments.m3sa.m3saAnalyze import org.opendc.experiments.m3sa.scenario.getOutputFolder import java.io.File diff --git a/opendc-experiments/opendc-experiments-m3sa/src/main/kotlin/org/opendc/experiments/m3sa/runner/M3SARunner.kt b/opendc-experiments/opendc-experiments-m3sa/src/main/kotlin/org/opendc/experiments/m3sa/runner/M3SARunner.kt index 89daf5f3..0068738a 100644 --- a/opendc-experiments/opendc-experiments-m3sa/src/main/kotlin/org/opendc/experiments/m3sa/runner/M3SARunner.kt +++ b/opendc-experiments/opendc-experiments-m3sa/src/main/kotlin/org/opendc/experiments/m3sa/runner/M3SARunner.kt @@ -24,9 +24,9 @@ package org.opendc.experiments.m3sa.runner +import org.opendc.experiments.base.experiment.Scenario import org.opendc.experiments.base.runner.runScenario import org.opendc.experiments.base.runner.setupOutputFolderStructure -import org.opendc.experiments.base.scenario.Scenario import java.util.concurrent.ForkJoinPool /** diff --git a/opendc-experiments/opendc-experiments-m3sa/src/main/kotlin/org/opendc/experiments/m3sa/scenario/M3SAFactories.kt b/opendc-experiments/opendc-experiments-m3sa/src/main/kotlin/org/opendc/experiments/m3sa/scenario/M3SAFactories.kt index a4df40e1..bb217f0d 100644 --- a/opendc-experiments/opendc-experiments-m3sa/src/main/kotlin/org/opendc/experiments/m3sa/scenario/M3SAFactories.kt +++ b/opendc-experiments/opendc-experiments-m3sa/src/main/kotlin/org/opendc/experiments/m3sa/scenario/M3SAFactories.kt @@ -22,7 +22,7 @@ package org.opendc.experiments.m3sa.scenario -import org.opendc.experiments.base.scenario.ExperimentReader +import org.opendc.experiments.base.experiment.ExperimentReader import java.io.File private val experimentReader = ExperimentReader() -- cgit v1.2.3