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

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

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

import org.testcontainers.containers.Network
import org.testcontainers.junit.jupiter.Testcontainers
import pl.allegro.tech.servicemesh.envoycontrol.utils.Ports

@Testcontainers
class ConsulSetup(
    network: Network,
    consulConfig: ConsulConfig,
    val port: Int = Ports.nextAvailable()
) {
    val container: ConsulContainer = ConsulContainer(consulConfig.dc, port, consulConfig.id, consulConfig)
        .withNetwork(network)
    val operations = ConsulOperations(port)
}

class ConsulClusterSetup(val consulSetups: List) {
    val container = consulSetups.first()
    val operations = consulSetups.first().operations
    val port = consulSetups.first().port

    fun start() {
        consulSetups.forEach { consul ->
            consul.container.start()
        }
        consulSetups.forEach { consul ->
            val consulContainerNames = consulSetups.map { it.container.containerName() }.toTypedArray()
            val args = arrayOf("consul", "join", *consulContainerNames)
            consul.container.execInContainer(*args)
        }
    }

    fun joinWith(other: ConsulClusterSetup) {
        consulSetups.forEach { consul ->
            val consulInDc2ContainerNames = other.consulSetups.map { it.container.containerName() }.toTypedArray()
            val args = arrayOf("consul", "join", "-wan", *consulInDc2ContainerNames)
            consul.container.execInContainer(*args)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy