Skip to content

Commit

Permalink
fix(agent): unregisterServer method map mismatch (jeremylvln#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylvln authored Jan 10, 2023
1 parent d20cedb commit b8a8d31
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ data class Configuration(
val proxyNamespace: String,
val proxyName: String,
val ttlSeconds: Long
)
) {
companion object {
fun load(): Configuration {
val proxyNamespace = System.getenv("SHULKER_PROXY_NAMESPACE")
?: throw IllegalStateException("No SHULKER_PROXY_NAMESPACE found in environment")

fun parse(): Configuration {
val proxyNamespace = System.getenv("SHULKER_PROXY_NAMESPACE")
?: throw IllegalStateException("No SHULKER_PROXY_NAMESPACE found in environment")
val proxyName = System.getenv("SHULKER_PROXY_NAME")
?: throw IllegalStateException("No SHULKER_PROXY_NAME found in environment")

val proxyName = System.getenv("SHULKER_PROXY_NAME")
?: throw IllegalStateException("No SHULKER_PROXY_NAME found in environment")
val ttlSecondsStr = System.getenv("SHULKER_PROXY_TTL_SECONDS")
?: throw IllegalStateException("No SHULKER_PROXY_TTL_SECONDS found in environment")
val ttlSeconds = ttlSecondsStr.toLong()

val ttlSecondsStr = System.getenv("SHULKER_PROXY_TTL_SECONDS")
?: throw IllegalStateException("No SHULKER_PROXY_TTL_SECONDS found in environment")
val ttlSeconds = ttlSecondsStr.toLong()

return Configuration(
proxyNamespace,
proxyName,
ttlSeconds
)
return Configuration(
proxyNamespace,
proxyName,
ttlSeconds
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ class ShulkerProxyAgentCommon(val proxyInterface: ProxyInterface, val logger: Lo

fun onProxyInitialization() {
try {
val config = parse()
val config = Configuration.load()

this.logger.info("Identified Shulker proxy: ${config.proxyNamespace}/${config.proxyName}")

val fileSystem = FileSystemAdapterImpl()
this.kubernetesGateway = KubernetesGatewayAdapterImpl(config.proxyNamespace, config.proxyName)

DrainFeature(this, fileSystem, kubernetesGateway!!, config.ttlSeconds)
DirectoryFeature(this, kubernetesGateway!!)
DrainFeature(this, fileSystem, this.kubernetesGateway!!, config.ttlSeconds)
DirectoryFeature(this, this.kubernetesGateway!!)
LimboFeature(this)

kubernetesGateway!!.emitAgentReady()
this.kubernetesGateway!!.emitAgentReady()
} catch (e: Exception) {
this.logger.severe("Failed to parse configuration")
e.printStackTrace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ class DirectoryAdapterImpl(
fun unregisterServer(name: ServerName) {
this.agent.logger.info("Unregistering server '$name' from directory")

if (this.serversByTag.containsKey(name)) {
val tags = this.tagsByServer[name]
if (tags != null) {
for (tag in tags) {
this.serversByTag[tag]!!.remove(name)
this.agent.logger.fine("Untagged '$tag' from server '${name}'")
}
val tags = this.tagsByServer[name]
if (tags != null) {
tags.forEach { tag ->
this.serversByTag[tag]!!.remove(name)
this.agent.logger.fine("Untagged '$tag' from server '${name}'")
}
this.tagsByServer.remove(name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ProxyInterfaceVelocity(
}

override fun addServerPreConnectHook(hook: ServerPreConnectHook) {
this.proxy.eventManager.register(plugin, ServerPreConnectEvent::class.java, PostOrder.LAST) { event ->
this.proxy.eventManager.register(this.plugin, ServerPreConnectEvent::class.java, PostOrder.LAST) { event ->
val result = hook(this.wrapPlayer(event.player), event.originalServer.serverInfo.name)

if (result.newServerName.isPresent)
Expand All @@ -45,7 +45,7 @@ class ProxyInterfaceVelocity(
}

override fun addPlayerPreLoginHook(hook: PlayerPreLoginHook) {
this.proxy.eventManager.register(plugin, PreLoginEvent::class.java, PostOrder.FIRST) { event ->
this.proxy.eventManager.register(this.plugin, PreLoginEvent::class.java, PostOrder.FIRST) { event ->
val result = hook()

if (!result.allowed)
Expand Down

0 comments on commit b8a8d31

Please sign in to comment.