From 4a8b32d288ba3ee986ecef7933fa77554d34e762 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 4 May 2021 19:19:47 +0200 Subject: harness: Split harness into separate modules This change splits the OpenDC Experiment Harness into separate modules. This prevents users from pulling in unnecessary dependencies when depending on the harness API. --- .../engine/strategy/CartesianExperimentStrategy.kt | 55 --------------------- .../CartesianExperimentStrategyProvider.kt | 32 ------------ .../harness/engine/strategy/ExperimentStrategy.kt | 40 --------------- .../engine/strategy/ExperimentStrategyProvider.kt | 57 ---------------------- 4 files changed, 184 deletions(-) delete mode 100644 opendc-harness/src/main/kotlin/org/opendc/harness/engine/strategy/CartesianExperimentStrategy.kt delete mode 100644 opendc-harness/src/main/kotlin/org/opendc/harness/engine/strategy/CartesianExperimentStrategyProvider.kt delete mode 100644 opendc-harness/src/main/kotlin/org/opendc/harness/engine/strategy/ExperimentStrategy.kt delete mode 100644 opendc-harness/src/main/kotlin/org/opendc/harness/engine/strategy/ExperimentStrategyProvider.kt (limited to 'opendc-harness/src/main/kotlin/org/opendc/harness/engine/strategy') diff --git a/opendc-harness/src/main/kotlin/org/opendc/harness/engine/strategy/CartesianExperimentStrategy.kt b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/strategy/CartesianExperimentStrategy.kt deleted file mode 100644 index e5e08003..00000000 --- a/opendc-harness/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.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 { - 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 mapParameter(param: Parameter): Sequence { - return when (param) { - is Parameter.Generic -> param.values.asSequence() - } - } -} diff --git a/opendc-harness/src/main/kotlin/org/opendc/harness/engine/strategy/CartesianExperimentStrategyProvider.kt b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/strategy/CartesianExperimentStrategyProvider.kt deleted file mode 100644 index f18795a3..00000000 --- a/opendc-harness/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/src/main/kotlin/org/opendc/harness/engine/strategy/ExperimentStrategy.kt b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/strategy/ExperimentStrategy.kt deleted file mode 100644 index 3a0148ad..00000000 --- a/opendc-harness/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 -} diff --git a/opendc-harness/src/main/kotlin/org/opendc/harness/engine/strategy/ExperimentStrategyProvider.kt b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/strategy/ExperimentStrategyProvider.kt deleted file mode 100644 index 7fa05f34..00000000 --- a/opendc-harness/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 } - } - } -} -- cgit v1.2.3