summaryrefslogtreecommitdiff
path: root/opendc-faas/opendc-faas-simulator/src
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-faas/opendc-faas-simulator/src')
-rw-r--r--opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/SimFunctionDeployer.kt16
-rw-r--r--opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimMetaFaaSWorkloadMapper.kt34
-rw-r--r--opendc-faas/opendc-faas-simulator/src/test/kotlin/org/opendc/faas/simulator/SimFaaSServiceTest.kt5
3 files changed, 49 insertions, 6 deletions
diff --git a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/SimFunctionDeployer.kt b/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/SimFunctionDeployer.kt
index a3d0d34e..22131b13 100644
--- a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/SimFunctionDeployer.kt
+++ b/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/SimFunctionDeployer.kt
@@ -31,6 +31,7 @@ import org.opendc.faas.service.deployer.FunctionInstanceListener
import org.opendc.faas.service.deployer.FunctionInstanceState
import org.opendc.faas.simulator.delay.DelayInjector
import org.opendc.faas.simulator.workload.SimFaaSWorkloadMapper
+import org.opendc.faas.simulator.workload.SimMetaFaaSWorkloadMapper
import org.opendc.simulator.compute.SimBareMetalMachine
import org.opendc.simulator.compute.SimMachine
import org.opendc.simulator.compute.model.MachineModel
@@ -41,6 +42,7 @@ import org.opendc.simulator.flow.FlowEngine
import java.time.Clock
import java.util.ArrayDeque
import kotlin.coroutines.Continuation
+import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
@@ -48,12 +50,16 @@ import kotlin.coroutines.resumeWithException
* A [FunctionDeployer] that uses that simulates the [FunctionInstance]s.
*/
public class SimFunctionDeployer(
+ context: CoroutineContext,
private val clock: Clock,
- private val scope: CoroutineScope,
private val model: MachineModel,
private val delayInjector: DelayInjector,
- private val mapper: SimFaaSWorkloadMapper
-) : FunctionDeployer {
+ private val mapper: SimFaaSWorkloadMapper = SimMetaFaaSWorkloadMapper()
+) : FunctionDeployer, AutoCloseable {
+ /**
+ * The [CoroutineScope] of this deployer.
+ */
+ private val scope = CoroutineScope(context + Job())
override fun deploy(function: FunctionObject, listener: FunctionInstanceListener): Instance {
val instance = Instance(function, listener)
@@ -172,6 +178,10 @@ public class SimFunctionDeployer(
}
}
+ override fun close() {
+ scope.cancel()
+ }
+
/**
* A function invocation request.
*/
diff --git a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimMetaFaaSWorkloadMapper.kt b/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimMetaFaaSWorkloadMapper.kt
new file mode 100644
index 00000000..8da8bd19
--- /dev/null
+++ b/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimMetaFaaSWorkloadMapper.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.faas.simulator.workload
+
+import org.opendc.faas.service.FunctionObject
+
+/**
+ * A [SimFaaSWorkloadMapper] that maps a [FunctionObject] to a workload via the meta-data.
+ */
+public class SimMetaFaaSWorkloadMapper(private val key: String = "workload") : SimFaaSWorkloadMapper {
+ override fun createWorkload(function: FunctionObject): SimFaaSWorkload {
+ return requireNotNull(function.meta[key]) as SimFaaSWorkload
+ }
+}
diff --git a/opendc-faas/opendc-faas-simulator/src/test/kotlin/org/opendc/faas/simulator/SimFaaSServiceTest.kt b/opendc-faas/opendc-faas-simulator/src/test/kotlin/org/opendc/faas/simulator/SimFaaSServiceTest.kt
index d528558c..5b730089 100644
--- a/opendc-faas/opendc-faas-simulator/src/test/kotlin/org/opendc/faas/simulator/SimFaaSServiceTest.kt
+++ b/opendc-faas/opendc-faas-simulator/src/test/kotlin/org/opendc/faas/simulator/SimFaaSServiceTest.kt
@@ -24,7 +24,6 @@ package org.opendc.faas.simulator
import io.mockk.coVerify
import io.mockk.spyk
-import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.yield
import org.junit.jupiter.api.Assertions.assertEquals
@@ -50,7 +49,6 @@ import java.util.*
/**
* A test suite for the [FaaSService] implementation under simulated conditions.
*/
-@OptIn(ExperimentalCoroutinesApi::class)
internal class SimFaaSServiceTest {
private lateinit var machineModel: MachineModel
@@ -75,7 +73,7 @@ internal class SimFaaSServiceTest {
})
val delayInjector = StochasticDelayInjector(ColdStartModel.GOOGLE, random)
- val deployer = SimFunctionDeployer(clock, this, machineModel, delayInjector) { workload }
+ val deployer = SimFunctionDeployer(coroutineContext, clock, machineModel, delayInjector) { workload }
val service = FaaSService(
coroutineContext,
clock,
@@ -91,6 +89,7 @@ internal class SimFaaSServiceTest {
delay(2000)
service.close()
+ deployer.close()
yield()