Skip to content

Commit

Permalink
fix: 1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
utfunderscore committed Aug 29, 2024
1 parent 1892bad commit 7cb5e8c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ApiWrapper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies {
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0-RC.2")

api("com.squareup.retrofit2:retrofit:2.11.0")

api("com.squareup.okhttp3:logging-interceptor:4.11.0")
api("com.squareup.retrofit2:converter-jackson:2.11.0")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package org.readutf.orchestrator.wrapper
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.jetbrains.annotations.Blocking
import org.readutf.orchestrator.shared.server.Server
import org.readutf.orchestrator.shared.utils.ApiResponse
Expand All @@ -13,8 +15,7 @@ import org.readutf.orchestrator.wrapper.types.ContainerPort
import org.readutf.orchestrator.wrapper.types.NetworkAddress
import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory
import java.util.Base64
import java.util.UUID
import java.util.*

class OrchestratorApi(
hostname: String,
Expand All @@ -23,11 +24,7 @@ class OrchestratorApi(
private val requestClient by lazy { GameRequestClient("ws://$hostname:$port/game/request") }

private val retrofit: Retrofit =
Retrofit
.Builder()
.baseUrl("http://$hostname:$port")
.addConverterFactory(JacksonConverterFactory.create(objectMapper))
.build()
getRetrofit(hostname, port)

private val serverService by lazy { retrofit.create(ServerService::class.java) }
private val dockerService by lazy { retrofit.create(DockerService::class.java) }
Expand All @@ -43,6 +40,8 @@ class OrchestratorApi(
return objectMapper.readValue(json, object : TypeReference<ApiResponse<List<ContainerPort>>>() {})
}

suspend fun getIp(shortId: String): ApiResponse<List<NetworkAddress>> = dockerService.getIp(shortId)

suspend fun getNetworks(shortId: String): ApiResponse<List<NetworkAddress>> = dockerService.getIp(shortId)

suspend fun getServerByType(gameType: String): Result<List<Server>> =
Expand Down Expand Up @@ -81,6 +80,22 @@ class OrchestratorApi(
Result.error(e.message.toString())
}

private fun getRetrofit(
hostname: String,
port: Int,
): Retrofit {
val interceptor = HttpLoggingInterceptor()
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY)
val client: OkHttpClient = OkHttpClient.Builder().addInterceptor(interceptor).build()

return Retrofit
.Builder()
.baseUrl("http://$hostname:$port")
.addConverterFactory(JacksonConverterFactory.create(objectMapper))
.client(client)
.build()
}

companion object {
val objectMapper = ObjectMapper().registerKotlinModule()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package org.readutf.orchestrator.wrapper.types

data class NetworkAddress(
val network: String,
val ipAddress: String,
val ip: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class ApiTests {
}
}

@Test
fun testGetIp() {
runBlocking {
println(orchestratorApi.getIp("0f9d687a09ce"))
}
}

@Test
fun testGetServer() {
runBlocking {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class OrchestratorClient(
}
}

fun setAttribute(
key: String,
value: Any,
) {
serverManager?.setAttribute(key, value)
}

fun onDisconnect() {
if (!autoReconnect || reconnectAttempts >= maxReconnectAttempts) {
disconnect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package org.readutf.orchestrator.client.server

import org.readutf.orchestrator.client.network.NetworkManager
import org.readutf.orchestrator.shared.game.GameFinderType
import org.readutf.orchestrator.shared.packets.ServerAttributeUpdate
import org.readutf.orchestrator.shared.packets.ServerHeartbeatPacket
import org.readutf.orchestrator.shared.packets.ServerRegisterPacket
import org.readutf.orchestrator.shared.packets.ServerUnregisterPacket
import org.readutf.orchestrator.shared.server.Server
import org.readutf.orchestrator.shared.server.ServerAddress
import org.readutf.orchestrator.shared.server.ServerHeartbeat
import java.util.UUID
Expand All @@ -24,12 +24,10 @@ class ServerManager(
fun registerServer() {
networkManager.sendPacket(
ServerRegisterPacket(
Server(
serverId = serverId,
address = address,
gameTypes = gameTypes,
gameFinders = gameFinders,
),
serverId = serverId,
address = address,
gameTypes = gameTypes,
gameFinders = gameFinders,
),
)
}
Expand Down Expand Up @@ -67,4 +65,17 @@ class ServerManager(
fun shutdown() {
unregisterServer(serverId)
}

fun setAttribute(
key: String,
value: Any,
) {
networkManager.sendPacket(
ServerAttributeUpdate(
serverId,
key,
value,
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fun main() {
val dockerManager =
DockerManager(
DockerSettings(
uri = "tcp://localhost:2375",
uri = "tcp://0.0.0.0:2375",
maxConnections = 100,
responseTimeout = 30,
connectionTimeout = 30,
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = "org.readutf.orchestrator"
version = "1.6.3"
version = "1.7.1"

dependencies {
testImplementation(kotlin("test"))
Expand All @@ -17,7 +17,7 @@ repositories {
}
}

extra["hermesVersion"] = "1.6.0"
extra["hermesVersion"] = "1.6.3"
extra["nettyVersion"] = "4.1.111.Final"
extra["log4jVersion"] = "2.23.1"

Expand Down

0 comments on commit 7cb5e8c

Please sign in to comment.