From dad4487fddaccf44240f5d62fa83830f7bbf8a5d Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 24 Oct 2017 12:07:09 +0200 Subject: bug(#6): Improve Docker deployment This change improves the Docker deployment by moving the build process from runtime to (image) build time. Also, the opendc-integration-jpa module now consists of a core and mysql module, where the mysql module is a specific deployment of the integration. --- Dockerfile | 20 -- opendc-integration-jpa/build.gradle | 105 ------- opendc-integration-jpa/core/build.gradle | 90 ++++++ .../nl/atlarge/opendc/integration/jpa/Jpa.kt | 38 +++ .../jpa/converter/ParallelizableConverter.kt | 62 ++++ .../jpa/converter/SchedulerConverter.kt | 66 +++++ .../atlarge/opendc/integration/jpa/schema/Cpu.kt | 58 ++++ .../opendc/integration/jpa/schema/Datacenter.kt | 66 +++++ .../opendc/integration/jpa/schema/Experiment.kt | 60 ++++ .../integration/jpa/schema/ExperimentState.kt | 53 ++++ .../atlarge/opendc/integration/jpa/schema/Gpu.kt | 58 ++++ .../atlarge/opendc/integration/jpa/schema/Job.kt | 59 ++++ .../opendc/integration/jpa/schema/Machine.kt | 45 +++ .../opendc/integration/jpa/schema/MachineState.kt | 53 ++++ .../atlarge/opendc/integration/jpa/schema/Path.kt | 40 +++ .../atlarge/opendc/integration/jpa/schema/Rack.kt | 52 ++++ .../atlarge/opendc/integration/jpa/schema/Room.kt | 50 ++++ .../opendc/integration/jpa/schema/RoomObject.kt | 36 +++ .../opendc/integration/jpa/schema/RoomType.kt | 34 +++ .../opendc/integration/jpa/schema/Section.kt | 45 +++ .../atlarge/opendc/integration/jpa/schema/Task.kt | 117 ++++++++ .../opendc/integration/jpa/schema/TaskState.kt | 49 ++++ .../atlarge/opendc/integration/jpa/schema/Trace.kt | 44 +++ .../nl/atlarge/opendc/platform/JpaExperiment.kt | 176 +++++++++++ .../opendc/platform/JpaExperimentManager.kt | 93 ++++++ .../atlarge/opendc/platform/JpaPlatformRunner.kt | 64 ++++ .../atlarge/opendc/topology/JpaTopologyFactory.kt | 87 ++++++ .../core/src/main/resources/jpa/schema.xml | 324 +++++++++++++++++++++ opendc-integration-jpa/mysql/Dockerfile | 30 ++ opendc-integration-jpa/mysql/build.gradle | 38 +++ .../src/main/resources/META-INF/persistence.xml | 41 +++ .../nl/atlarge/opendc/integration/jpa/Jpa.kt | 38 --- .../jpa/converter/ParallelizableConverter.kt | 62 ---- .../jpa/converter/SchedulerConverter.kt | 66 ----- .../atlarge/opendc/integration/jpa/schema/Cpu.kt | 58 ---- .../opendc/integration/jpa/schema/Datacenter.kt | 66 ----- .../opendc/integration/jpa/schema/Experiment.kt | 60 ---- .../integration/jpa/schema/ExperimentState.kt | 53 ---- .../atlarge/opendc/integration/jpa/schema/Gpu.kt | 58 ---- .../atlarge/opendc/integration/jpa/schema/Job.kt | 59 ---- .../opendc/integration/jpa/schema/Machine.kt | 45 --- .../opendc/integration/jpa/schema/MachineState.kt | 53 ---- .../atlarge/opendc/integration/jpa/schema/Path.kt | 40 --- .../atlarge/opendc/integration/jpa/schema/Rack.kt | 52 ---- .../atlarge/opendc/integration/jpa/schema/Room.kt | 50 ---- .../opendc/integration/jpa/schema/RoomObject.kt | 36 --- .../opendc/integration/jpa/schema/RoomType.kt | 34 --- .../opendc/integration/jpa/schema/Section.kt | 45 --- .../atlarge/opendc/integration/jpa/schema/Task.kt | 117 -------- .../opendc/integration/jpa/schema/TaskState.kt | 49 ---- .../atlarge/opendc/integration/jpa/schema/Trace.kt | 44 --- .../nl/atlarge/opendc/platform/JpaExperiment.kt | 176 ----------- .../opendc/platform/JpaExperimentManager.kt | 93 ------ .../atlarge/opendc/platform/JpaPlatformRunner.kt | 64 ---- .../atlarge/opendc/topology/JpaTopologyFactory.kt | 87 ------ .../src/main/resources/META-INF/persistence.xml | 45 --- .../src/main/resources/jpa/schema.xml | 324 --------------------- settings.gradle | 3 +- 58 files changed, 2030 insertions(+), 2000 deletions(-) delete mode 100644 Dockerfile delete mode 100644 opendc-integration-jpa/build.gradle create mode 100644 opendc-integration-jpa/core/build.gradle create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/Jpa.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/ParallelizableConverter.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/SchedulerConverter.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Cpu.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Datacenter.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Experiment.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/ExperimentState.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Gpu.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Job.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Machine.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/MachineState.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Path.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Rack.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Room.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomObject.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomType.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Section.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Task.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/TaskState.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Trace.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperiment.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperimentManager.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/platform/JpaPlatformRunner.kt create mode 100644 opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/topology/JpaTopologyFactory.kt create mode 100644 opendc-integration-jpa/core/src/main/resources/jpa/schema.xml create mode 100644 opendc-integration-jpa/mysql/Dockerfile create mode 100644 opendc-integration-jpa/mysql/build.gradle create mode 100644 opendc-integration-jpa/mysql/src/main/resources/META-INF/persistence.xml delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/Jpa.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/ParallelizableConverter.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/SchedulerConverter.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Cpu.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Datacenter.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Experiment.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/ExperimentState.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Gpu.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Job.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Machine.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/MachineState.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Path.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Rack.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Room.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomObject.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomType.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Section.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Task.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/TaskState.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Trace.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperiment.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperimentManager.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/platform/JpaPlatformRunner.kt delete mode 100644 opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/topology/JpaTopologyFactory.kt delete mode 100644 opendc-integration-jpa/src/main/resources/META-INF/persistence.xml delete mode 100644 opendc-integration-jpa/src/main/resources/jpa/schema.xml diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index f8de6b54..00000000 --- a/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -FROM gradle:alpine -MAINTAINER Fabian Mastenbroek - -# Copy OpenDC simulator -COPY ./ /home/gradle/simulator - -# Fix permissions -USER root -RUN chown -R gradle:gradle /home/gradle/simulator && \ - chmod -R 771 /home/gradle/simulator -USER gradle - -# Set the working directory to the JPA integration -WORKDIR /home/gradle/simulator/opendc-integration-jpa - -# Build the application -RUN gradle --no-daemon installDist - -# Run the application -CMD build/install/opendc-integration-jpa/bin/opendc-integration-jpa diff --git a/opendc-integration-jpa/build.gradle b/opendc-integration-jpa/build.gradle deleted file mode 100644 index e5be0f46..00000000 --- a/opendc-integration-jpa/build.gradle +++ /dev/null @@ -1,105 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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. - */ - -/* Build configuration */ -buildscript { - ext.kotlin_version = '1.1.4-3' - ext.dokka_version = '0.9.15' - - repositories { - mavenCentral() - jcenter() - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version" - classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version" - classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-RC3' - } -} - -apply plugin: 'java' -apply plugin: 'kotlin' -apply plugin: 'kotlin-jpa' -apply plugin: 'application' -apply plugin: 'org.jetbrains.dokka' -apply plugin: 'org.junit.platform.gradle.plugin' - -mainClassName = "nl.atlarge.opendc.platform.JpaPlatformRunnerKt" - -compileKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} - -compileTestKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} - -kotlin { - experimental { - coroutines 'enable' - } -} - -dokka { - outputFormat = 'html' - outputDirectory = "$buildDir/javadoc" -} - -/* Project configuration */ -group 'nl.atlarge.opendc' -version '1.0' - -repositories { - jcenter() -} - -import org.apache.tools.ant.filters.* - -processResources { - filter ReplaceTokens, tokens: [ - 'persistence.url': project.findProperty('persistence.url') ?: '', - 'persistence.user': project.findProperty('persistence.user') ?: '', - 'persistence.password': project.findProperty('persistence.password') ?: '', - ] -} - -dependencies { - compile project(':opendc-core') - compile project(':opendc-stdlib') - compile project(':opendc-omega') - compile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final' - runtime 'org.slf4j:slf4j-simple:1.7.25' - runtime 'org.hibernate:hibernate-core:5.2.5.Final' - runtime 'mysql:mysql-connector-java:5.1.13' - - testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.0-RC3' - testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.0-RC3' - testCompile 'org.junit.platform:junit-platform-launcher:1.0.0-RC3' -} diff --git a/opendc-integration-jpa/core/build.gradle b/opendc-integration-jpa/core/build.gradle new file mode 100644 index 00000000..ed510560 --- /dev/null +++ b/opendc-integration-jpa/core/build.gradle @@ -0,0 +1,90 @@ +/* + * MIT License + * + * Copyright (c) 2017 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. + */ + +/* Build configuration */ +buildscript { + ext.kotlin_version = '1.1.4-3' + ext.dokka_version = '0.9.15' + + repositories { + mavenCentral() + jcenter() + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version" + classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version" + classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-RC3' + } +} + +apply plugin: 'java' +apply plugin: 'kotlin' +apply plugin: 'kotlin-jpa' +apply plugin: 'org.jetbrains.dokka' +apply plugin: 'org.junit.platform.gradle.plugin' + + +compileKotlin { + kotlinOptions { + jvmTarget = "1.8" + } +} + +compileTestKotlin { + kotlinOptions { + jvmTarget = "1.8" + } +} + +kotlin { + experimental { + coroutines 'enable' + } +} + +dokka { + outputFormat = 'html' + outputDirectory = "$buildDir/javadoc" +} + +/* Project configuration */ +group 'nl.atlarge.opendc' +version '1.0' + +repositories { + jcenter() +} + +dependencies { + compile project(':opendc-core') + compile project(':opendc-stdlib') + compile project(':opendc-omega') + compile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final' + + testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.0-RC3' + testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.0-RC3' + testCompile 'org.junit.platform:junit-platform-launcher:1.0.0-RC3' +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/Jpa.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/Jpa.kt new file mode 100644 index 00000000..cbbe280a --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/Jpa.kt @@ -0,0 +1,38 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa + +import javax.persistence.EntityManager + +/** + * Run the given block in a transaction, committing on return of the block. + * + * @param block The block to execute in the transaction. + */ +inline fun EntityManager.transaction(block: () -> Unit) { + transaction.begin() + block() + transaction.commit() +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/ParallelizableConverter.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/ParallelizableConverter.kt new file mode 100644 index 00000000..11d5836e --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/ParallelizableConverter.kt @@ -0,0 +1,62 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.converter + +import javax.persistence.AttributeConverter + +/** + * An internal [AttributeConverter] that maps the values _PARALLEL_ and _SEQUENTIAL_ to a + * boolean value indicating whether a task is parallelizable. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +class ParallelizableConverter : AttributeConverter { + /** + * Converts the data stored in the database column into the + * value to be stored in the entity attribute. + * Note that it is the responsibility of the converter writer to + * specify the correct dbData type for the corresponding column + * for use by the JDBC driver: i.e., persistence providers are + * not expected to do such type conversion. + * + * @param dbData the data from the database column to be converted + * @return the converted value to be stored in the entity attribute + */ + override fun convertToEntityAttribute(dbData: String?): Boolean = when(dbData?.toUpperCase()) { + "SEQUENTIAL" -> false + "PARALLEL" -> true + else -> false + } + + /** + * Converts the value stored in the entity attribute into the + * data representation to be stored in the database. + * + * @param attribute the entity attribute value to be converted + * @return the converted data to be stored in the database column + */ + override fun convertToDatabaseColumn(attribute: Boolean?): String = + if (attribute == true) "PARALLEL" else "SEQUENTIAL" +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/SchedulerConverter.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/SchedulerConverter.kt new file mode 100644 index 00000000..95027440 --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/SchedulerConverter.kt @@ -0,0 +1,66 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.converter + +import nl.atlarge.opendc.platform.scheduler.FifoScheduler +import nl.atlarge.opendc.platform.scheduler.Scheduler +import nl.atlarge.opendc.platform.scheduler.SrtfScheduler +import javax.persistence.AttributeConverter + +/** + * An internal [AttributeConverter] that maps a name of a scheduler to the actual scheduler implementation. + * The converter currently chooses between the following two schedulers: + * - [FifoScheduler] (default) + * - [SrtfScheduler] + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +class SchedulerConverter : AttributeConverter { + /** + * Converts the data stored in the database column into the + * value to be stored in the entity attribute. + * Note that it is the responsibility of the converter writer to + * specify the correct dbData type for the corresponding column + * for use by the JDBC driver: i.e., persistence providers are + * not expected to do such type conversion. + * + * @param dbData the data from the database column to be converted + * @return the converted value to be stored in the entity attribute + */ + override fun convertToEntityAttribute(dbData: String?): Scheduler = when(dbData?.toUpperCase()) { + "SRTF" -> SrtfScheduler() + else -> FifoScheduler() + } + + /** + * Converts the value stored in the entity attribute into the + * data representation to be stored in the database. + * + * @param attribute the entity attribute value to be converted + * @return the converted data to be stored in the database column + */ + override fun convertToDatabaseColumn(attribute: Scheduler?): String = + attribute?.name?.toUpperCase() ?: "FIFO" +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Cpu.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Cpu.kt new file mode 100644 index 00000000..b775eb6e --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Cpu.kt @@ -0,0 +1,58 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import nl.atlarge.opendc.topology.machine.Cpu +import javax.persistence.Entity + +/** + * A cpu entity in the persistent schema. + * + * @property id The unique identifier of the cpu. + * @property manufacturer The manufacturer of the cpu. + * @property family The family of the cpu. + * @property generation The generation of the cpu. + * @property model The model of the cpu. + * @property clockRate The clock rate of the cpu. + * @property cores The amount of cores in the gpu. + * @property energyConsumption The energy consumption of the cpu in Watt. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +data class Cpu( + val id: Int, + val manufacturer: String, + val family: String, + val generation: String, + val model: String, + override val clockRate: Int, + override val cores: Int, + override val energyConsumption: Double +) : Cpu { + /** + * The initial state of the entity. + */ + override val initialState = Unit +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Datacenter.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Datacenter.kt new file mode 100644 index 00000000..1e6eaa2b --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Datacenter.kt @@ -0,0 +1,66 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import nl.atlarge.opendc.kernel.time.Duration +import nl.atlarge.opendc.platform.scheduler.Scheduler +import nl.atlarge.opendc.topology.container.Datacenter +import javax.persistence.Entity + +/** + * A datacenter entity in the persistent schema. + * + * @property id The unique identifier of the datacenter. + * @property rooms The rooms in the datacenter. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +data class Datacenter( + val id: Int, + val rooms: Set +): Datacenter { + /** + * Construct a datacenter. We need this useless constructor in order for Kotlin correctly initialise the + * constant fields of the class. + */ + private constructor() : this(-1, emptySet()) + + /** + * The task scheduler the datacenter uses. + */ + override lateinit var scheduler: Scheduler + internal set + + /** + * The interval at which task will be (re)scheduled. + * We set this to a fixed constant since the database provides no way of configuring this. + */ + override val interval: Duration = 10 + + /** + * The initial state of the datacenter. + */ + override val initialState = Unit +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Experiment.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Experiment.kt new file mode 100644 index 00000000..0b352cb4 --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Experiment.kt @@ -0,0 +1,60 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import nl.atlarge.opendc.kernel.time.Instant +import nl.atlarge.opendc.platform.Experiment +import nl.atlarge.opendc.platform.scheduler.Scheduler +import nl.atlarge.opendc.platform.workload.Trace +import javax.persistence.Entity + +/** + * An experiment definition for the OpenDC database schema. + * + * @property id The identifier of the experiment. + * @property name The name of the experiment. + * @property scheduler The scheduler used in the experiment. + * @property trace The trace used for the simulation. + * @property path The path of the experiment. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +data class Experiment( + val id: Int, + val name: String, + val scheduler: Scheduler, + val trace: Trace, + val path: Path +) { + /** + * The state of the experiment. + */ + var state: ExperimentState = ExperimentState.QUEUED + + /** + * The last tick that has been simulated. + */ + var last: Instant = 0 +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/ExperimentState.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/ExperimentState.kt new file mode 100644 index 00000000..96fc112c --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/ExperimentState.kt @@ -0,0 +1,53 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +/** + * Enumerations of the states an [Experiment] can assume. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +enum class ExperimentState { + /** + * This state indicates the experiment has been queued for simulation, but has not yet started. + */ + QUEUED, + + /** + * This state indicates the experiment has been claimed by a simulator for simulation, but + * not yet started. + */ + CLAIMED, + + /** + * This state indicates the experiment is currently in simulation. + */ + SIMULATING, + + /** + * This state indicates the experiment has finished simulating. + */ + FINISHED, +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Gpu.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Gpu.kt new file mode 100644 index 00000000..94625242 --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Gpu.kt @@ -0,0 +1,58 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import nl.atlarge.opendc.topology.machine.Gpu +import javax.persistence.Entity + +/** + * A gpu entity in the persistent schema. + * + * @property id The unique identifier of the gpu. + * @property manufacturer The manufacturer of the gpu. + * @property family The family of the gpu. + * @property generation The generation of the gpu. + * @property model The model of the gpu. + * @property clockRate The clock rate of the gpu. + * @property cores The amount of cores in the gpu. + * @property energyConsumption The energy consumption of the gpu in Watt. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +data class Gpu( + val id: Int, + val manufacturer: String, + val family: String, + val generation: String, + val model: String, + override val clockRate: Int, + override val cores: Int, + override val energyConsumption: Double +) : Gpu { + /** + * The initial state of the entity. + */ + override val initialState = Unit +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Job.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Job.kt new file mode 100644 index 00000000..394cf478 --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Job.kt @@ -0,0 +1,59 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import nl.atlarge.opendc.platform.workload.Job +import nl.atlarge.opendc.platform.workload.Task +import nl.atlarge.opendc.platform.workload.User +import javax.persistence.* + +/** + * A [Job] backed by the JPA API and an underlying database connection. + * + * @property id The unique identifier of the job. + * @property tasks The collection of tasks the job consists of. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +data class Job( + override val id: Int, + override val tasks: Set +) : Job { + /** + * The owner of the job, which is a singleton, since the database has no + * concept of ownership yet. + */ + override val owner: User = object : User { + /** + * The unique identifier of the user. + */ + override val id: Int = 0 + + /** + * The name of this user. + */ + override val name: String = "admin" + } +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Machine.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Machine.kt new file mode 100644 index 00000000..4071b342 --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Machine.kt @@ -0,0 +1,45 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import nl.atlarge.opendc.topology.machine.Machine +import javax.persistence.Entity + +/** + * A machine entity in the persistent schema. + * + * @property id The unique identifier of the machine. + * @property position The position of the machine in the rack. + * @property cpus The CPUs in the machine. + * @property gpus The GPUs in the machine. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +data class Machine( + val id: Int, + val position: Int, + val cpus: Set, + val gpus: Set +): Machine() diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/MachineState.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/MachineState.kt new file mode 100644 index 00000000..23efe888 --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/MachineState.kt @@ -0,0 +1,53 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import nl.atlarge.opendc.kernel.time.Instant +import javax.persistence.Entity + +/** + * The state of a [Machine]. + * + * @property id The unique identifier of the state. + * @property machine The machine of the state. + * @property task The task the machine has been assigned. + * @property experiment The experiment the machine is running in. + * @property time The current moment in time. + * @property temperature The temperature of the machine. + * @property memoryUsage The memory usage of the machine. + * @property load The load of the machine. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +data class MachineState( + val id: Int, + val machine: Machine, + val task: Task?, + val experiment: Experiment, + val time: Instant, + val temperature: Double, + val memoryUsage: Int, + val load: Double +) diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Path.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Path.kt new file mode 100644 index 00000000..ccf3b6e8 --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Path.kt @@ -0,0 +1,40 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import javax.persistence.Entity + +/** + * A [Path] holds all sections of the parent experiment. + * + * @property id The unique identifier of the path. + * @property sections The sections of the path. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +open class Path( + val id: Int, + val sections: List
+) diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Rack.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Rack.kt new file mode 100644 index 00000000..2d2099a2 --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Rack.kt @@ -0,0 +1,52 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import nl.atlarge.opendc.topology.container.Rack +import javax.persistence.Entity + +/** + * A rack entity in a room in the persistent schema. + * + * @property id The unique identifier of the rack. + * @property name The name of the rack. + * @property capacity The capacity of the rack in terms of units. + * @property powerCapacity The power capacity of the rack in Watt. + * @property machines The machines in the rack. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +class Rack( + id: Int, + val name: String, + val capacity: Int, + val powerCapacity: Int, + val machines: List +): RoomObject(id), Rack { + /** + * The initial state of the entity. + */ + override val initialState = Unit +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Room.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Room.kt new file mode 100644 index 00000000..f3b7ae06 --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Room.kt @@ -0,0 +1,50 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import nl.atlarge.opendc.topology.container.Room +import javax.persistence.Entity + +/** + * A room entity in the persistent schema. + * + * @property id The unique identifier of the room. + * @property name The name of the room. + * @property type The type of the room. + * @property objects The objects in the room. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +data class Room( + val id: Int, + val name: String, + val type: RoomType, + val objects: Set +): Room { + /** + * The initial state of the entity. + */ + override val initialState = Unit +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomObject.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomObject.kt new file mode 100644 index 00000000..0e9fb84f --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomObject.kt @@ -0,0 +1,36 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import javax.persistence.Entity + +/** + * An object in a room. + * + * @property id The unique identifier of the room. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +abstract class RoomObject(val id: Int) diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomType.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomType.kt new file mode 100644 index 00000000..5e138947 --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomType.kt @@ -0,0 +1,34 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +/** + * This enumeration defines the room types available in the OpenDC frontend. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +enum class RoomType { + COOLING, HALLWAY, OFFICE, POWER, SERVER +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Section.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Section.kt new file mode 100644 index 00000000..e3b8c350 --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Section.kt @@ -0,0 +1,45 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import nl.atlarge.opendc.kernel.time.Instant +import javax.persistence.Entity + +/** + * A [Section] holds a datacenter and the tick on which the parent experiment should + * switch to this section. + * + * @property id The unique identifier of the section. + * @property datacenter The datacenter of this section. + * @property startTime The position in time when the experiment should start using the + * topology of this section. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +data class Section( + val id: Int, + val datacenter: Datacenter, + val startTime: Instant +) diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Task.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Task.kt new file mode 100644 index 00000000..83a98cfb --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Task.kt @@ -0,0 +1,117 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import nl.atlarge.opendc.kernel.time.Instant +import nl.atlarge.opendc.platform.workload.Task +import nl.atlarge.opendc.platform.workload.TaskState +import javax.persistence.* + +/** + * A [Task] backed by the JPA API and an underlying database connection. + * + * @property id The unique identifier of the job. + * @property flops The total amount of flops for the task. + * @property dependency A dependency on another task. + * @property parallelizable A flag to indicate the task is parallelizable. + * @property startTime The start time in the simulation. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +data class Task( + override val id: Int, + override val flops: Long, + private val dependency: Task?, + override val parallelizable: Boolean, + val startTime: Instant +) : Task { + /** + * The dependencies of the task. + */ + override lateinit var dependencies: Set + private set + + /** + * The remaining flops for this task. + */ + override var remaining: Long = 0 + private set + + /** + * A flag to indicate whether the task has finished. + */ + override var finished: Boolean = false + private set + + /** + * The state of the task. + */ + override lateinit var state: TaskState + private set + + /** + * This method initialises the task object after it has been created by the JPA implementation. We use this + * initialisation method because JPA implementations only call the default constructor + */ + @PostLoad + internal fun init() { + remaining = flops + dependencies = dependency?.let(::setOf) ?: emptySet() + state = TaskState.Underway + } + + /** + * This method is invoked when a task has arrived at a datacenter. + * + * @param time The moment in time the task has arrived at the datacenter. + */ + override fun arrive(time: Instant) { + if (state !is TaskState.Underway) { + throw IllegalStateException("The task has already been submitted to a datacenter") + } + remaining = flops + state = TaskState.Queued(time) + } + + /** + * Consume the given amount of flops of this task. + * + * @param time The current moment in time of the consumption. + * @param flops The total amount of flops to consume. + */ + override fun consume(time: Instant, flops: Long) { + if (state is TaskState.Queued) { + state = TaskState.Running(state as TaskState.Queued, time) + } else if (finished) { + return + } + remaining -= flops + if (remaining <= 0) { + remaining = 0 + finished = true + state = TaskState.Finished(state as TaskState.Running, time) + } + } +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/TaskState.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/TaskState.kt new file mode 100644 index 00000000..14441752 --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/TaskState.kt @@ -0,0 +1,49 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import nl.atlarge.opendc.kernel.time.Instant +import javax.persistence.Entity + +/** + * The state of a [Task]. + * + * @property id The unique identifier of the state. + * @property task The task this is the state of. + * @property experiment The experiment the machine is running in. + * @property time The current moment in time. + * @property remaining The remaining flops for the task. + * @property cores The cores used for the task. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +data class TaskState( + val id: Int, + val task: Task, + val experiment: Experiment, + val time: Instant, + val remaining: Int, + val cores: Int +) diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Trace.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Trace.kt new file mode 100644 index 00000000..cd3d9348 --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Trace.kt @@ -0,0 +1,44 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema + +import nl.atlarge.opendc.platform.workload.Job +import nl.atlarge.opendc.platform.workload.Trace +import javax.persistence.Entity + +/** + * A [Trace] backed by the JPA API and an underlying database connection. + * + * @property id The unique identifier of the trace. + * @property name The name of the trace. + * @property jobs The collection of jobs for this trace. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +@Entity +data class Trace( + val id: Int, + val name: String, + override val jobs: Set +) : Trace diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperiment.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperiment.kt new file mode 100644 index 00000000..59b28d0b --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperiment.kt @@ -0,0 +1,176 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.platform + +import mu.KotlinLogging +import nl.atlarge.opendc.integration.jpa.schema.ExperimentState +import nl.atlarge.opendc.integration.jpa.schema.MachineState +import nl.atlarge.opendc.integration.jpa.transaction +import nl.atlarge.opendc.integration.jpa.schema.Trace as InternalTrace +import nl.atlarge.opendc.integration.jpa.schema.TaskState as InternalTaskState +import nl.atlarge.opendc.integration.jpa.schema.Experiment as InternalExperiment +import nl.atlarge.opendc.integration.jpa.schema.Task as InternalTask +import nl.atlarge.opendc.kernel.Kernel +import nl.atlarge.opendc.platform.workload.TaskState +import nl.atlarge.opendc.topology.JpaTopologyFactory +import nl.atlarge.opendc.topology.container.Rack +import nl.atlarge.opendc.topology.container.Room +import nl.atlarge.opendc.topology.destinations +import nl.atlarge.opendc.topology.machine.Machine +import java.util.* +import javax.persistence.EntityManager + +/** + * An [Experiment] backed by the JPA API and an underlying database connection. + * + * @property manager The entity manager for the database connection. + * @property experiment The internal experiment definition to use. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +class JpaExperiment(private val manager: EntityManager, + private val experiment: InternalExperiment): Experiment, AutoCloseable { + /** + * The logging instance. + */ + private val logger = KotlinLogging.logger {} + + /** + * Run the experiment on the specified simulation [Kernel]. + * + * @param kernel The simulation kernel to run the experiment. + * @throws IllegalStateException if the simulation is already running or finished. + */ + override fun run(kernel: Kernel) { + if (experiment.state != ExperimentState.CLAIMED) { + throw IllegalStateException("The experiment is in illegal state ${experiment.state}") + } + + // Set the simulation state + manager.transaction { + experiment.state = ExperimentState.SIMULATING + } + + val section = experiment.path.sections.first() + + // Important: initialise the scheduler of the datacenter + section.datacenter.scheduler = experiment.scheduler + + val topology = JpaTopologyFactory(section).create() + val simulation = kernel.create(topology) + val trace = experiment.trace + val tasks = trace.jobs.flatMap { it.tasks } + + logger.info { "Sending trace to kernel ${Objects.hashCode(trace)} ${(trace as InternalTrace).id}" } + + // Schedule all messages in the trace + tasks.forEach { task -> + if (task is InternalTask) { + simulation.schedule(task, section.datacenter, delay = task.startTime) + } else { + logger.warn { "Dropped invalid task $task" } + } + } + + // Find all machines in the datacenter + val machines = topology.run { + section.datacenter.outgoingEdges.destinations("room").asSequence() + .flatMap { it.outgoingEdges.destinations("rack").asSequence() } + .flatMap { it.outgoingEdges.destinations("machine").asSequence() }.toList() + } + + logger.info { "Starting simulation" } + + while (trace.jobs.any { !it.finished }) { + // Collect data of simulation cycle + manager.transaction { + experiment.last = simulation.clock.now + + machines.forEach { machine -> + val state = simulation.run { machine.state } + val wrapped = MachineState(0, + machine as nl.atlarge.opendc.integration.jpa.schema.Machine, + state.task as nl.atlarge.opendc.integration.jpa.schema.Task?, + experiment, + simulation.clock.now, + state.temperature, + state.memory, + state.load + ) + manager.persist(wrapped) + } + + trace.jobs.asSequence() + .flatMap { it.tasks.asSequence() } + .forEach { task -> + val state = InternalTaskState(0, + task as nl.atlarge.opendc.integration.jpa.schema.Task, + experiment, + simulation.clock.now, + task.remaining.toInt(), + 1 + ) + manager.persist(state) + } + } + + // Run next simulation cycle + simulation.run(simulation.clock.now + 1) + } + + // Set the experiment state + manager.transaction { + experiment.state = ExperimentState.FINISHED + } + + logger.info { "Simulation done" } + val waiting: Long = tasks.fold(0.toLong()) { acc, task -> + val finished = task.state as TaskState.Finished + acc + (finished.previous.at - finished.previous.previous.at) + } / tasks.size + + val execution: Long = tasks.fold(0.toLong()) { acc, task -> + val finished = task.state as TaskState.Finished + acc + (finished.at - finished.previous.at) + } / tasks.size + + val turnaround: Long = tasks.fold(0.toLong()) { acc, task -> + val finished = task.state as TaskState.Finished + acc + (finished.at - finished.previous.previous.at) + } / tasks.size + + logger.info { "Average waiting time: $waiting seconds" } + logger.info { "Average execution time: $execution seconds" } + logger.info { "Average turnaround time: $turnaround seconds" } + } + + /** + * Closes this resource, relinquishing any underlying resources. + * This method is invoked automatically on objects managed by the + * `try`-with-resources statement. + * + * @throws Exception if this resource cannot be closed + */ + override fun close() = manager.close() +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperimentManager.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperimentManager.kt new file mode 100644 index 00000000..1d1e118d --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperimentManager.kt @@ -0,0 +1,93 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.platform + +import nl.atlarge.opendc.integration.jpa.transaction +import nl.atlarge.opendc.integration.jpa.schema.Experiment as InternalExperiment +import nl.atlarge.opendc.integration.jpa.schema.ExperimentState +import javax.persistence.EntityManager +import javax.persistence.EntityManagerFactory + +/** + * A manager for [Experiment]s received from a JPA database. + * + * @property factory The JPA entity manager factory to create [EntityManager]s to retrieve entities from the database + * from. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +class JpaExperimentManager(private val factory: EntityManagerFactory): AutoCloseable { + /** + * The entity manager for this experiment. + */ + private var manager: EntityManager = factory.createEntityManager() + + /** + * The amount of experiments in the queue. This property makes a call to the database and does therefore not + * run in O(1) time. + */ + val size: Int + get() { + return manager.createQuery("SELECT COUNT(e.id) FROM experiments e WHERE e.state = :s", + java.lang.Long::class.java) + .setParameter("s", ExperimentState.QUEUED) + .singleResult.toInt() + } + + /** + * Poll an [Experiment] from the database and claim it. + * + * @return The experiment that has been polled from the database or `null` if there are no experiments in the + * queue. + */ + fun poll(): JpaExperiment? { + var result: JpaExperiment? = null + manager.transaction { + var experiment: InternalExperiment? = null + val results = manager.createQuery("SELECT e FROM experiments e WHERE e.state = :s", + InternalExperiment::class.java) + .setParameter("s", ExperimentState.QUEUED) + .setMaxResults(1) + .resultList + + + if (!results.isEmpty()) { + experiment = results.first() + experiment!!.state = ExperimentState.CLAIMED + } + result = experiment?.let { JpaExperiment(manager, it) } + } + manager = factory.createEntityManager() + return result + } + + /** + * Close this resource, relinquishing any underlying resources. + * This method is invoked automatically on objects managed by the + * `try`-with-resources statement.* + * + * @throws Exception if this resource cannot be closed + */ + override fun close() = manager.close() +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/platform/JpaPlatformRunner.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/platform/JpaPlatformRunner.kt new file mode 100644 index 00000000..794ca44e --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/platform/JpaPlatformRunner.kt @@ -0,0 +1,64 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.platform + +import mu.KotlinLogging +import nl.atlarge.opendc.kernel.omega.OmegaKernel +import java.util.concurrent.Executors +import javax.persistence.Persistence + +val logger = KotlinLogging.logger {} + +/** + * The main entry point of the program. This program polls experiments from a database and runs the + * simulation and reports the results back to the database. + * + * @param args The command line arguments of the program. + */ +fun main(args: Array) { + val properties = HashMap() + val env = System.getenv() + properties["javax.persistence.jdbc.url"] = env["PERSISTENCE_URL"] ?: "" + properties["javax.persistence.jdbc.user"] = env["PERSISTENCE_USER"] ?: "" + properties["javax.persistence.jdbc.password"] = env["PERSISTENCE_PASSWORD"] ?: "" + val factory = Persistence.createEntityManagerFactory("opendc-simulator", properties) + + val threads = 4 + val executorService = Executors.newFixedThreadPool(threads) + val experiments = JpaExperimentManager(factory) + val kernel = OmegaKernel + + logger.info { "Waiting for enqueued experiments..." } + while (true) { + experiments.poll()?.let { experiment -> + logger.info { "Found experiment. Submitting for simulation now..." } + executorService.submit { + experiment.use { it.run(kernel) } + } + } + + Thread.sleep(500) + } +} diff --git a/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/topology/JpaTopologyFactory.kt b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/topology/JpaTopologyFactory.kt new file mode 100644 index 00000000..8def721e --- /dev/null +++ b/opendc-integration-jpa/core/src/main/kotlin/nl/atlarge/opendc/topology/JpaTopologyFactory.kt @@ -0,0 +1,87 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.topology + +import nl.atlarge.opendc.integration.jpa.schema.* + +/** + * A [TopologyFactory] that converts a [Section] of an experiment as defined by the API, into a proper [Topology]. + * + * @property section The section to convert into a topology. + * @property builder A builder for a topology to use. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +class JpaTopologyFactory(val section: Section, val builder: TopologyBuilder = AdjacencyList.builder()) : TopologyFactory { + /** + * Create a [MutableTopology] instance. + * + * @return A mutable topology. + */ + override fun create(): MutableTopology = builder.construct { + val datacenter = section.datacenter + add(datacenter) + datacenter.rooms.forEach { room -> + add(room) + connect(datacenter, room, tag = "room") + + room.objects.forEach { roomObject(room, it) } + } + } + + /** + * Handle the objects in a room. + * + * @param obj The obj to handle. + */ + private fun MutableTopology.roomObject(parent: Room, obj: RoomObject) = when(obj) { + is Rack -> rack(parent, obj) + else -> Unit + } + + /** + * Handle a rack in a room. + * + * @param parent The parent of the rack. + * @param rack The rack to handle. + */ + private fun MutableTopology.rack(parent: Room, rack: Rack) { + add(rack) + connect(parent, rack, tag = "rack") + rack.machines.forEach { machine -> + add(machine) + connect(rack, machine, tag = "machine") + + machine.cpus.forEach { cpu -> + add(cpu) + connect(machine, cpu, tag = "cpu") + } + + machine.gpus.forEach { gpu -> + add(gpu) + connect(machine, gpu, tag = "gpu") + } + } + } +} diff --git a/opendc-integration-jpa/core/src/main/resources/jpa/schema.xml b/opendc-integration-jpa/core/src/main/resources/jpa/schema.xml new file mode 100644 index 00000000..bd6ea7a1 --- /dev/null +++ b/opendc-integration-jpa/core/src/main/resources/jpa/schema.xml @@ -0,0 +1,324 @@ + + + + + nl.atlarge.opendc.integration.jpa.schema + + + + + + + + + + + + + STRING + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + STRING + + + + + + + + + + + + + + + + + + + + + RACK + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/opendc-integration-jpa/mysql/Dockerfile b/opendc-integration-jpa/mysql/Dockerfile new file mode 100644 index 00000000..75e419b4 --- /dev/null +++ b/opendc-integration-jpa/mysql/Dockerfile @@ -0,0 +1,30 @@ +# Docker mysql image for the OpenDC simulator project +# This image requires the context to be set to the root directory of the project in order to correctly build. +FROM gradle:alpine +MAINTAINER Fabian Mastenbroek + +# Set the home directory to our gradle user's home. +ENV HOME=/home/gradle +ENV APP_HOME=$HOME/simulator + +# Copy OpenDC simulator +COPY ./ $APP_HOME + +# Build as root +USER root + +# Set the working directory to the simulator +WORKDIR $APP_HOME + +# Build the application +RUN gradle --no-daemon :opendc-integration-jpa:mysql:installDist + +# Fix permissions +RUN chown -R gradle:gradle $APP_HOME + +# Downgrade user +USER gradle + +# Start the Gradle application on run +CMD opendc-integration-jpa/mysql/build/install/mysql/bin/mysql + diff --git a/opendc-integration-jpa/mysql/build.gradle b/opendc-integration-jpa/mysql/build.gradle new file mode 100644 index 00000000..c1cc6f58 --- /dev/null +++ b/opendc-integration-jpa/mysql/build.gradle @@ -0,0 +1,38 @@ +/* + * MIT License + * + * Copyright (c) 2017 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. + */ + +apply plugin: 'java' +apply plugin: 'application' +mainClassName = "nl.atlarge.opendc.platform.JpaPlatformRunnerKt" + +repositories { + jcenter() +} + +dependencies { + compile project(':opendc-integration-jpa:core') + runtime 'org.slf4j:slf4j-simple:1.7.25' + runtime 'org.hibernate:hibernate-core:5.2.5.Final' + runtime 'mysql:mysql-connector-java:5.1.13' +} diff --git a/opendc-integration-jpa/mysql/src/main/resources/META-INF/persistence.xml b/opendc-integration-jpa/mysql/src/main/resources/META-INF/persistence.xml new file mode 100644 index 00000000..0e40dc6e --- /dev/null +++ b/opendc-integration-jpa/mysql/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,41 @@ + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + jpa/schema.xml + + + + + + + + + diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/Jpa.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/Jpa.kt deleted file mode 100644 index cbbe280a..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/Jpa.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa - -import javax.persistence.EntityManager - -/** - * Run the given block in a transaction, committing on return of the block. - * - * @param block The block to execute in the transaction. - */ -inline fun EntityManager.transaction(block: () -> Unit) { - transaction.begin() - block() - transaction.commit() -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/ParallelizableConverter.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/ParallelizableConverter.kt deleted file mode 100644 index 11d5836e..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/ParallelizableConverter.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.converter - -import javax.persistence.AttributeConverter - -/** - * An internal [AttributeConverter] that maps the values _PARALLEL_ and _SEQUENTIAL_ to a - * boolean value indicating whether a task is parallelizable. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -class ParallelizableConverter : AttributeConverter { - /** - * Converts the data stored in the database column into the - * value to be stored in the entity attribute. - * Note that it is the responsibility of the converter writer to - * specify the correct dbData type for the corresponding column - * for use by the JDBC driver: i.e., persistence providers are - * not expected to do such type conversion. - * - * @param dbData the data from the database column to be converted - * @return the converted value to be stored in the entity attribute - */ - override fun convertToEntityAttribute(dbData: String?): Boolean = when(dbData?.toUpperCase()) { - "SEQUENTIAL" -> false - "PARALLEL" -> true - else -> false - } - - /** - * Converts the value stored in the entity attribute into the - * data representation to be stored in the database. - * - * @param attribute the entity attribute value to be converted - * @return the converted data to be stored in the database column - */ - override fun convertToDatabaseColumn(attribute: Boolean?): String = - if (attribute == true) "PARALLEL" else "SEQUENTIAL" -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/SchedulerConverter.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/SchedulerConverter.kt deleted file mode 100644 index 95027440..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/converter/SchedulerConverter.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.converter - -import nl.atlarge.opendc.platform.scheduler.FifoScheduler -import nl.atlarge.opendc.platform.scheduler.Scheduler -import nl.atlarge.opendc.platform.scheduler.SrtfScheduler -import javax.persistence.AttributeConverter - -/** - * An internal [AttributeConverter] that maps a name of a scheduler to the actual scheduler implementation. - * The converter currently chooses between the following two schedulers: - * - [FifoScheduler] (default) - * - [SrtfScheduler] - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -class SchedulerConverter : AttributeConverter { - /** - * Converts the data stored in the database column into the - * value to be stored in the entity attribute. - * Note that it is the responsibility of the converter writer to - * specify the correct dbData type for the corresponding column - * for use by the JDBC driver: i.e., persistence providers are - * not expected to do such type conversion. - * - * @param dbData the data from the database column to be converted - * @return the converted value to be stored in the entity attribute - */ - override fun convertToEntityAttribute(dbData: String?): Scheduler = when(dbData?.toUpperCase()) { - "SRTF" -> SrtfScheduler() - else -> FifoScheduler() - } - - /** - * Converts the value stored in the entity attribute into the - * data representation to be stored in the database. - * - * @param attribute the entity attribute value to be converted - * @return the converted data to be stored in the database column - */ - override fun convertToDatabaseColumn(attribute: Scheduler?): String = - attribute?.name?.toUpperCase() ?: "FIFO" -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Cpu.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Cpu.kt deleted file mode 100644 index b775eb6e..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Cpu.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import nl.atlarge.opendc.topology.machine.Cpu -import javax.persistence.Entity - -/** - * A cpu entity in the persistent schema. - * - * @property id The unique identifier of the cpu. - * @property manufacturer The manufacturer of the cpu. - * @property family The family of the cpu. - * @property generation The generation of the cpu. - * @property model The model of the cpu. - * @property clockRate The clock rate of the cpu. - * @property cores The amount of cores in the gpu. - * @property energyConsumption The energy consumption of the cpu in Watt. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -data class Cpu( - val id: Int, - val manufacturer: String, - val family: String, - val generation: String, - val model: String, - override val clockRate: Int, - override val cores: Int, - override val energyConsumption: Double -) : Cpu { - /** - * The initial state of the entity. - */ - override val initialState = Unit -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Datacenter.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Datacenter.kt deleted file mode 100644 index 1e6eaa2b..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Datacenter.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import nl.atlarge.opendc.kernel.time.Duration -import nl.atlarge.opendc.platform.scheduler.Scheduler -import nl.atlarge.opendc.topology.container.Datacenter -import javax.persistence.Entity - -/** - * A datacenter entity in the persistent schema. - * - * @property id The unique identifier of the datacenter. - * @property rooms The rooms in the datacenter. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -data class Datacenter( - val id: Int, - val rooms: Set -): Datacenter { - /** - * Construct a datacenter. We need this useless constructor in order for Kotlin correctly initialise the - * constant fields of the class. - */ - private constructor() : this(-1, emptySet()) - - /** - * The task scheduler the datacenter uses. - */ - override lateinit var scheduler: Scheduler - internal set - - /** - * The interval at which task will be (re)scheduled. - * We set this to a fixed constant since the database provides no way of configuring this. - */ - override val interval: Duration = 10 - - /** - * The initial state of the datacenter. - */ - override val initialState = Unit -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Experiment.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Experiment.kt deleted file mode 100644 index 0b352cb4..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Experiment.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import nl.atlarge.opendc.kernel.time.Instant -import nl.atlarge.opendc.platform.Experiment -import nl.atlarge.opendc.platform.scheduler.Scheduler -import nl.atlarge.opendc.platform.workload.Trace -import javax.persistence.Entity - -/** - * An experiment definition for the OpenDC database schema. - * - * @property id The identifier of the experiment. - * @property name The name of the experiment. - * @property scheduler The scheduler used in the experiment. - * @property trace The trace used for the simulation. - * @property path The path of the experiment. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -data class Experiment( - val id: Int, - val name: String, - val scheduler: Scheduler, - val trace: Trace, - val path: Path -) { - /** - * The state of the experiment. - */ - var state: ExperimentState = ExperimentState.QUEUED - - /** - * The last tick that has been simulated. - */ - var last: Instant = 0 -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/ExperimentState.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/ExperimentState.kt deleted file mode 100644 index 96fc112c..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/ExperimentState.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -/** - * Enumerations of the states an [Experiment] can assume. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -enum class ExperimentState { - /** - * This state indicates the experiment has been queued for simulation, but has not yet started. - */ - QUEUED, - - /** - * This state indicates the experiment has been claimed by a simulator for simulation, but - * not yet started. - */ - CLAIMED, - - /** - * This state indicates the experiment is currently in simulation. - */ - SIMULATING, - - /** - * This state indicates the experiment has finished simulating. - */ - FINISHED, -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Gpu.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Gpu.kt deleted file mode 100644 index 94625242..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Gpu.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import nl.atlarge.opendc.topology.machine.Gpu -import javax.persistence.Entity - -/** - * A gpu entity in the persistent schema. - * - * @property id The unique identifier of the gpu. - * @property manufacturer The manufacturer of the gpu. - * @property family The family of the gpu. - * @property generation The generation of the gpu. - * @property model The model of the gpu. - * @property clockRate The clock rate of the gpu. - * @property cores The amount of cores in the gpu. - * @property energyConsumption The energy consumption of the gpu in Watt. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -data class Gpu( - val id: Int, - val manufacturer: String, - val family: String, - val generation: String, - val model: String, - override val clockRate: Int, - override val cores: Int, - override val energyConsumption: Double -) : Gpu { - /** - * The initial state of the entity. - */ - override val initialState = Unit -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Job.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Job.kt deleted file mode 100644 index 394cf478..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Job.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import nl.atlarge.opendc.platform.workload.Job -import nl.atlarge.opendc.platform.workload.Task -import nl.atlarge.opendc.platform.workload.User -import javax.persistence.* - -/** - * A [Job] backed by the JPA API and an underlying database connection. - * - * @property id The unique identifier of the job. - * @property tasks The collection of tasks the job consists of. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -data class Job( - override val id: Int, - override val tasks: Set -) : Job { - /** - * The owner of the job, which is a singleton, since the database has no - * concept of ownership yet. - */ - override val owner: User = object : User { - /** - * The unique identifier of the user. - */ - override val id: Int = 0 - - /** - * The name of this user. - */ - override val name: String = "admin" - } -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Machine.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Machine.kt deleted file mode 100644 index 4071b342..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Machine.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import nl.atlarge.opendc.topology.machine.Machine -import javax.persistence.Entity - -/** - * A machine entity in the persistent schema. - * - * @property id The unique identifier of the machine. - * @property position The position of the machine in the rack. - * @property cpus The CPUs in the machine. - * @property gpus The GPUs in the machine. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -data class Machine( - val id: Int, - val position: Int, - val cpus: Set, - val gpus: Set -): Machine() diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/MachineState.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/MachineState.kt deleted file mode 100644 index 23efe888..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/MachineState.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import nl.atlarge.opendc.kernel.time.Instant -import javax.persistence.Entity - -/** - * The state of a [Machine]. - * - * @property id The unique identifier of the state. - * @property machine The machine of the state. - * @property task The task the machine has been assigned. - * @property experiment The experiment the machine is running in. - * @property time The current moment in time. - * @property temperature The temperature of the machine. - * @property memoryUsage The memory usage of the machine. - * @property load The load of the machine. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -data class MachineState( - val id: Int, - val machine: Machine, - val task: Task?, - val experiment: Experiment, - val time: Instant, - val temperature: Double, - val memoryUsage: Int, - val load: Double -) diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Path.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Path.kt deleted file mode 100644 index ccf3b6e8..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Path.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import javax.persistence.Entity - -/** - * A [Path] holds all sections of the parent experiment. - * - * @property id The unique identifier of the path. - * @property sections The sections of the path. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -open class Path( - val id: Int, - val sections: List
-) diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Rack.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Rack.kt deleted file mode 100644 index 2d2099a2..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Rack.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import nl.atlarge.opendc.topology.container.Rack -import javax.persistence.Entity - -/** - * A rack entity in a room in the persistent schema. - * - * @property id The unique identifier of the rack. - * @property name The name of the rack. - * @property capacity The capacity of the rack in terms of units. - * @property powerCapacity The power capacity of the rack in Watt. - * @property machines The machines in the rack. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -class Rack( - id: Int, - val name: String, - val capacity: Int, - val powerCapacity: Int, - val machines: List -): RoomObject(id), Rack { - /** - * The initial state of the entity. - */ - override val initialState = Unit -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Room.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Room.kt deleted file mode 100644 index f3b7ae06..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Room.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import nl.atlarge.opendc.topology.container.Room -import javax.persistence.Entity - -/** - * A room entity in the persistent schema. - * - * @property id The unique identifier of the room. - * @property name The name of the room. - * @property type The type of the room. - * @property objects The objects in the room. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -data class Room( - val id: Int, - val name: String, - val type: RoomType, - val objects: Set -): Room { - /** - * The initial state of the entity. - */ - override val initialState = Unit -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomObject.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomObject.kt deleted file mode 100644 index 0e9fb84f..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomObject.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import javax.persistence.Entity - -/** - * An object in a room. - * - * @property id The unique identifier of the room. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -abstract class RoomObject(val id: Int) diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomType.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomType.kt deleted file mode 100644 index 5e138947..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/RoomType.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -/** - * This enumeration defines the room types available in the OpenDC frontend. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -enum class RoomType { - COOLING, HALLWAY, OFFICE, POWER, SERVER -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Section.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Section.kt deleted file mode 100644 index e3b8c350..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Section.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import nl.atlarge.opendc.kernel.time.Instant -import javax.persistence.Entity - -/** - * A [Section] holds a datacenter and the tick on which the parent experiment should - * switch to this section. - * - * @property id The unique identifier of the section. - * @property datacenter The datacenter of this section. - * @property startTime The position in time when the experiment should start using the - * topology of this section. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -data class Section( - val id: Int, - val datacenter: Datacenter, - val startTime: Instant -) diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Task.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Task.kt deleted file mode 100644 index 83a98cfb..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Task.kt +++ /dev/null @@ -1,117 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import nl.atlarge.opendc.kernel.time.Instant -import nl.atlarge.opendc.platform.workload.Task -import nl.atlarge.opendc.platform.workload.TaskState -import javax.persistence.* - -/** - * A [Task] backed by the JPA API and an underlying database connection. - * - * @property id The unique identifier of the job. - * @property flops The total amount of flops for the task. - * @property dependency A dependency on another task. - * @property parallelizable A flag to indicate the task is parallelizable. - * @property startTime The start time in the simulation. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -data class Task( - override val id: Int, - override val flops: Long, - private val dependency: Task?, - override val parallelizable: Boolean, - val startTime: Instant -) : Task { - /** - * The dependencies of the task. - */ - override lateinit var dependencies: Set - private set - - /** - * The remaining flops for this task. - */ - override var remaining: Long = 0 - private set - - /** - * A flag to indicate whether the task has finished. - */ - override var finished: Boolean = false - private set - - /** - * The state of the task. - */ - override lateinit var state: TaskState - private set - - /** - * This method initialises the task object after it has been created by the JPA implementation. We use this - * initialisation method because JPA implementations only call the default constructor - */ - @PostLoad - internal fun init() { - remaining = flops - dependencies = dependency?.let(::setOf) ?: emptySet() - state = TaskState.Underway - } - - /** - * This method is invoked when a task has arrived at a datacenter. - * - * @param time The moment in time the task has arrived at the datacenter. - */ - override fun arrive(time: Instant) { - if (state !is TaskState.Underway) { - throw IllegalStateException("The task has already been submitted to a datacenter") - } - remaining = flops - state = TaskState.Queued(time) - } - - /** - * Consume the given amount of flops of this task. - * - * @param time The current moment in time of the consumption. - * @param flops The total amount of flops to consume. - */ - override fun consume(time: Instant, flops: Long) { - if (state is TaskState.Queued) { - state = TaskState.Running(state as TaskState.Queued, time) - } else if (finished) { - return - } - remaining -= flops - if (remaining <= 0) { - remaining = 0 - finished = true - state = TaskState.Finished(state as TaskState.Running, time) - } - } -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/TaskState.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/TaskState.kt deleted file mode 100644 index 14441752..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/TaskState.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import nl.atlarge.opendc.kernel.time.Instant -import javax.persistence.Entity - -/** - * The state of a [Task]. - * - * @property id The unique identifier of the state. - * @property task The task this is the state of. - * @property experiment The experiment the machine is running in. - * @property time The current moment in time. - * @property remaining The remaining flops for the task. - * @property cores The cores used for the task. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -data class TaskState( - val id: Int, - val task: Task, - val experiment: Experiment, - val time: Instant, - val remaining: Int, - val cores: Int -) diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Trace.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Trace.kt deleted file mode 100644 index cd3d9348..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/integration/jpa/schema/Trace.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.integration.jpa.schema - -import nl.atlarge.opendc.platform.workload.Job -import nl.atlarge.opendc.platform.workload.Trace -import javax.persistence.Entity - -/** - * A [Trace] backed by the JPA API and an underlying database connection. - * - * @property id The unique identifier of the trace. - * @property name The name of the trace. - * @property jobs The collection of jobs for this trace. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Entity -data class Trace( - val id: Int, - val name: String, - override val jobs: Set -) : Trace diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperiment.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperiment.kt deleted file mode 100644 index 59b28d0b..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperiment.kt +++ /dev/null @@ -1,176 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.platform - -import mu.KotlinLogging -import nl.atlarge.opendc.integration.jpa.schema.ExperimentState -import nl.atlarge.opendc.integration.jpa.schema.MachineState -import nl.atlarge.opendc.integration.jpa.transaction -import nl.atlarge.opendc.integration.jpa.schema.Trace as InternalTrace -import nl.atlarge.opendc.integration.jpa.schema.TaskState as InternalTaskState -import nl.atlarge.opendc.integration.jpa.schema.Experiment as InternalExperiment -import nl.atlarge.opendc.integration.jpa.schema.Task as InternalTask -import nl.atlarge.opendc.kernel.Kernel -import nl.atlarge.opendc.platform.workload.TaskState -import nl.atlarge.opendc.topology.JpaTopologyFactory -import nl.atlarge.opendc.topology.container.Rack -import nl.atlarge.opendc.topology.container.Room -import nl.atlarge.opendc.topology.destinations -import nl.atlarge.opendc.topology.machine.Machine -import java.util.* -import javax.persistence.EntityManager - -/** - * An [Experiment] backed by the JPA API and an underlying database connection. - * - * @property manager The entity manager for the database connection. - * @property experiment The internal experiment definition to use. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -class JpaExperiment(private val manager: EntityManager, - private val experiment: InternalExperiment): Experiment, AutoCloseable { - /** - * The logging instance. - */ - private val logger = KotlinLogging.logger {} - - /** - * Run the experiment on the specified simulation [Kernel]. - * - * @param kernel The simulation kernel to run the experiment. - * @throws IllegalStateException if the simulation is already running or finished. - */ - override fun run(kernel: Kernel) { - if (experiment.state != ExperimentState.CLAIMED) { - throw IllegalStateException("The experiment is in illegal state ${experiment.state}") - } - - // Set the simulation state - manager.transaction { - experiment.state = ExperimentState.SIMULATING - } - - val section = experiment.path.sections.first() - - // Important: initialise the scheduler of the datacenter - section.datacenter.scheduler = experiment.scheduler - - val topology = JpaTopologyFactory(section).create() - val simulation = kernel.create(topology) - val trace = experiment.trace - val tasks = trace.jobs.flatMap { it.tasks } - - logger.info { "Sending trace to kernel ${Objects.hashCode(trace)} ${(trace as InternalTrace).id}" } - - // Schedule all messages in the trace - tasks.forEach { task -> - if (task is InternalTask) { - simulation.schedule(task, section.datacenter, delay = task.startTime) - } else { - logger.warn { "Dropped invalid task $task" } - } - } - - // Find all machines in the datacenter - val machines = topology.run { - section.datacenter.outgoingEdges.destinations("room").asSequence() - .flatMap { it.outgoingEdges.destinations("rack").asSequence() } - .flatMap { it.outgoingEdges.destinations("machine").asSequence() }.toList() - } - - logger.info { "Starting simulation" } - - while (trace.jobs.any { !it.finished }) { - // Collect data of simulation cycle - manager.transaction { - experiment.last = simulation.clock.now - - machines.forEach { machine -> - val state = simulation.run { machine.state } - val wrapped = MachineState(0, - machine as nl.atlarge.opendc.integration.jpa.schema.Machine, - state.task as nl.atlarge.opendc.integration.jpa.schema.Task?, - experiment, - simulation.clock.now, - state.temperature, - state.memory, - state.load - ) - manager.persist(wrapped) - } - - trace.jobs.asSequence() - .flatMap { it.tasks.asSequence() } - .forEach { task -> - val state = InternalTaskState(0, - task as nl.atlarge.opendc.integration.jpa.schema.Task, - experiment, - simulation.clock.now, - task.remaining.toInt(), - 1 - ) - manager.persist(state) - } - } - - // Run next simulation cycle - simulation.run(simulation.clock.now + 1) - } - - // Set the experiment state - manager.transaction { - experiment.state = ExperimentState.FINISHED - } - - logger.info { "Simulation done" } - val waiting: Long = tasks.fold(0.toLong()) { acc, task -> - val finished = task.state as TaskState.Finished - acc + (finished.previous.at - finished.previous.previous.at) - } / tasks.size - - val execution: Long = tasks.fold(0.toLong()) { acc, task -> - val finished = task.state as TaskState.Finished - acc + (finished.at - finished.previous.at) - } / tasks.size - - val turnaround: Long = tasks.fold(0.toLong()) { acc, task -> - val finished = task.state as TaskState.Finished - acc + (finished.at - finished.previous.previous.at) - } / tasks.size - - logger.info { "Average waiting time: $waiting seconds" } - logger.info { "Average execution time: $execution seconds" } - logger.info { "Average turnaround time: $turnaround seconds" } - } - - /** - * Closes this resource, relinquishing any underlying resources. - * This method is invoked automatically on objects managed by the - * `try`-with-resources statement. - * - * @throws Exception if this resource cannot be closed - */ - override fun close() = manager.close() -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperimentManager.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperimentManager.kt deleted file mode 100644 index 1d1e118d..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/platform/JpaExperimentManager.kt +++ /dev/null @@ -1,93 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.platform - -import nl.atlarge.opendc.integration.jpa.transaction -import nl.atlarge.opendc.integration.jpa.schema.Experiment as InternalExperiment -import nl.atlarge.opendc.integration.jpa.schema.ExperimentState -import javax.persistence.EntityManager -import javax.persistence.EntityManagerFactory - -/** - * A manager for [Experiment]s received from a JPA database. - * - * @property factory The JPA entity manager factory to create [EntityManager]s to retrieve entities from the database - * from. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -class JpaExperimentManager(private val factory: EntityManagerFactory): AutoCloseable { - /** - * The entity manager for this experiment. - */ - private var manager: EntityManager = factory.createEntityManager() - - /** - * The amount of experiments in the queue. This property makes a call to the database and does therefore not - * run in O(1) time. - */ - val size: Int - get() { - return manager.createQuery("SELECT COUNT(e.id) FROM experiments e WHERE e.state = :s", - java.lang.Long::class.java) - .setParameter("s", ExperimentState.QUEUED) - .singleResult.toInt() - } - - /** - * Poll an [Experiment] from the database and claim it. - * - * @return The experiment that has been polled from the database or `null` if there are no experiments in the - * queue. - */ - fun poll(): JpaExperiment? { - var result: JpaExperiment? = null - manager.transaction { - var experiment: InternalExperiment? = null - val results = manager.createQuery("SELECT e FROM experiments e WHERE e.state = :s", - InternalExperiment::class.java) - .setParameter("s", ExperimentState.QUEUED) - .setMaxResults(1) - .resultList - - - if (!results.isEmpty()) { - experiment = results.first() - experiment!!.state = ExperimentState.CLAIMED - } - result = experiment?.let { JpaExperiment(manager, it) } - } - manager = factory.createEntityManager() - return result - } - - /** - * Close this resource, relinquishing any underlying resources. - * This method is invoked automatically on objects managed by the - * `try`-with-resources statement.* - * - * @throws Exception if this resource cannot be closed - */ - override fun close() = manager.close() -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/platform/JpaPlatformRunner.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/platform/JpaPlatformRunner.kt deleted file mode 100644 index 794ca44e..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/platform/JpaPlatformRunner.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.platform - -import mu.KotlinLogging -import nl.atlarge.opendc.kernel.omega.OmegaKernel -import java.util.concurrent.Executors -import javax.persistence.Persistence - -val logger = KotlinLogging.logger {} - -/** - * The main entry point of the program. This program polls experiments from a database and runs the - * simulation and reports the results back to the database. - * - * @param args The command line arguments of the program. - */ -fun main(args: Array) { - val properties = HashMap() - val env = System.getenv() - properties["javax.persistence.jdbc.url"] = env["PERSISTENCE_URL"] ?: "" - properties["javax.persistence.jdbc.user"] = env["PERSISTENCE_USER"] ?: "" - properties["javax.persistence.jdbc.password"] = env["PERSISTENCE_PASSWORD"] ?: "" - val factory = Persistence.createEntityManagerFactory("opendc-simulator", properties) - - val threads = 4 - val executorService = Executors.newFixedThreadPool(threads) - val experiments = JpaExperimentManager(factory) - val kernel = OmegaKernel - - logger.info { "Waiting for enqueued experiments..." } - while (true) { - experiments.poll()?.let { experiment -> - logger.info { "Found experiment. Submitting for simulation now..." } - executorService.submit { - experiment.use { it.run(kernel) } - } - } - - Thread.sleep(500) - } -} diff --git a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/topology/JpaTopologyFactory.kt b/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/topology/JpaTopologyFactory.kt deleted file mode 100644 index 8def721e..00000000 --- a/opendc-integration-jpa/src/main/kotlin/nl/atlarge/opendc/topology/JpaTopologyFactory.kt +++ /dev/null @@ -1,87 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.topology - -import nl.atlarge.opendc.integration.jpa.schema.* - -/** - * A [TopologyFactory] that converts a [Section] of an experiment as defined by the API, into a proper [Topology]. - * - * @property section The section to convert into a topology. - * @property builder A builder for a topology to use. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -class JpaTopologyFactory(val section: Section, val builder: TopologyBuilder = AdjacencyList.builder()) : TopologyFactory { - /** - * Create a [MutableTopology] instance. - * - * @return A mutable topology. - */ - override fun create(): MutableTopology = builder.construct { - val datacenter = section.datacenter - add(datacenter) - datacenter.rooms.forEach { room -> - add(room) - connect(datacenter, room, tag = "room") - - room.objects.forEach { roomObject(room, it) } - } - } - - /** - * Handle the objects in a room. - * - * @param obj The obj to handle. - */ - private fun MutableTopology.roomObject(parent: Room, obj: RoomObject) = when(obj) { - is Rack -> rack(parent, obj) - else -> Unit - } - - /** - * Handle a rack in a room. - * - * @param parent The parent of the rack. - * @param rack The rack to handle. - */ - private fun MutableTopology.rack(parent: Room, rack: Rack) { - add(rack) - connect(parent, rack, tag = "rack") - rack.machines.forEach { machine -> - add(machine) - connect(rack, machine, tag = "machine") - - machine.cpus.forEach { cpu -> - add(cpu) - connect(machine, cpu, tag = "cpu") - } - - machine.gpus.forEach { gpu -> - add(gpu) - connect(machine, gpu, tag = "gpu") - } - } - } -} diff --git a/opendc-integration-jpa/src/main/resources/META-INF/persistence.xml b/opendc-integration-jpa/src/main/resources/META-INF/persistence.xml deleted file mode 100644 index 311772f4..00000000 --- a/opendc-integration-jpa/src/main/resources/META-INF/persistence.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - org.hibernate.jpa.HibernatePersistenceProvider - jpa/schema.xml - - - - - - - - - - - - - diff --git a/opendc-integration-jpa/src/main/resources/jpa/schema.xml b/opendc-integration-jpa/src/main/resources/jpa/schema.xml deleted file mode 100644 index bd6ea7a1..00000000 --- a/opendc-integration-jpa/src/main/resources/jpa/schema.xml +++ /dev/null @@ -1,324 +0,0 @@ - - - - - nl.atlarge.opendc.integration.jpa.schema - - - - - - - - - - - - - STRING - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - STRING - - - - - - - - - - - - - - - - - - - - - RACK - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/settings.gradle b/settings.gradle index 0daac5d7..a92d3d2c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -26,4 +26,5 @@ rootProject.name = "opendc-simulator" include 'opendc-core' include 'opendc-omega' include 'opendc-stdlib' -include 'opendc-integration-jpa' +include 'opendc-integration-jpa:core' +include 'opendc-integration-jpa:mysql' -- cgit v1.2.3