summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-topology
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-compute/opendc-compute-topology')
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt16
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/BatterySpec.kt33
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/ClusterSpec.kt1
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt27
4 files changed, 76 insertions, 1 deletions
diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt
index f271c028..721119cd 100644
--- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt
+++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt
@@ -24,6 +24,7 @@
package org.opendc.compute.topology
+import org.opendc.compute.topology.specs.BatterySpec
import org.opendc.compute.topology.specs.ClusterJSONSpec
import org.opendc.compute.topology.specs.ClusterSpec
import org.opendc.compute.topology.specs.HostJSONSpec
@@ -109,8 +110,21 @@ private fun ClusterJSONSpec.toClusterSpec(random: RandomGenerator): ClusterSpec
totalPower = this.powerSource.totalPower,
carbonTracePath = this.powerSource.carbonTracePath,
)
+
+ var batterySpec: BatterySpec? = null
+ if (this.battery != null) {
+ batterySpec =
+ BatterySpec(
+ UUID(random.nextLong(), clusterId.toLong()),
+ this.battery.capacity,
+ this.battery.chargingSpeed,
+ this.battery.batteryPolicy,
+ this.battery.initialCharge,
+ )
+ }
+
clusterId++
- return ClusterSpec(this.name, hostSpecs, powerSourceSpec)
+ return ClusterSpec(this.name, hostSpecs, powerSourceSpec, batterySpec)
}
/**
diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/BatterySpec.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/BatterySpec.kt
new file mode 100644
index 00000000..fd849b01
--- /dev/null
+++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/BatterySpec.kt
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2025 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.compute.topology.specs
+
+import java.util.UUID
+
+public data class BatterySpec(
+ val uid: UUID,
+ val capacity: Double,
+ val chargingSpeed: Double,
+ val batteryPolicy: BatteryPolicyJSONSpec,
+ val initialCharge: Double,
+)
diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/ClusterSpec.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/ClusterSpec.kt
index 3b49b266..6e7c8dfa 100644
--- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/ClusterSpec.kt
+++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/ClusterSpec.kt
@@ -26,4 +26,5 @@ public data class ClusterSpec(
val name: String,
val hostSpecs: List<HostSpec>,
val powerSource: PowerSourceSpec,
+ val battery: BatterySpec? = null,
)
diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt
index 39b95347..3ccb4e59 100644
--- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt
+++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt
@@ -51,6 +51,7 @@ public data class ClusterJSONSpec(
val count: Int = 1,
val hosts: List<HostJSONSpec>,
val powerSource: PowerSourceJSONSpec = PowerSourceJSONSpec.DFLT,
+ val battery: BatteryJSONSpec? = null,
val location: String = "NL",
)
@@ -155,3 +156,29 @@ public data class PowerSourceJSONSpec(
)
}
}
+
+/**
+ * Definition of a power source used for JSON input.
+ *
+ * @property vendor
+ * @property modelName
+ * @property arch
+ * @property totalPower
+ */
+@Serializable
+public data class BatteryJSONSpec(
+ var capacity: Double,
+ val chargingSpeed: Double,
+ val batteryPolicy: BatteryPolicyJSONSpec,
+ var initialCharge: Double = 0.0,
+) {
+ init {
+ this.capacity *= 3600000
+ this.initialCharge *= 3600000
+ }
+}
+
+@Serializable
+public data class BatteryPolicyJSONSpec(
+ val carbonThreshold: Double,
+)