summaryrefslogtreecommitdiff
path: root/opendc-trace/opendc-trace-wtf
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-09-20 22:04:23 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-09-20 22:04:23 +0200
commitc7fff03408ee3109d0a39a96c043584a2d8f67ca (patch)
tree8c4a877e0f00f14a9091f9c26fdb0e85cad94904 /opendc-trace/opendc-trace-wtf
parent140aafdaa711b0fdeacf99b9c7e70b706b8490f4 (diff)
refactor(trace): Simplify TraceFormat SPI interface
This change simplifies the TraceFormat SPI interface by reducing the number of interfaces that implementors need to implement to only TraceFormat.
Diffstat (limited to 'opendc-trace/opendc-trace-wtf')
-rw-r--r--opendc-trace/opendc-trace-wtf/src/main/kotlin/org/opendc/trace/wtf/WtfTaskTable.kt63
-rw-r--r--opendc-trace/opendc-trace-wtf/src/main/kotlin/org/opendc/trace/wtf/WtfTrace.kt47
-rw-r--r--opendc-trace/opendc-trace-wtf/src/main/kotlin/org/opendc/trace/wtf/WtfTraceFormat.kt43
-rw-r--r--opendc-trace/opendc-trace-wtf/src/test/kotlin/org/opendc/trace/wtf/WtfTraceFormatTest.kt57
4 files changed, 46 insertions, 164 deletions
diff --git a/opendc-trace/opendc-trace-wtf/src/main/kotlin/org/opendc/trace/wtf/WtfTaskTable.kt b/opendc-trace/opendc-trace-wtf/src/main/kotlin/org/opendc/trace/wtf/WtfTaskTable.kt
deleted file mode 100644
index 410bb347..00000000
--- a/opendc-trace/opendc-trace-wtf/src/main/kotlin/org/opendc/trace/wtf/WtfTaskTable.kt
+++ /dev/null
@@ -1,63 +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.wtf
-
-import org.apache.avro.generic.GenericRecord
-import org.opendc.trace.*
-import org.opendc.trace.util.parquet.LocalParquetReader
-import java.nio.file.Path
-
-/**
- * A [Table] containing the tasks in a GWF trace.
- */
-internal class WtfTaskTable(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_SUBMIT_TIME,
- TASK_WAIT_TIME,
- TASK_RUNTIME,
- TASK_REQ_NCPUS,
- TASK_PARENTS,
- TASK_CHILDREN,
- TASK_GROUP_ID,
- TASK_USER_ID
- )
-
- override val partitionKeys: List<TableColumn<*>> = listOf(TASK_SUBMIT_TIME)
-
- override fun newReader(): TableReader {
- val reader = LocalParquetReader<GenericRecord>(path.resolve("tasks/schema-1.0"))
- return WtfTaskTableReader(reader)
- }
-
- override fun newReader(partition: String): TableReader {
- throw IllegalArgumentException("Invalid partition $partition")
- }
-
- override fun toString(): String = "WtfTaskTable"
-}
diff --git a/opendc-trace/opendc-trace-wtf/src/main/kotlin/org/opendc/trace/wtf/WtfTrace.kt b/opendc-trace/opendc-trace-wtf/src/main/kotlin/org/opendc/trace/wtf/WtfTrace.kt
deleted file mode 100644
index a755a107..00000000
--- a/opendc-trace/opendc-trace-wtf/src/main/kotlin/org/opendc/trace/wtf/WtfTrace.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.wtf
-
-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 WTF format.
- */
-public class WtfTrace internal constructor(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? {
- if (!containsTable(name)) {
- return null
- }
-
- return WtfTaskTable(path)
- }
-
- override fun toString(): String = "WtfTrace[$path]"
-}
diff --git a/opendc-trace/opendc-trace-wtf/src/main/kotlin/org/opendc/trace/wtf/WtfTraceFormat.kt b/opendc-trace/opendc-trace-wtf/src/main/kotlin/org/opendc/trace/wtf/WtfTraceFormat.kt
index 781cb335..2f17694f 100644
--- a/opendc-trace/opendc-trace-wtf/src/main/kotlin/org/opendc/trace/wtf/WtfTraceFormat.kt
+++ b/opendc-trace/opendc-trace-wtf/src/main/kotlin/org/opendc/trace/wtf/WtfTraceFormat.kt
@@ -22,10 +22,12 @@
package org.opendc.trace.wtf
+import org.apache.avro.generic.GenericRecord
+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 org.opendc.trace.util.parquet.LocalParquetReader
+import java.nio.file.Path
/**
* A [TraceFormat] implementation for the Workflow Trace Format (WTF).
@@ -33,9 +35,36 @@ import kotlin.io.path.exists
public class WtfTraceFormat : TraceFormat {
override val name: String = "wtf"
- override fun open(url: URL): WtfTrace {
- val path = Paths.get(url.toURI())
- require(path.exists()) { "URL $url does not exist" }
- return WtfTrace(path)
+ 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_SUBMIT_TIME,
+ TASK_WAIT_TIME,
+ TASK_RUNTIME,
+ TASK_REQ_NCPUS,
+ TASK_PARENTS,
+ TASK_CHILDREN,
+ TASK_GROUP_ID,
+ TASK_USER_ID
+ ),
+ listOf(TASK_SUBMIT_TIME)
+ )
+ else -> throw IllegalArgumentException("Table $table not supported")
+ }
+ }
+
+ override fun newReader(path: Path, table: String): TableReader {
+ return when (table) {
+ TABLE_TASKS -> {
+ val reader = LocalParquetReader<GenericRecord>(path.resolve("tasks/schema-1.0"))
+ WtfTaskTableReader(reader)
+ }
+ else -> throw IllegalArgumentException("Table $table not supported")
+ }
}
}
diff --git a/opendc-trace/opendc-trace-wtf/src/test/kotlin/org/opendc/trace/wtf/WtfTraceFormatTest.kt b/opendc-trace/opendc-trace-wtf/src/test/kotlin/org/opendc/trace/wtf/WtfTraceFormatTest.kt
index b155f265..09c3703a 100644
--- a/opendc-trace/opendc-trace-wtf/src/test/kotlin/org/opendc/trace/wtf/WtfTraceFormatTest.kt
+++ b/opendc-trace/opendc-trace-wtf/src/test/kotlin/org/opendc/trace/wtf/WtfTraceFormatTest.kt
@@ -26,8 +26,7 @@ import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.opendc.trace.*
-import java.io.File
-import java.net.URL
+import java.nio.file.Paths
import java.time.Duration
import java.time.Instant
@@ -35,51 +34,25 @@ import java.time.Instant
* Test suite for the [WtfTraceFormat] class.
*/
class WtfTraceFormatTest {
- @Test
- fun testTraceExists() {
- val input = File("src/test/resources/wtf-trace").toURI().toURL()
- val format = WtfTraceFormat()
- org.junit.jupiter.api.assertDoesNotThrow {
- format.open(input)
- }
- }
-
- @Test
- fun testTraceDoesNotExists() {
- val input = File("src/test/resources/wtf-trace").toURI().toURL()
- val format = WtfTraceFormat()
- assertThrows<IllegalArgumentException> {
- format.open(URL(input.toString() + "help"))
- }
- }
+ private val format = WtfTraceFormat()
@Test
fun testTables() {
- val input = File("src/test/resources/wtf-trace").toURI().toURL()
- val format = WtfTraceFormat()
- val trace = format.open(input)
-
- assertEquals(listOf(TABLE_TASKS), trace.tables)
+ val path = Paths.get("src/test/resources/wtf-trace")
+ assertEquals(listOf(TABLE_TASKS), format.getTables(path))
}
@Test
fun testTableExists() {
- val input = File("src/test/resources/wtf-trace").toURI().toURL()
- val format = WtfTraceFormat()
- val table = format.open(input).getTable(TABLE_TASKS)
-
- assertNotNull(table)
- org.junit.jupiter.api.assertDoesNotThrow { table!!.newReader() }
+ val path = Paths.get("src/test/resources/wtf-trace")
+ assertDoesNotThrow { format.getDetails(path, TABLE_TASKS) }
}
@Test
fun testTableDoesNotExist() {
- val input = File("src/test/resources/wtf-trace").toURI().toURL()
- val format = WtfTraceFormat()
- val trace = format.open(input)
+ val path = Paths.get("src/test/resources/wtf-trace")
- assertFalse(trace.containsTable("test"))
- assertNull(trace.getTable("test"))
+ assertThrows<IllegalArgumentException> { format.getDetails(path, "test") }
}
/**
@@ -87,9 +60,8 @@ class WtfTraceFormatTest {
*/
@Test
fun testTableReader() {
- val input = File("src/test/resources/wtf-trace")
- val trace = WtfTraceFormat().open(input.toURI().toURL())
- val reader = trace.getTable(TABLE_TASKS)!!.newReader()
+ val path = Paths.get("src/test/resources/wtf-trace")
+ val reader = format.newReader(path, TABLE_TASKS)
assertAll(
{ assertTrue(reader.nextRow()) },
@@ -111,13 +83,4 @@ class WtfTraceFormatTest {
reader.close()
}
-
- @Test
- fun testTableReaderPartition() {
- val input = File("src/test/resources/wtf-trace").toURI().toURL()
- val format = WtfTraceFormat()
- val table = format.open(input).getTable(TABLE_TASKS)!!
-
- assertThrows<IllegalArgumentException> { table.newReader("test") }
- }
}