-
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
0dfd5df
commit dc1191e
Showing
15 changed files
with
143 additions
and
29 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
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
6 changes: 6 additions & 0 deletions
6
ApiWrapper/src/main/kotlin/org/readutf/orchestrator/wrapper/types/NetworkAddress.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,6 @@ | ||
package org.readutf.orchestrator.wrapper.types | ||
|
||
data class NetworkAddress( | ||
val network: String, | ||
val ipAddress: 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
13 changes: 13 additions & 0 deletions
13
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,17 @@ | ||
package org.readutf.orchestrator.server | ||
|
||
import org.readutf.orchestrator.server.docker.DockerManager | ||
import org.readutf.orchestrator.server.settings.DockerSettings | ||
import java.util.* | ||
|
||
fun main() { | ||
val dockerManager = | ||
DockerManager( | ||
DockerSettings( | ||
uri = "tcp://localhost:2375", | ||
maxConnections = 100, | ||
responseTimeout = 30, | ||
connectionTimeout = 30, | ||
), | ||
) | ||
} |
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
25 changes: 13 additions & 12 deletions
25
Shared/src/main/kotlin/org/readutf/orchestrator/shared/server/Server.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,21 +1,22 @@ | ||
package org.readutf.orchestrator.shared.server | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo.As | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id | ||
import com.fasterxml.jackson.annotation.JsonIgnore | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import org.readutf.orchestrator.shared.game.GameFinderType | ||
import org.readutf.orchestrator.shared.utils.TypeWrapper | ||
import java.util.UUID | ||
|
||
open class Server( | ||
val serverId: UUID, | ||
val address: ServerAddress, | ||
val gameTypes: List<String>, | ||
val gameFinders: List<GameFinderType>, | ||
var heartbeat: ServerHeartbeat = ServerHeartbeat(serverId, System.currentTimeMillis()), | ||
@JsonTypeInfo(include = As.WRAPPER_OBJECT, use = Id.CLASS) var attributes: MutableMap<String, Any>, | ||
@JsonProperty("serverId") val serverId: UUID, | ||
@JsonProperty("address") val address: ServerAddress, | ||
@JsonProperty("gameTypes") val gameTypes: List<String>, | ||
@JsonProperty("gameFinders") val gameFinders: List<GameFinderType>, | ||
@JsonProperty("heartbeat") var heartbeat: ServerHeartbeat = ServerHeartbeat(serverId, System.currentTimeMillis()), | ||
@JsonProperty("attributes") var attributes: MutableMap<String, TypeWrapper>, | ||
) { | ||
override fun toString(): String = | ||
"Server(serverId=$serverId, address=$address, gameTypes=$gameTypes, gameFinders=$gameFinders, heartbeat=$heartbeat)" | ||
|
||
@JsonIgnore | ||
fun getShortId(): String = serverId.toString().substring(0, 8) | ||
|
||
override fun toString(): String = | ||
"Server(serverId=$serverId, address=$address, gameTypes=$gameTypes, gameFinders=$gameFinders, heartbeat=$heartbeat, attributes=$attributes)" | ||
} |
6 changes: 4 additions & 2 deletions
6
Shared/src/main/kotlin/org/readutf/orchestrator/shared/server/ServerAddress.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,8 +1,10 @@ | ||
package org.readutf.orchestrator.shared.server | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class ServerAddress( | ||
val host: String, | ||
val port: Int, | ||
@JsonProperty("host") val host: String, | ||
@JsonProperty("port") val port: Int, | ||
) { | ||
override fun toString(): String = "$host:$port" | ||
} |
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
14 changes: 14 additions & 0 deletions
14
Shared/src/main/kotlin/org/readutf/orchestrator/shared/utils/TypeWrapper.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,14 @@ | ||
package org.readutf.orchestrator.shared.utils | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize | ||
|
||
class TypeWrapper( | ||
data: Any, | ||
) { | ||
@JsonSerialize(using = TypeWrapperSerializer::class) | ||
@JsonDeserialize(using = TypeWrapperDeserializer::class) | ||
val data: Any = data | ||
|
||
override fun toString(): String = "TypeWrapper(data=$data)" | ||
} |
37 changes: 37 additions & 0 deletions
37
Shared/src/main/kotlin/org/readutf/orchestrator/shared/utils/TypeWrapperSerializer.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,37 @@ | ||
package org.readutf.orchestrator.shared.utils | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator | ||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.* | ||
|
||
class TypeWrapperSerializer : JsonSerializer<Any>() { | ||
override fun serialize( | ||
data: Any, | ||
generator: JsonGenerator, | ||
provider: SerializerProvider, | ||
) { | ||
generator.writeStartObject() | ||
generator.writeStringField("__type", data::class.java.canonicalName) | ||
generator.writeObjectField("data", data) | ||
generator.writeEndObject() | ||
} | ||
} | ||
|
||
class TypeWrapperDeserializer : JsonDeserializer<Any>() { | ||
override fun deserialize( | ||
parser: JsonParser, | ||
context: DeserializationContext, | ||
): Any { | ||
val node: JsonNode = parser.codec.readTree(parser) | ||
|
||
val type = Class.forName(node.get("__type").asText()) | ||
|
||
val rootNode = node.get("data") | ||
|
||
val jacksonType: JavaType = context.typeFactory.constructType(type) | ||
val deserializer: JsonDeserializer<*> = context.findRootValueDeserializer(jacksonType) | ||
val nodeParser: JsonParser = rootNode.traverse(context.parser.codec) | ||
nodeParser.nextToken() | ||
return deserializer.deserialize(nodeParser, context) | ||
} | ||
} |
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