summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-client
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-05-18 18:17:03 +0200
committerGitHub <noreply@github.com>2022-05-18 18:17:03 +0200
commit61b6550d7a476ab1aae45a5b9385dfd6ca4f6b6f (patch)
tree8632e8e26e409b6909a0bd90488356b1dcd70ba6 /opendc-web/opendc-web-client
parent00b5ee4bd423d8d9682a9ed9cd2af7c19a715459 (diff)
parentfb88cf197d9fe814e9692e7dafdc0d31b940acbc (diff)
merge: Add embedded experiment runner for dev mode (#87)
This pull request adds a new Quarkus extension that starts an embedded experiment runner while the user is in development mode. This allows users to deploy the entire OpenDC stack by using the `quarkusDev` command. By default, the experiment runner will only run experiments on one thread. Though, this setting is configurable. ## Implementation Notes :hammer_and_pick: * Use correct group for Gradle modules * Support client construction without AuthController * Move runner CLI into separate configuration * Remove module nesting in Quarkus extension * Add Quarkus extension for OpenDC runner * Add initial server distribution ## Breaking API Changes :warning: * N/A
Diffstat (limited to 'opendc-web/opendc-web-client')
-rw-r--r--opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/OpenDCClient.kt2
-rw-r--r--opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/runner/OpenDCRunnerClient.kt2
-rw-r--r--opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/transport/HttpTransportClient.kt46
3 files changed, 35 insertions, 15 deletions
diff --git a/opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/OpenDCClient.kt b/opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/OpenDCClient.kt
index 33f2b41e..a34c7864 100644
--- a/opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/OpenDCClient.kt
+++ b/opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/OpenDCClient.kt
@@ -39,7 +39,7 @@ public class OpenDCClient(client: TransportClient) {
* @param baseUrl The base url of the API.
* @param auth Helper class for managing authentication.
*/
- public constructor(baseUrl: URI, auth: AuthController) : this(HttpTransportClient(baseUrl, auth))
+ public constructor(baseUrl: URI, auth: AuthController? = null) : this(HttpTransportClient(baseUrl, auth))
/**
* A resource for the available projects.
diff --git a/opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/runner/OpenDCRunnerClient.kt b/opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/runner/OpenDCRunnerClient.kt
index a3cff6c3..e2112b8c 100644
--- a/opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/runner/OpenDCRunnerClient.kt
+++ b/opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/runner/OpenDCRunnerClient.kt
@@ -40,7 +40,7 @@ public class OpenDCRunnerClient(client: TransportClient) {
* @param baseUrl The base url of the API.
* @param auth Helper class for managing authentication.
*/
- public constructor(baseUrl: URI, auth: AuthController) : this(HttpTransportClient(baseUrl, auth))
+ public constructor(baseUrl: URI, auth: AuthController? = null) : this(HttpTransportClient(baseUrl, auth))
/**
* A resource for the available simulation jobs.
diff --git a/opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/transport/HttpTransportClient.kt b/opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/transport/HttpTransportClient.kt
index 03b3945f..e407380b 100644
--- a/opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/transport/HttpTransportClient.kt
+++ b/opendc-web/opendc-web-client/src/main/kotlin/org/opendc/web/client/transport/HttpTransportClient.kt
@@ -42,7 +42,7 @@ import java.nio.file.Paths
*/
public class HttpTransportClient(
private val baseUrl: URI,
- private val auth: AuthController,
+ private val auth: AuthController?,
private val client: HttpClient = HttpClient.newHttpClient()
) : TransportClient {
/**
@@ -58,15 +58,20 @@ public class HttpTransportClient(
override fun <T> get(path: String, targetType: TypeReference<T>): T? {
val request = HttpRequest.newBuilder(buildUri(path))
.GET()
- .also { auth.injectToken(it) }
+ .also { auth?.injectToken(it) }
.build()
val response = client.send(request, HttpResponse.BodyHandlers.ofInputStream())
return when (val code = response.statusCode()) {
in 200..299 -> mapper.readValue(response.body(), targetType)
401 -> {
- auth.refreshToken()
- get(path, targetType)
+ val auth = auth
+ if (auth != null) {
+ auth.refreshToken()
+ get(path, targetType)
+ } else {
+ throw IllegalStateException("Authorization required")
+ }
}
404 -> null
else -> throw IllegalStateException("Invalid response $code")
@@ -80,15 +85,20 @@ public class HttpTransportClient(
val request = HttpRequest.newBuilder(buildUri(path))
.POST(HttpRequest.BodyPublishers.ofByteArray(mapper.writeValueAsBytes(body)))
.header("Content-Type", "application/json")
- .also { auth.injectToken(it) }
+ .also { auth?.injectToken(it) }
.build()
val response = client.send(request, HttpResponse.BodyHandlers.ofInputStream())
return when (val code = response.statusCode()) {
in 200..299 -> mapper.readValue(response.body(), targetType)
401 -> {
- auth.refreshToken()
- post(path, body, targetType)
+ val auth = auth
+ if (auth != null) {
+ auth.refreshToken()
+ post(path, body, targetType)
+ } else {
+ throw IllegalStateException("Authorization required")
+ }
}
404 -> null
else -> throw IllegalStateException("Invalid response $code")
@@ -102,15 +112,20 @@ public class HttpTransportClient(
val request = HttpRequest.newBuilder(buildUri(path))
.PUT(HttpRequest.BodyPublishers.ofByteArray(mapper.writeValueAsBytes(body)))
.header("Content-Type", "application/json")
- .also { auth.injectToken(it) }
+ .also { auth?.injectToken(it) }
.build()
val response = client.send(request, HttpResponse.BodyHandlers.ofInputStream())
return when (val code = response.statusCode()) {
in 200..299 -> mapper.readValue(response.body(), targetType)
401 -> {
- auth.refreshToken()
- put(path, body, targetType)
+ val auth = auth
+ if (auth != null) {
+ auth.refreshToken()
+ put(path, body, targetType)
+ } else {
+ throw IllegalStateException("Authorization required")
+ }
}
404 -> null
else -> throw IllegalStateException("Invalid response $code")
@@ -123,15 +138,20 @@ public class HttpTransportClient(
override fun <T> delete(path: String, targetType: TypeReference<T>): T? {
val request = HttpRequest.newBuilder(buildUri(path))
.DELETE()
- .also { auth.injectToken(it) }
+ .also { auth?.injectToken(it) }
.build()
val response = client.send(request, HttpResponse.BodyHandlers.ofInputStream())
return when (val code = response.statusCode()) {
in 200..299 -> mapper.readValue(response.body(), targetType)
401 -> {
- auth.refreshToken()
- delete(path, targetType)
+ val auth = auth
+ if (auth != null) {
+ auth.refreshToken()
+ delete(path, targetType)
+ } else {
+ throw IllegalStateException("Authorization required")
+ }
}
404 -> null
else -> throw IllegalStateException("Invalid response $code")