summaryrefslogtreecommitdiff
path: root/opendc-trace/opendc-trace-wfformat/src/main
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2024-04-16 09:29:53 +0200
committerGitHub <noreply@github.com>2024-04-16 09:29:53 +0200
commitfff89d25bd3c7b874e68261d21695c473c30ed7d (patch)
treebe368dd745e8119dbdefd9cd0b012c7ff9080a7a /opendc-trace/opendc-trace-wfformat/src/main
parenta7b0afbb5b7059274962ade234a50240677008fd (diff)
Revamped the trace system. All TraceFormat files are now in the api m… (#216)
* Revamped the trace system. All TraceFormat files are now in the api module. This fixes some problems with not being able to use types of traces * applied spotless
Diffstat (limited to 'opendc-trace/opendc-trace-wfformat/src/main')
-rw-r--r--opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTaskTableReader.kt314
-rw-r--r--opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormat.kt95
-rw-r--r--opendc-trace/opendc-trace-wfformat/src/main/resources/META-INF/services/org.opendc.trace.spi.TraceFormat1
3 files changed, 0 insertions, 410 deletions
diff --git a/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTaskTableReader.kt b/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTaskTableReader.kt
deleted file mode 100644
index 8f84e51f..00000000
--- a/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTaskTableReader.kt
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- * 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.trace.wfformat
-
-import com.fasterxml.jackson.core.JsonParseException
-import com.fasterxml.jackson.core.JsonParser
-import com.fasterxml.jackson.core.JsonToken
-import org.opendc.trace.TableColumnType
-import org.opendc.trace.TableReader
-import org.opendc.trace.conv.TASK_CHILDREN
-import org.opendc.trace.conv.TASK_ID
-import org.opendc.trace.conv.TASK_PARENTS
-import org.opendc.trace.conv.TASK_REQ_NCPUS
-import org.opendc.trace.conv.TASK_RUNTIME
-import org.opendc.trace.conv.TASK_WORKFLOW_ID
-import org.opendc.trace.util.convertTo
-import java.time.Duration
-import java.time.Instant
-import java.util.UUID
-import kotlin.math.roundToInt
-
-/**
- * A [TableReader] implementation for the WfCommons workload trace format.
- */
-internal class WfFormatTaskTableReader(private val parser: JsonParser) : TableReader {
- /**
- * The current nesting of the parser.
- */
- private var level: ParserLevel = ParserLevel.TOP
-
- override fun nextRow(): Boolean {
- reset()
-
- var hasJob = false
-
- while (!hasJob) {
- when (level) {
- ParserLevel.TOP -> {
- val token = parser.nextToken()
-
- // Check whether the document is not empty and starts with an object
- if (token == null) {
- parser.close()
- break
- } else if (token != JsonToken.START_OBJECT) {
- throw JsonParseException(parser, "Expected object", parser.currentLocation)
- } else {
- level = ParserLevel.TRACE
- }
- }
- ParserLevel.TRACE -> {
- // Seek for the workflow object in the file
- if (!seekWorkflow()) {
- parser.close()
- break
- } else if (!parser.isExpectedStartObjectToken) {
- throw JsonParseException(parser, "Expected object", parser.currentLocation)
- } else {
- level = ParserLevel.WORKFLOW
- }
- }
- ParserLevel.WORKFLOW -> {
- // Seek for the jobs object in the file
- level =
- if (!seekJobs()) {
- ParserLevel.TRACE
- } else if (!parser.isExpectedStartArrayToken) {
- throw JsonParseException(parser, "Expected array", parser.currentLocation)
- } else {
- ParserLevel.JOB
- }
- }
- ParserLevel.JOB -> {
- when (parser.nextToken()) {
- JsonToken.END_ARRAY -> level = ParserLevel.WORKFLOW
- JsonToken.START_OBJECT -> {
- parseJob()
- hasJob = true
- break
- }
- else -> throw JsonParseException(parser, "Unexpected token", parser.currentLocation)
- }
- }
- }
- }
-
- return hasJob
- }
-
- override fun resolve(name: String): Int {
- return when (name) {
- TASK_ID -> colID
- TASK_WORKFLOW_ID -> colWorkflowID
- TASK_RUNTIME -> colRuntime
- TASK_REQ_NCPUS -> colNproc
- TASK_PARENTS -> colParents
- TASK_CHILDREN -> colChildren
- else -> -1
- }
- }
-
- override fun isNull(index: Int): Boolean {
- require(index in 0..colChildren) { "Invalid column value" }
- return false
- }
-
- override fun getBoolean(index: Int): Boolean {
- throw IllegalArgumentException("Invalid column")
- }
-
- override fun getInt(index: Int): Int {
- checkActive()
- return when (index) {
- colNproc -> cores
- else -> throw IllegalArgumentException("Invalid column")
- }
- }
-
- override fun getLong(index: Int): Long {
- throw IllegalArgumentException("Invalid column")
- }
-
- override fun getFloat(index: Int): Float {
- throw IllegalArgumentException("Invalid column")
- }
-
- override fun getDouble(index: Int): Double {
- throw IllegalArgumentException("Invalid column")
- }
-
- override fun getString(index: Int): String? {
- checkActive()
- return when (index) {
- colID -> id
- colWorkflowID -> workflowId
- else -> throw IllegalArgumentException("Invalid column")
- }
- }
-
- override fun getUUID(index: Int): UUID? {
- throw IllegalArgumentException("Invalid column")
- }
-
- override fun getInstant(index: Int): Instant? {
- throw IllegalArgumentException("Invalid column")
- }
-
- override fun getDuration(index: Int): Duration? {
- checkActive()
- return when (index) {
- colRuntime -> runtime
- else -> throw IllegalArgumentException("Invalid column")
- }
- }
-
- override fun <T> getList(
- index: Int,
- elementType: Class<T>,
- ): List<T>? {
- throw IllegalArgumentException("Invalid column")
- }
-
- override fun <T> getSet(
- index: Int,
- elementType: Class<T>,
- ): Set<T>? {
- checkActive()
- return when (index) {
- colParents -> typeParents.convertTo(parents, elementType)
- colChildren -> typeChildren.convertTo(children, elementType)
- else -> throw IllegalArgumentException("Invalid column")
- }
- }
-
- override fun <K, V> getMap(
- index: Int,
- keyType: Class<K>,
- valueType: Class<V>,
- ): Map<K, V>? {
- throw IllegalArgumentException("Invalid column")
- }
-
- override fun close() {
- parser.close()
- }
-
- /**
- * Helper method to check if the reader is active.
- */
- private fun checkActive() {
- check(level != ParserLevel.TOP && !parser.isClosed) { "No active row. Did you call nextRow()?" }
- }
-
- /**
- * Parse the trace and seek until the workflow description.
- */
- private fun seekWorkflow(): Boolean {
- while (parser.nextValue() != JsonToken.END_OBJECT && !parser.isClosed) {
- when (parser.currentName) {
- "name" -> workflowId = parser.text
- "workflow" -> return true
- else -> parser.skipChildren()
- }
- }
-
- return false
- }
-
- /**
- * Parse the workflow description in the file and seek until the first job.
- */
- private fun seekJobs(): Boolean {
- while (parser.nextValue() != JsonToken.END_OBJECT) {
- when (parser.currentName) {
- "jobs" -> return true
- else -> parser.skipChildren()
- }
- }
-
- return false
- }
-
- /**
- * Parse a single job in the file.
- */
- private fun parseJob() {
- while (parser.nextValue() != JsonToken.END_OBJECT) {
- when (parser.currentName) {
- "name" -> id = parser.text
- "parents" -> parents = parseIds()
- "children" -> children = parseIds()
- "runtime" -> runtime = Duration.ofSeconds(parser.numberValue.toLong())
- "cores" -> cores = parser.floatValue.roundToInt()
- else -> parser.skipChildren()
- }
- }
- }
-
- /**
- * Parse the parents/children of a job.
- */
- private fun parseIds(): Set<String> {
- if (!parser.isExpectedStartArrayToken) {
- throw JsonParseException(parser, "Expected array", parser.currentLocation)
- }
-
- val ids = mutableSetOf<String>()
-
- while (parser.nextToken() != JsonToken.END_ARRAY) {
- if (parser.currentToken != JsonToken.VALUE_STRING) {
- throw JsonParseException(parser, "Expected token", parser.currentLocation)
- }
-
- ids.add(parser.valueAsString)
- }
-
- return ids
- }
-
- private enum class ParserLevel {
- TOP,
- TRACE,
- WORKFLOW,
- JOB,
- }
-
- /**
- * State fields for the parser.
- */
- private var id: String? = null
- private var workflowId: String? = null
- private var runtime: Duration? = null
- private var parents: Set<String>? = null
- private var children: Set<String>? = null
- private var cores = -1
-
- private fun reset() {
- id = null
- runtime = null
- parents = null
- children = null
- cores = -1
- }
-
- private val colID = 0
- private val colWorkflowID = 1
- private val colRuntime = 3
- private val colNproc = 4
- private val colParents = 5
- private val colChildren = 6
-
- private val typeParents = TableColumnType.Set(TableColumnType.String)
- private val typeChildren = TableColumnType.Set(TableColumnType.String)
-}
diff --git a/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormat.kt b/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormat.kt
deleted file mode 100644
index 2178fac6..00000000
--- a/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormat.kt
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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.trace.wfformat
-
-import com.fasterxml.jackson.core.JsonFactory
-import org.opendc.trace.TableColumn
-import org.opendc.trace.TableColumnType
-import org.opendc.trace.TableReader
-import org.opendc.trace.TableWriter
-import org.opendc.trace.conv.TABLE_TASKS
-import org.opendc.trace.conv.TASK_CHILDREN
-import org.opendc.trace.conv.TASK_ID
-import org.opendc.trace.conv.TASK_PARENTS
-import org.opendc.trace.conv.TASK_REQ_NCPUS
-import org.opendc.trace.conv.TASK_RUNTIME
-import org.opendc.trace.conv.TASK_WORKFLOW_ID
-import org.opendc.trace.spi.TableDetails
-import org.opendc.trace.spi.TraceFormat
-import java.nio.file.Path
-
-/**
- * A [TraceFormat] implementation for the WfCommons workload trace format.
- */
-public class WfFormatTraceFormat : TraceFormat {
- /**
- * The [JsonFactory] that is used to created JSON parsers.
- */
- private val factory = JsonFactory()
-
- override val name: String = "wfformat"
-
- override fun create(path: Path) {
- throw UnsupportedOperationException("Writing not supported for this format")
- }
-
- override fun getTables(path: Path): List<String> = listOf(TABLE_TASKS)
-
- override fun getDetails(
- path: Path,
- table: String,
- ): TableDetails {
- return when (table) {
- TABLE_TASKS ->
- TableDetails(
- listOf(
- TableColumn(TASK_ID, TableColumnType.String),
- TableColumn(TASK_WORKFLOW_ID, TableColumnType.String),
- TableColumn(TASK_RUNTIME, TableColumnType.Duration),
- TableColumn(TASK_REQ_NCPUS, TableColumnType.Int),
- TableColumn(TASK_PARENTS, TableColumnType.Set(TableColumnType.String)),
- TableColumn(TASK_CHILDREN, TableColumnType.Set(TableColumnType.String)),
- ),
- )
- else -> throw IllegalArgumentException("Table $table not supported")
- }
- }
-
- override fun newReader(
- path: Path,
- table: String,
- projection: List<String>?,
- ): TableReader {
- return when (table) {
- TABLE_TASKS -> WfFormatTaskTableReader(factory.createParser(path.toFile()))
- else -> throw IllegalArgumentException("Table $table not supported")
- }
- }
-
- override fun newWriter(
- path: Path,
- table: String,
- ): TableWriter {
- throw UnsupportedOperationException("Writing not supported for this format")
- }
-}
diff --git a/opendc-trace/opendc-trace-wfformat/src/main/resources/META-INF/services/org.opendc.trace.spi.TraceFormat b/opendc-trace/opendc-trace-wfformat/src/main/resources/META-INF/services/org.opendc.trace.spi.TraceFormat
deleted file mode 100644
index ee3aa2f6..00000000
--- a/opendc-trace/opendc-trace-wfformat/src/main/resources/META-INF/services/org.opendc.trace.spi.TraceFormat
+++ /dev/null
@@ -1 +0,0 @@
-org.opendc.trace.wfformat.WfFormatTraceFormat