summaryrefslogtreecommitdiff
path: root/simulator/opendc-format/src
diff options
context:
space:
mode:
Diffstat (limited to 'simulator/opendc-format/src')
-rw-r--r--simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/EnvironmentReader.kt6
-rw-r--r--simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/MachineDef.kt35
-rw-r--r--simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc18/Sc18EnvironmentReader.kt45
-rw-r--r--simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc20/Sc20ClusterEnvironmentReader.kt39
-rw-r--r--simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc20/Sc20EnvironmentReader.kt42
5 files changed, 64 insertions, 103 deletions
diff --git a/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/EnvironmentReader.kt b/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/EnvironmentReader.kt
index 1f73bb61..81fe04a1 100644
--- a/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/EnvironmentReader.kt
+++ b/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/EnvironmentReader.kt
@@ -22,17 +22,15 @@
package org.opendc.format.environment
-import kotlinx.coroutines.CoroutineScope
import org.opendc.core.Environment
import java.io.Closeable
-import java.time.Clock
/**
* An interface for reading descriptions of topology environments into memory as [Environment].
*/
public interface EnvironmentReader : Closeable {
/**
- * Construct an [Environment] in the specified [CoroutineScope].
+ * Read the environment into a list.
*/
- public suspend fun construct(coroutineScope: CoroutineScope, clock: Clock): Environment
+ public fun read(): List<MachineDef>
}
diff --git a/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/MachineDef.kt b/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/MachineDef.kt
new file mode 100644
index 00000000..b5b3b84b
--- /dev/null
+++ b/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/MachineDef.kt
@@ -0,0 +1,35 @@
+/*
+ * 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.format.environment
+
+import org.opendc.compute.simulator.power.api.CpuPowerModel
+import org.opendc.simulator.compute.SimMachineModel
+import java.util.*
+
+public data class MachineDef(
+ val uid: UUID,
+ val name: String,
+ val meta: Map<String, Any>,
+ val model: SimMachineModel,
+ val powerModel: CpuPowerModel
+)
diff --git a/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc18/Sc18EnvironmentReader.kt b/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc18/Sc18EnvironmentReader.kt
index bbbbe87c..3da8d0b3 100644
--- a/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc18/Sc18EnvironmentReader.kt
+++ b/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc18/Sc18EnvironmentReader.kt
@@ -25,21 +25,14 @@ package org.opendc.format.environment.sc18
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
-import kotlinx.coroutines.CoroutineScope
-import org.opendc.compute.simulator.SimBareMetalDriver
-import org.opendc.core.Environment
-import org.opendc.core.Platform
-import org.opendc.core.Zone
-import org.opendc.core.services.ServiceRegistry
+import org.opendc.compute.simulator.power.models.ConstantPowerModel
import org.opendc.format.environment.EnvironmentReader
-import org.opendc.metal.service.ProvisioningService
-import org.opendc.metal.service.SimpleProvisioningService
+import org.opendc.format.environment.MachineDef
import org.opendc.simulator.compute.SimMachineModel
import org.opendc.simulator.compute.model.MemoryUnit
import org.opendc.simulator.compute.model.ProcessingNode
import org.opendc.simulator.compute.model.ProcessingUnit
import java.io.InputStream
-import java.time.Clock
import java.util.*
/**
@@ -55,9 +48,12 @@ public class Sc18EnvironmentReader(input: InputStream, mapper: ObjectMapper = ja
*/
private val setup: Setup = mapper.readValue(input)
- override suspend fun construct(coroutineScope: CoroutineScope, clock: Clock): Environment {
+ /**
+ * Read the environment.
+ */
+ public override fun read(): List<MachineDef> {
var counter = 0
- val nodes = setup.rooms.flatMap { room ->
+ return setup.rooms.flatMap { room ->
room.objects.flatMap { roomObject ->
when (roomObject) {
is RoomObject.Rack -> {
@@ -75,35 +71,18 @@ public class Sc18EnvironmentReader(input: InputStream, mapper: ObjectMapper = ja
else -> throw IllegalArgumentException("The cpu id $id is not recognized")
}
}
- SimBareMetalDriver(
- coroutineScope,
- clock,
- UUID.randomUUID(),
- "node-${counter++}",
+ MachineDef(
+ UUID(0L, counter++.toLong()),
+ "node-$counter",
emptyMap(),
- SimMachineModel(cores, listOf(MemoryUnit("", "", 2300.0, 16000)))
+ SimMachineModel(cores, listOf(MemoryUnit("", "", 2300.0, 16000))),
+ ConstantPowerModel(0.0)
)
}
}
}
}
}
-
- val provisioningService = SimpleProvisioningService()
- for (node in nodes) {
- provisioningService.create(node)
- }
-
- val serviceRegistry = ServiceRegistry().put(ProvisioningService, provisioningService)
- val platform = Platform(
- UUID.randomUUID(),
- "sc18-platform",
- listOf(
- Zone(UUID.randomUUID(), "zone", serviceRegistry)
- )
- )
-
- return Environment(setup.name, null, listOf(platform))
}
override fun close() {}
diff --git a/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc20/Sc20ClusterEnvironmentReader.kt b/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc20/Sc20ClusterEnvironmentReader.kt
index 998f9cd6..9a06a40f 100644
--- a/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc20/Sc20ClusterEnvironmentReader.kt
+++ b/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc20/Sc20ClusterEnvironmentReader.kt
@@ -22,17 +22,9 @@
package org.opendc.format.environment.sc20
-import kotlinx.coroutines.CoroutineScope
-import org.opendc.compute.simulator.SimBareMetalDriver
import org.opendc.compute.simulator.power.models.LinearPowerModel
-import org.opendc.core.Environment
-import org.opendc.core.Platform
-import org.opendc.core.Zone
-import org.opendc.core.services.ServiceRegistry
import org.opendc.format.environment.EnvironmentReader
-import org.opendc.metal.NODE_CLUSTER
-import org.opendc.metal.service.ProvisioningService
-import org.opendc.metal.service.SimpleProvisioningService
+import org.opendc.format.environment.MachineDef
import org.opendc.simulator.compute.SimMachineModel
import org.opendc.simulator.compute.model.MemoryUnit
import org.opendc.simulator.compute.model.ProcessingNode
@@ -40,7 +32,6 @@ import org.opendc.simulator.compute.model.ProcessingUnit
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
-import java.time.Clock
import java.util.*
/**
@@ -54,8 +45,7 @@ public class Sc20ClusterEnvironmentReader(
public constructor(file: File) : this(FileInputStream(file))
- @Suppress("BlockingMethodInNonBlockingContext")
- override suspend fun construct(coroutineScope: CoroutineScope, clock: Clock): Environment {
+ public override fun read(): List<MachineDef> {
var clusterIdCol = 0
var speedCol = 0
var numberOfHostsCol = 0
@@ -69,7 +59,7 @@ public class Sc20ClusterEnvironmentReader(
var memoryPerHost: Long
var coresPerHost: Int
- val nodes = mutableListOf<SimBareMetalDriver>()
+ val nodes = mutableListOf<MachineDef>()
val random = Random(0)
input.bufferedReader().use { reader ->
@@ -103,12 +93,10 @@ public class Sc20ClusterEnvironmentReader(
repeat(numberOfHosts) {
nodes.add(
- SimBareMetalDriver(
- coroutineScope,
- clock,
+ MachineDef(
UUID(random.nextLong(), random.nextLong()),
"node-$clusterId-$it",
- mapOf(NODE_CLUSTER to clusterId),
+ mapOf("cluster" to clusterId),
SimMachineModel(
List(coresPerHost) { coreId ->
ProcessingUnit(unknownProcessingNode, coreId, speed)
@@ -125,22 +113,7 @@ public class Sc20ClusterEnvironmentReader(
}
}
- val provisioningService = SimpleProvisioningService()
- for (node in nodes) {
- provisioningService.create(node)
- }
-
- val serviceRegistry = ServiceRegistry().put(ProvisioningService, provisioningService)
-
- val platform = Platform(
- UUID.randomUUID(),
- "sc20-platform",
- listOf(
- Zone(UUID.randomUUID(), "zone", serviceRegistry)
- )
- )
-
- return Environment("SC20 Environment", null, listOf(platform))
+ return nodes
}
override fun close() {}
diff --git a/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc20/Sc20EnvironmentReader.kt b/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc20/Sc20EnvironmentReader.kt
index 6cf65f7f..effd0286 100644
--- a/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc20/Sc20EnvironmentReader.kt
+++ b/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/sc20/Sc20EnvironmentReader.kt
@@ -25,22 +25,14 @@ package org.opendc.format.environment.sc20
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
-import kotlinx.coroutines.CoroutineScope
-import org.opendc.compute.simulator.SimBareMetalDriver
import org.opendc.compute.simulator.power.models.LinearPowerModel
-import org.opendc.core.Environment
-import org.opendc.core.Platform
-import org.opendc.core.Zone
-import org.opendc.core.services.ServiceRegistry
import org.opendc.format.environment.EnvironmentReader
-import org.opendc.metal.service.ProvisioningService
-import org.opendc.metal.service.SimpleProvisioningService
+import org.opendc.format.environment.MachineDef
import org.opendc.simulator.compute.SimMachineModel
import org.opendc.simulator.compute.model.MemoryUnit
import org.opendc.simulator.compute.model.ProcessingNode
import org.opendc.simulator.compute.model.ProcessingUnit
import java.io.InputStream
-import java.time.Clock
import java.util.*
/**
@@ -55,9 +47,12 @@ public class Sc20EnvironmentReader(input: InputStream, mapper: ObjectMapper = ja
*/
private val setup: Setup = mapper.readValue(input)
- override suspend fun construct(coroutineScope: CoroutineScope, clock: Clock): Environment {
+ /**
+ * Read the environment.
+ */
+ public override fun read(): List<MachineDef> {
var counter = 0
- val nodes = setup.rooms.flatMap { room ->
+ return setup.rooms.flatMap { room ->
room.objects.flatMap { roomObject ->
when (roomObject) {
is RoomObject.Rack -> {
@@ -81,11 +76,9 @@ public class Sc20EnvironmentReader(input: InputStream, mapper: ObjectMapper = ja
else -> throw IllegalArgumentException("The cpu id $id is not recognized")
}
}
- SimBareMetalDriver(
- coroutineScope,
- clock,
- UUID.randomUUID(),
- "node-${counter++}",
+ MachineDef(
+ UUID(0L, counter++.toLong()),
+ "node-$counter",
emptyMap(),
SimMachineModel(cores, memories),
// For now we assume a simple linear load model with an idle draw of ~200W and a maximum
@@ -98,23 +91,6 @@ public class Sc20EnvironmentReader(input: InputStream, mapper: ObjectMapper = ja
}
}
}
-
- val provisioningService = SimpleProvisioningService()
- for (node in nodes) {
- provisioningService.create(node)
- }
-
- val serviceRegistry = ServiceRegistry().put(ProvisioningService, provisioningService)
-
- val platform = Platform(
- UUID.randomUUID(),
- "sc20-platform",
- listOf(
- Zone(UUID.randomUUID(), "zone", serviceRegistry)
- )
- )
-
- return Environment(setup.name, null, listOf(platform))
}
override fun close() {}