Import upstream v0.16.22, stripped
Upstream commit: 474dd0229cb20cf513036619781ed97bd8073c3f Enterprise-only files removed or emptied: 63 Enterprise-only snippets removed: 117 in 50 files Dangling module declarations removed: 5 Cargo edits turning enterprise off: 14 Verification: clean Enterprise feature gates left for rebuilt features: 19 in 18 files Produced by tools/fork/strip.py. The full report is in docs/fork/strip-reports/ on main.
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use crate::Coordinator;
|
||||
use registry::schema::{prelude::ObjectType, structs};
|
||||
use store::{InMemoryStore, registry::bootstrap::Bootstrap};
|
||||
|
||||
#[allow(unreachable_patterns)]
|
||||
impl Coordinator {
|
||||
pub async fn build(bp: &mut Bootstrap, _in_memory: &InMemoryStore) -> Option<Self> {
|
||||
let result = match bp.setting_infallible::<structs::Coordinator>().await {
|
||||
structs::Coordinator::Disabled => Ok(Coordinator::None),
|
||||
#[cfg(feature = "redis")]
|
||||
structs::Coordinator::Default => {
|
||||
if let InMemoryStore::Redis(redis) = &_in_memory {
|
||||
Ok(Coordinator::Redis(redis.clone()))
|
||||
} else {
|
||||
Err(
|
||||
"Default coordinator requires Redis or Redis Cluster in-memory backend"
|
||||
.to_string(),
|
||||
)
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "kafka")]
|
||||
structs::Coordinator::Kafka(kafka_coordinator) => {
|
||||
crate::backend::kafka::KafkaPubSub::open(kafka_coordinator).await
|
||||
}
|
||||
#[cfg(feature = "nats")]
|
||||
structs::Coordinator::Nats(nats_coordinator) => {
|
||||
crate::backend::nats::NatsPubSub::open(nats_coordinator).await
|
||||
}
|
||||
#[cfg(feature = "zenoh")]
|
||||
structs::Coordinator::Zenoh(zenoh_coordinator) => {
|
||||
crate::backend::zenoh::ZenohPubSub::open(zenoh_coordinator).await
|
||||
}
|
||||
#[cfg(feature = "redis")]
|
||||
structs::Coordinator::Redis(redis_store) => {
|
||||
store::backend::redis::RedisStore::open_single(redis_store)
|
||||
.await
|
||||
.map(unwrap_redis)
|
||||
}
|
||||
#[cfg(feature = "redis")]
|
||||
structs::Coordinator::RedisCluster(redis_cluster_store) => {
|
||||
store::backend::redis::RedisStore::open_cluster(redis_cluster_store)
|
||||
.await
|
||||
.map(unwrap_redis)
|
||||
}
|
||||
#[cfg(feature = "redis")]
|
||||
structs::Coordinator::RedisSentinel(redis_sentinel_store) => {
|
||||
store::backend::redis::RedisStore::open_sentinel(redis_sentinel_store)
|
||||
.await
|
||||
.map(unwrap_redis)
|
||||
}
|
||||
_ => Err("Binary was not compiled with the selected coordinator backend".to_string()),
|
||||
};
|
||||
|
||||
match result {
|
||||
Ok(store) => Some(store),
|
||||
Err(err) => {
|
||||
bp.build_error(ObjectType::Coordinator.singleton(), err);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_enabled(&self) -> bool {
|
||||
!matches!(self, Coordinator::None)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "redis")]
|
||||
fn unwrap_redis(store: InMemoryStore) -> Coordinator {
|
||||
if let InMemoryStore::Redis(redis) = store {
|
||||
Coordinator::Redis(redis)
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user