summaryrefslogtreecommitdiff
path: root/opendc-compute
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-02-18 14:59:54 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-02-18 15:32:49 +0100
commitc82b1725cc606769084155d6c4fba982cd320c41 (patch)
tree510659fc8c85fc4a7196d1a769ed2dbcfd4ed787 /opendc-compute
parent77aaf078650c054ccbaf5f46a71ab218390a571e (diff)
fix(compute): Disallow duplicate UIDs for SimHost
This change fixes an issue with the ComputeServiceHelper where it allowed users to register multiple SimHost objects with the same UID. See this issue for more information: https://github.com/atlarge-research/opendc/issues/51
Diffstat (limited to 'opendc-compute')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt6
-rw-r--r--opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt2
2 files changed, 7 insertions, 1 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt
index 95921e8b..43f33f27 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt
@@ -249,6 +249,12 @@ public class SimHost(
machine.cancel()
}
+ override fun hashCode(): Int = uid.hashCode()
+
+ override fun equals(other: Any?): Boolean {
+ return other is SimHost && uid == other.uid
+ }
+
override fun toString(): String = "SimHost[uid=$uid,name=$name,model=$model]"
public suspend fun fail() {
diff --git a/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt b/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt
index a1a65da3..4b0b343f 100644
--- a/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt
+++ b/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt
@@ -169,7 +169,7 @@ public class ComputeServiceHelper(
optimize = optimize
)
- _hosts.add(host)
+ require(_hosts.add(host)) { "Host with uid ${spec.uid} already exists" }
service.addHost(host)
return host