summaryrefslogtreecommitdiff
path: root/simulator/opendc-metal
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-03-07 15:58:06 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-03-07 16:19:16 +0100
commit75751865179c6cd5a05abb4a0641193595f59b45 (patch)
tree7c3464a424891ab7c3cb9c0ac77d67256b144f97 /simulator/opendc-metal
parent9bb91897404bbeac1d5f7a7f890abd3a9d5d9084 (diff)
compute: Move bare-metal provisioning in separate module
This change moves the bare-metal provisioning packages outside the compute module since these modules represent different layers in the ecosystem and should not be mixed.
Diffstat (limited to 'simulator/opendc-metal')
-rw-r--r--simulator/opendc-metal/build.gradle.kts38
-rw-r--r--simulator/opendc-metal/src/main/kotlin/org/opendc/metal/Metadata.kt34
-rw-r--r--simulator/opendc-metal/src/main/kotlin/org/opendc/metal/Node.kt72
-rw-r--r--simulator/opendc-metal/src/main/kotlin/org/opendc/metal/NodeEvent.kt41
-rw-r--r--simulator/opendc-metal/src/main/kotlin/org/opendc/metal/NodeState.kt55
-rw-r--r--simulator/opendc-metal/src/main/kotlin/org/opendc/metal/driver/BareMetalDriver.kt84
-rw-r--r--simulator/opendc-metal/src/main/kotlin/org/opendc/metal/service/ProvisioningService.kt64
-rw-r--r--simulator/opendc-metal/src/main/kotlin/org/opendc/metal/service/SimpleProvisioningService.kt65
8 files changed, 453 insertions, 0 deletions
diff --git a/simulator/opendc-metal/build.gradle.kts b/simulator/opendc-metal/build.gradle.kts
new file mode 100644
index 00000000..9207de18
--- /dev/null
+++ b/simulator/opendc-metal/build.gradle.kts
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+description = "Bare-metal provisioning in OpenDC"
+
+/* Build configuration */
+plugins {
+ `kotlin-library-conventions`
+}
+
+dependencies {
+ api(platform(project(":opendc-platform")))
+ api(project(":opendc-core"))
+ api(project(":opendc-compute:opendc-compute-api"))
+ api(project(":opendc-trace:opendc-trace-core"))
+ implementation(project(":opendc-utils"))
+
+ implementation("io.github.microutils:kotlin-logging")
+}
diff --git a/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/Metadata.kt b/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/Metadata.kt
new file mode 100644
index 00000000..ca98dab0
--- /dev/null
+++ b/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/Metadata.kt
@@ -0,0 +1,34 @@
+/*
+ * 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 org.opendc.metal
+
+/*
+ * Common metadata keys for bare-metal nodes.
+ */
+
+/**
+ * The cluster to which the node belongs.
+ */
+public const val NODE_CLUSTER: String = "bare-metal:cluster"
diff --git a/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/Node.kt b/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/Node.kt
new file mode 100644
index 00000000..1c5c7a8d
--- /dev/null
+++ b/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/Node.kt
@@ -0,0 +1,72 @@
+/*
+ * 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.metal
+
+import kotlinx.coroutines.flow.Flow
+import org.opendc.compute.api.Flavor
+import org.opendc.compute.api.Image
+import org.opendc.core.Identity
+import java.util.UUID
+
+/**
+ * A bare-metal compute node.
+ */
+public data class Node(
+ /**
+ * The unique identifier of the node.
+ */
+ public override val uid: UUID,
+
+ /**
+ * The optional name of the node.
+ */
+ public override val name: String,
+
+ /**
+ * Metadata of the node.
+ */
+ public val metadata: Map<String, Any>,
+
+ /**
+ * The last known state of the compute node.
+ */
+ public val state: NodeState,
+
+ /**
+ * The flavor of the node.
+ */
+ public val flavor: Flavor,
+
+ /**
+ * The boot image of the node.
+ */
+ public val image: Image,
+
+ /**
+ * The events that are emitted by the node.
+ */
+ public val events: Flow<NodeEvent>
+) : Identity {
+ override fun hashCode(): Int = uid.hashCode()
+ override fun equals(other: Any?): Boolean = other is Node && uid == other.uid
+}
diff --git a/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/NodeEvent.kt b/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/NodeEvent.kt
new file mode 100644
index 00000000..30ce423c
--- /dev/null
+++ b/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/NodeEvent.kt
@@ -0,0 +1,41 @@
+/*
+ * 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.metal
+
+/**
+ * An event that is emitted by a [Node].
+ */
+public sealed class NodeEvent {
+ /**
+ * The node that emitted the event.
+ */
+ public abstract val node: Node
+
+ /**
+ * This event is emitted when the state of [node] changes.
+ *
+ * @property node The node of which the state changed.
+ * @property previousState The previous state of the node.
+ */
+ public data class StateChanged(override val node: Node, val previousState: NodeState) : NodeEvent()
+}
diff --git a/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/NodeState.kt b/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/NodeState.kt
new file mode 100644
index 00000000..f1d4ea2e
--- /dev/null
+++ b/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/NodeState.kt
@@ -0,0 +1,55 @@
+/*
+ * 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 org.opendc.metal
+
+/**
+ * An enumeration describing the possible states of a bare-metal compute node.
+ */
+public enum class NodeState {
+ /**
+ * The node is booting.
+ */
+ BOOT,
+
+ /**
+ * The node is powered off.
+ */
+ SHUTOFF,
+
+ /**
+ * The node is active and running.
+ */
+ ACTIVE,
+
+ /**
+ * The node is in error.
+ */
+ ERROR,
+
+ /**
+ * The state of the node is unknown.
+ */
+ UNKNOWN,
+}
diff --git a/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/driver/BareMetalDriver.kt b/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/driver/BareMetalDriver.kt
new file mode 100644
index 00000000..3b15be94
--- /dev/null
+++ b/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/driver/BareMetalDriver.kt
@@ -0,0 +1,84 @@
+/*
+ * 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.metal.driver
+
+import kotlinx.coroutines.flow.Flow
+import org.opendc.compute.api.Image
+import org.opendc.compute.api.Server
+import org.opendc.core.services.AbstractServiceKey
+import org.opendc.metal.Node
+import java.util.UUID
+
+/**
+ * A driver interface for the management interface of a bare-metal compute node.
+ */
+public interface BareMetalDriver {
+ /**
+ * The [Node] that is controlled by this driver.
+ */
+ public val node: Flow<Node>
+
+ /**
+ * The amount of work done by the machine in percentage with respect to the total amount of processing power
+ * available.
+ */
+ public val usage: Flow<Double>
+
+ /**
+ * Initialize the driver.
+ */
+ public suspend fun init(): Node
+
+ /**
+ * Start the bare metal node with the specified boot disk image.
+ */
+ public suspend fun start(): Node
+
+ /**
+ * Stop the bare metal node if it is running.
+ */
+ public suspend fun stop(): Node
+
+ /**
+ * Reboot the bare metal node.
+ */
+ public suspend fun reboot(): Node
+
+ /**
+ * Update the boot disk image of the compute node.
+ *
+ * Changing the boot disk image of node does not affect it while the node is running. In order to start the new boot
+ * disk image, the compute node must be restarted.
+ */
+ public suspend fun setImage(image: Image): Node
+
+ /**
+ * Obtain the state of the compute node.
+ */
+ public suspend fun refresh(): Node
+
+ /**
+ * A key that allows access to the [BareMetalDriver] instance from a [Server] that runs on the bare-metal machine.
+ */
+ public companion object Key : AbstractServiceKey<BareMetalDriver>(UUID.randomUUID(), "bare-metal:driver")
+}
diff --git a/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/service/ProvisioningService.kt b/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/service/ProvisioningService.kt
new file mode 100644
index 00000000..6548767e
--- /dev/null
+++ b/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/service/ProvisioningService.kt
@@ -0,0 +1,64 @@
+/*
+ * 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.metal.service
+
+import org.opendc.compute.api.Image
+import org.opendc.core.services.AbstractServiceKey
+import org.opendc.metal.Node
+import org.opendc.metal.driver.BareMetalDriver
+import java.util.UUID
+
+/**
+ * A cloud platform service for provisioning bare-metal compute nodes on the platform.
+ */
+public interface ProvisioningService {
+ /**
+ * Create a new bare-metal compute node.
+ */
+ public suspend fun create(driver: BareMetalDriver): Node
+
+ /**
+ * Obtain the available nodes.
+ */
+ public suspend fun nodes(): Set<Node>
+
+ /**
+ * Refresh the state of a compute node.
+ */
+ public suspend fun refresh(node: Node): Node
+
+ /**
+ * Deploy the specified [Image] on a compute node.
+ */
+ public suspend fun deploy(node: Node, image: Image): Node
+
+ /**
+ * Stop the specified [Node] .
+ */
+ public suspend fun stop(node: Node): Node
+
+ /**
+ * The service key of this service.
+ */
+ public companion object Key : AbstractServiceKey<ProvisioningService>(UUID.randomUUID(), "provisioner")
+}
diff --git a/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/service/SimpleProvisioningService.kt b/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/service/SimpleProvisioningService.kt
new file mode 100644
index 00000000..2d6353c8
--- /dev/null
+++ b/simulator/opendc-metal/src/main/kotlin/org/opendc/metal/service/SimpleProvisioningService.kt
@@ -0,0 +1,65 @@
+/*
+ * 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.metal.service
+
+import kotlinx.coroutines.CancellationException
+import org.opendc.compute.api.Image
+import org.opendc.metal.Node
+import org.opendc.metal.driver.BareMetalDriver
+
+/**
+ * A very basic implementation of the [ProvisioningService].
+ */
+public class SimpleProvisioningService : ProvisioningService {
+ /**
+ * The active nodes in this service.
+ */
+ private val nodes: MutableMap<Node, BareMetalDriver> = mutableMapOf()
+
+ override suspend fun create(driver: BareMetalDriver): Node {
+ val node = driver.init()
+ 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): Node {
+ val driver = nodes[node]!!
+ driver.setImage(image)
+ return driver.reboot()
+ }
+
+ override suspend fun stop(node: Node): Node {
+ val driver = nodes[node]!!
+ return try {
+ driver.stop()
+ } catch (e: CancellationException) {
+ node
+ }
+ }
+}