summaryrefslogtreecommitdiff
path: root/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery')
-rw-r--r--opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/Discovery.kt39
-rw-r--r--opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryFilter.kt51
-rw-r--r--opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryProvider.kt65
-rw-r--r--opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryRequest.kt34
-rw-r--r--opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoverySelector.kt49
5 files changed, 238 insertions, 0 deletions
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
new file mode 100644
index 00000000..f7f73b38
--- /dev/null
+++ b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/Discovery.kt
@@ -0,0 +1,39 @@
+/*
+ * 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/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryFilter.kt b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryFilter.kt
new file mode 100644
index 00000000..219d09cd
--- /dev/null
+++ b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryFilter.kt
@@ -0,0 +1,51 @@
+/*
+ * 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/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryProvider.kt b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryProvider.kt
new file mode 100644
index 00000000..fad255de
--- /dev/null
+++ b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryProvider.kt
@@ -0,0 +1,65 @@
+/*
+ * 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
new file mode 100644
index 00000000..5bc08dac
--- /dev/null
+++ b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoveryRequest.kt
@@ -0,0 +1,34 @@
+/*
+ * 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/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoverySelector.kt b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoverySelector.kt
new file mode 100644
index 00000000..67681303
--- /dev/null
+++ b/opendc-harness/src/main/kotlin/org/opendc/harness/engine/discovery/DiscoverySelector.kt
@@ -0,0 +1,49 @@
+/*
+ * 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
+ }
+}