From 83de527c2ffa6341b858c29aec5042b04cd7cea3 Mon Sep 17 00:00:00 2001 From: Marcel Becker <stu117960@mail.uni-kiel.de> Date: Mon, 10 Jan 2022 18:22:51 +0100 Subject: [PATCH] Execution yaml restructuring, strategy.name indicates strategy type --- theodolite/crd/crd-execution.yaml | 3 +- .../benchmark/BenchmarkExecution.kt | 1 + .../execution/TheodoliteExecutor.kt | 7 ++++- .../theodolite/strategies/StrategyFactory.kt | 29 +++++++++++++++++-- .../src/main/kotlin/theodolite/util/Config.kt | 4 ++- 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/theodolite/crd/crd-execution.yaml b/theodolite/crd/crd-execution.yaml index fde590bbb..185b0b494 100644 --- a/theodolite/crd/crd-execution.yaml +++ b/theodolite/crd/crd-execution.yaml @@ -93,11 +93,12 @@ spec: name: string properties: restrictions: - description: List of restriction strategys used to delimit the search space. + description: List of restriction strategies used to delimit the search space. type: array items: type: string guessStrategy: string + searchStrategy: object properties: duration: description: Defines the duration of each experiment in seconds. diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt b/theodolite/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt index 168daa457..b27533419 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt @@ -59,6 +59,7 @@ class BenchmarkExecution : KubernetesResource { lateinit var name: String lateinit var restrictions: List<String> lateinit var guessStrategy: String + lateinit var searchStrategy: String } /** diff --git a/theodolite/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt b/theodolite/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt index 4091a058e..a334dc8f3 100644 --- a/theodolite/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt +++ b/theodolite/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt @@ -92,7 +92,8 @@ class TheodoliteExecutor( resourcePatcherDefinition ) }, - searchStrategy = strategyFactory.createSearchStrategy(executor, config.execution.strategy, results) + searchStrategy = strategyFactory.createSearchStrategy(executor, config.execution.strategy, results), + metric = config.execution.metric ) } @@ -119,6 +120,10 @@ class TheodoliteExecutor( val config = buildConfig() //TODO: Differentiate metrics here +// when (config.metric) { +// "demand" -> // execute benchmarks for each load +// "capacity" -> // execute benchmarks for each resource amount +// } // execute benchmarks for each load try { for (load in config.loads) { diff --git a/theodolite/src/main/kotlin/theodolite/strategies/StrategyFactory.kt b/theodolite/src/main/kotlin/theodolite/strategies/StrategyFactory.kt index 7de70c5d2..a4c51bc0c 100644 --- a/theodolite/src/main/kotlin/theodolite/strategies/StrategyFactory.kt +++ b/theodolite/src/main/kotlin/theodolite/strategies/StrategyFactory.kt @@ -27,15 +27,21 @@ class StrategyFactory { "FullSearch" -> FullSearch(executor) "LinearSearch" -> LinearSearch(executor) "BinarySearch" -> BinarySearch(executor) + "RestrictionSearch" -> when (searchStrategyObject.searchStrategy){ + //TODO: Do we only need LinearSearch here as valid searchstrat? Or actually just allow all? + // If we dont have restriction Strat specified but still RestrictionSearch just do normal Search + "FullSearch" -> composeSearchRestrictionStrategy(executor, FullSearch(executor), results, searchStrategyObject.restrictions) + "LinearSearch" -> composeSearchRestrictionStrategy(executor, LinearSearch(executor), results, searchStrategyObject.restrictions) + "BinarySearch" -> composeSearchRestrictionStrategy(executor, BinarySearch(executor), results, searchStrategyObject.restrictions) + else -> throw IllegalArgumentException("Search Strategy ${searchStrategyObject.searchStrategy} for RestrictionSearch not found") + } "InitialGuessSearch" -> when (searchStrategyObject.guessStrategy){ "PrevResourceMinGuess" -> InitialGuessSearchStrategy(executor,PrevResourceMinGuess(), results) else -> throw IllegalArgumentException("Guess Strategy ${searchStrategyObject.guessStrategy} not found") } else -> throw IllegalArgumentException("Search Strategy $searchStrategyObject not found") } - if(searchStrategyObject.restrictions.isNotEmpty()){ - strategy = RestrictionSearch(executor,strategy,createRestrictionStrategy(results, searchStrategyObject.restrictions)) - } + return strategy } @@ -58,4 +64,21 @@ class StrategyFactory { } }.toSet() } + + /** + * Create a RestrictionSearch, if the provided restriction list is not empty. Otherwise just return the given + * searchStrategy. + * + * @param executor The [theodolite.execution.BenchmarkExecutor] that executes individual experiments. + * @param searchStrategy The [SearchStrategy] to use + * @param results The [Results] saves the state of the Theodolite benchmark run. + * @param restrictions The [RestrictionStrategy]'s to use + */ + private fun composeSearchRestrictionStrategy(executor: BenchmarkExecutor, searchStrategy: SearchStrategy, + results: Results, restrictions: List<String>): SearchStrategy { + if(restrictions.isNotEmpty()){ + return RestrictionSearch(executor,searchStrategy,createRestrictionStrategy(results, restrictions)) + } + return searchStrategy + } } diff --git a/theodolite/src/main/kotlin/theodolite/util/Config.kt b/theodolite/src/main/kotlin/theodolite/util/Config.kt index e3fde8fcf..fb4c0b641 100644 --- a/theodolite/src/main/kotlin/theodolite/util/Config.kt +++ b/theodolite/src/main/kotlin/theodolite/util/Config.kt @@ -10,10 +10,12 @@ import theodolite.strategies.searchstrategy.SearchStrategy * @param loads the [LoadDimension] of the execution * @param resources the [Resource] of the execution * @param searchStrategy the [SearchStrategy] of the execution + * @param metric the Metric of the execution */ @RegisterForReflection data class Config( val loads: List<LoadDimension>, val resources: List<Resource>, - val searchStrategy: SearchStrategy + val searchStrategy: SearchStrategy, + val metric: String ) -- GitLab