diff options
| author | mjkwiatkowski <mati.rewa@gmail.com> | 2026-06-18 23:38:00 +0200 |
|---|---|---|
| committer | mjkwiatkowski <mati.rewa@gmail.com> | 2026-06-18 23:38:00 +0200 |
| commit | 54f94861da743cbd72d9755c2fbe4223176d90f4 (patch) | |
| tree | a4c2eddb01662e00a1c17514e9fb1218e8515efc /opendc-common/src | |
| parent | 4562f52c9b540944200b33d4ffbd60b3cbc5ee79 (diff) | |
feat: complete system redesign: KafkaComputeMonitor stays, SmartScheduler is working and only HTTPClient remains, the rest will be moved to Python scriptsHEADmaster
Diffstat (limited to 'opendc-common/src')
6 files changed, 0 insertions, 264 deletions
diff --git a/opendc-common/src/main/kotlin/org/opendc/common/annotations/Endpoint.kt b/opendc-common/src/main/kotlin/org/opendc/common/annotations/Endpoint.kt deleted file mode 100644 index 4ef08a71..00000000 --- a/opendc-common/src/main/kotlin/org/opendc/common/annotations/Endpoint.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.opendc.common.annotations - -@RequiresOptIn(message = "This is a registered API endpoint.") -@Retention(AnnotationRetention.BINARY) -@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.CONSTRUCTOR) -public annotation class Endpoint(val method: String, val name : String)
\ No newline at end of file diff --git a/opendc-common/src/main/kotlin/org/opendc/common/api/AssetsController.kt b/opendc-common/src/main/kotlin/org/opendc/common/api/AssetsController.kt deleted file mode 100644 index c6f34d19..00000000 --- a/opendc-common/src/main/kotlin/org/opendc/common/api/AssetsController.kt +++ /dev/null @@ -1,72 +0,0 @@ -package org.opendc.common.api - -import org.opendc.common.annotations.Endpoint -import io.javalin.http.Handler - -/** - * This class represents the `/assets` endpoint. - * - * @author Mateusz Kwiatkowski - * - * */ - - -//TODO: fix -> this is all wrong. -// Sending the experiment file is completely useless. -// You need to send tasks.parquet -public class AssetsController { - /** - * Returns a concatenated JSON string of all assets. - */ - @Endpoint("GET","/assets") - public fun getAssets() : Handler { - return Handler { ctx -> ctx.status(200) - println(ctx.body()) - } - } - - /** - * Returns an asset with `id` as a JSON string. - */ - @Endpoint("GET", "/assets/{id}") - public fun getAssetsId(): Handler { - return Handler { ctx -> ctx.status(200) } - } - - /** - * Saves the asset specified in the HTTP body. - * Returns the asset `id`. - */ - @Endpoint("POST", "/assets") - public fun postAsset() : Handler { - return Handler { ctx -> ctx.status(200) - println(ctx.body()) - } - } - - /** - * Modifies the specified asset. - * Deletes all results from experiments with this asset. - */ - @Endpoint("PUT", "/assets/{id}") - public fun putAssetId() : Handler { - return Handler { ctx -> ctx.status(200) } - } - - /** - * Deletes an asset with `id`. - * Deletes all results from experiments with this asset. - */ - @Endpoint("DELETE", "/assets/{id}") - public fun deleteAssetId() : Handler { - return Handler { ctx -> ctx.status(200) } - } - - /** - * Deletes all assets - */ - @Endpoint("DELETE", "/assets") - public fun deleteAsset() : Handler { - return Handler { ctx -> ctx.status(200) } - } -}
\ No newline at end of file diff --git a/opendc-common/src/main/kotlin/org/opendc/common/api/ResourceController.kt b/opendc-common/src/main/kotlin/org/opendc/common/api/ResourceController.kt deleted file mode 100644 index cf1d3cac..00000000 --- a/opendc-common/src/main/kotlin/org/opendc/common/api/ResourceController.kt +++ /dev/null @@ -1,30 +0,0 @@ -package org.opendc.common.api - -import org.opendc.common.annotations.Endpoint - -/** - * This class represents the `/resources` endpoint. - * - * @author Mateusz Kwiatkowski - * - * */ - -public class ResourceController { - - /** - * Returns all data analytics for all experiments. - */ - @Endpoint("GET", "/resources") - public fun getResources() { - return - } - - /** - * Returns data analytics for experiment with `id`. - * - * */ - @Endpoint("GET", "/resources") - public fun getResourcesId() { - return - } -}
\ No newline at end of file diff --git a/opendc-common/src/main/kotlin/org/opendc/common/utils/JavalinRunner.kt b/opendc-common/src/main/kotlin/org/opendc/common/utils/JavalinRunner.kt deleted file mode 100644 index 23baac27..00000000 --- a/opendc-common/src/main/kotlin/org/opendc/common/utils/JavalinRunner.kt +++ /dev/null @@ -1,33 +0,0 @@ -package org.opendc.common.utils - -import io.javalin.Javalin -import org.opendc.common.annotations.Endpoint -import org.opendc.common.api.AssetsController - -/** - * Represents the digital twin monitoring server. - * For endpoint documentation see `AssetsController`. - * @author Mateusz Kwiatkowski - * @see <a href=https://javalin.io/documentation>https://javalin.io/documentation</a> - * @see org.opendc.common.api.AssetsController - */ - -@OptIn(Endpoint::class) -public class JavalinRunner { - private val assetsController : AssetsController = AssetsController() - - init { - val app = Javalin.create().start() - app.get("/assets", assetsController.getAssets()) - - app.get("/assets/{id}", assetsController.getAssetsId()) - - app.post("/assets", assetsController.postAsset()) - - app.put("/assets/{id}", assetsController.putAssetId()) - - app.delete("/assets/{id}", assetsController.deleteAssetId()) - - app.delete("/assets", assetsController.deleteAsset()) - } -}
\ No newline at end of file diff --git a/opendc-common/src/main/kotlin/org/opendc/common/utils/PostgresqlDB.kt b/opendc-common/src/main/kotlin/org/opendc/common/utils/PostgresqlDB.kt deleted file mode 100644 index 35d03feb..00000000 --- a/opendc-common/src/main/kotlin/org/opendc/common/utils/PostgresqlDB.kt +++ /dev/null @@ -1,52 +0,0 @@ -package org.opendc.common.utils - -import com.fasterxml.jackson.dataformat.toml.TomlMapper -import java.sql.Connection -import java.sql.DriverManager -import java.sql.SQLException -import java.util.Properties -/** - * Represents the Postgresql database. - * On setup cleans the entire database. - * - * @author Mateusz Kwiatkowski - * - * @see <a href=https://docs.oracle.com/en/java/javase/21/docs/api/java.sql/java/sql/DriverManager.html> - * https://docs.oracle.com/en/java/javase/21/docs/api/java.sql/java/sql/DriverManager.html</a> - */ -@Suppress("DEPRECATION") -public class PostgresqlDB { - private var properties = Properties() - private var connection : Connection? = null - - init { - try { - properties = TomlMapper().readerFor(Properties().javaClass) - .readValue(PostgresqlDB::class.java.getResource("/database.toml")) - connection = DriverManager.getConnection( - properties.getProperty("address").asJdbc(properties.getProperty("database")), - properties.getProperty("user"), - properties.getProperty("password")) - clear() - } catch (e: SQLException) { - print("${e.message}") - } - } - public fun clear(){ - val DELETE_ALL_TABLES = """ - DROP SCHEMA public CASCADE; - CREATE SCHEMA public; - """.trimIndent() - try { - val st = connection?.createStatement() - st?.executeQuery(DELETE_ALL_TABLES) - } catch (e: SQLException){ - println("${e.message}") - } - } - - private fun String.asJdbc(database : String) : String { - return "jdbc:postgresql://$this/$database" - } - -}
\ No newline at end of file diff --git a/opendc-common/src/main/kotlin/org/opendc/common/utils/Redis.kt b/opendc-common/src/main/kotlin/org/opendc/common/utils/Redis.kt deleted file mode 100644 index bf674a33..00000000 --- a/opendc-common/src/main/kotlin/org/opendc/common/utils/Redis.kt +++ /dev/null @@ -1,71 +0,0 @@ -package org.opendc.common.utils - -import com.fasterxml.jackson.dataformat.toml.TomlMapper -import redis.clients.jedis.RedisClient -import redis.clients.jedis.StreamEntryID -import redis.clients.jedis.params.XReadParams -import java.util.Map -import java.util.Properties - - -/** - * This class represents the Redis server instance. - * @author Mateusz Kwiatkowski - * @see <a href=https://redis.io/docs/latest/>https://redis.io/docs/latest/</a> - * - * @see <a href=https://redis.io/docs/latest/develop/data-types/streams/>https://redis.io/docs/latest/develop/data-types/streams/</a> - * - * @see <a href=https://www.javadoc.io/doc/redis.clients/jedis/latest/index.html>https://www.javadoc.io/doc/redis.clients/jedis/latest/index.html</a> - */ - -@Suppress("DEPRECATION") -public class Redis private constructor() { - private var jedis : RedisClient? = null - private var properties : Properties? = null - - init { - properties = TomlMapper().readerFor(Properties().javaClass).readValue(Kafka::class.java.getResource("/subscriber.toml")) - jedis = RedisClient.create("redis://localhost:${properties?.getProperty("port")}") - } - - public companion object { - private var instance: Redis? = null - - public fun getInstance(): Redis? { - if (instance == null) { - instance = Redis() - } - return instance - } - } - - public fun readOne() { - while(true) { - val messages = jedis?.xread( - XReadParams.xReadParams(), - Map.of("${properties?.getProperty("table")}", StreamEntryID() - )); - - if (messages != null) { - for (stream in messages) { - for (entry in stream.value) { - if(entry.getFields().get("downtime") != null) { - entry.getFields().get("downtime")?.toDouble()?.let { - if (it > 0) { - println("ID: " + entry.getID()) - } - } - } - } - } - } - } - // https://redis.io/docs/latest/develop/use-cases/streaming/java-jedis/ - // In Redis you can subscribe to updates to a stream. - // You should base your application off this. - // You can listen for new items with XREAD - - // do not close for now - //jedis.close() - } -} |
