summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-simulator/src
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-compute/opendc-compute-simulator/src')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/failure/FailureModelFactory.kt41
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/failure/models/Grid5000.kt (renamed from opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/failure/FailureModels.kt)52
2 files changed, 68 insertions, 25 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/failure/FailureModelFactory.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/failure/FailureModelFactory.kt
new file mode 100644
index 00000000..406665c7
--- /dev/null
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/failure/FailureModelFactory.kt
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2024 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.compute.simulator.failure
+
+import org.opendc.compute.simulator.failure.models.Grid5000
+import java.time.Duration
+import kotlin.math.roundToLong
+
+/**
+ * Get failure model
+ *
+ * @param failureInterval The interval of failures occurring in s
+ * @return
+ */
+public fun getFailureModel(failureInterval: Double): FailureModel? {
+ return if (failureInterval > 0) {
+ Grid5000(Duration.ofSeconds(failureInterval.roundToLong()))
+ } else {
+ null
+ }
+}
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/failure/FailureModels.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/failure/models/Grid5000.kt
index b8887627..8aacc49d 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/failure/FailureModels.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/failure/models/Grid5000.kt
@@ -22,12 +22,16 @@
@file:JvmName("FailureModels")
-package org.opendc.compute.simulator.failure
+package org.opendc.compute.simulator.failure.models
import org.apache.commons.math3.distribution.LogNormalDistribution
import org.apache.commons.math3.random.Well19937c
import org.opendc.compute.service.ComputeService
import org.opendc.compute.simulator.SimHost
+import org.opendc.compute.simulator.failure.FailureModel
+import org.opendc.compute.simulator.failure.HostFaultInjector
+import org.opendc.compute.simulator.failure.StartStopHostFault
+import org.opendc.compute.simulator.failure.StochasticVictimSelector
import java.time.Duration
import java.time.InstantSource
import java.util.random.RandomGenerator
@@ -35,34 +39,32 @@ import kotlin.coroutines.CoroutineContext
import kotlin.math.ln
/**
- * Obtain a [FailureModel] based on the GRID'5000 failure trace.
+ * A [FailureModel] based on the GRID'5000 failure trace.
*
* This fault injector uses parameters from the GRID'5000 failure trace as described in
* "A Framework for the Study of Grid Inter-Operation Mechanisms", A. Iosup, 2009.
*/
-public fun grid5000(failureInterval: Duration): FailureModel {
- return object : FailureModel {
- override fun createInjector(
- context: CoroutineContext,
- clock: InstantSource,
- service: ComputeService,
- random: RandomGenerator,
- ): HostFaultInjector {
- val rng = Well19937c(random.nextLong())
- val hosts = service.hosts.map { it as SimHost }.toSet()
+public class Grid5000(private val failureInterval: Duration) : FailureModel {
+ override fun createInjector(
+ context: CoroutineContext,
+ clock: InstantSource,
+ service: ComputeService,
+ random: RandomGenerator,
+ ): HostFaultInjector {
+ val rng = Well19937c(random.nextLong())
+ val hosts = service.hosts.map { it as SimHost }.toSet()
- // Parameters from A. Iosup, A Framework for the Study of Grid Inter-Operation Mechanisms, 2009
- // GRID'5000
- return HostFaultInjector(
- context,
- clock,
- hosts,
- iat = LogNormalDistribution(rng, ln(failureInterval.toHours().toDouble()), 1.03),
- selector = StochasticVictimSelector(LogNormalDistribution(rng, 1.88, 1.25), random),
- fault = StartStopHostFault(LogNormalDistribution(rng, 8.89, 2.71)),
- )
- }
-
- override fun toString(): String = "Grid5000FailureModel"
+ // Parameters from A. Iosup, A Framework for the Study of Grid Inter-Operation Mechanisms, 2009
+ // GRID'5000
+ return HostFaultInjector(
+ context,
+ clock,
+ hosts,
+ iat = LogNormalDistribution(rng, ln(failureInterval.toHours().toDouble()), 1.03),
+ selector = StochasticVictimSelector(LogNormalDistribution(rng, 1.88, 1.25), random),
+ fault = StartStopHostFault(LogNormalDistribution(rng, 8.89, 2.71)),
+ )
}
+
+ override fun toString(): String = "Grid5000FailureModel"
}