-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2961d48
commit f802bd0
Showing
15 changed files
with
198 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
ApiWrapper/src/main/kotlin/org/readutf/orchestrator/wrapper/services/DockerService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.readutf.orchestrator.wrapper.services | ||
|
||
import org.readutf.orchestrator.shared.utils.ApiResponse | ||
import org.readutf.orchestrator.wrapper.types.ContainerPort | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface DockerService { | ||
@GET("/docker/port") | ||
suspend fun getPort( | ||
@Query("shortId") shortId: String, | ||
): ApiResponse<List<ContainerPort>> | ||
} |
2 changes: 1 addition & 1 deletion
2
...utf/orchestrator/wrapper/ServerService.kt → ...strator/wrapper/services/ServerService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
ApiWrapper/src/main/kotlin/org/readutf/orchestrator/wrapper/types/ContainerPort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.readutf.orchestrator.wrapper.types | ||
|
||
data class ContainerPort( | ||
val ip: String, | ||
val privatePort: Int, | ||
val publicPort: Int, | ||
val type: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 29 additions & 2 deletions
31
Server/src/main/kotlin/org/readutf/orchestrator/server/Test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
package org.readutf.orchestrator.server | ||
|
||
class Test { | ||
} | ||
import org.readutf.orchestrator.server.settings.ApiSettings | ||
import org.readutf.orchestrator.server.settings.DockerSettings | ||
import org.readutf.orchestrator.server.settings.ServerSettings | ||
import org.readutf.orchestrator.server.settings.Settings | ||
import java.net.URI | ||
|
||
fun main() { | ||
val settings = | ||
Settings( | ||
apiSettings = | ||
ApiSettings( | ||
host = "localhost", | ||
port = 9393, | ||
virtualThreads = true, | ||
), | ||
dockerSettings = | ||
DockerSettings( | ||
uri = URI("http://localhost:2375"), | ||
maxConnections = 100, | ||
responseTimeout = java.time.Duration.ofSeconds(10), | ||
connectionTimeout = java.time.Duration.ofSeconds(10), | ||
), | ||
serverSettings = | ||
ServerSettings( | ||
"localhost", | ||
port = 2980, | ||
), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Server/src/main/kotlin/org/readutf/orchestrator/server/api/endpoint/DockerEndpoint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.readutf.orchestrator.server.api.endpoint | ||
|
||
import io.javalin.community.routing.annotations.Endpoints | ||
import io.javalin.community.routing.annotations.Get | ||
import io.javalin.http.Context | ||
import org.readutf.orchestrator.server.docker.DockerManager | ||
import org.readutf.orchestrator.shared.utils.ApiResponse | ||
|
||
@Endpoints("/docker") | ||
class DockerEndpoint( | ||
val dockerManager: DockerManager, | ||
) { | ||
@Get("port") | ||
fun getPort( | ||
context: Context, | ||
shortId: String, | ||
) { | ||
val containerByShortId = dockerManager.getContainerByShortId(shortId) | ||
|
||
if (containerByShortId.isError()) { | ||
context.json(ApiResponse.failure<String>(containerByShortId.getError())) | ||
} | ||
|
||
context.json(ApiResponse.success(containerByShortId.get().getPorts())) | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
Server/src/main/kotlin/org/readutf/orchestrator/server/docker/DockerManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.readutf.orchestrator.server.docker | ||
|
||
import com.github.dockerjava.api.model.Container | ||
import com.github.dockerjava.core.DefaultDockerClientConfig | ||
import com.github.dockerjava.core.DockerClientConfig | ||
import com.github.dockerjava.core.DockerClientImpl | ||
import com.github.dockerjava.zerodep.ZerodepDockerHttpClient | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.readutf.orchestrator.server.settings.DockerSettings | ||
import org.readutf.orchestrator.shared.utils.Result | ||
import java.net.URI | ||
import java.time.Duration | ||
|
||
class DockerManager( | ||
dockerSettings: DockerSettings, | ||
) { | ||
private val logger = KotlinLogging.logger { } | ||
|
||
private var config: DockerClientConfig = | ||
DefaultDockerClientConfig | ||
.createDefaultConfigBuilder() | ||
.build() | ||
|
||
private val httpClient = | ||
ZerodepDockerHttpClient | ||
.Builder() | ||
.dockerHost(URI(dockerSettings.uri)) | ||
.maxConnections(dockerSettings.maxConnections) | ||
.connectionTimeout(Duration.ofSeconds(dockerSettings.connectionTimeout)) | ||
.responseTimeout(Duration.ofSeconds(dockerSettings.responseTimeout)) | ||
.build() | ||
|
||
private val dockerClient = DockerClientImpl.getInstance(config, httpClient) | ||
|
||
fun getContainerByShortId(shortId: String): Result<Container> { | ||
val containers = dockerClient.listContainersCmd().exec() | ||
|
||
val found = containers.filter { container -> container.id.startsWith(shortId) } | ||
|
||
if (found.isEmpty()) { | ||
return Result.error("Could not find container with id $shortId") | ||
} | ||
|
||
return Result.ok(found.first()) | ||
} | ||
} |
15 changes: 6 additions & 9 deletions
15
Server/src/main/kotlin/org/readutf/orchestrator/server/settings/DockerSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
package org.readutf.orchestrator.server.settings | ||
|
||
import java.net.URI | ||
import java.time.Duration | ||
|
||
object Docker { | ||
val URI = URI("tcp://localhost:2375") | ||
val maxConnections = 100 | ||
val responseTimeout: Duration = Duration.ofSeconds(15) | ||
val connectionTimeout: Duration = Duration.ofSeconds(15) | ||
} | ||
data class DockerSettings( | ||
val uri: String, | ||
val maxConnections: Int, | ||
val responseTimeout: Long, | ||
val connectionTimeout: Long, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
api-settings: | ||
api: | ||
host: localhost | ||
port: 9393 | ||
virtual-threads: false | ||
server-settings: | ||
server: | ||
host: localhost | ||
port: 2980 | ||
port: 2980 | ||
docker: | ||
uri: "tcp://localhost:2375" | ||
maxConnections: 100 | ||
responseTimeout: 30 | ||
connectionTimeout: 30 |