diff options
50 files changed, 1 insertions, 2494 deletions
diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index e975bcbe..42cbf842 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -37,7 +37,6 @@ dependencies { implementation(libs.ktlint.gradle) implementation(libs.jmh.gradle) implementation(libs.dokka.gradle) - implementation(libs.shadow) implementation(libs.jandex.gradle) implementation(libs.quarkus.gradle.application) diff --git a/buildSrc/src/main/kotlin/distribution-conventions.gradle.kts b/buildSrc/src/main/kotlin/distribution-conventions.gradle.kts index 57e5b284..51dbbe63 100644 --- a/buildSrc/src/main/kotlin/distribution-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/distribution-conventions.gradle.kts @@ -45,17 +45,7 @@ distributions { getTasksByName("assembleDist", true) .filter { it.project != project } .map { it.project.name to it.project.the<DistributionContainer>() } - .forEach { (name, dist) -> - dist.findByName("main")?.let { with(it.contents) } - - // Include experiments if they exist - val experiment = dist.findByName("experiment") - if (experiment != null) { - into("experiments/${name.removePrefix("opendc-experiments-")}") { - with(experiment.contents) - } - } - } + .forEach { (name, dist) -> dist.findByName("main")?.let { with(it.contents) } } } } } diff --git a/buildSrc/src/main/kotlin/experiment-conventions.gradle.kts b/buildSrc/src/main/kotlin/experiment-conventions.gradle.kts deleted file mode 100644 index c1750a40..00000000 --- a/buildSrc/src/main/kotlin/experiment-conventions.gradle.kts +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -plugins { - distribution - id("kotlin-conventions") - id("com.github.johnrengelman.shadow") -} - -dependencies { - runtimeOnly(project(":opendc-harness:opendc-harness-junit5")) -} - -tasks.register<Test>("experiment") { - // Ensure JUnit Platform is used for resolving tests - useJUnitPlatform() - - description = "Runs OpenDC experiments" - group = "application" - - testClassesDirs = sourceSets["main"].output.classesDirs - classpath = sourceSets["main"].runtimeClasspath -} - -distributions { - create("experiment") { - contents { - from("README.md") - from(tasks.shadowJar.get()) - } - } -} - -tasks.shadowJar { - dependencies { - // Do not include the JUnit 5 runner in the final shadow jar, since it is only necessary for development - // inside IDE - exclude(project(":opendc-harness:opendc-harness-junit5")) - } -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 55975919..a7956ce3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,7 +13,6 @@ jline = "3.21.0" jmh-gradle = "0.6.6" jakarta-validation = "2.0.2" junit-jupiter = "5.8.2" -junit-platform = "1.8.2" kotlin = "1.6.21" kotlin-logging = "2.1.21" kotlinx-coroutines = "1.6.1" @@ -26,7 +25,6 @@ progressbar = "0.9.2" quarkus = "2.8.1.Final" quarkus-junit5-mockk = "0.3.0" sentry = "5.7.2" -shadow = "7.1.2" slf4j = "1.7.36" [libraries] @@ -46,8 +44,6 @@ sentry-log4j2 = { module = "io.sentry:sentry-log4j2", version.ref = "sentry" } junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-jupiter" } junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-jupiter" } junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit-jupiter" } -junit-platform-commons = { module = "org.junit.platform:junit-platform-commons", version.ref = "junit-platform" } -junit-platform-engine = { module = "org.junit.platform:junit-platform-engine", version.ref = "junit-platform" } mockk = { module = "io.mockk:mockk", version.ref = "mockk" } # CLI @@ -112,4 +108,3 @@ gradle-node = { module = "com.github.node-gradle:gradle-node-plugin", version.re jandex-gradle = { module = "org.kordamp.gradle:jandex-gradle-plugin", version.ref = "jandex-gradle" } ktlint-gradle = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlint-gradle" } jmh-gradle = { module = "me.champeau.jmh:jmh-gradle-plugin", version.ref = "jmh-gradle" } -shadow = { module = "gradle.plugin.com.github.johnrengelman:shadow", version.ref = "shadow" } diff --git a/opendc-harness/build.gradle.kts b/opendc-harness/build.gradle.kts deleted file mode 100644 index ddb8b5bf..00000000 --- a/opendc-harness/build.gradle.kts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2020 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. - */ - -description = "Harness for defining repeatable experiments using OpenDC" - -subprojects { - group = "org.opendc.harness" -} diff --git a/opendc-harness/opendc-harness-api/build.gradle.kts b/opendc-harness/opendc-harness-api/build.gradle.kts deleted file mode 100644 index c37f14c2..00000000 --- a/opendc-harness/opendc-harness-api/build.gradle.kts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -description = "API for OpenDC Experiment Harness" - -/* Build configuration */ -plugins { - `kotlin-library-conventions` -} - -dependencies { - api(libs.junit.platform.commons) - - implementation(libs.kotlin.logging) -} diff --git a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/api/ExperimentDefinition.kt b/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/api/ExperimentDefinition.kt deleted file mode 100644 index c90717d2..00000000 --- a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/api/ExperimentDefinition.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.api - -/** - * A definition for a repeatable experiment which consists of multiple scenarios derived from pre-defined experiment - * parameters. - * - * @property name The name of the experiment. - * @property parameters The parameters of the experiments. - * @property evaluator The function to evaluate a single experiment trial. - * @property meta The metadata for the experiment. - */ -public data class ExperimentDefinition( - val name: String, - val parameters: Set<Parameter<*>>, - val evaluator: (Trial) -> Unit, - val meta: Map<String, Any> = emptyMap() -) diff --git a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/api/Parameter.kt b/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/api/Parameter.kt deleted file mode 100644 index 1f4fdde1..00000000 --- a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/api/Parameter.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.api - -/** - * A [Parameter] defines a single dimension of exploration in the design space of an experiment. - */ -public sealed class Parameter<T> { - /** - * The name of the parameter. - */ - public abstract val name: String - - /** - * A generic dimension of the experiment design space that is defined fully by a collection of [values]. - */ - public data class Generic<T>(override val name: String, val values: Collection<T>) : Parameter<T>() -} diff --git a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/api/Scenario.kt b/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/api/Scenario.kt deleted file mode 100644 index a8dbf01e..00000000 --- a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/api/Scenario.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.api - -/** - * A [Scenario] represents a single point in the design space of an experiment. - */ -public interface Scenario { - /** - * A unique identifier that identifies a single scenario. - */ - public val id: Int - - /** - * The [ExperimentDefinition] describing the experiment this scenario is part of. - */ - public val experiment: ExperimentDefinition - - /** - * Obtain the instantiated value for a [parameter][param] of the experiment. - * - * @param param The parameter to obtain the value of. - * @throws IllegalArgumentException if [param] is not defined for the experiment. - */ - public operator fun <T> get(param: Parameter<T>): T -} diff --git a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/api/Trial.kt b/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/api/Trial.kt deleted file mode 100644 index 2d6ecd19..00000000 --- a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/api/Trial.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.api - -/** - * A [Trial] represents a single trial (run) of an experiment. - */ -public data class Trial(val scenario: Scenario, val repeat: Int) diff --git a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/dsl/Experiment.kt b/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/dsl/Experiment.kt deleted file mode 100644 index 41d4207a..00000000 --- a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/dsl/Experiment.kt +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.dsl - -import org.junit.platform.commons.annotation.Testable -import org.opendc.harness.api.ExperimentDefinition -import org.opendc.harness.api.Scenario -import org.opendc.harness.api.Trial -import org.opendc.harness.internal.ParameterDelegate - -/** - * An [Experiment] defines a blueprint for a repeatable experiment consisting of multiple scenarios based on pre-defined - * experiment parameters. - * - * @param name The name of the experiment or `null` to select the class name. - */ -@Testable -public abstract class Experiment(name: String? = null) : Cloneable { - /** - * The name of the experiment. - */ - public val name: String = name ?: javaClass.simpleName - - /** - * An identifier that uniquely identifies a single point in the design space of this [Experiment]. - */ - public val id: Int - get() { - val scenario = scenario ?: throw IllegalStateException("Cannot use id before activation") - return scenario.id - } - - /** - * Convert this experiment to an [ExperimentDefinition]. - */ - public fun toDefinition(): ExperimentDefinition = - ExperimentDefinition(name, HashSet(delegates.map { it.parameter }), this::run, mapOf("class.name" to javaClass.name)) - - /** - * Perform a single execution of the experiment based on the experiment parameters. - * - * @param repeat A number representing the repeat index of an identical scenario. - */ - protected abstract fun doRun(repeat: Int) - - /** - * A map to track the parameter delegates registered with this experiment. - */ - private val delegates: MutableSet<ParameterDelegate<*>> = mutableSetOf() - - /** - * The current active scenario. - */ - internal var scenario: Scenario? = null - - /** - * Perform a single execution of the experiment based on the experiment parameters. - * - * This operation will cause the [ParameterProvider]s of this group to be instantiated to some value in its design - * space. - * - * @param trial The experiment trial to run. - */ - private fun run(trial: Trial) { - val scenario = trial.scenario - - // XXX We clone the current class to prevent concurrency issues. - val res = clone() as Experiment - res.scenario = scenario - res.doRun(trial.repeat) - } - - /** - * Register a delegate for this experiment. - */ - internal fun register(delegate: ParameterDelegate<*>) { - delegates += delegate - } -} diff --git a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/dsl/ParameterProvider.kt b/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/dsl/ParameterProvider.kt deleted file mode 100644 index e4bb9c64..00000000 --- a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/dsl/ParameterProvider.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.dsl - -import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KProperty - -/** - * A [ParameterProvider] defines a single dimension of exploration in the design space of an [Experiment]. - */ -public interface ParameterProvider<T> { - /** - * Provide a delegate defining a parameter for the specified [Experiment][experiment]. - * - * @param experiment The experiment for which the parameter is defined. - * @param prop The property to create the delegate for. - */ - public operator fun provideDelegate(experiment: Experiment, prop: KProperty<*>): ReadOnlyProperty<Experiment, T> -} diff --git a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/dsl/Parameters.kt b/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/dsl/Parameters.kt deleted file mode 100644 index 7d269ba1..00000000 --- a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/dsl/Parameters.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.dsl - -import org.opendc.harness.api.Parameter -import org.opendc.harness.internal.ParameterDelegate -import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KProperty - -/** - * Define a dimension in the design space of an [Experiment] of type [T] consisting of the specified collection of - * [values]. - * - * @param values The values in the dimension to define.. - */ -public fun <T> anyOf(vararg values: T): ParameterProvider<T> = object : ParameterProvider<T> { - override fun provideDelegate(experiment: Experiment, prop: KProperty<*>): ReadOnlyProperty<Experiment, T> { - val delegate = ParameterDelegate(Parameter.Generic(prop.name, listOf(*values))) - experiment.register(delegate) - return delegate - } - - override fun toString(): String = "GenericParameter" -} diff --git a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/internal/ParameterDelegate.kt b/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/internal/ParameterDelegate.kt deleted file mode 100644 index aaf90b99..00000000 --- a/opendc-harness/opendc-harness-api/src/main/kotlin/org/opendc/harness/internal/ParameterDelegate.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.internal - -import org.opendc.harness.api.Parameter -import org.opendc.harness.dsl.Experiment -import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KProperty - -/** - * A delegate for an experiment parameter. - * - * @property parameter The parameter descriptor of this delegate. - */ -internal class ParameterDelegate<T>(val parameter: Parameter<T>) : ReadOnlyProperty<Experiment, T> { - /** - * Obtain the value for the parameter. - */ - override fun getValue(thisRef: Experiment, property: KProperty<*>): T { - val scenario = thisRef.scenario ?: throw IllegalStateException("Cannot use parameters before activation") - return scenario[parameter] - } -} diff --git a/opendc-harness/opendc-harness-cli/build.gradle.kts b/opendc-harness/opendc-harness-cli/build.gradle.kts deleted file mode 100644 index 4d0f469f..00000000 --- a/opendc-harness/opendc-harness-cli/build.gradle.kts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -description = "Command line interface of OpenDC Harness" - -/* Build configuration */ -plugins { - `kotlin-conventions` - application -} - -application { - applicationName = "opendc-harness" - mainClass.set("org.opendc.harness.runner.cli.ConsoleRunnerKt") -} - -dependencies { - api(projects.opendcHarness.opendcHarnessEngine) - - implementation(libs.kotlin.logging) - implementation(libs.clikt) - implementation(libs.progressbar) - - runtimeOnly(libs.log4j.slf4j) -} diff --git a/opendc-harness/opendc-harness-cli/src/main/kotlin/org/opendc/harness/runner/cli/ConsoleExperimentReporter.kt b/opendc-harness/opendc-harness-cli/src/main/kotlin/org/opendc/harness/runner/cli/ConsoleExperimentReporter.kt deleted file mode 100644 index 7177467a..00000000 --- a/opendc-harness/opendc-harness-cli/src/main/kotlin/org/opendc/harness/runner/cli/ConsoleExperimentReporter.kt +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.runner.cli - -import me.tongfei.progressbar.ProgressBar -import me.tongfei.progressbar.ProgressBarBuilder -import mu.KotlinLogging -import org.opendc.harness.api.Trial -import org.opendc.harness.engine.ExperimentExecutionListener - -/** - * A reporter that reports the experiment progress to the console. - */ -public class ConsoleExperimentReporter : ExperimentExecutionListener, AutoCloseable { - /** - * The active [Trial]s. - */ - private val trials: MutableSet<Trial> = mutableSetOf() - - /** - * The total number of runs. - */ - private var total = 0 - - /** - * The logger for this reporter. - */ - private val logger = KotlinLogging.logger {} - - /** - * The progress bar to keep track of the progress. - */ - private val pb: ProgressBar = ProgressBarBuilder() - .setTaskName("") - .setInitialMax(1) - .build() - - override fun trialFinished(trial: Trial, throwable: Throwable?) { - trials -= trial - - pb.stepTo(total - trials.size.toLong()) - if (trials.isEmpty()) { - pb.close() - } - - if (throwable != null) { - logger.warn(throwable) { "Trial $trial failed" } - } - } - - override fun trialStarted(trial: Trial) { - trials += trial - pb.maxHint((++total).toLong()) - } - - override fun close() { - pb.close() - } -} diff --git a/opendc-harness/opendc-harness-cli/src/main/kotlin/org/opendc/harness/runner/cli/ConsoleRunner.kt b/opendc-harness/opendc-harness-cli/src/main/kotlin/org/opendc/harness/runner/cli/ConsoleRunner.kt deleted file mode 100644 index 06800f0e..00000000 --- a/opendc-harness/opendc-harness-cli/src/main/kotlin/org/opendc/harness/runner/cli/ConsoleRunner.kt +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.runner.cli - -import com.github.ajalt.clikt.core.CliktCommand -import com.github.ajalt.clikt.parameters.arguments.argument -import com.github.ajalt.clikt.parameters.arguments.multiple -import com.github.ajalt.clikt.parameters.arguments.unique -import com.github.ajalt.clikt.parameters.options.default -import com.github.ajalt.clikt.parameters.options.multiple -import com.github.ajalt.clikt.parameters.options.option -import com.github.ajalt.clikt.parameters.options.unique -import com.github.ajalt.clikt.parameters.types.file -import com.github.ajalt.clikt.parameters.types.int -import mu.KotlinLogging -import org.junit.platform.commons.util.ClassLoaderUtils -import org.opendc.harness.engine.ExperimentEngineLauncher -import org.opendc.harness.engine.discovery.DiscoveryProvider -import org.opendc.harness.engine.discovery.DiscoveryRequest -import org.opendc.harness.engine.discovery.DiscoverySelector -import org.opendc.harness.engine.scheduler.ThreadPoolExperimentScheduler -import java.net.URLClassLoader - -/** - * The logger for this experiment runner. - */ -private val logger = KotlinLogging.logger {} - -/** - * The command line interface for the console experiment runner. - */ -public class ConsoleRunner : CliktCommand(name = "opendc-harness") { - /** - * The number of repeats per scenario. - */ - private val repeats by option("-r", "--repeats", help = "Number of repeats per scenario") - .int() - .default(1) - - /** - * The selected experiments to run by name. - */ - private val experiments by argument(help = "Experiments to explore") - .multiple() - .unique() - - /** - * The maximum number of worker threads to use. - */ - private val parallelism by option("-p", "--parallelism", help = "Maximum number of concurrent simulation runs") - .int() - .default(Runtime.getRuntime().availableProcessors() - 1) - - /** - * Additional classpath entries to load. - */ - private val additionalClasspathEntries by option("--class-path", help = "Additional classpath entries to load") - .file(mustExist = true) - .multiple() - .unique() - - /** - * Configuration file to load. - */ - private val config by option("-c", "--config", help = "Configuration file for the experiments") - .file(mustExist = true, canBeDir = false, mustBeReadable = true) - - override fun run() { - logger.info { "Starting OpenDC Console Experiment Runner" } - - val config = config - if (config != null) { - System.setProperty("config.file", config.path) - } - - val classLoader = createClassLoader() - // TODO: Add way to specify class loader for scheduler - Thread.currentThread().contextClassLoader = classLoader - - val discovery = DiscoveryProvider.createComposite(classLoader) - val experiments = discovery.discover( - DiscoveryRequest( - selectors = experiments.flatMap { - listOf(DiscoverySelector.Name(it), DiscoverySelector.Meta("class.name", it)) - } - ) - ) - - val reporter = ConsoleExperimentReporter() - val scheduler = ThreadPoolExperimentScheduler(parallelism) - - try { - ExperimentEngineLauncher() - .withListener(reporter) - .withRepeats(repeats) - .withScheduler(scheduler) - .runBlocking(experiments) - } catch (e: Throwable) { - logger.error(e) { "Failed to finish experiments" } - } finally { - reporter.close() - scheduler.close() - } - - logger.info { "Finished all experiments. Exiting." } - } - - /** - * Create a [ClassLoader] that is used to load the - */ - private fun createClassLoader(): ClassLoader { - val parent = ClassLoaderUtils.getDefaultClassLoader() - - if (additionalClasspathEntries.isNotEmpty()) { - val urls = additionalClasspathEntries.flatMap { file -> - if (file.isDirectory) { - file.walk() - .filter { it.extension == "jar" } - .map { it.toURI().toURL() } - .toList() - } else { - listOf(file.toURI().toURL()) - } - } - - return URLClassLoader.newInstance(urls.toTypedArray(), parent) - } - - return parent - } -} - -/** - * Main entry point of the experiment runner. - */ -public fun main(args: Array<String>): Unit = ConsoleRunner().main(args) diff --git a/opendc-harness/opendc-harness-cli/src/main/resources/log4j2.xml b/opendc-harness/opendc-harness-cli/src/main/resources/log4j2.xml deleted file mode 100644 index 32d81416..00000000 --- a/opendc-harness/opendc-harness-cli/src/main/resources/log4j2.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Copyright (c) 2021 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. - --> - -<Configuration status="WARN"> - <Appenders> - <Console name="Console" target="SYSTEM_OUT"> - <PatternLayout pattern="%d{HH:mm:ss.SSS} [%highlight{%-5level}] %logger{36} - %msg%n" disableAnsi="false"/> - </Console> - </Appenders> - <Loggers> - <Logger name="org.opendc" level="info" additivity="false"> - <AppenderRef ref="Console"/> - </Logger> - <Root level="error"> - <AppenderRef ref="Console"/> - </Root> - </Loggers> -</Configuration> diff --git a/opendc-harness/opendc-harness-engine/build.gradle.kts b/opendc-harness/opendc-harness-engine/build.gradle.kts deleted file mode 100644 index 471f692d..00000000 --- a/opendc-harness/opendc-harness-engine/build.gradle.kts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -description = "Engine for running experiments using the OpenDC Harness" - -/* Build configuration */ -plugins { - `kotlin-library-conventions` -} - -dependencies { - api(projects.opendcHarness.opendcHarnessApi) - api(libs.kotlinx.coroutines) - - implementation(libs.classgraph) - implementation(libs.kotlin.logging) -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/ExperimentEngine.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/ExperimentEngine.kt deleted file mode 100644 index a36f1f9b..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/ExperimentEngine.kt +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine - -import kotlinx.coroutines.* -import kotlinx.coroutines.flow.asFlow -import kotlinx.coroutines.flow.buffer -import kotlinx.coroutines.flow.collect -import kotlinx.coroutines.flow.map -import org.opendc.harness.api.ExperimentDefinition -import org.opendc.harness.api.Trial -import org.opendc.harness.engine.scheduler.ExperimentScheduler -import org.opendc.harness.engine.strategy.ExperimentStrategy - -/** - * The [ExperimentEngine] orchestrates the execution of experiments. - * - * @property strategy The [ExperimentStrategy] used to explore the experiment design space. - * @property scheduler The [ExperimentScheduler] to schedule the trials over compute resources. - * @property listener The [ExperimentExecutionListener] to observe the progress. - * @property repeats The number of repeats to perform. - */ -public class ExperimentEngine( - private val strategy: ExperimentStrategy, - private val scheduler: ExperimentScheduler, - private val listener: ExperimentExecutionListener, - private val repeats: Int -) { - /** - * Execute the specified [experiment][root]. - * - * @param root The experiment to execute. - */ - public suspend fun execute(root: ExperimentDefinition) { - listener.experimentStarted(root) - - try { - supervisorScope { - strategy.generate(root) - .asFlow() - .map { scenario -> - listener.scenarioStarted(scenario) - scenario - } - .buffer(100) - .collect { scenario -> - launch { - val jobs = (0 until repeats).map { repeat -> - val worker = scheduler.allocate() - launch { - val trial = Trial(scenario, repeat) - try { - listener.trialStarted(trial) - worker.dispatch(trial) - listener.trialFinished(trial, null) - } catch (e: Throwable) { - listener.trialFinished(trial, e) - throw e - } - } - } - - try { - jobs.joinAll() - listener.scenarioFinished(scenario, null) - } catch (e: CancellationException) { - listener.scenarioFinished(scenario, null) - throw e - } catch (e: Throwable) { - listener.scenarioFinished(scenario, e) - } - } - } - } - - listener.experimentFinished(root, null) - } catch (e: Throwable) { - listener.experimentFinished(root, e) - throw e - } - } - - override fun toString(): String = "ExperimentEngine" -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/ExperimentEngineLauncher.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/ExperimentEngineLauncher.kt deleted file mode 100644 index 759e96f8..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/ExperimentEngineLauncher.kt +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine - -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.collect -import kotlinx.coroutines.runBlocking -import org.opendc.harness.api.ExperimentDefinition -import org.opendc.harness.engine.internal.CompositeExperimentExecutionListener -import org.opendc.harness.engine.scheduler.ExperimentScheduler -import org.opendc.harness.engine.scheduler.ThreadPoolExperimentScheduler -import org.opendc.harness.engine.strategy.CartesianExperimentStrategy -import org.opendc.harness.engine.strategy.ExperimentStrategy - -/** - * A builder class for conducting experiments via the [ExperimentEngine]. - */ -public class ExperimentEngineLauncher private constructor( - private val strategy: ExperimentStrategy?, - private val scheduler: ExperimentScheduler?, - private val listeners: List<ExperimentExecutionListener>, - private val repeats: Int -) { - /** - * Construct an [ExperimentEngineLauncher] instance. - */ - public constructor() : this(null, null, emptyList(), 1) - - /** - * Create an [ExperimentEngineLauncher] with the specified [strategy]. - */ - public fun withScheduler(strategy: ExperimentStrategy): ExperimentEngineLauncher { - return ExperimentEngineLauncher(strategy, scheduler, listeners, repeats) - } - - /** - * Create an [ExperimentEngineLauncher] with the specified [scheduler]. - */ - public fun withScheduler(scheduler: ExperimentScheduler): ExperimentEngineLauncher { - return ExperimentEngineLauncher(strategy, scheduler, listeners, repeats) - } - - /** - * Create an [ExperimentEngineLauncher] with the specified [listener] added. - */ - public fun withListener(listener: ExperimentExecutionListener): ExperimentEngineLauncher { - return ExperimentEngineLauncher(strategy, scheduler, listeners + listener, repeats) - } - - /** - * Create an [ExperimentEngineLauncher] with the specified number of repeats. - */ - public fun withRepeats(repeats: Int): ExperimentEngineLauncher { - require(repeats > 0) { "Invalid number of repeats; must be greater than zero. " } - return ExperimentEngineLauncher(strategy, scheduler, listeners, repeats) - } - - /** - * Launch the specified experiments via the [ExperimentEngine] and block execution until finished. - */ - public suspend fun run(experiments: Flow<ExperimentDefinition>) { - val engine = ExperimentEngine(createStrategy(), createScheduler(), createListener(), repeats) - experiments.collect { experiment -> engine.execute(experiment) } - } - - /** - * Launch the specified experiments via the [ExperimentEngine] and block the current thread until finished. - */ - public fun runBlocking(experiments: Flow<ExperimentDefinition>) { - runBlocking { - run(experiments) - } - } - - /** - * Return a string representation of this instance. - */ - public override fun toString(): String = "ExperimentEngineLauncher" - - /** - * Create the [ExperimentStrategy] that explores the experiment design space. - */ - private fun createStrategy(): ExperimentStrategy { - return strategy ?: CartesianExperimentStrategy - } - - /** - * Create the [ExperimentScheduler] that schedules the trials over the compute resources. - */ - private fun createScheduler(): ExperimentScheduler { - return scheduler ?: ThreadPoolExperimentScheduler(Runtime.getRuntime().availableProcessors()) - } - - /** - * Create the [ExperimentExecutionListener] that listens the to the execution of the experiments. - */ - private fun createListener(): ExperimentExecutionListener { - require(listeners.isNotEmpty()) { "No listeners registered." } - return CompositeExperimentExecutionListener(listeners) - } -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/ExperimentExecutionListener.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/ExperimentExecutionListener.kt deleted file mode 100644 index 9ef71863..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/ExperimentExecutionListener.kt +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine - -import org.opendc.harness.api.ExperimentDefinition -import org.opendc.harness.api.Scenario -import org.opendc.harness.api.Trial - -/** - * Listener to be notified of experiment execution events by experiment runners. - */ -public interface ExperimentExecutionListener { - /** - * A method that is invoked when an experiment is started. - * - * @param experiment The [ExperimentDefinition] that started. - */ - public fun experimentStarted(experiment: ExperimentDefinition) {} - - /** - * A method that is invoked when an experiment is finished, regardless of the outcome. - * - * @param experiment The [ExperimentDefinition] that finished. - * @param throwable The exception that was thrown during execution or `null` if the execution completed successfully. - */ - public fun experimentFinished(experiment: ExperimentDefinition, throwable: Throwable?) {} - - /** - * A method that is invoked when a scenario is started. - * - * @param scenario The scenario that is started. - */ - public fun scenarioStarted(scenario: Scenario) {} - - /** - * A method that is invoked when a scenario is finished, regardless of the outcome. - * - * @param scenario The [Scenario] that has finished. - * @param throwable The exception that was thrown during execution or `null` if the execution completed successfully. - */ - public fun scenarioFinished(scenario: Scenario, throwable: Throwable?) {} - - /** - * A method that is invoked when a trial is started. - * - * @param trial The trial that is started. - */ - public fun trialStarted(trial: Trial) {} - - /** - * A method that is invoked when a scenario is finished, regardless of the outcome. - * - * @param trial The [Trial] that has finished. - * @param throwable The exception that was thrown during execution or `null` if the execution completed successfully. - */ - public fun trialFinished(trial: Trial, throwable: Throwable?) {} -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/Discovery.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/Discovery.kt deleted file mode 100644 index f7f73b38..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/Discovery.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.discovery - -import kotlinx.coroutines.flow.Flow -import org.opendc.harness.api.ExperimentDefinition - -/** - * Component responsible for scanning for [ExperimentDefinition]s. - */ -public interface Discovery { - /** - * Start discovery of experiments. - * - * @param request The [DiscoveryRequest] to determine the experiments to discover. - * @return A flow of [ExperimentDefinition]s that have been discovered by the implementation. - */ - public fun discover(request: DiscoveryRequest): Flow<ExperimentDefinition> -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryFilter.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryFilter.kt deleted file mode 100644 index 219d09cd..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryFilter.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.discovery - -import org.opendc.harness.api.ExperimentDefinition -import java.util.function.Predicate - -/** - * A [DiscoveryFilter] decides how the selected experiments are filtered. - */ -public sealed class DiscoveryFilter { - /** - * Test whether the specified [ExperimentDefinition] should be selected. - */ - public abstract fun test(definition: ExperimentDefinition): Boolean - - /** - * Filter an experiment based on its name. - */ - public data class Name(val predicate: Predicate<String>) : DiscoveryFilter() { - override fun test(definition: ExperimentDefinition): Boolean = predicate.test(definition.name) - } - - /** - * Filter an experiment based on its metadata. - */ - public data class Meta(val key: String, val predicate: Predicate<Any>) : DiscoveryFilter() { - override fun test(definition: ExperimentDefinition): Boolean = - definition.meta[key]?.let { predicate.test(it) } ?: false - } -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryProvider.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryProvider.kt deleted file mode 100644 index c4b420c5..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryProvider.kt +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.discovery - -import org.opendc.harness.engine.internal.CompositeDiscovery -import java.util.* - -/** - * A provider interface for the [Discovery] component. - */ -public interface DiscoveryProvider { - /** - * A unique identifier for this discovery implementation. - * - * Each discovery implementation must provide a unique ID, so that they can be selected by the user. - * When in doubt, you may use the fully qualified name of your custom [Discovery] implementation class. - */ - public val id: String - - /** - * Factory method for creating a new [Discovery] instance. - */ - public fun create(classLoader: ClassLoader): Discovery - - public companion object { - /** - * The available [DiscoveryProvider]s. - */ - private val providers by lazy { ServiceLoader.load(DiscoveryProvider::class.java) } - - /** - * Obtain the [DiscoveryProvider] with the specified [id] or return `null`. - */ - public fun findById(id: String): DiscoveryProvider? { - return providers.find { it.id == id } - } - - /** - * Obtain a composite [Discovery] that combines the results of all available providers. - */ - public fun createComposite(classLoader: ClassLoader): Discovery { - return CompositeDiscovery(classLoader, providers) - } - } -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryRequest.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryRequest.kt deleted file mode 100644 index 5bc08dac..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryRequest.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.discovery - -/** - * A request for discovering experiments according to the specified information. - * - * @param selectors The selectors for this discovery request. - * @param filters The filters for this discovery request. - */ -public data class DiscoveryRequest( - val selectors: List<DiscoverySelector> = emptyList(), - val filters: List<DiscoveryFilter> = emptyList(), -) diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoverySelector.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoverySelector.kt deleted file mode 100644 index 67681303..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoverySelector.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.discovery - -import org.opendc.harness.api.ExperimentDefinition - -/** - * A [DiscoverySelector] defines the properties used to discover experiments. - */ -public sealed class DiscoverySelector { - /** - * Test whether the specified [ExperimentDefinition] should be selected. - */ - public abstract fun test(definition: ExperimentDefinition): Boolean - - /** - * Select an experiment based on its name. - */ - public data class Name(val name: String) : DiscoverySelector() { - override fun test(definition: ExperimentDefinition): Boolean = definition.name == name - } - - /** - * Select an experiment based on its metadata. - */ - public data class Meta(val key: String, val value: Any) : DiscoverySelector() { - override fun test(definition: ExperimentDefinition): Boolean = definition.meta[key] == value - } -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/CompositeDiscovery.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/CompositeDiscovery.kt deleted file mode 100644 index 726125a8..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/CompositeDiscovery.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.internal - -import kotlinx.coroutines.FlowPreview -import kotlinx.coroutines.flow.* -import org.opendc.harness.api.ExperimentDefinition -import org.opendc.harness.engine.discovery.Discovery -import org.opendc.harness.engine.discovery.DiscoveryProvider -import org.opendc.harness.engine.discovery.DiscoveryRequest - -/** - * A composite [Discovery] instance that combines the results of multiple delegate instances. - */ -internal class CompositeDiscovery(classLoader: ClassLoader, providers: Iterable<DiscoveryProvider>) : Discovery { - /** - * The [Discovery] instances to delegate to. - */ - private val delegates = providers.map { it.create(classLoader) } - - @OptIn(FlowPreview::class) - override fun discover(request: DiscoveryRequest): Flow<ExperimentDefinition> { - return delegates.asFlow() - .map { it.discover(request) } - .flattenMerge(delegates.size) - } -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/CompositeExperimentExecutionListener.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/CompositeExperimentExecutionListener.kt deleted file mode 100644 index 62b4ca8b..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/CompositeExperimentExecutionListener.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.internal - -import org.opendc.harness.api.ExperimentDefinition -import org.opendc.harness.api.Scenario -import org.opendc.harness.api.Trial -import org.opendc.harness.engine.ExperimentExecutionListener - -/** - * An [ExperimentExecutionListener] that composes multiple other listeners. - */ -public class CompositeExperimentExecutionListener(private val listeners: List<ExperimentExecutionListener>) : ExperimentExecutionListener { - override fun experimentStarted(experiment: ExperimentDefinition) { - listeners.forEach { it.experimentStarted(experiment) } - } - - override fun experimentFinished(experiment: ExperimentDefinition, throwable: Throwable?) { - listeners.forEach { it.experimentFinished(experiment, throwable) } - } - - override fun scenarioStarted(scenario: Scenario) { - listeners.forEach { it.scenarioStarted(scenario) } - } - - override fun scenarioFinished(scenario: Scenario, throwable: Throwable?) { - listeners.forEach { it.scenarioFinished(scenario, throwable) } - } - - override fun trialStarted(trial: Trial) { - listeners.forEach { it.trialStarted(trial) } - } - - override fun trialFinished(trial: Trial, throwable: Throwable?) { - listeners.forEach { it.trialFinished(trial, throwable) } - } -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/DslDiscovery.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/DslDiscovery.kt deleted file mode 100644 index 3fa3fe35..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/DslDiscovery.kt +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.internal - -import io.github.classgraph.ClassGraph -import io.github.classgraph.ScanResult -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.asFlow -import org.opendc.harness.api.ExperimentDefinition -import org.opendc.harness.dsl.Experiment -import org.opendc.harness.engine.discovery.Discovery -import org.opendc.harness.engine.discovery.DiscoveryFilter -import org.opendc.harness.engine.discovery.DiscoveryRequest -import org.opendc.harness.engine.discovery.DiscoverySelector - -/** - * A [Discovery] implementation that discovers [Experiment] instances on the classpath. - */ -internal class DslDiscovery(private val classLoader: ClassLoader) : Discovery { - /* - * Lazily memoize the results of the classpath scan. - */ - private val scanResult by lazy { scan() } - - override fun discover(request: DiscoveryRequest): Flow<ExperimentDefinition> { - return findExperiments() - .map { cls -> - val exp = cls.constructors[0].newInstance() as Experiment - exp.toDefinition() - } - .filter(select(request.selectors)) - .filter(filter(request.filters)) - .asFlow() - } - - /** - * Find the classes on the classpath implementing the [Experiment] class. - */ - private fun findExperiments(): Sequence<Class<out Experiment>> { - return scanResult - .getSubclasses(Experiment::class.java.name) - .filter { !(it.isAbstract || it.isInterface) } - .map { it.loadClass() } - .filterIsInstance<Class<out Experiment>>() - .asSequence() - } - - /** - * Create a predicate for filtering the experiments based on the specified [filters]. - */ - private fun filter(filters: List<DiscoveryFilter>): (ExperimentDefinition) -> Boolean = { def -> - filters.isEmpty() || filters.all { it.test(def) } - } - - /** - * Create a predicate for selecting the experiments based on the specified [selectors]. - */ - private fun select(selectors: List<DiscoverySelector>): (ExperimentDefinition) -> Boolean = { def -> - selectors.isEmpty() || selectors.any { it.test(def) } - } - - /** - * Scan the classpath using [ClassGraph]. - */ - private fun scan(): ScanResult { - return ClassGraph() - .addClassLoader(classLoader) - .enableClassInfo() - .enableExternalClasses() - .ignoreClassVisibility() - .rejectPackages( - "java.*", - "javax.*", - "sun.*", - "com.sun.*", - "kotlin.*", - "androidx.*", - "org.jetbrains.kotlin.*", - "org.junit.*" - ).scan() - } -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/DslDiscoveryProvider.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/DslDiscoveryProvider.kt deleted file mode 100644 index 6a9bd599..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/DslDiscoveryProvider.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.internal - -import org.opendc.harness.dsl.Experiment -import org.opendc.harness.engine.discovery.Discovery -import org.opendc.harness.engine.discovery.DiscoveryProvider - -/** - * A [DiscoveryProvider] for the [Experiment]s on the classpath. - */ -public class DslDiscoveryProvider : DiscoveryProvider { - override val id: String = "dsl" - - override fun create(classLoader: ClassLoader): Discovery = DslDiscovery(classLoader) -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/ScenarioImpl.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/ScenarioImpl.kt deleted file mode 100644 index 65d19e87..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/internal/ScenarioImpl.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.internal - -import org.opendc.harness.api.ExperimentDefinition -import org.opendc.harness.api.Parameter -import org.opendc.harness.api.Scenario - -/** - * Internal implementation of a [Scenario]. - */ -internal data class ScenarioImpl( - override val id: Int, - override val experiment: ExperimentDefinition, - val parameters: Map<Parameter<*>, Any?> -) : Scenario { - - override fun <T> get(param: Parameter<T>): T { - if (!parameters.containsKey(param)) { - throw IllegalArgumentException("Unknown parameter for this scenario.") - } - - // This cast should always succeed - @Suppress("UNCHECKED_CAST") - return parameters[param] as T - } - - override fun toString(): String = "Scenario" -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/scheduler/ExperimentScheduler.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/scheduler/ExperimentScheduler.kt deleted file mode 100644 index 0265554a..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/scheduler/ExperimentScheduler.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.scheduler - -import org.opendc.harness.api.Trial - -/** - * The [ExperimentScheduler] is responsible for scheduling the execution of experiment runs over some set of compute - * resources (e.g., threads or even multiple machines). - */ -public interface ExperimentScheduler : AutoCloseable { - /** - * Allocate a [Worker] for executing an experiment trial. This method may suspend in case no resources are directly - * available at the moment. - * - * @return The available worker. - */ - public suspend fun allocate(): Worker - - /** - * An isolated worker of an [ExperimentScheduler] that is responsible for conducting a single experiment trial. - */ - public interface Worker { - /** - * Dispatch an experiment trial immediately to one of the available compute resources and block execution until - * the trial has finished. - * - * @param trial The trial to dispatch. - */ - public suspend fun dispatch(trial: Trial) - } -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/scheduler/ExperimentSchedulerProvider.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/scheduler/ExperimentSchedulerProvider.kt deleted file mode 100644 index a93d4bf6..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/scheduler/ExperimentSchedulerProvider.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.scheduler - -import java.util.* - -/** - * A factory for constructing an [ExperimentScheduler]. - */ -public interface ExperimentSchedulerProvider { - /** - * A unique identifier for this scheduler implementation. - * - * Each experiment scheduler must provide a unique ID, so that they can be selected by the user. - * When in doubt, you may use the fully qualified name of your custom [ExperimentScheduler] implementation class. - */ - public val id: String - - /** - * Factory method for creating a new [ExperimentScheduler] instance. - */ - public fun create(): ExperimentScheduler - - public companion object { - /** - * The available [ExperimentSchedulerProvider]s. - */ - private val providers by lazy { ServiceLoader.load(ExperimentSchedulerProvider::class.java) } - - /** - * Obtain the [ExperimentScheduler] with the specified [id] or return `null`. - */ - public fun findById(id: String): ExperimentSchedulerProvider? { - return providers.find { it.id == id } - } - } -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/scheduler/ThreadPoolExperimentScheduler.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/scheduler/ThreadPoolExperimentScheduler.kt deleted file mode 100644 index 1ae533cf..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/scheduler/ThreadPoolExperimentScheduler.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.scheduler - -import kotlinx.coroutines.asCoroutineDispatcher -import kotlinx.coroutines.sync.Semaphore -import kotlinx.coroutines.withContext -import org.opendc.harness.api.Trial -import java.util.concurrent.Executors - -/** - * An [ExperimentScheduler] that runs experiment trials using a local thread pool. - * - * @param parallelism The maximum amount of concurrent workers. - */ -public class ThreadPoolExperimentScheduler(parallelism: Int) : ExperimentScheduler { - private val dispatcher = Executors.newCachedThreadPool().asCoroutineDispatcher() - private val tickets = Semaphore(parallelism) - - override suspend fun allocate(): ExperimentScheduler.Worker { - tickets.acquire() - return object : ExperimentScheduler.Worker { - override suspend fun dispatch(trial: Trial) { - try { - withContext(dispatcher) { - trial.scenario.experiment.evaluator(trial) - } - } finally { - tickets.release() - } - } - } - } - - override fun close(): Unit = dispatcher.close() - - override fun toString(): String = "ThreadPoolScheduler" -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/scheduler/ThreadPoolExperimentSchedulerProvider.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/scheduler/ThreadPoolExperimentSchedulerProvider.kt deleted file mode 100644 index cf9a132f..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/scheduler/ThreadPoolExperimentSchedulerProvider.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.scheduler - -/** - * An [ExperimentSchedulerProvider] for constructing a [ThreadPoolExperimentScheduler]. - */ -public class ThreadPoolExperimentSchedulerProvider : ExperimentSchedulerProvider { - override val id: String = "thread-pool" - - override fun create(): ExperimentScheduler = - ThreadPoolExperimentScheduler(Runtime.getRuntime().availableProcessors()) -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/strategy/CartesianExperimentStrategy.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/strategy/CartesianExperimentStrategy.kt deleted file mode 100644 index 733eca8f..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/strategy/CartesianExperimentStrategy.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.strategy - -import org.opendc.harness.api.ExperimentDefinition -import org.opendc.harness.api.Parameter -import org.opendc.harness.api.Scenario -import org.opendc.harness.engine.internal.ScenarioImpl - -/** - * An [ExperimentStrategy] that takes the cartesian product of the parameters and evaluates every combination. - */ -public object CartesianExperimentStrategy : ExperimentStrategy { - /** - * Build the trials of an experiment. - */ - override fun generate(experiment: ExperimentDefinition): Sequence<Scenario> { - return experiment.parameters - .asSequence() - .map { param -> mapParameter(param).map { value -> listOf(param to value) } } - .reduce { acc, param -> - acc.flatMap { x -> param.map { y -> x + y } } - } - .mapIndexed { id, values -> ScenarioImpl(id, experiment, values.toMap()) } - } - - /** - * Instantiate a parameter and return a sequence of possible values. - */ - private fun <T> mapParameter(param: Parameter<T>): Sequence<T> { - return when (param) { - is Parameter.Generic<T> -> param.values.asSequence() - } - } -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/strategy/CartesianExperimentStrategyProvider.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/strategy/CartesianExperimentStrategyProvider.kt deleted file mode 100644 index f18795a3..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/strategy/CartesianExperimentStrategyProvider.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.strategy - -/** - * An [ExperimentStrategyProvider] for constructing a [CartesianExperimentStrategy]. - */ -public class CartesianExperimentStrategyProvider : ExperimentStrategyProvider { - override val id: String = "cartesian" - - override fun create(): ExperimentStrategy = CartesianExperimentStrategy -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/strategy/ExperimentStrategy.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/strategy/ExperimentStrategy.kt deleted file mode 100644 index 3a0148ad..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/strategy/ExperimentStrategy.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.strategy - -import org.opendc.harness.api.ExperimentDefinition -import org.opendc.harness.api.Scenario - -/** - * The [ExperimentStrategy] is responsible for traversing the design space of an [ExperimentDefinition] based on its - * parameters, generating concrete points in the space represented as [Scenario]s. - */ -public interface ExperimentStrategy { - /** - * Generate the points in the design space of the specified [experiment] to explore. - * - * @param experiment The experiment design space to explore. - * @return A sequence of [Scenario]s which may be explored by the [ExperimentEngine]. - */ - public fun generate(experiment: ExperimentDefinition): Sequence<Scenario> -} diff --git a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/strategy/ExperimentStrategyProvider.kt b/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/strategy/ExperimentStrategyProvider.kt deleted file mode 100644 index 7fa05f34..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/kotlin/org/opendc/harness/engine/strategy/ExperimentStrategyProvider.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.engine.strategy - -import java.util.* - -/** - * A factory for constructing an [ExperimentStrategy]. - */ -public interface ExperimentStrategyProvider { - /** - * A unique identifier for this strategy implementation. - * - * Each experiment strategy must provide a unique ID, so that they can be selected by the user. - * When in doubt, you may use the fully qualified name of your custom [ExperimentStrategy] implementation class. - */ - public val id: String - - /** - * Factory method for creating a new [ExperimentStrategy] instance. - */ - public fun create(): ExperimentStrategy - - public companion object { - /** - * The available [ExperimentStrategyProvider]s. - */ - private val providers by lazy { ServiceLoader.load(ExperimentStrategyProvider::class.java) } - - /** - * Obtain the [ExperimentStrategy] with the specified [id] or return `null`. - */ - public fun findById(id: String): ExperimentStrategyProvider? { - return providers.find { it.id == id } - } - } -} diff --git a/opendc-harness/opendc-harness-engine/src/main/resources/META-INF/services/org.opendc.harness.engine.discovery.DiscoveryProvider b/opendc-harness/opendc-harness-engine/src/main/resources/META-INF/services/org.opendc.harness.engine.discovery.DiscoveryProvider deleted file mode 100644 index 83ac5015..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/resources/META-INF/services/org.opendc.harness.engine.discovery.DiscoveryProvider +++ /dev/null @@ -1 +0,0 @@ -org.opendc.harness.engine.internal.DslDiscoveryProvider diff --git a/opendc-harness/opendc-harness-engine/src/main/resources/META-INF/services/org.opendc.harness.engine.scheduler.ExperimentSchedulerProvider b/opendc-harness/opendc-harness-engine/src/main/resources/META-INF/services/org.opendc.harness.engine.scheduler.ExperimentSchedulerProvider deleted file mode 100644 index 2ba3a7cb..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/resources/META-INF/services/org.opendc.harness.engine.scheduler.ExperimentSchedulerProvider +++ /dev/null @@ -1 +0,0 @@ -org.opendc.harness.engine.scheduler.ThreadPoolExperimentSchedulerProvider diff --git a/opendc-harness/opendc-harness-engine/src/main/resources/META-INF/services/org.opendc.harness.engine.strategy.ExperimentStrategyProvider b/opendc-harness/opendc-harness-engine/src/main/resources/META-INF/services/org.opendc.harness.engine.strategy.ExperimentStrategyProvider deleted file mode 100644 index cb1c70ac..00000000 --- a/opendc-harness/opendc-harness-engine/src/main/resources/META-INF/services/org.opendc.harness.engine.strategy.ExperimentStrategyProvider +++ /dev/null @@ -1 +0,0 @@ -org.opendc.harness.engine.strategy.CartesianExperimentStrategyProvider diff --git a/opendc-harness/opendc-harness-engine/src/test/kotlin/org/opendc/harness/EngineTest.kt b/opendc-harness/opendc-harness-engine/src/test/kotlin/org/opendc/harness/EngineTest.kt deleted file mode 100644 index 6955f7c5..00000000 --- a/opendc-harness/opendc-harness-engine/src/test/kotlin/org/opendc/harness/EngineTest.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2021 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.harness - -import kotlinx.coroutines.flow.flowOf -import kotlinx.coroutines.flow.toList -import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Test -import org.opendc.harness.api.ExperimentDefinition -import org.opendc.harness.engine.ExperimentEngine -import org.opendc.harness.engine.ExperimentEngineLauncher -import org.opendc.harness.engine.ExperimentExecutionListener -import org.opendc.harness.engine.discovery.DiscoveryProvider -import org.opendc.harness.engine.discovery.DiscoveryRequest - -/** - * A test suite for the [ExperimentEngine]. - */ -internal class EngineTest { - @Test - fun test() { - val listener = object : ExperimentExecutionListener {} - ExperimentEngineLauncher() - .withListener(listener) - .runBlocking(flowOf(TestExperiment().toDefinition())) - } - - @Test - fun discovery() { - runBlocking { - val discovery = DiscoveryProvider.findById("dsl")?.create(Thread.currentThread().contextClassLoader) - assertNotNull(discovery) - val res = mutableListOf<ExperimentDefinition>() - discovery?.discover(DiscoveryRequest())?.toList(res) - println(res) - assertEquals(1, res.size) - } - } -} diff --git a/opendc-harness/opendc-harness-engine/src/test/kotlin/org/opendc/harness/TestExperiment.kt b/opendc-harness/opendc-harness-engine/src/test/kotlin/org/opendc/harness/TestExperiment.kt deleted file mode 100644 index bedd1c76..00000000 --- a/opendc-harness/opendc-harness-engine/src/test/kotlin/org/opendc/harness/TestExperiment.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2021 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.harness - -import org.opendc.harness.dsl.Experiment -import org.opendc.harness.dsl.anyOf - -/** - * An experiment to test the harness' functionality. - */ -class TestExperiment : Experiment("Design Space Exploration") { - /** - * The cloud environment to use. - */ - private val environment: String by anyOf( - "../../traces/setup-small.json", - "../../traces/setup.json", - "../../traces/setup-large.json" - ) - - /** - * The trace to use. - */ - private val trace: String by anyOf( - "../../traces/gwf/askalon_workload_olde.gwf", - "../../traces/gwf/askalon_workload_ee.gwf", - "../../traces/gwf/chronos_exp_noscaler_ca.gwf" - ) - - override fun doRun(repeat: Int) { - println("Id $id, Run $repeat, Environment $environment, Trace $trace") - Thread.sleep(500 * id.toLong()) - } -} diff --git a/opendc-harness/opendc-harness-junit5/build.gradle.kts b/opendc-harness/opendc-harness-junit5/build.gradle.kts deleted file mode 100644 index f78a4c30..00000000 --- a/opendc-harness/opendc-harness-junit5/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -description = "JUnit Platform interface to the OpenDC Harness" - -/* Build configuration */ -plugins { - `kotlin-library-conventions` -} - -dependencies { - api(projects.opendcHarness.opendcHarnessEngine) - - implementation(libs.kotlin.logging) - implementation(libs.junit.platform.engine) -} diff --git a/opendc-harness/opendc-harness-junit5/src/main/kotlin/org/opendc/harness/runner/junit5/JUnitExperimentExecutionListener.kt b/opendc-harness/opendc-harness-junit5/src/main/kotlin/org/opendc/harness/runner/junit5/JUnitExperimentExecutionListener.kt deleted file mode 100644 index 9e2b629d..00000000 --- a/opendc-harness/opendc-harness-junit5/src/main/kotlin/org/opendc/harness/runner/junit5/JUnitExperimentExecutionListener.kt +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.runner.junit5 - -import org.junit.platform.engine.* -import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor -import org.junit.platform.engine.support.descriptor.ClassSource -import org.junit.platform.engine.support.descriptor.EngineDescriptor -import org.opendc.harness.api.ExperimentDefinition -import org.opendc.harness.api.Scenario -import org.opendc.harness.api.Trial -import org.opendc.harness.engine.ExperimentExecutionListener -import java.util.* - -/** - * An [ExperimentExecutionListener] that notifies JUnit platform of the progress of the experiment trials. - */ -public class JUnitExperimentExecutionListener( - private val listener: EngineExecutionListener, - private val root: EngineDescriptor -) : ExperimentExecutionListener { - /** - * The current active experiments. - */ - private val experiments = mutableMapOf<ExperimentDefinition, TestDescriptor>() - - /** - * The current active scenarios. - */ - private val scenarios = mutableMapOf<Scenario, TestDescriptor>() - - /** - * The current active trials. - */ - private val trials = mutableMapOf<Trial, TestDescriptor>() - - override fun experimentStarted(experiment: ExperimentDefinition) { - val descriptor = experiment.toDescriptor(root) - root.addChild(descriptor) - experiments[experiment] = descriptor - - listener.dynamicTestRegistered(descriptor) - listener.executionStarted(descriptor) - } - - override fun experimentFinished(experiment: ExperimentDefinition, throwable: Throwable?) { - val descriptor = experiments.remove(experiment) - - if (throwable != null) { - listener.executionFinished(descriptor, TestExecutionResult.failed(throwable)) - } else { - listener.executionFinished(descriptor, TestExecutionResult.successful()) - } - } - - override fun scenarioStarted(scenario: Scenario) { - val parent = experiments[scenario.experiment] ?: return - val descriptor = scenario.toDescriptor(parent) - parent.addChild(descriptor) - scenarios[scenario] = descriptor - - listener.dynamicTestRegistered(descriptor) - listener.executionStarted(descriptor) - } - - override fun scenarioFinished(scenario: Scenario, throwable: Throwable?) { - val descriptor = scenarios.remove(scenario) - - if (throwable != null) { - listener.executionFinished(descriptor, TestExecutionResult.failed(throwable)) - } else { - listener.executionFinished(descriptor, TestExecutionResult.successful()) - } - } - - override fun trialStarted(trial: Trial) { - val parent = scenarios[trial.scenario] ?: return - val descriptor = trial.toDescriptor(parent) - parent.addChild(descriptor) - trials[trial] = descriptor - - listener.dynamicTestRegistered(descriptor) - listener.executionStarted(descriptor) - } - - override fun trialFinished(trial: Trial, throwable: Throwable?) { - val descriptor = trials.remove(trial) - - if (throwable != null) { - listener.executionFinished(descriptor, TestExecutionResult.failed(throwable)) - } else { - listener.executionFinished(descriptor, TestExecutionResult.successful()) - } - } - - /** - * Create a [TestDescriptor] for an [ExperimentDefinition]. - */ - private fun ExperimentDefinition.toDescriptor(parent: TestDescriptor): TestDescriptor { - return object : AbstractTestDescriptor(parent.uniqueId.append("experiment", name), name) { - override fun getType(): TestDescriptor.Type = TestDescriptor.Type.CONTAINER - - override fun mayRegisterTests(): Boolean = true - - override fun toString(): String = "ExperimentDescriptor" - - override fun getSource(): Optional<TestSource> { - val cls = meta["class.name"] as? String - return if (cls != null) - Optional.of(ClassSource.from(cls)) - else - Optional.empty() - } - } - } - - /** - * Create a [TestDescriptor] for a [Scenario]. - */ - private fun Scenario.toDescriptor(parent: TestDescriptor): TestDescriptor { - return object : AbstractTestDescriptor(parent.uniqueId.append("scenario", id.toString()), "Scenario $id") { - override fun getType(): TestDescriptor.Type = TestDescriptor.Type.CONTAINER_AND_TEST - - override fun mayRegisterTests(): Boolean = true - - override fun toString(): String = "ScenarioDescriptor" - } - } - - /** - * Create a [TestDescriptor] for a [Trial]. - */ - private fun Trial.toDescriptor(parent: TestDescriptor): TestDescriptor { - return object : AbstractTestDescriptor(parent.uniqueId.append("repeat", repeat.toString()), "Repeat $repeat") { - override fun getType(): TestDescriptor.Type = TestDescriptor.Type.TEST - - override fun mayRegisterTests(): Boolean = false - - override fun toString(): String = "TrialDescriptor" - } - } -} diff --git a/opendc-harness/opendc-harness-junit5/src/main/kotlin/org/opendc/harness/runner/junit5/OpenDCTestEngine.kt b/opendc-harness/opendc-harness-junit5/src/main/kotlin/org/opendc/harness/runner/junit5/OpenDCTestEngine.kt deleted file mode 100644 index 7fc97f6d..00000000 --- a/opendc-harness/opendc-harness-junit5/src/main/kotlin/org/opendc/harness/runner/junit5/OpenDCTestEngine.kt +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2021 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.harness.runner.junit5 - -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.emptyFlow -import mu.KotlinLogging -import org.junit.platform.commons.util.ClassLoaderUtils -import org.junit.platform.engine.* -import org.junit.platform.engine.discovery.ClassNameFilter -import org.junit.platform.engine.discovery.ClassSelector -import org.junit.platform.engine.discovery.MethodSelector -import org.junit.platform.engine.support.descriptor.EngineDescriptor -import org.opendc.harness.api.ExperimentDefinition -import org.opendc.harness.engine.ExperimentEngineLauncher -import org.opendc.harness.engine.discovery.DiscoveryFilter -import org.opendc.harness.engine.discovery.DiscoveryProvider -import org.opendc.harness.engine.discovery.DiscoveryRequest -import org.opendc.harness.engine.discovery.DiscoverySelector -import java.util.* - -/** - * A [TestEngine] implementation that is able to run experiments defined using the harness. - */ -public class OpenDCTestEngine : TestEngine { - /** - * The logging instance for this engine. - */ - private val logger = KotlinLogging.logger {} - - override fun getId(): String = "opendc-harness" - - override fun getGroupId(): Optional<String> = Optional.of("org.opendc") - - override fun getArtifactId(): Optional<String> = Optional.of("opendc-harness") - - override fun discover(request: EngineDiscoveryRequest, uniqueId: UniqueId): TestDescriptor { - // IntelliJ will pass a [MethodSelector] to run just a single method inside a file. In that - // case, no experiments should be discovered, since we support only experiments by class. - if (request.getSelectorsByType(MethodSelector::class.java).isNotEmpty()) { - return ExperimentEngineDescriptor(uniqueId, emptyFlow()) - } - - val classNames = request.getSelectorsByType(ClassSelector::class.java).map { DiscoverySelector.Meta("class.name", it.className) } - val classNameFilters = request.getFiltersByType(ClassNameFilter::class.java).map { DiscoveryFilter.Name(it.toPredicate()) } - - val discovery = DiscoveryProvider.createComposite(ClassLoaderUtils.getDefaultClassLoader()) - val definitions = discovery.discover(DiscoveryRequest(classNames, classNameFilters)) - - return ExperimentEngineDescriptor(uniqueId, definitions) - } - - override fun execute(request: ExecutionRequest) { - logger.debug { "JUnit ExecutionRequest[${request::class.java.name}] [configurationParameters=${request.configurationParameters}; rootTestDescriptor=${request.rootTestDescriptor}]" } - val root = request.rootTestDescriptor as ExperimentEngineDescriptor - val listener = request.engineExecutionListener - - listener.executionStarted(root) - - try { - ExperimentEngineLauncher() - .withListener(JUnitExperimentExecutionListener(listener, root)) - .runBlocking(root.experiments) - listener.executionFinished(root, TestExecutionResult.successful()) - } catch (e: Throwable) { - listener.executionFinished(root, TestExecutionResult.failed(e)) - } - } - - private class ExperimentEngineDescriptor(id: UniqueId, val experiments: Flow<ExperimentDefinition>) : EngineDescriptor(id, "opendc") { - override fun mayRegisterTests(): Boolean = true - } -} diff --git a/opendc-harness/opendc-harness-junit5/src/main/resources/META-INF/services/org.junit.platform.engine.TestEngine b/opendc-harness/opendc-harness-junit5/src/main/resources/META-INF/services/org.junit.platform.engine.TestEngine deleted file mode 100644 index b83eec0c..00000000 --- a/opendc-harness/opendc-harness-junit5/src/main/resources/META-INF/services/org.junit.platform.engine.TestEngine +++ /dev/null @@ -1 +0,0 @@ -org.opendc.harness.runner.junit5.OpenDCTestEngine diff --git a/settings.gradle.kts b/settings.gradle.kts index 6198b2ae..805e8364 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -58,9 +58,5 @@ include(":opendc-trace:opendc-trace-opendc") include(":opendc-trace:opendc-trace-parquet") include(":opendc-trace:opendc-trace-calcite") include(":opendc-trace:opendc-trace-tools") -include(":opendc-harness:opendc-harness-api") -include(":opendc-harness:opendc-harness-engine") -include(":opendc-harness:opendc-harness-cli") -include(":opendc-harness:opendc-harness-junit5") enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") |
