summaryrefslogtreecommitdiff
path: root/opendc-trace/opendc-trace-swf/src
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-swf/src
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-swf/src')
-rw-r--r--opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTaskTable.kt62
-rw-r--r--opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTrace.kt46
-rw-r--r--opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTraceFormat.kt39
-rw-r--r--opendc-trace/opendc-trace-swf/src/test/kotlin/org/opendc/trace/swf/SwfTraceFormatTest.kt53
4 files changed, 42 insertions, 158 deletions
diff --git a/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTaskTable.kt b/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTaskTable.kt
deleted file mode 100644
index 4898779d..00000000
--- a/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTaskTable.kt
+++ /dev/null
@@ -1,62 +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.swf
-
-import org.opendc.trace.*
-import java.nio.file.Path
-import kotlin.io.path.bufferedReader
-
-/**
- * A [Table] containing the tasks in a SWF trace.
- */
-internal class SwfTaskTable(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_SUBMIT_TIME,
- TASK_WAIT_TIME,
- TASK_RUNTIME,
- TASK_REQ_NCPUS,
- TASK_ALLOC_NCPUS,
- TASK_PARENTS,
- TASK_STATUS,
- TASK_GROUP_ID,
- TASK_USER_ID
- )
-
- override val partitionKeys: List<TableColumn<*>> = emptyList()
-
- override fun newReader(): TableReader {
- val reader = path.bufferedReader()
- return SwfTaskTableReader(reader)
- }
-
- override fun newReader(partition: String): TableReader {
- throw IllegalArgumentException("Invalid partition $partition")
- }
-
- override fun toString(): String = "SwfTaskTable"
-}
diff --git a/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTrace.kt b/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTrace.kt
deleted file mode 100644
index d4da735e..00000000
--- a/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTrace.kt
+++ /dev/null
@@ -1,46 +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.swf
-
-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 SWF format.
- */
-public class SwfTrace 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 SwfTaskTable(path)
- }
-
- override fun toString(): String = "SwfTrace[$path]"
-}
diff --git a/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTraceFormat.kt b/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTraceFormat.kt
index 36c3122e..4cb7e49e 100644
--- a/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTraceFormat.kt
+++ b/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTraceFormat.kt
@@ -22,10 +22,11 @@
package org.opendc.trace.swf
+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
+import kotlin.io.path.bufferedReader
/**
* Support for the Standard Workload Format (SWF) in OpenDC.
@@ -35,9 +36,33 @@ import kotlin.io.path.exists
public class SwfTraceFormat : TraceFormat {
override val name: String = "swf"
- override fun open(url: URL): SwfTrace {
- val path = Paths.get(url.toURI())
- require(path.exists()) { "URL $url does not exist" }
- return SwfTrace(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_SUBMIT_TIME,
+ TASK_WAIT_TIME,
+ TASK_RUNTIME,
+ TASK_REQ_NCPUS,
+ TASK_ALLOC_NCPUS,
+ TASK_PARENTS,
+ TASK_STATUS,
+ TASK_GROUP_ID,
+ TASK_USER_ID
+ ),
+ emptyList()
+ )
+ else -> throw IllegalArgumentException("Table $table not supported")
+ }
+ }
+
+ override fun newReader(path: Path, table: String): TableReader {
+ return when (table) {
+ TABLE_TASKS -> SwfTaskTableReader(path.bufferedReader())
+ else -> throw IllegalArgumentException("Table $table not supported")
+ }
}
}
diff --git a/opendc-trace/opendc-trace-swf/src/test/kotlin/org/opendc/trace/swf/SwfTraceFormatTest.kt b/opendc-trace/opendc-trace-swf/src/test/kotlin/org/opendc/trace/swf/SwfTraceFormatTest.kt
index 828c2bfa..4dcd43f6 100644
--- a/opendc-trace/opendc-trace-swf/src/test/kotlin/org/opendc/trace/swf/SwfTraceFormatTest.kt
+++ b/opendc-trace/opendc-trace-swf/src/test/kotlin/org/opendc/trace/swf/SwfTraceFormatTest.kt
@@ -27,61 +27,38 @@ import org.junit.jupiter.api.Assertions.*
import org.opendc.trace.TABLE_TASKS
import org.opendc.trace.TASK_ALLOC_NCPUS
import org.opendc.trace.TASK_ID
-import java.net.URL
+import java.nio.file.Paths
/**
* Test suite for the [SwfTraceFormat] class.
*/
internal class SwfTraceFormatTest {
- @Test
- fun testTraceExists() {
- val input = checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf"))
- val format = SwfTraceFormat()
- assertDoesNotThrow {
- format.open(input)
- }
- }
-
- @Test
- fun testTraceDoesNotExists() {
- val input = checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf"))
- val format = SwfTraceFormat()
- assertThrows<IllegalArgumentException> {
- format.open(URL(input.toString() + "help"))
- }
- }
+ private val format = SwfTraceFormat()
@Test
fun testTables() {
- val input = checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf"))
- val trace = SwfTraceFormat().open(input)
+ val path = Paths.get(checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf")).toURI())
- assertEquals(listOf(TABLE_TASKS), trace.tables)
+ assertEquals(listOf(TABLE_TASKS), format.getTables(path))
}
@Test
fun testTableExists() {
- val input = checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf"))
- val table = SwfTraceFormat().open(input).getTable(TABLE_TASKS)
-
- assertNotNull(table)
- assertDoesNotThrow { table!!.newReader() }
+ val path = Paths.get(checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf")).toURI())
+ assertDoesNotThrow { format.getDetails(path, TABLE_TASKS) }
}
@Test
fun testTableDoesNotExist() {
- val input = checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf"))
- val trace = SwfTraceFormat().open(input)
+ val path = Paths.get(checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf")).toURI())
- assertFalse(trace.containsTable("test"))
- assertNull(trace.getTable("test"))
+ assertThrows<IllegalArgumentException> { format.getDetails(path, "test") }
}
@Test
fun testReader() {
- val input = checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf"))
- val trace = SwfTraceFormat().open(input)
- val reader = trace.getTable(TABLE_TASKS)!!.newReader()
+ val path = Paths.get(checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf")).toURI())
+ val reader = format.newReader(path, TABLE_TASKS)
assertAll(
{ assertTrue(reader.nextRow()) },
@@ -94,14 +71,4 @@ internal class SwfTraceFormatTest {
reader.close()
}
-
- @Test
- fun testReaderPartition() {
- val input = checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf"))
- val trace = SwfTraceFormat().open(input)
-
- assertThrows<IllegalArgumentException> {
- trace.getTable(TABLE_TASKS)!!.newReader("test")
- }
- }
}