public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: Lukas Wagner <l.wagner@proxmox.com>, pdm-devel@lists.proxmox.com
Subject: Re: [PATCH datacenter-manager v2 12/20] parallel fetcher: support a custom client factory
Date: Mon, 24 Aug 2026 14:33:39 +0200	[thread overview]
Message-ID: <a6ff965b-fd46-4007-822b-8b29a1111f28@proxmox.com> (raw)
In-Reply-To: <20260820145220.418032-13-l.wagner@proxmox.com>

just a question:

wouldn't it be more future-proof if we always give a
a PdmApplication to the parallel fetcher and extract
the client factory from there?

no way to forget it that way...

would probably mean that the commit comes later,
after we introduce the pdmapplication state in every
api call that uses a parallel fetcher..

On 8/20/26 4:52 PM, Lukas Wagner wrote:
> Add a client_factory() builder method and thread the resulting handle
> through fetch_remote/fetch_node, defaulting to the client factory of
> the current PdmApplication when none is set explicitly. This lets
> callers, and later tests, supply a fake client factory instead of
> always going through the real one.
> 
> Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
> ---
>   server/src/parallel_fetcher.rs | 34 ++++++++++++++++++++++++++++++++--
>   1 file changed, 32 insertions(+), 2 deletions(-)
> 
> diff --git a/server/src/parallel_fetcher.rs b/server/src/parallel_fetcher.rs
> index 0819eb86..74ba91b3 100644
> --- a/server/src/parallel_fetcher.rs
> +++ b/server/src/parallel_fetcher.rs
> @@ -73,7 +73,8 @@ use pve_api_types::ClusterNodeIndexResponse;
>   
>   use pdm_api_types::remotes::{Remote, RemoteType};
>   
> -use crate::connection;
> +use crate::connection::ClientFactory;
> +use crate::context;
>   
>   /// Maximum number of parallel outgoing API requests.
>   pub const DEFAULT_MAX_CONNECTIONS: usize = 20;
> @@ -229,6 +230,7 @@ impl<T> NodeResponse<T> {
>   pub struct ParallelFetcherBuilder<C> {
>       max_connections: Option<usize>,
>       max_connections_per_remote: Option<usize>,
> +    client_factory: Option<Arc<dyn ClientFactory + Send + Sync>>,
>       context: C,
>   }
>   
> @@ -238,6 +240,7 @@ impl<C> ParallelFetcherBuilder<C> {
>               context,
>               max_connections: None,
>               max_connections_per_remote: None,
> +            client_factory: None,
>           }
>       }
>   
> @@ -255,6 +258,12 @@ impl<C> ParallelFetcherBuilder<C> {
>           self
>       }
>   
> +    /// Set the client factory that should be used.
> +    pub fn client_factory(mut self, client_factory: Arc<dyn ClientFactory + Send + Sync>) -> Self {
> +        self.client_factory = Some(client_factory);
> +        self
> +    }
> +
>       /// Build the [`ParallelFetcher`] instance.
>       pub fn build(self) -> ParallelFetcher<C> {
>           ParallelFetcher {
> @@ -262,6 +271,9 @@ impl<C> ParallelFetcherBuilder<C> {
>               max_connections_per_remote: self
>                   .max_connections_per_remote
>                   .unwrap_or(DEFAULT_MAX_CONNECTIONS_PER_REMOTE),
> +            client_factory: self
> +                .client_factory
> +                .unwrap_or_else(|| context::pdm_application().client_factory_shared()),
>               context: self.context,
>           }
>       }
> @@ -279,12 +291,15 @@ pub struct ParallelFetcherArgs<C> {
>       /// The node. This may be 'localhost' for PBS remotes or if using
>       /// [`ParallelFetcher::do_for_all_remotes`].
>       pub node: String,
> +    /// A handle to the client factory.
> +    pub client_factory: Arc<dyn ClientFactory + Send + Sync>,
>   }
>   
>   /// Helper for parallelizing API requests to multiple remotes/nodes.
>   pub struct ParallelFetcher<C> {
>       max_connections: usize,
>       max_connections_per_remote: usize,
> +    client_factory: Arc<dyn ClientFactory + Send + Sync>,
>       context: C,
>   }
>   
> @@ -318,13 +333,16 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
>           for remote in remotes {
>               let semaphore = Arc::clone(&total_connections_semaphore);
>   
> +            let client_factory = Arc::clone(&self.client_factory);
>               let f = func.clone();
> +
>               let future = Self::fetch_remote(
>                   remote,
>                   self.context.clone(),
>                   semaphore,
>                   f,
>                   self.max_connections_per_remote,
> +                client_factory,
>               );
>   
>               if let Some(log_context) = LogContext::current() {
> @@ -356,6 +374,7 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
>           semaphore: Arc<Semaphore>,
>           func: F,
>           max_connections_per_remote: usize,
> +        client_factory: Arc<dyn ClientFactory + Send + Sync>,
>       ) -> RemoteResponse<MultipleNodesResponse<T>>
>       where
>           F: Fn(ParallelFetcherArgs<C>) -> Ft + Clone + Send + 'static,
> @@ -371,8 +390,10 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
>               RemoteType::Pve => {
>                   let remote_clone = remote.clone();
>   
> +                let cf = Arc::clone(&client_factory);
> +
>                   let nodes = match async move {
> -                    let client = connection::make_pve_client(&remote_clone)?;
> +                    let client = cf.make_pve_client(&remote_clone)?;
>                       let nodes = client.list_nodes().await?;
>   
>                       Ok::<Vec<ClusterNodeIndexResponse>, Error>(nodes)
> @@ -407,12 +428,14 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
>                       let remote_clone = remote.clone();
>                       let node_name = node.node.clone();
>                       let context_clone = context.clone();
> +                    let client_factory = Arc::clone(&client_factory);
>   
>                       let future = Self::fetch_node(
>                           func_clone,
>                           context_clone,
>                           remote_clone,
>                           node_name,
> +                        client_factory,
>                           permit,
>                           Some(per_remote_connections_permit),
>                       );
> @@ -441,6 +464,7 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
>                       context,
>                       remote.clone(),
>                       "localhost".into(),
> +                    client_factory,
>                       permit.unwrap(), // Always set to `Some` at this point
>                       None,
>                   )
> @@ -464,6 +488,7 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
>           context: C,
>           remote: Remote,
>           node: String,
> +        client_factory: Arc<dyn ClientFactory + Send + Sync>,
>           _permit: OwnedSemaphorePermit,
>           _per_remote_connections_permit: Option<OwnedSemaphorePermit>,
>       ) -> NodeResponse<T>
> @@ -478,6 +503,7 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
>               context,
>               remote,
>               node: node.clone(),
> +            client_factory,
>           };
>   
>           let result = func(parallel_fetcher_context).await;
> @@ -514,6 +540,9 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
>   
>               let context = self.context.clone();
>               let func = func.clone();
> +
> +            let client_factory = Arc::clone(&self.client_factory);
> +
>               let future = async move {
>                   let permit = total_connections_semaphore.acquire_owned().await.unwrap();
>   
> @@ -525,6 +554,7 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
>                           context,
>                           remote,
>                           "localhost".into(),
> +                        client_factory,
>                           permit,
>                           None,
>                       )





  reply	other threads:[~2026-08-24 12:33 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-20 14:52 [PATCH datacenter-manager/proxmox v2 00/20] inject application context via API macro for easier integration testing Lukas Wagner
2026-08-20 14:52 ` [PATCH proxmox v2 01/20] router: introduce shared state Lukas Wagner
2026-08-20 14:52 ` [PATCH proxmox v2 02/20] rest-server: allow to inject " Lukas Wagner
2026-08-20 14:52 ` [PATCH proxmox v2 03/20] api-macro: support shared state extraction type Lukas Wagner
2026-08-24 12:33   ` Dominik Csapak
2026-08-24 13:17     ` Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 04/20] context: promote context to a dir-style module Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 05/20] pdm-config: remotes: rename trait methods to read/write/lock Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 06/20] pdm-config: subscriptions: " Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 07/20] remote iterator: pass remote config reader explicitly Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 08/20] context: introduce a ContextFactory to build application context Lukas Wagner
2026-08-24 12:33   ` Dominik Csapak
2026-08-24 13:48     ` Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 09/20] context: establish PdmApplication object Lukas Wagner
2026-08-21  9:52   ` Thomas Ellmenreich
2026-08-21 12:26     ` Lukas Wagner
2026-08-24 12:33   ` Dominik Csapak
2026-08-24 13:23     ` Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 10/20] context: register PdmApplication in router Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 11/20] parallel fetcher: pass arguments to closure in a single type Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 12/20] parallel fetcher: support a custom client factory Lukas Wagner
2026-08-24 12:33   ` Dominik Csapak [this message]
2026-08-24 13:42     ` Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 13/20] api: sdn: use PdmApplication handle for accessing remotes Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 14/20] tests: add helpers for building API-handler-level integration tests Lukas Wagner
2026-08-21  9:57   ` Thomas Ellmenreich
2026-08-21 12:25     ` Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 15/20] tests: add example tests for SDN API routes Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 16/20] api-cache: add wrapper type Lukas Wagner
2026-08-24 12:33   ` Dominik Csapak
2026-08-24 13:47     ` Lukas Wagner
2026-08-24 13:57       ` Dominik Csapak
2026-08-20 14:52 ` [PATCH datacenter-manager v2 17/20] context: provide api-cache on the app object Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 18/20] api: subscriptions: use PdmApplication instead of globals Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 19/20] pdm-config: subscriptions: drop unused accessor functions Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 20/20] tests: add example tests for remote subscription management Lukas Wagner
2026-08-24 12:33 ` [PATCH datacenter-manager/proxmox v2 00/20] inject application context via API macro for easier integration testing Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a6ff965b-fd46-4007-822b-8b29a1111f28@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=l.wagner@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal