From 898e0bd8285e943d23d77ced6aa63fd81f41d003 Mon Sep 17 00:00:00 2001 From: fys <40801205+fengys1996@users.noreply.github.com> Date: Thu, 27 Mar 2025 17:00:51 +0800 Subject: [PATCH] chore: expose some methods (#5784) --- src/cmd/src/frontend.rs | 8 ++++++++ src/cmd/src/standalone.rs | 8 ++++++++ src/frontend/src/frontend.rs | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/src/cmd/src/frontend.rs b/src/cmd/src/frontend.rs index 5b10afa051..256c565eee 100644 --- a/src/cmd/src/frontend.rs +++ b/src/cmd/src/frontend.rs @@ -61,6 +61,14 @@ impl Instance { pub fn new(frontend: Frontend, _guard: Vec) -> Self { Self { frontend, _guard } } + + pub fn inner(&self) -> &Frontend { + &self.frontend + } + + pub fn mut_inner(&mut self) -> &mut Frontend { + &mut self.frontend + } } #[async_trait] diff --git a/src/cmd/src/standalone.rs b/src/cmd/src/standalone.rs index 57c21f2ca9..82ebf24a2d 100644 --- a/src/cmd/src/standalone.rs +++ b/src/cmd/src/standalone.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::net::SocketAddr; use std::sync::Arc; use std::{fs, path}; @@ -254,6 +255,13 @@ pub struct Instance { _guard: Vec, } +impl Instance { + /// Find the socket addr of a server by its `name`. + pub async fn server_addr(&self, name: &str) -> Option { + self.frontend.server_handlers().addr(name).await + } +} + #[async_trait] impl App for Instance { fn name(&self) -> &str { diff --git a/src/frontend/src/frontend.rs b/src/frontend/src/frontend.rs index 4f868b72fc..983550d0e7 100644 --- a/src/frontend/src/frontend.rs +++ b/src/frontend/src/frontend.rs @@ -131,6 +131,10 @@ impl Frontend { .await .context(error::ShutdownServerSnafu) } + + pub fn server_handlers(&self) -> &ServerHandlers { + &self.servers + } } #[cfg(test)]