summaryrefslogtreecommitdiff
path: root/opendc-trace/opendc-trace-wfformat
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-trace/opendc-trace-wfformat')
-rw-r--r--opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTaskTable.kt56
-rw-r--r--opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTaskTableReader.kt62
-rw-r--r--opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTrace.kt47
-rw-r--r--opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormat.kt42
-rw-r--r--opendc-trace/opendc-trace-wfformat/src/test/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormatTest.kt58
5 files changed, 83 insertions, 182 deletions
diff --git a/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTaskTable.kt b/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTaskTable.kt
deleted file mode 100644
index 7b7f979f..00000000
--- a/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTaskTable.kt
+++ /dev/null
@@ -1,56 +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.*
-import java.nio.file.Path
-
-/**
- * A [Table] containing the tasks in a WfCommons workload trace.
- */
-internal class WfFormatTaskTable(private val factory: JsonFactory, private val path: Path) : Table {
- override val name: String = TABLE_TASKS
-
- override val isSynthetic: Boolean = false
-
- override val columns: List<TableColumn<*>> = listOf(
- TASK_ID,
- TASK_WORKFLOW_ID,
- TASK_RUNTIME,
- TASK_REQ_NCPUS,
- TASK_PARENTS,
- TASK_CHILDREN
- )
-
- override fun newReader(): TableReader {
- val parser = factory.createParser(path.toFile())
- return WfFormatTaskTableReader(parser)
- }
-
- override fun newReader(partition: String): TableReader {
- throw IllegalArgumentException("Invalid partition $partition")
- }
-
- override fun toString(): String = "WfFormatTaskTable"
-}
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
index 4408ba5c..7f378d80 100644
--- 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
@@ -94,49 +94,41 @@ internal class WfFormatTaskTableReader(private val parser: JsonParser) : TableRe
return hasJob
}
- override fun hasColumn(column: TableColumn<*>): Boolean {
- return when (column) {
- TASK_ID -> true
- TASK_WORKFLOW_ID -> true
- TASK_RUNTIME -> true
- TASK_REQ_NCPUS -> true
- TASK_PARENTS -> true
- TASK_CHILDREN -> true
- else -> false
- }
+ override fun resolve(column: TableColumn<*>): Int = columns[column] ?: -1
+
+ override fun isNull(index: Int): Boolean {
+ check(index in 0..columns.size) { "Invalid column value" }
+ return false
}
- override fun <T> get(column: TableColumn<T>): T {
- val res: Any? = when (column) {
- TASK_ID -> id
- TASK_WORKFLOW_ID -> workflowId
- TASK_RUNTIME -> runtime
- TASK_PARENTS -> parents
- TASK_CHILDREN -> children
- TASK_REQ_NCPUS -> getInt(TASK_REQ_NCPUS)
+ override fun get(index: Int): Any? {
+ return when (index) {
+ COL_ID -> id
+ COL_WORKFLOW_ID -> workflowId
+ COL_RUNTIME -> runtime
+ COL_PARENTS -> parents
+ COL_CHILDREN -> children
+ COL_NPROC -> getInt(index)
else -> throw IllegalArgumentException("Invalid column")
}
-
- @Suppress("UNCHECKED_CAST")
- return res as T
}
- override fun getBoolean(column: TableColumn<Boolean>): Boolean {
+ override fun getBoolean(index: Int): Boolean {
throw IllegalArgumentException("Invalid column")
}
- override fun getInt(column: TableColumn<Int>): Int {
- return when (column) {
- TASK_REQ_NCPUS -> cores
+ override fun getInt(index: Int): Int {
+ return when (index) {
+ COL_NPROC -> cores
else -> throw IllegalArgumentException("Invalid column")
}
}
- override fun getLong(column: TableColumn<Long>): Long {
+ override fun getLong(index: Int): Long {
throw IllegalArgumentException("Invalid column")
}
- override fun getDouble(column: TableColumn<Double>): Double {
+ override fun getDouble(index: Int): Double {
throw IllegalArgumentException("Invalid column")
}
@@ -231,4 +223,20 @@ internal class WfFormatTaskTableReader(private val parser: JsonParser) : TableRe
children = null
cores = -1
}
+
+ private val COL_ID = 0
+ private val COL_WORKFLOW_ID = 1
+ private val COL_RUNTIME = 3
+ private val COL_NPROC = 4
+ private val COL_PARENTS = 5
+ private val COL_CHILDREN = 6
+
+ private val columns = mapOf(
+ TASK_ID to COL_ID,
+ TASK_WORKFLOW_ID to COL_WORKFLOW_ID,
+ TASK_RUNTIME to COL_RUNTIME,
+ TASK_REQ_NCPUS to COL_NPROC,
+ TASK_PARENTS to COL_PARENTS,
+ TASK_CHILDREN to COL_CHILDREN,
+ )
}
diff --git a/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTrace.kt b/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTrace.kt
deleted file mode 100644
index 2d9c79fb..00000000
--- a/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTrace.kt
+++ /dev/null
@@ -1,47 +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.TABLE_TASKS
-import org.opendc.trace.Table
-import org.opendc.trace.Trace
-import java.nio.file.Path
-
-/**
- * [Trace] implementation for the WfCommons workload trace format.
- */
-public class WfFormatTrace internal constructor(private val factory: JsonFactory, private val path: Path) : Trace {
- override val tables: List<String> = listOf(TABLE_TASKS)
-
- override fun containsTable(name: String): Boolean = TABLE_TASKS == name
-
- override fun getTable(name: String): Table? {
- return when (name) {
- TABLE_TASKS -> WfFormatTaskTable(factory, path)
- else -> null
- }
- }
-
- override fun toString(): String = "WfFormatTrace[$path]"
-}
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
index ff8d054c..c75e3cbb 100644
--- 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
@@ -23,10 +23,10 @@
package org.opendc.trace.wfformat
import com.fasterxml.jackson.core.JsonFactory
+import org.opendc.trace.*
+import org.opendc.trace.spi.TableDetails
import org.opendc.trace.spi.TraceFormat
-import java.net.URL
-import java.nio.file.Paths
-import kotlin.io.path.exists
+import java.nio.file.Path
/**
* A [TraceFormat] implementation for the WfCommons workload trace format.
@@ -39,9 +39,37 @@ public class WfFormatTraceFormat : TraceFormat {
override val name: String = "wfformat"
- override fun open(url: URL): WfFormatTrace {
- val path = Paths.get(url.toURI())
- require(path.exists()) { "URL $url does not exist" }
- return WfFormatTrace(factory, path)
+ 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(
+ TASK_ID,
+ TASK_WORKFLOW_ID,
+ TASK_RUNTIME,
+ TASK_REQ_NCPUS,
+ TASK_PARENTS,
+ TASK_CHILDREN
+ ),
+ emptyList()
+ )
+ else -> throw IllegalArgumentException("Table $table not supported")
+ }
+ }
+
+ override fun newReader(path: Path, table: 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/test/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormatTest.kt b/opendc-trace/opendc-trace-wfformat/src/test/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormatTest.kt
index 0bfc8840..217b175d 100644
--- a/opendc-trace/opendc-trace-wfformat/src/test/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormatTest.kt
+++ b/opendc-trace/opendc-trace-wfformat/src/test/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormatTest.kt
@@ -22,59 +22,38 @@
package org.opendc.trace.wfformat
+import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows
import org.opendc.trace.*
-import java.io.File
-import java.net.URL
+import java.nio.file.Paths
/**
* Test suite for the [WfFormatTraceFormat] class.
*/
class WfFormatTraceFormatTest {
- @Test
- fun testTraceExists() {
- val input = File("src/test/resources/trace.json").toURI().toURL()
- val format = WfFormatTraceFormat()
- assertDoesNotThrow { format.open(input) }
- }
-
- @Test
- fun testTraceDoesNotExists() {
- val input = File("src/test/resources/trace.json").toURI().toURL()
- val format = WfFormatTraceFormat()
- assertThrows<IllegalArgumentException> { format.open(URL(input.toString() + "help")) }
- }
+ private val format = WfFormatTraceFormat()
@Test
fun testTables() {
- val input = File("src/test/resources/trace.json").toURI().toURL()
- val format = WfFormatTraceFormat()
- val trace = format.open(input)
+ val path = Paths.get("src/test/resources/trace.json")
- assertEquals(listOf(TABLE_TASKS), trace.tables)
+ assertEquals(listOf(TABLE_TASKS), format.getTables(path))
}
@Test
fun testTableExists() {
- val input = File("src/test/resources/trace.json").toURI().toURL()
- val format = WfFormatTraceFormat()
- val table = format.open(input).getTable(TABLE_TASKS)
-
- assertNotNull(table)
- assertDoesNotThrow { table!!.newReader() }
+ val path = Paths.get("src/test/resources/trace.json")
+ Assertions.assertDoesNotThrow { format.getDetails(path, TABLE_TASKS) }
}
@Test
fun testTableDoesNotExist() {
- val input = File("src/test/resources/trace.json").toURI().toURL()
- val format = WfFormatTraceFormat()
- val trace = format.open(input)
+ val path = Paths.get("src/test/resources/trace.json")
- assertFalse(trace.containsTable("test"))
- assertNull(trace.getTable("test"))
+ assertThrows<IllegalArgumentException> { format.getDetails(path, "test") }
}
/**
@@ -82,9 +61,8 @@ class WfFormatTraceFormatTest {
*/
@Test
fun testTableReader() {
- val input = File("src/test/resources/trace.json").toURI().toURL()
- val trace = WfFormatTraceFormat().open(input)
- val reader = trace.getTable(TABLE_TASKS)!!.newReader()
+ val path = Paths.get("src/test/resources/trace.json")
+ val reader = format.newReader(path, TABLE_TASKS)
assertAll(
{ assertTrue(reader.nextRow()) },
@@ -110,9 +88,8 @@ class WfFormatTraceFormatTest {
*/
@Test
fun testTableReaderFull() {
- val input = File("src/test/resources/trace.json").toURI().toURL()
- val trace = WfFormatTraceFormat().open(input)
- val reader = trace.getTable(TABLE_TASKS)!!.newReader()
+ val path = Paths.get("src/test/resources/trace.json")
+ val reader = format.newReader(path, TABLE_TASKS)
assertDoesNotThrow {
while (reader.nextRow()) {
@@ -121,13 +98,4 @@ class WfFormatTraceFormatTest {
reader.close()
}
}
-
- @Test
- fun testTableReaderPartition() {
- val input = File("src/test/resources/trace.json").toURI().toURL()
- val format = WfFormatTraceFormat()
- val table = format.open(input).getTable(TABLE_TASKS)!!
-
- assertThrows<IllegalArgumentException> { table.newReader("test") }
- }
}