summaryrefslogtreecommitdiff
path: root/opendc/opendc-compute
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2020-02-14 10:54:53 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-02-14 10:54:53 +0100
commit5095d42c0a1fe0a593c84bccfdd594712e12ca1a (patch)
tree591ef25417033d87e88147f4826f94d054058ac6 /opendc/opendc-compute
parent3fc32c0b6f02d245a544aaaa061094231830f661 (diff)
feat: Implement basic provisioner service
Diffstat (limited to 'opendc/opendc-compute')
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/Server.kt2
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/FakeBareMetalDriver.kt2
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/Allocation.kt37
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/ProvisioningService.kt6
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningService.kt73
-rw-r--r--opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningServiceTest.kt76
6 files changed, 154 insertions, 42 deletions
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/Server.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/Server.kt
index 0dc1562c..dad24ebe 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/Server.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/Server.kt
@@ -60,5 +60,5 @@ public data class Server(
) : Identity {
override fun hashCode(): Int = uid.hashCode()
- override fun equals(other: Any?): Boolean = other is Node && uid == other.uid
+ override fun equals(other: Any?): Boolean = other is Server && uid == other.uid
}
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/FakeBareMetalDriver.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/FakeBareMetalDriver.kt
index 9d984017..1b3782f6 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/FakeBareMetalDriver.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/FakeBareMetalDriver.kt
@@ -96,7 +96,7 @@ public class FakeBareMetalDriver(
* Launch the server image on the machine.
*/
private suspend fun launch() {
- val serverCtx = this.serverCtx.serialize()
+ val serverCtx = this.serverCtx
processContext.spawn {
serverCtx.init()
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/Allocation.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/Allocation.kt
deleted file mode 100644
index 3f9ca71b..00000000
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/Allocation.kt
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2020 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 com.atlarge.opendc.compute.metal.service
-
-import com.atlarge.opendc.compute.metal.Node
-
-/**
- * Represents an allocation of bare-metal compute nodes.
- */
-public interface Allocation {
- /**
- * The compute nodes that have been allocated.
- */
- public val nodes: List<Node>
-}
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/ProvisioningService.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/ProvisioningService.kt
index df96f47f..ba2ebc80 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/ProvisioningService.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/ProvisioningService.kt
@@ -39,9 +39,9 @@ public interface ProvisioningService {
public suspend fun create(driver: BareMetalDriver): Node
/**
- * Allocate the given number of nodes from the provisioner.
+ * Obtain the available nodes.
*/
- public suspend fun allocate(num: Int): Allocation
+ public suspend fun nodes(): Set<Node>
/**
* Refresh the state of a compute node.
@@ -51,5 +51,5 @@ public interface ProvisioningService {
/**
* Deploy the specified [Image] on a compute node.
*/
- public suspend fun deploy(node: Node, allocation: Allocation, image: Image, monitor: ServerMonitor): Node
+ public suspend fun deploy(node: Node, image: Image, monitor: ServerMonitor): Node
}
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningService.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningService.kt
new file mode 100644
index 00000000..dc860405
--- /dev/null
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningService.kt
@@ -0,0 +1,73 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2020 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 com.atlarge.opendc.compute.metal.service
+
+import com.atlarge.opendc.compute.core.Server
+import com.atlarge.opendc.compute.core.ServerState
+import com.atlarge.opendc.compute.core.image.Image
+import com.atlarge.opendc.compute.core.monitor.ServerMonitor
+import com.atlarge.opendc.compute.metal.Node
+import com.atlarge.opendc.compute.metal.PowerState
+import com.atlarge.opendc.compute.metal.driver.BareMetalDriver
+
+/**
+ * A very basic implementation of the [ProvisioningService].
+ */
+public class SimpleProvisioningService : ProvisioningService, ServerMonitor {
+ /**
+ * The active nodes in this service.
+ */
+ private val nodes: MutableMap<Node, BareMetalDriver> = mutableMapOf()
+
+ /**
+ * The installed monitors.
+ */
+ private val monitors: MutableMap<Server, ServerMonitor> = mutableMapOf()
+
+ override suspend fun create(driver: BareMetalDriver): Node {
+ val node = driver.init(this)
+ nodes[node] = driver
+ return node
+ }
+
+ override suspend fun nodes(): Set<Node> = nodes.keys
+
+ override suspend fun refresh(node: Node): Node {
+ return nodes[node]!!.refresh()
+ }
+
+ override suspend fun deploy(node: Node, image: Image, monitor: ServerMonitor): Node {
+ val driver = nodes[node]!!
+
+ driver.setImage(image)
+ val newNode = driver.setPower(PowerState.POWER_ON)
+ monitors[newNode.server!!] = monitor
+ return newNode
+ }
+
+ override suspend fun onUpdate(server: Server, previousState: ServerState) {
+ monitors[server]?.onUpdate(server, previousState)
+ }
+}
diff --git a/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningServiceTest.kt b/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningServiceTest.kt
new file mode 100644
index 00000000..0bbd4b75
--- /dev/null
+++ b/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/metal/service/SimpleProvisioningServiceTest.kt
@@ -0,0 +1,76 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2020 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 com.atlarge.opendc.compute.metal.service
+
+import com.atlarge.odcsim.SimulationEngineProvider
+import com.atlarge.opendc.compute.core.Flavor
+import com.atlarge.opendc.compute.core.ProcessingUnit
+import com.atlarge.opendc.compute.core.Server
+import com.atlarge.opendc.compute.core.ServerState
+import com.atlarge.opendc.compute.core.image.FlopsApplicationImage
+import com.atlarge.opendc.compute.core.monitor.ServerMonitor
+import com.atlarge.opendc.compute.metal.PowerState
+import com.atlarge.opendc.compute.metal.driver.FakeBareMetalDriver
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.runBlocking
+import org.junit.jupiter.api.Test
+import java.util.ServiceLoader
+import java.util.UUID
+
+
+/**
+ * Test suite for the [SimpleProvisioningService].
+ */
+internal class SimpleProvisioningServiceTest {
+ /**
+ * A basic smoke test.
+ */
+ @Test
+ fun smoke() {
+ val provider = ServiceLoader.load(SimulationEngineProvider::class.java).first()
+ val system = provider({ ctx ->
+ val flavor = Flavor(listOf(ProcessingUnit("Intel", "Xeon", "amd64", 2300.0, 4)))
+ val image = FlopsApplicationImage(1000, 2)
+ val monitor = object : ServerMonitor {
+ override suspend fun onUpdate(server: Server, previousState: ServerState) {
+ println(server)
+ }
+ }
+ val driver = FakeBareMetalDriver(UUID.randomUUID(), "test", flavor)
+
+
+ val provisioner = SimpleProvisioningService()
+ provisioner.create(driver)
+ delay(5)
+ val nodes = provisioner.nodes()
+ provisioner.deploy(nodes.first(), image, monitor)
+ }, name = "sim")
+
+ runBlocking {
+ system.run()
+ system.terminate()
+ }
+ }
+}