All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.allegro.tech.servicemesh.envoycontrol.config.consul.ConsulConfig.kt Maven / Gradle / Ivy

There is a newer version: 0.22.4
Show newest version
package pl.allegro.tech.servicemesh.envoycontrol.config.consul

import java.io.File

sealed class ConsulConfig(
    val id: Int,
    val dc: String,
    val config: Map,
    val jsonFiles: List = listOf()
) {
    fun launchCommand(): String {
        val base = mapOf(
            "datacenter" to dc
        )

        return "consul agent " + (config + base).map { (key, value) -> format(key, value) }.joinToString(" ")
    }

    private fun format(key: String, value: String): String {
        return if (value.isEmpty()) "-$key" else "-$key=$value"
    }
}

val defaultConfig = mapOf(
    "data-dir" to "/data",
    "pid-file" to ConsulContainer.pidFile,
    "config-dir" to ConsulContainer.configDir,
    "bind" to "0.0.0.0",
    "client" to "0.0.0.0"
)

class ConsulClientConfig(id: Int, dc: String, serverAddress: String, jsonFiles: List = listOf()) : ConsulConfig(
    id,
    dc,
    defaultConfig + mapOf(
        "retry-join" to serverAddress,
        "node" to "consul-client-$id"
    ),
    jsonFiles
)

class ConsulServerConfig(id: Int, dc: String, expectNodes: Int = 3, jsonFiles: List = listOf()) : ConsulConfig(
    id,
    dc,
    defaultConfig + mapOf(
        "server" to "",
        "bootstrap-expect" to expectNodes.toString(),
        "ui" to "",
        "node" to "consul-server-$dc-$id"
    ),
    jsonFiles
)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy