pl.allegro.tech.servicemesh.envoycontrol.consul.services.ConsulLocalClusterStateChanges.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of envoy-control-source-consul Show documentation
Show all versions of envoy-control-source-consul Show documentation
Production-ready Control Plane for Service Mesh based on Envoy Proxy.
The newest version!
package pl.allegro.tech.servicemesh.envoycontrol.consul.services
import pl.allegro.tech.servicemesh.envoycontrol.services.LocalClusterStateChanges
import pl.allegro.tech.servicemesh.envoycontrol.services.Locality
import pl.allegro.tech.servicemesh.envoycontrol.services.ClusterState
import pl.allegro.tech.servicemesh.envoycontrol.services.MultiClusterState
import pl.allegro.tech.servicemesh.envoycontrol.services.MultiClusterState.Companion.toMultiClusterState
import pl.allegro.tech.servicemesh.envoycontrol.services.ServiceInstances
import pl.allegro.tech.servicemesh.envoycontrol.services.ServicesState
import pl.allegro.tech.servicemesh.envoycontrol.services.transformers.ServiceInstancesTransformer
import reactor.core.publisher.Flux
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicReference
class ConsulLocalClusterStateChanges(
private val consulChanges: ConsulServiceChanges,
private val locality: Locality,
private val cluster: String,
private val transformers: List = emptyList(),
override val latestServiceState: AtomicReference = AtomicReference(ServicesState())
) : LocalClusterStateChanges {
override fun stream(): Flux =
consulChanges
.watchState()
.map { state ->
transformers
.fold(state.allInstances().asSequence()) { instancesSequence, transformer ->
transformer.transform(instancesSequence)
}
.associateBy { it.serviceName }
.toConcurrentHashMap()
.let(::ServicesState)
}
.doOnNext { latestServiceState.set(it) }
.map {
ClusterState(it, locality, cluster).toMultiClusterState()
}
override fun isInitialStateLoaded(): Boolean = latestServiceState.get() != ServicesState()
private fun Map.toConcurrentHashMap() = ConcurrentHashMap(this)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy