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. --- .../opendc/harness/engine/discovery/Discovery.kt | 39 ------------- .../harness/engine/discovery/DiscoveryFilter.kt | 51 ----------------- .../harness/engine/discovery/DiscoveryProvider.kt | 65 ---------------------- .../harness/engine/discovery/DiscoveryRequest.kt | 34 ----------- .../harness/engine/discovery/DiscoverySelector.kt | 49 ---------------- 5 files changed, 238 deletions(-) delete mode 100644 opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/Discovery.kt delete mode 100644 opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryFilter.kt delete mode 100644 opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryProvider.kt delete mode 100644 opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryRequest.kt delete mode 100644 opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoverySelector.kt (limited to 'opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery') diff --git a/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/Discovery.kt b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/Discovery.kt deleted file mode 100644 index f7f73b38..00000000 --- a/opendc-harness/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 -} diff --git a/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryFilter.kt b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryFilter.kt deleted file mode 100644 index 219d09cd..00000000 --- a/opendc-harness/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) : 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) : DiscoveryFilter() { - override fun test(definition: ExperimentDefinition): Boolean = - definition.meta[key]?.let { predicate.test(it) } ?: false - } -} diff --git a/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryProvider.kt b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryProvider.kt deleted file mode 100644 index fad255de..00000000 --- a/opendc-harness/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.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(): 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(): Discovery { - return CompositeDiscovery(providers) - } - } -} diff --git a/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryRequest.kt b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryRequest.kt deleted file mode 100644 index 5bc08dac..00000000 --- a/opendc-harness/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 = emptyList(), - val filters: List = emptyList(), -) diff --git a/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoverySelector.kt b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoverySelector.kt deleted file mode 100644 index 67681303..00000000 --- a/opendc-harness/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 - } -} -- cgit v1.2.3