summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-simulator/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-compute/opendc-compute-simulator/src/main')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/ServiceRegistry.kt25
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltTaskExportColumns.kt14
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/task/TaskTableReader.kt2
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/task/TaskTableReaderImpl.kt18
4 files changed, 45 insertions, 14 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/ServiceRegistry.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/ServiceRegistry.kt
index e2f6c9d0..36e413d9 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/ServiceRegistry.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/ServiceRegistry.kt
@@ -32,8 +32,29 @@ public class ServiceRegistry(private val registry: MutableMap<String, MutableMap
): T? {
val servicesForName = registry[name] ?: return null
- @Suppress("UNCHECKED_CAST")
- return servicesForName[type] as T?
+ val service = servicesForName[type]
+
+ if (service == null) {
+ throw IllegalStateException("Service $type not registered for name $name")
+ }
+
+ try {
+ @Suppress("UNCHECKED_CAST")
+ return service as T?
+ } catch (e: ClassCastException) {
+ throw IllegalStateException("Service $type registered for name $name is not of the given type")
+ }
+ }
+
+ public fun <T : Any> hasService(
+ name: String,
+ type: Class<T>,
+ ): Boolean {
+ val servicesForName = registry[name] ?: return false
+
+ servicesForName[type] ?: return false
+
+ return true
}
public fun <T : Any> register(
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltTaskExportColumns.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltTaskExportColumns.kt
index 5c3ef3bf..f862a843 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltTaskExportColumns.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltTaskExportColumns.kt
@@ -80,7 +80,12 @@ public object DfltTaskExportColumns {
Types.required(BINARY)
.`as`(LogicalTypeAnnotation.stringType())
.named("host_name"),
- ) { Binary.fromString(it.host?.name) }
+ ) {
+ if (it.hostInfo == null) {
+ return@ExportColumn Binary.fromString("")
+ }
+ return@ExportColumn Binary.fromString(it.hostInfo!!.name)
+ }
public val MEM_CAPACITY: ExportColumn<TaskTableReader> =
ExportColumn(
@@ -168,7 +173,12 @@ public object DfltTaskExportColumns {
Types.optional(BINARY)
.`as`(LogicalTypeAnnotation.stringType())
.named("task_state"),
- ) { Binary.fromString(it.taskState?.name) }
+ ) {
+ if (it.taskState == null) {
+ return@ExportColumn Binary.fromString("")
+ }
+ return@ExportColumn Binary.fromString(it.taskState!!.name)
+ }
/**
* The columns that are always included in the output file.
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/task/TaskTableReader.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/task/TaskTableReader.kt
index 771ced37..8861eabb 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/task/TaskTableReader.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/task/TaskTableReader.kt
@@ -58,7 +58,7 @@ public interface TaskTableReader : Exportable {
/**
* The [HostInfo] of the host on which the task is hosted or `null` if it has no host.
*/
- public val host: HostInfo?
+ public val hostInfo: HostInfo?
/**
* The uptime of the host since last time in ms.
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/task/TaskTableReaderImpl.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/task/TaskTableReaderImpl.kt
index 881b9916..f6a52759 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/task/TaskTableReaderImpl.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/task/TaskTableReaderImpl.kt
@@ -50,7 +50,7 @@ public class TaskTableReaderImpl(
}
override fun setValues(table: TaskTableReader) {
- host = table.host
+ hostInfo = table.hostInfo
_timestamp = table.timestamp
_timestampAbsolute = table.timestampAbsolute
@@ -90,8 +90,8 @@ public class TaskTableReaderImpl(
/**
* The [HostInfo] of the host on which the task is hosted.
*/
- override var host: HostInfo? = null
- private var _host: SimHost? = null
+ override var hostInfo: HostInfo? = null
+ private var simHost: SimHost? = null
private var _timestamp = Instant.MIN
override val timestamp: Instant
@@ -172,9 +172,9 @@ public class TaskTableReaderImpl(
*/
override fun record(now: Instant) {
val newHost = service.lookupHost(task)
- if (newHost != null && newHost.getName() != _host?.getName()) {
- _host = newHost
- host =
+ if (newHost != null && newHost.getName() != simHost?.getName()) {
+ simHost = newHost
+ hostInfo =
HostInfo(
newHost.getName(),
newHost.getClusterName(),
@@ -185,8 +185,8 @@ public class TaskTableReaderImpl(
)
}
- val cpuStats = _host?.getCpuStats(task)
- val sysStats = _host?.getSystemStats(task)
+ val cpuStats = simHost?.getCpuStats(task)
+ val sysStats = simHost?.getSystemStats(task)
_timestamp = now
_timestampAbsolute = now + startTime
@@ -221,7 +221,7 @@ public class TaskTableReaderImpl(
previousCpuStealTime = _cpuStealTime
previousCpuLostTime = _cpuLostTime
- _host = null
+ simHost = null
_cpuLimit = 0.0
}
}