feat(mq): implement Apache Pulsar message queue admin

* feat(mq): implement Apache Pulsar message queue admin

- Add complete MQ admin adapter layer with version detection
  * Pulsar adapter with multi-version API support
  * OAuth2 token caching and authentication
  * JWT token signing for Pulsar clients
  * Transport layer (SSH/Proxy) integration

- Implement comprehensive admin operations
  * Tenant, namespace, topic management
  * Subscription and consumer/producer monitoring
  * Rate limits, backlog quotas, retention policies
  * Permissions and role-based access control
  * Raw admin API for advanced operations

- Add desktop UI components
  * MQ admin console with tabbed interface
  * Tenant, namespace, topic panels
  * Subscription management and cursor operations
  * Monitoring panel with stats visualization
  * Policy configuration UI

- Add web routes for MQ admin operations
- Add secret store support for MQ auth credentials
- Add comprehensive test coverage

* fix: del local test files

* fix(mq): mark message queue as unsupported mcpMode in driver manifest

MQ admin connections do not use the MCP query bridge - they use a
separate REST admin API. Mark mcpMode as 'unsupported' to align with
the test expectations and reflect the actual architecture.

Fixes CI test: driver-manifest.test.ts

* fix(mq): fix TypeScript errors in MQ components

- Fix typo in SubscriptionsPanel.vue: messagformatError(e)Id -> message.messageId
- Use formatError() helper in RawApiPanel.vue instead of accessing e?.message
- Fix undefined 'tab' reference in ConnectionTree.vue: use config.db_type instead

Fixes frontend CI TypeScript check errors.

* fix(mcp): add 'mq' to MCP server connection type description

The MCP server's connection type description must include all database
types from the driver manifest. Add 'mq' to the list to fix the test:
'add connection database type description includes every manifest database type'

Fixes: packages/mcp-server/tests/driver-manifest.test.ts

* fix(mq): add missing ConnectionConfig fields for Rust compilation

- Add gbase_server and keepalive_interval_secs fields to all ConnectionConfig
  test constructors in mq/config.rs, mq/service.rs, and storage.rs
- Import uses_bare_mysql_pool in connection.rs tests module

Fixes compilation errors from upstream ConnectionConfig changes.

* chore(ui): simplify Pulsar icon to logo-only version

Remove text from Pulsar icon (127x30 -> 35x30), keeping only
the wave logo symbol for a cleaner, more consistent appearance
with other database icons.

* fix(mq): return removed pools from drain_connection_pools

---------

Co-authored-by: t8y2 <1156263951@qq.com>
This commit is contained in:
miracleandt8y2 authored and GitHub committed 2026-06-16 21:57:17 +08:00
1 parent 8339d23df5
commit 2a59d3143e
83 files changed
+15979 -37

No files matched your search

+259 -5
View File
@@ -1,3 +1,4 @@
use std::collections::HashSet;
use std::sync::Arc;
use axum::extract::State;
@@ -50,6 +51,7 @@ pub async fn test_connection(
// Clean up any pool keys created for the temporary connection, including
// database-scoped keys like "__test_uuid:database".
app.remove_connection_pools(&temp_id).await;
app.reset_connection_transport_for_config(&temp_id, &config).await;
app.configs.write().await.remove(&temp_id);
match result {
@@ -66,6 +68,8 @@ pub async fn connect_db(
let app = &state.app;
let connection_id = config.id.clone();
app.remove_connection_pools(&connection_id).await;
app.reset_connection_transport_for_config(&connection_id, &config).await;
app.configs.write().await.insert(connection_id.clone(), config.clone());
app.get_or_create_pool(&connection_id, None).await.map_err(AppError)?;
@@ -120,26 +124,86 @@ pub async fn save_connections(
Json(body): Json<SaveConnectionsRequest>,
) -> Result<Json<()>, AppError> {
state.app.storage.save_connections(&body.configs).await.map_err(AppError)?;
cache_connection_configs(&state, &body.configs).await;
let sync = sync_connection_configs(&state, &body.configs).await;
remove_connection_pools_for_connection_ids(&state, &sync.connection_pool_ids_to_drop).await;
drop_mq_adapters_for_connection_ids(&state, &sync.mq_adapter_ids_to_drop).await;
Ok(Json(()))
}
pub async fn load_connections(State(state): State<Arc<WebState>>) -> Result<Json<Vec<ConnectionConfig>>, AppError> {
let configs = state.app.storage.load_connections().await.map_err(AppError)?;
cache_connection_configs(&state, &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_mq_adapters_for_connection_ids(&state, &sync.mq_adapter_ids_to_drop).await;
Ok(Json(configs))
}
async fn cache_connection_configs(state: &WebState, configs: &[ConnectionConfig]) {
struct ConnectionConfigSync {
mq_adapter_ids_to_drop: Vec<String>,
connection_pool_ids_to_drop: Vec<String>,
}
async fn sync_connection_configs(state: &WebState, configs: &[ConnectionConfig]) -> ConnectionConfigSync {
let saved_ids: HashSet<&str> = configs.iter().map(|config| config.id.as_str()).collect();
let mut mq_adapter_ids_to_drop = HashSet::new();
let mut connection_pool_ids_to_drop = HashSet::new();
let mut runtime_configs = state.app.configs.write().await;
runtime_configs.retain(|id, existing| {
if saved_ids.contains(id.as_str()) || is_transient_runtime_config_id(id) {
true
} else {
connection_pool_ids_to_drop.insert(id.clone());
if existing.db_type == dbx_core::models::connection::DatabaseType::MessageQueue {
mq_adapter_ids_to_drop.insert(id.clone());
}
false
}
});
for config in configs {
runtime_configs.insert(config.id.clone(), config.clone());
if config.db_type == dbx_core::models::connection::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 == dbx_core::models::connection::DatabaseType::MessageQueue {
mq_adapter_ids_to_drop.insert(config.id.clone());
}
if &previous != config {
connection_pool_ids_to_drop.insert(config.id.clone());
}
}
}
ConnectionConfigSync {
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(),
}
}
fn is_transient_runtime_config_id(id: &str) -> bool {
id.starts_with("__test_") || id.starts_with("__visible_draft_")
}
#[cfg(feature = "mq-admin")]
async fn drop_mq_adapters_for_connection_ids(state: &WebState, connection_ids: &[String]) {
for connection_id in connection_ids {
state.app.mq_registry.drop_connection(connection_id).await;
}
}
#[cfg(not(feature = "mq-admin"))]
async fn drop_mq_adapters_for_connection_ids(_state: &WebState, _connection_ids: &[String]) {}
async fn remove_connection_pools_for_connection_ids(state: &WebState, connection_ids: &[String]) {
for connection_id in connection_ids {
state.app.remove_connection_pools(connection_id).await;
}
}
#[cfg(test)]
mod tests {
use super::{disconnect_db, save_connections, DisconnectRequest, SaveConnectionsRequest};
use super::{
connect_db, disconnect_db, load_connections, save_connections, ConnectRequest, DisconnectRequest,
SaveConnectionsRequest,
};
use crate::state::{LoginRateLimit, WebState};
use axum::extract::State;
use axum::Json;
@@ -148,6 +212,8 @@ mod tests {
use dbx_core::storage::Storage;
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpListener;
use tokio::sync::{Mutex, RwLock};
fn sqlite_config(id: &str, path: &str) -> ConnectionConfig {
@@ -196,6 +262,19 @@ mod tests {
}
}
fn mq_config(id: &str, admin_url: &str) -> ConnectionConfig {
let mut config = sqlite_config(id, "");
config.name = "Pulsar".to_string();
config.db_type = DatabaseType::MessageQueue;
config.external_config = Some(serde_json::json!({
"systemKind": "pulsar",
"adminUrl": admin_url,
"auth": { "kind": "none" },
"pinnedVersion": "3.1"
}));
config
}
async fn test_web_state() -> (Arc<WebState>, std::path::PathBuf) {
let dir = std::env::temp_dir().join(format!("dbx-web-test-{}", uuid::Uuid::new_v4()));
std::fs::create_dir_all(&dir).unwrap();
@@ -215,6 +294,34 @@ mod tests {
(state, dir)
}
async fn spawn_pulsar_clusters_server() -> String {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();
tokio::spawn(async move {
loop {
let Ok((mut stream, _)) = listener.accept().await else {
break;
};
tokio::spawn(async move {
let mut buf = [0_u8; 1024];
let Ok(n) = stream.read(&mut buf).await else {
return;
};
let request = String::from_utf8_lossy(&buf[..n]);
let status =
if request.starts_with("GET /admin/v2/clusters ") { "200 OK" } else { "404 Not Found" };
let body = if status.starts_with("200") { r#"["ec-pulsar"]"# } else { r#"{"reason":"missing"}"# };
let response = format!(
"HTTP/1.1 {status}\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
body.len()
);
let _ = stream.write_all(response.as_bytes()).await;
});
}
});
format!("http://{addr}")
}
#[tokio::test]
async fn save_connections_updates_runtime_config_cache() {
let (state, dir) = test_web_state().await;
@@ -232,6 +339,133 @@ mod tests {
let _ = std::fs::remove_dir_all(dir);
}
#[tokio::test]
async fn save_connections_drops_cached_mq_adapter_for_updated_config() {
let (state, dir) = test_web_state().await;
let initial = mq_config("mq-conn", "http://127.0.0.1:8080");
state.app.configs.write().await.insert(initial.id.clone(), initial.clone());
state.app.connections.write().await.insert(initial.id.clone(), PoolKind::MessageQueue);
let first = state.app.mq_registry.get_or_build(&initial).await.unwrap();
let updated = mq_config("mq-conn", "http://127.0.0.1:8081");
let result =
save_connections(State(state.clone()), Json(SaveConnectionsRequest { configs: vec![updated.clone()] }))
.await;
assert!(result.is_ok());
let cached_admin_url = state
.app
.configs
.read()
.await
.get("mq-conn")
.and_then(|config| config.external_config.as_ref())
.and_then(|external| external.get("adminUrl"))
.and_then(serde_json::Value::as_str)
.map(str::to_string);
assert_eq!(cached_admin_url.as_deref(), Some("http://127.0.0.1:8081"));
let second = state.app.mq_registry.get_or_build(&updated).await.unwrap();
assert!(!Arc::ptr_eq(&first, &second));
assert!(!state.app.connections.read().await.contains_key(&initial.id));
let _ = std::fs::remove_dir_all(dir);
}
#[cfg(feature = "mq-admin")]
#[tokio::test]
async fn connect_db_rebuilds_mq_adapter_for_updated_config_with_same_id() {
let (state, dir) = test_web_state().await;
let initial = mq_config("mq-conn", "http://127.0.0.1:8080");
state.app.configs.write().await.insert(initial.id.clone(), initial.clone());
state.app.connections.write().await.insert(initial.id.clone(), PoolKind::MessageQueue);
let first = state.app.mq_registry.get_or_build(&initial).await.unwrap();
let updated = mq_config("mq-conn", &spawn_pulsar_clusters_server().await);
let result = connect_db(State(state.clone()), Json(ConnectRequest { config: updated.clone() })).await;
assert!(result.is_ok());
let second = state.app.mq_registry.get_or_build(&updated).await.unwrap();
assert!(!Arc::ptr_eq(&first, &second));
let _ = std::fs::remove_dir_all(dir);
}
#[tokio::test]
async fn load_connections_drops_cached_pool_for_updated_config() {
let (state, dir) = test_web_state().await;
let initial = mq_config("mq-conn", "http://127.0.0.1:8080");
let updated = mq_config("mq-conn", "http://127.0.0.1:8081");
state.app.storage.save_connections(&[updated.clone()]).await.unwrap();
state.app.configs.write().await.insert(initial.id.clone(), initial.clone());
state.app.connections.write().await.insert(initial.id.clone(), PoolKind::MessageQueue);
let result = load_connections(State(state.clone())).await;
assert!(result.is_ok());
let configs = state.app.configs.read().await;
let cached_admin_url = configs
.get("mq-conn")
.and_then(|config| config.external_config.as_ref())
.and_then(|external| external.get("adminUrl"))
.and_then(serde_json::Value::as_str);
assert_eq!(cached_admin_url, Some("http://127.0.0.1:8081"));
drop(configs);
assert!(!state.app.connections.read().await.contains_key(&initial.id));
let _ = std::fs::remove_dir_all(dir);
}
#[cfg(feature = "mq-admin")]
#[tokio::test]
async fn save_connections_removes_deleted_runtime_config_and_mq_adapter() {
let (state, dir) = test_web_state().await;
let kept = sqlite_config("kept", &dir.join("kept.db").to_string_lossy());
let removed = mq_config("removed-mq", "http://127.0.0.1:8080");
{
let mut configs = state.app.configs.write().await;
configs.insert(kept.id.clone(), kept.clone());
configs.insert(removed.id.clone(), removed.clone());
}
let stale = state.app.mq_registry.get_or_build(&removed).await.unwrap();
let result =
save_connections(State(state.clone()), Json(SaveConnectionsRequest { configs: vec![kept.clone()] })).await;
assert!(result.is_ok());
let configs = state.app.configs.read().await;
assert!(configs.contains_key("kept"));
assert!(!configs.contains_key("removed-mq"));
drop(configs);
let rebuilt = state.app.mq_registry.get_or_build(&removed).await.unwrap();
assert!(!Arc::ptr_eq(&stale, &rebuilt));
let _ = std::fs::remove_dir_all(dir);
}
#[cfg(feature = "mq-admin")]
#[tokio::test]
async fn save_connections_removes_deleted_connection_pools() {
let (state, dir) = test_web_state().await;
let kept = sqlite_config("kept", &dir.join("kept.db").to_string_lossy());
let removed = mq_config("removed-mq", "http://127.0.0.1:8080");
{
let mut configs = state.app.configs.write().await;
configs.insert(kept.id.clone(), kept.clone());
configs.insert(removed.id.clone(), removed.clone());
}
state.app.connections.write().await.insert(removed.id.clone(), PoolKind::MessageQueue);
let result =
save_connections(State(state.clone()), Json(SaveConnectionsRequest { configs: vec![kept.clone()] })).await;
assert!(result.is_ok());
assert!(!state.app.connections.read().await.contains_key(&removed.id));
let _ = std::fs::remove_dir_all(dir);
}
#[tokio::test]
async fn disconnect_db_keeps_connections_with_similar_prefixes() {
let (state, dir) = test_web_state().await;
@@ -285,6 +519,26 @@ mod tests {
let _ = std::fs::remove_dir_all(dir);
}
#[cfg(feature = "mq-admin")]
#[tokio::test]
async fn disconnect_db_drops_cached_mq_adapter() {
let (state, dir) = test_web_state().await;
let config = mq_config("mq-conn", "http://127.0.0.1:8080");
state.app.configs.write().await.insert(config.id.clone(), config.clone());
state.app.connections.write().await.insert(config.id.clone(), PoolKind::MessageQueue);
let first = state.app.mq_registry.get_or_build(&config).await.unwrap();
let result =
disconnect_db(State(state.clone()), Json(DisconnectRequest { connection_id: config.id.clone() })).await;
assert!(result.is_ok());
assert!(!state.app.connections.read().await.contains_key(&config.id));
let second = state.app.mq_registry.get_or_build(&config).await.unwrap();
assert!(!Arc::ptr_eq(&first, &second));
let _ = std::fs::remove_dir_all(dir);
}
#[tokio::test]
async fn disconnect_db_removes_visible_database_draft_config() {
let (state, dir) = test_web_state().await;
+2
View File
@@ -9,6 +9,8 @@ pub mod history;
pub mod jdbc;
pub mod layout;
pub mod mongo;
#[cfg(feature = "mq-admin")]
pub mod mq;
pub mod plugins;
pub mod query;
pub mod redis;
+711
View File
@@ -0,0 +1,711 @@
//! Web (Axum) routes for message queue admin operations.
//!
//! Mirrors the desktop command layer, sharing the same `dbx_core::mq::service::*_core`
//! functions, with read-only protection for mutating operations.
use axum::extract::State;
use axum::Json;
use std::sync::Arc;
use crate::error::AppError;
use crate::state::WebState;
// Request wrappers for endpoints that need more than just connection_id.
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ConnReq {
connection_id: String,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct TenantReq {
connection_id: String,
name: String,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct CreateTenantReq {
connection_id: String,
name: String,
config: dbx_core::mq::TenantConfig,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct UpdateTenantReq {
connection_id: String,
name: String,
config: dbx_core::mq::TenantConfig,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct DeleteTenantReq {
connection_id: String,
name: String,
#[serde(default)]
force: bool,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ListNamespacesReq {
connection_id: String,
tenant: String,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct CreateNamespaceReq {
connection_id: String,
ns: dbx_core::mq::NamespaceRef,
config: dbx_core::mq::NamespaceConfig,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct DeleteNamespaceReq {
connection_id: String,
ns: dbx_core::mq::NamespaceRef,
#[serde(default)]
force: bool,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct NamespacePoliciesReq {
connection_id: String,
ns: dbx_core::mq::NamespaceRef,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ListTopicsReq {
connection_id: String,
ns: dbx_core::mq::NamespaceRef,
opts: dbx_core::mq::ListTopicsOpts,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct CreateTopicReq {
connection_id: String,
topic: dbx_core::mq::TopicRef,
partitions: Option<u32>,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct DeleteTopicReq {
connection_id: String,
topic: dbx_core::mq::TopicRef,
#[serde(default)]
force: bool,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct UpdatePartitionsReq {
connection_id: String,
topic: dbx_core::mq::TopicRef,
partitions: u32,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct TopicReq {
connection_id: String,
topic: dbx_core::mq::TopicRef,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct CreateSubscriptionReq {
connection_id: String,
topic: dbx_core::mq::TopicRef,
sub: String,
pos: dbx_core::mq::ResetPosition,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct DeleteSubscriptionReq {
connection_id: String,
topic: dbx_core::mq::TopicRef,
sub: String,
#[serde(default)]
force: bool,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct SkipMessagesReq {
connection_id: String,
topic: dbx_core::mq::TopicRef,
sub: String,
count: dbx_core::mq::SkipCount,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ResetCursorReq {
connection_id: String,
topic: dbx_core::mq::TopicRef,
sub: String,
pos: dbx_core::mq::ResetPosition,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct SubscriptionReq {
connection_id: String,
topic: dbx_core::mq::TopicRef,
sub: String,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct PeekMessagesReq {
connection_id: String,
topic: dbx_core::mq::TopicRef,
sub: String,
count: u32,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ExpireMessagesReq {
connection_id: String,
topic: dbx_core::mq::TopicRef,
sub: String,
expire_seconds: i64,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct SetPublishRateReq {
connection_id: String,
scope: dbx_core::mq::PolicyScope,
rate: dbx_core::mq::PublishRate,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct SetDispatchRateReq {
connection_id: String,
scope: dbx_core::mq::PolicyScope,
rate: dbx_core::mq::DispatchRate,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct SetSubscribeRateReq {
connection_id: String,
scope: dbx_core::mq::PolicyScope,
rate: dbx_core::mq::SubscribeRate,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct SetBacklogQuotaReq {
connection_id: String,
scope: dbx_core::mq::PolicyScope,
quota: dbx_core::mq::BacklogQuota,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct SetRetentionReq {
connection_id: String,
scope: dbx_core::mq::PolicyScope,
retention: dbx_core::mq::RetentionPolicy,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct PolicyScopeReq {
connection_id: String,
scope: dbx_core::mq::PolicyScope,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct GrantPermissionReq {
connection_id: String,
scope: dbx_core::mq::PolicyScope,
role: String,
actions: Vec<dbx_core::mq::AuthAction>,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct RevokePermissionReq {
connection_id: String,
scope: dbx_core::mq::PolicyScope,
role: String,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct IssueTokenReq {
connection_id: String,
req: dbx_core::mq::MqTokenIssueRequest,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ListTokenRecordsReq {
connection_id: String,
subject: Option<String>,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct BacklogReq {
connection_id: String,
topic: dbx_core::mq::TopicRef,
sub: Option<String>,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct RawRequestReq {
connection_id: String,
req: dbx_core::mq::MqRawRequest,
}
// ---- Helper: writable check ----
async fn ensure_writable(app: &dbx_core::connection::AppState, conn_id: &str, action: &str) -> Result<(), AppError> {
if let Some(name) = dbx_core::query::connection_readonly_name(app, conn_id).await {
return Err(AppError(format!("Read-only connection '{name}'. {action} is blocked.")));
}
Ok(())
}
// ---- Handlers ----
pub async fn test_connection(
State(state): State<Arc<WebState>>,
Json(req): Json<ConnReq>,
) -> Result<Json<dbx_core::mq::MqClusterInfo>, AppError> {
let result =
dbx_core::mq::service::mq_test_connection_core(&state.app, &req.connection_id).await.map_err(AppError)?;
Ok(Json(result))
}
pub async fn list_tenants(
State(state): State<Arc<WebState>>,
Json(req): Json<ConnReq>,
) -> Result<Json<Vec<dbx_core::mq::TenantInfo>>, AppError> {
let result = dbx_core::mq::service::mq_list_tenants_core(&state.app, &req.connection_id).await.map_err(AppError)?;
Ok(Json(result))
}
pub async fn get_tenant(
State(state): State<Arc<WebState>>,
Json(req): Json<TenantReq>,
) -> Result<Json<dbx_core::mq::TenantInfo>, AppError> {
let result =
dbx_core::mq::service::mq_get_tenant_core(&state.app, &req.connection_id, &req.name).await.map_err(AppError)?;
Ok(Json(result))
}
pub async fn create_tenant(
State(state): State<Arc<WebState>>,
Json(req): Json<CreateTenantReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Create tenant").await?;
dbx_core::mq::service::mq_create_tenant_core(&state.app, &req.connection_id, &req.name, req.config)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn update_tenant(
State(state): State<Arc<WebState>>,
Json(req): Json<UpdateTenantReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Update tenant").await?;
dbx_core::mq::service::mq_update_tenant_core(&state.app, &req.connection_id, &req.name, req.config)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn delete_tenant(
State(state): State<Arc<WebState>>,
Json(req): Json<DeleteTenantReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Delete tenant").await?;
dbx_core::mq::service::mq_delete_tenant_core(&state.app, &req.connection_id, &req.name, req.force)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn list_namespaces(
State(state): State<Arc<WebState>>,
Json(req): Json<ListNamespacesReq>,
) -> Result<Json<Vec<dbx_core::mq::NamespaceInfo>>, AppError> {
let result = dbx_core::mq::service::mq_list_namespaces_core(&state.app, &req.connection_id, &req.tenant)
.await
.map_err(AppError)?;
Ok(Json(result))
}
pub async fn create_namespace(
State(state): State<Arc<WebState>>,
Json(req): Json<CreateNamespaceReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Create namespace").await?;
dbx_core::mq::service::mq_create_namespace_core(&state.app, &req.connection_id, req.ns, req.config)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn delete_namespace(
State(state): State<Arc<WebState>>,
Json(req): Json<DeleteNamespaceReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Delete namespace").await?;
dbx_core::mq::service::mq_delete_namespace_core(&state.app, &req.connection_id, req.ns, req.force)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn get_namespace_policies(
State(state): State<Arc<WebState>>,
Json(req): Json<NamespacePoliciesReq>,
) -> Result<Json<serde_json::Value>, AppError> {
let result = dbx_core::mq::service::mq_get_namespace_policies_core(&state.app, &req.connection_id, req.ns)
.await
.map_err(AppError)?;
Ok(Json(result))
}
pub async fn list_topics(
State(state): State<Arc<WebState>>,
Json(req): Json<ListTopicsReq>,
) -> Result<Json<Vec<dbx_core::mq::TopicInfo>>, AppError> {
let result = dbx_core::mq::service::mq_list_topics_core(&state.app, &req.connection_id, req.ns, req.opts)
.await
.map_err(AppError)?;
Ok(Json(result))
}
pub async fn create_topic(
State(state): State<Arc<WebState>>,
Json(req): Json<CreateTopicReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Create topic").await?;
dbx_core::mq::service::mq_create_topic_core(&state.app, &req.connection_id, req.topic, req.partitions)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn delete_topic(
State(state): State<Arc<WebState>>,
Json(req): Json<DeleteTopicReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Delete topic").await?;
dbx_core::mq::service::mq_delete_topic_core(&state.app, &req.connection_id, req.topic, req.force)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn update_partitions(
State(state): State<Arc<WebState>>,
Json(req): Json<UpdatePartitionsReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Update partitions").await?;
dbx_core::mq::service::mq_update_partitions_core(&state.app, &req.connection_id, req.topic, req.partitions)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn get_topic_stats(
State(state): State<Arc<WebState>>,
Json(req): Json<TopicReq>,
) -> Result<Json<dbx_core::mq::TopicStats>, AppError> {
let result = dbx_core::mq::service::mq_get_topic_stats_core(&state.app, &req.connection_id, req.topic)
.await
.map_err(AppError)?;
Ok(Json(result))
}
pub async fn get_topic_internal_stats(
State(state): State<Arc<WebState>>,
Json(req): Json<TopicReq>,
) -> Result<Json<serde_json::Value>, AppError> {
let result = dbx_core::mq::service::mq_get_topic_internal_stats_core(&state.app, &req.connection_id, req.topic)
.await
.map_err(AppError)?;
Ok(Json(result))
}
pub async fn list_subscriptions(
State(state): State<Arc<WebState>>,
Json(req): Json<TopicReq>,
) -> Result<Json<Vec<dbx_core::mq::SubscriptionInfo>>, AppError> {
let result = dbx_core::mq::service::mq_list_subscriptions_core(&state.app, &req.connection_id, req.topic)
.await
.map_err(AppError)?;
Ok(Json(result))
}
pub async fn create_subscription(
State(state): State<Arc<WebState>>,
Json(req): Json<CreateSubscriptionReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Create subscription").await?;
dbx_core::mq::service::mq_create_subscription_core(&state.app, &req.connection_id, req.topic, req.sub, req.pos)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn delete_subscription(
State(state): State<Arc<WebState>>,
Json(req): Json<DeleteSubscriptionReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Delete subscription").await?;
dbx_core::mq::service::mq_delete_subscription_core(&state.app, &req.connection_id, req.topic, req.sub, req.force)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn skip_messages(
State(state): State<Arc<WebState>>,
Json(req): Json<SkipMessagesReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Skip messages").await?;
dbx_core::mq::service::mq_skip_messages_core(&state.app, &req.connection_id, req.topic, req.sub, req.count)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn reset_cursor(
State(state): State<Arc<WebState>>,
Json(req): Json<ResetCursorReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Reset cursor").await?;
dbx_core::mq::service::mq_reset_cursor_core(&state.app, &req.connection_id, req.topic, req.sub, req.pos)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn clear_backlog(
State(state): State<Arc<WebState>>,
Json(req): Json<SubscriptionReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Clear backlog").await?;
dbx_core::mq::service::mq_clear_backlog_core(&state.app, &req.connection_id, req.topic, req.sub)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn peek_messages(
State(state): State<Arc<WebState>>,
Json(req): Json<PeekMessagesReq>,
) -> Result<Json<Vec<dbx_core::mq::PeekedMessage>>, AppError> {
let result =
dbx_core::mq::service::mq_peek_messages_core(&state.app, &req.connection_id, req.topic, req.sub, req.count)
.await
.map_err(AppError)?;
Ok(Json(result))
}
pub async fn expire_messages(
State(state): State<Arc<WebState>>,
Json(req): Json<ExpireMessagesReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Expire messages").await?;
dbx_core::mq::service::mq_expire_messages_core(
&state.app,
&req.connection_id,
req.topic,
req.sub,
req.expire_seconds,
)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn list_producers(
State(state): State<Arc<WebState>>,
Json(req): Json<TopicReq>,
) -> Result<Json<Vec<dbx_core::mq::ProducerInfo>>, AppError> {
let result = dbx_core::mq::service::mq_list_producers_core(&state.app, &req.connection_id, req.topic)
.await
.map_err(AppError)?;
Ok(Json(result))
}
pub async fn list_consumers(
State(state): State<Arc<WebState>>,
Json(req): Json<SubscriptionReq>,
) -> Result<Json<Vec<dbx_core::mq::ConsumerInfo>>, AppError> {
let result = dbx_core::mq::service::mq_list_consumers_core(&state.app, &req.connection_id, req.topic, req.sub)
.await
.map_err(AppError)?;
Ok(Json(result))
}
pub async fn unload_topic(State(state): State<Arc<WebState>>, Json(req): Json<TopicReq>) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Unload topic").await?;
dbx_core::mq::service::mq_unload_topic_core(&state.app, &req.connection_id, req.topic).await.map_err(AppError)?;
Ok(Json(()))
}
pub async fn set_publish_rate(
State(state): State<Arc<WebState>>,
Json(req): Json<SetPublishRateReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Set publish rate").await?;
dbx_core::mq::service::mq_set_publish_rate_core(&state.app, &req.connection_id, req.scope, req.rate)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn set_dispatch_rate(
State(state): State<Arc<WebState>>,
Json(req): Json<SetDispatchRateReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Set dispatch rate").await?;
dbx_core::mq::service::mq_set_dispatch_rate_core(&state.app, &req.connection_id, req.scope, req.rate)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn set_subscribe_rate(
State(state): State<Arc<WebState>>,
Json(req): Json<SetSubscribeRateReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Set subscribe rate").await?;
dbx_core::mq::service::mq_set_subscribe_rate_core(&state.app, &req.connection_id, req.scope, req.rate)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn set_backlog_quota(
State(state): State<Arc<WebState>>,
Json(req): Json<SetBacklogQuotaReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Set backlog quota").await?;
dbx_core::mq::service::mq_set_backlog_quota_core(&state.app, &req.connection_id, req.scope, req.quota)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn set_retention(
State(state): State<Arc<WebState>>,
Json(req): Json<SetRetentionReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Set retention").await?;
dbx_core::mq::service::mq_set_retention_core(&state.app, &req.connection_id, req.scope, req.retention)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn get_effective_policies(
State(state): State<Arc<WebState>>,
Json(req): Json<PolicyScopeReq>,
) -> Result<Json<serde_json::Value>, AppError> {
let result = dbx_core::mq::service::mq_get_effective_policies_core(&state.app, &req.connection_id, req.scope)
.await
.map_err(AppError)?;
Ok(Json(result))
}
pub async fn grant_permission(
State(state): State<Arc<WebState>>,
Json(req): Json<GrantPermissionReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Grant permission").await?;
dbx_core::mq::service::mq_grant_permission_core(&state.app, &req.connection_id, req.scope, req.role, req.actions)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn revoke_permission(
State(state): State<Arc<WebState>>,
Json(req): Json<RevokePermissionReq>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Revoke permission").await?;
dbx_core::mq::service::mq_revoke_permission_core(&state.app, &req.connection_id, req.scope, req.role)
.await
.map_err(AppError)?;
Ok(Json(()))
}
pub async fn list_permissions(
State(state): State<Arc<WebState>>,
Json(req): Json<PolicyScopeReq>,
) -> Result<Json<dbx_core::mq::PermissionMap>, AppError> {
let result = dbx_core::mq::service::mq_list_permissions_core(&state.app, &req.connection_id, req.scope)
.await
.map_err(AppError)?;
Ok(Json(result))
}
pub async fn issue_token(
State(state): State<Arc<WebState>>,
Json(req): Json<IssueTokenReq>,
) -> Result<Json<dbx_core::mq::MqIssuedToken>, AppError> {
ensure_writable(&state.app, &req.connection_id, "Issue MQ token").await?;
let result =
dbx_core::mq::service::mq_issue_token_core(&state.app, &req.connection_id, req.req).await.map_err(AppError)?;
Ok(Json(result))
}
pub async fn list_token_records(
State(state): State<Arc<WebState>>,
Json(req): Json<ListTokenRecordsReq>,
) -> Result<Json<Vec<dbx_core::mq::MqTokenRecord>>, AppError> {
let result = dbx_core::mq::service::mq_list_token_records_core(&state.app, &req.connection_id, req.subject)
.await
.map_err(AppError)?;
Ok(Json(result))
}
pub async fn get_backlog(
State(state): State<Arc<WebState>>,
Json(req): Json<BacklogReq>,
) -> Result<Json<dbx_core::mq::BacklogStats>, AppError> {
let result = dbx_core::mq::service::mq_get_backlog_core(&state.app, &req.connection_id, req.topic, req.sub)
.await
.map_err(AppError)?;
Ok(Json(result))
}
pub async fn raw_request(
State(state): State<Arc<WebState>>,
Json(req): Json<RawRequestReq>,
) -> Result<Json<dbx_core::mq::MqRawResponse>, AppError> {
if req.req.is_mutating() {
ensure_writable(&state.app, &req.connection_id, "MQ admin write").await?;
}
let result =
dbx_core::mq::service::mq_raw_request_core(&state.app, &req.connection_id, req.req).await.map_err(AppError)?;
Ok(Json(result))
}