feat(nacos): add Nacos management console (#1456)
This commit is contained in:
62 files changed
+7314
-55
No files matched your search
@@ -433,17 +433,20 @@ async fn save_connection_configs(state: &AppState, configs: &[ConnectionConfig])
|
||||
state.storage.save_connections(configs).await?;
|
||||
let sync = sync_connection_configs(state, configs).await;
|
||||
remove_connection_pools_for_connection_ids(state, &sync.connection_pool_ids_to_drop).await;
|
||||
drop_nacos_adapters_for_connection_ids(state, &sync.nacos_adapter_ids_to_drop).await;
|
||||
drop_mq_adapters_for_connection_ids(state, &sync.mq_adapter_ids_to_drop).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct ConnectionConfigSync {
|
||||
nacos_adapter_ids_to_drop: Vec<String>,
|
||||
mq_adapter_ids_to_drop: Vec<String>,
|
||||
connection_pool_ids_to_drop: Vec<String>,
|
||||
}
|
||||
|
||||
async fn sync_connection_configs(state: &AppState, configs: &[ConnectionConfig]) -> ConnectionConfigSync {
|
||||
let saved_ids: HashSet<&str> = configs.iter().map(|config| config.id.as_str()).collect();
|
||||
let mut nacos_adapter_ids_to_drop = HashSet::new();
|
||||
let mut mq_adapter_ids_to_drop = HashSet::new();
|
||||
let mut connection_pool_ids_to_drop = HashSet::new();
|
||||
let mut runtime_configs = state.configs.write().await;
|
||||
@@ -452,6 +455,9 @@ async fn sync_connection_configs(state: &AppState, configs: &[ConnectionConfig])
|
||||
true
|
||||
} else {
|
||||
connection_pool_ids_to_drop.insert(id.clone());
|
||||
if existing.db_type == DatabaseType::Nacos {
|
||||
nacos_adapter_ids_to_drop.insert(id.clone());
|
||||
}
|
||||
if existing.db_type == DatabaseType::MessageQueue {
|
||||
mq_adapter_ids_to_drop.insert(id.clone());
|
||||
}
|
||||
@@ -459,10 +465,16 @@ async fn sync_connection_configs(state: &AppState, configs: &[ConnectionConfig])
|
||||
}
|
||||
});
|
||||
for config in configs {
|
||||
if config.db_type == DatabaseType::Nacos {
|
||||
nacos_adapter_ids_to_drop.insert(config.id.clone());
|
||||
}
|
||||
if config.db_type == DatabaseType::MessageQueue {
|
||||
mq_adapter_ids_to_drop.insert(config.id.clone());
|
||||
}
|
||||
if let Some(previous) = runtime_configs.insert(config.id.clone(), config.clone()) {
|
||||
if previous.db_type == DatabaseType::Nacos {
|
||||
nacos_adapter_ids_to_drop.insert(config.id.clone());
|
||||
}
|
||||
if previous.db_type == DatabaseType::MessageQueue {
|
||||
mq_adapter_ids_to_drop.insert(config.id.clone());
|
||||
}
|
||||
@@ -472,6 +484,7 @@ async fn sync_connection_configs(state: &AppState, configs: &[ConnectionConfig])
|
||||
}
|
||||
}
|
||||
ConnectionConfigSync {
|
||||
nacos_adapter_ids_to_drop: nacos_adapter_ids_to_drop.into_iter().collect(),
|
||||
mq_adapter_ids_to_drop: mq_adapter_ids_to_drop.into_iter().collect(),
|
||||
connection_pool_ids_to_drop: connection_pool_ids_to_drop.into_iter().collect(),
|
||||
}
|
||||
@@ -481,6 +494,12 @@ fn is_transient_runtime_config_id(id: &str) -> bool {
|
||||
id.starts_with("__test_") || id.starts_with("__visible_draft_")
|
||||
}
|
||||
|
||||
async fn drop_nacos_adapters_for_connection_ids(state: &AppState, connection_ids: &[String]) {
|
||||
for connection_id in connection_ids {
|
||||
state.nacos_registry.drop_connection(connection_id).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "mq-admin")]
|
||||
async fn drop_mq_adapters_for_connection_ids(state: &AppState, connection_ids: &[String]) {
|
||||
for connection_id in connection_ids {
|
||||
@@ -507,6 +526,7 @@ async fn load_connection_configs(state: &AppState) -> Result<Vec<ConnectionConfi
|
||||
state.storage.load_connections().await?.into_iter().map(|config| config.canonicalized()).collect();
|
||||
let sync = sync_connection_configs(state, &configs).await;
|
||||
remove_connection_pools_for_connection_ids(state, &sync.connection_pool_ids_to_drop).await;
|
||||
drop_nacos_adapters_for_connection_ids(state, &sync.nacos_adapter_ids_to_drop).await;
|
||||
drop_mq_adapters_for_connection_ids(state, &sync.mq_adapter_ids_to_drop).await;
|
||||
Ok(configs)
|
||||
}
|
||||
@@ -762,6 +782,12 @@ pub async fn test_connection(state: State<'_, Arc<AppState>>, config: Connection
|
||||
.await
|
||||
.map(|_| "Connection successful".to_string())
|
||||
}
|
||||
DatabaseType::Nacos => {
|
||||
let admin_config = state.nacos_admin_config_for_connection(connection_id, &config).await?;
|
||||
let adapter = state.nacos_registry.build_transient_config(admin_config).await?;
|
||||
adapter.test_connection().await?;
|
||||
Ok("Connection successful".to_string())
|
||||
}
|
||||
#[cfg(feature = "mq-admin")]
|
||||
DatabaseType::MessageQueue => {
|
||||
let mqc = state.mq_admin_config_for_connection(connection_id, &config).await?;
|
||||
@@ -1028,6 +1054,12 @@ pub async fn connect_db(state: State<'_, Arc<AppState>>, config: ConnectionConfi
|
||||
db::influxdb_driver::test_connection(&client, connect_timeout).await?;
|
||||
PoolKind::InfluxDb(client)
|
||||
}
|
||||
DatabaseType::Nacos => {
|
||||
let admin_config = state.nacos_admin_config_for_connection(&id, &config).await?;
|
||||
let adapter = state.nacos_registry.build_transient_config(admin_config).await?;
|
||||
adapter.test_connection().await?;
|
||||
PoolKind::Nacos
|
||||
}
|
||||
#[cfg(feature = "mq-admin")]
|
||||
DatabaseType::MessageQueue => {
|
||||
let mqc = state.mq_admin_config_for_connection(&id, &config).await?;
|
||||
@@ -1080,6 +1112,7 @@ pub async fn connection_final_proxy_port(
|
||||
#[tauri::command]
|
||||
pub async fn disconnect_db(state: State<'_, Arc<AppState>>, connection_id: String) -> Result<(), String> {
|
||||
state.remove_connection_pools(&connection_id).await;
|
||||
drop_nacos_adapters_for_connection_ids(state.inner(), std::slice::from_ref(&connection_id)).await;
|
||||
drop_mq_adapters_for_connection_ids(state.inner(), std::slice::from_ref(&connection_id)).await;
|
||||
state.reset_connection_transport(&connection_id).await;
|
||||
if connection_id.starts_with("__visible_draft_") {
|
||||
|
||||
Reference in new issue
Block a user