From c7e303ad1b5217e2ff24cee9538ac841d6149706 Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Tue, 20 May 2025 11:06:12 +0200 Subject: Fixed bug when not providing a Carbon Model (#339) --- .../opendc/compute/simulator/ServiceRegistry.kt | 25 ++++++++++++++++++++-- .../telemetry/parquet/DfltTaskExportColumns.kt | 14 ++++++++++-- .../telemetry/table/task/TaskTableReader.kt | 2 +- .../telemetry/table/task/TaskTableReaderImpl.kt | 18 ++++++++-------- 4 files changed, 45 insertions(+), 14 deletions(-) (limited to 'opendc-compute') 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 hasService( + name: String, + type: Class, + ): Boolean { + val servicesForName = registry[name] ?: return false + + servicesForName[type] ?: return false + + return true } public fun 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 = 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 } } -- cgit v1.2.3