diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-09-30 21:14:20 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-09-30 23:40:57 +0200 |
| commit | c41d201343263346ac84855a0b2254051ed33c21 (patch) | |
| tree | 9141a382f9e1b2d924e9a191e53cc6daa9107563 /simulator/opendc/opendc-core | |
| parent | c543f55e961f9f7468e19c1c0f5f20566d07dfb5 (diff) | |
Eliminate use of Domain and simulationContext in OpenDC
This change takes the first step in eliminating the explict use of
Domain and simulationContext from OpenDC. In this way, we decouple the
logic of various datacenter services from simulation logic, which should
promote re-use.
Diffstat (limited to 'simulator/opendc/opendc-core')
2 files changed, 10 insertions, 13 deletions
diff --git a/simulator/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/CorrelatedFaultInjector.kt b/simulator/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/CorrelatedFaultInjector.kt index f77a581e..87d6b7bd 100644 --- a/simulator/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/CorrelatedFaultInjector.kt +++ b/simulator/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/CorrelatedFaultInjector.kt @@ -24,23 +24,20 @@ package com.atlarge.opendc.core.failure -import com.atlarge.odcsim.Domain -import com.atlarge.odcsim.simulationContext +import kotlinx.coroutines.* +import java.time.Clock import kotlin.math.exp import kotlin.math.max import kotlin.random.Random import kotlin.random.asJavaRandom -import kotlinx.coroutines.Job -import kotlinx.coroutines.delay -import kotlinx.coroutines.ensureActive -import kotlinx.coroutines.launch /** * A [FaultInjector] that injects fault in the system which are correlated to each other. Failures do not occur in * isolation, but will trigger other faults. */ public class CorrelatedFaultInjector( - private val domain: Domain, + private val coroutineScope: CoroutineScope, + private val clock: Clock, private val iatScale: Double, private val iatShape: Double, private val sizeScale: Double, @@ -72,7 +69,7 @@ public class CorrelatedFaultInjector( // Clean up the domain if it finishes domain.scope.coroutineContext[Job]!!.invokeOnCompletion { - this@CorrelatedFaultInjector.domain.launch { + this@CorrelatedFaultInjector.coroutineScope.launch { active -= domain if (active.isEmpty()) { @@ -86,7 +83,7 @@ public class CorrelatedFaultInjector( return } - job = this.domain.launch { + job = this.coroutineScope.launch { while (active.isNotEmpty()) { ensureActive() @@ -94,7 +91,7 @@ public class CorrelatedFaultInjector( val d = lognvariate(iatScale, iatShape) * 3.6e6 // Handle long overflow - if (simulationContext.clock.millis() + d <= 0) { + if (clock.millis() + d <= 0) { return@launch } @@ -111,7 +108,7 @@ public class CorrelatedFaultInjector( val df = max(lognvariate(dScale, dShape) * 6e4, 15 * 6e4) // Handle long overflow - if (simulationContext.clock.millis() + df <= 0) { + if (clock.millis() + df <= 0) { return@launch } diff --git a/simulator/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt b/simulator/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt index 0f62667f..1b896858 100644 --- a/simulator/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt +++ b/simulator/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt @@ -25,11 +25,11 @@ package com.atlarge.opendc.core.failure import com.atlarge.odcsim.simulationContext +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import kotlin.math.ln1p import kotlin.math.pow import kotlin.random.Random -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch /** * A [FaultInjector] that injects uncorrelated faults into the system, meaning that failures of the subsystems are |
