diff --git a/crates/libs/core/src/client/health_client.rs b/crates/libs/core/src/client/health_client.rs index 40ea85c..919a091 100644 --- a/crates/libs/core/src/client/health_client.rs +++ b/crates/libs/core/src/client/health_client.rs @@ -33,6 +33,10 @@ pub struct HealthClient { // Public implementation block impl HealthClient { + pub fn get_com(&self) -> IFabricHealthClient4 { + self.com.clone() + } + pub fn from_com(com: IFabricHealthClient4) -> Self { Self { com: com.clone() } } diff --git a/crates/libs/core/src/client/mod.rs b/crates/libs/core/src/client/mod.rs index 8c1ac57..a74f9b8 100644 --- a/crates/libs/core/src/client/mod.rs +++ b/crates/libs/core/src/client/mod.rs @@ -202,10 +202,10 @@ impl FabricClientBuilder { // https://github.com/microsoft/service-fabric/blob/master/src/prod/src/managed/Api/src/System/Fabric/FabricClient.cs #[derive(Debug, Clone)] pub struct FabricClient { - com_property_client: IFabricPropertyManagementClient2, - com_service_client: IFabricServiceManagementClient6, - com_query_client: IFabricQueryClient10, - com_health_client: IFabricHealthClient4, + property_client: PropertyManagementClient, + service_client: ServiceManagementClient, + query_client: QueryClient, + health_client: HealthClient, } impl FabricClient { @@ -214,11 +214,6 @@ impl FabricClient { FabricClientBuilder::new() } - /// Get a copy of COM object - pub fn get_com(&self) -> IFabricPropertyManagementClient2 { - self.com_property_client.clone() - } - /// Creates from com directly. This gives the user freedom to create com from /// custom code and pass it in. /// For the final state of FabricClient, this function should be private. @@ -231,36 +226,46 @@ impl FabricClient { let com_query_client = com.clone().cast::().unwrap(); let com_health_client = com.clone().cast::().unwrap(); Self { - com_property_client, - com_service_client, - com_query_client, - com_health_client, + property_client: PropertyManagementClient::from_com(com_property_client), + service_client: ServiceManagementClient::from_com(com_service_client), + query_client: QueryClient::from_com(com_query_client), + health_client: HealthClient::from_com(com_health_client), } } /// Get the client for managing Fabric Properties in Naming Service - pub fn get_property_manager(&self) -> PropertyManagementClient { - PropertyManagementClient { - _com: self.com_property_client.clone(), - } + pub fn get_property_manager(&self) -> &PropertyManagementClient { + &self.property_client } /// Get the client for quering Service Fabric information. - pub fn get_query_manager(&self) -> QueryClient { - QueryClient::from_com(self.com_query_client.clone()) + pub fn get_query_manager(&self) -> &QueryClient { + &self.query_client } /// Get the client for managing service information and lifecycles. - pub fn get_service_manager(&self) -> ServiceManagementClient { - ServiceManagementClient::from_com(self.com_service_client.clone()) + pub fn get_service_manager(&self) -> &ServiceManagementClient { + &self.service_client } /// Get the client for get/set Service Fabric health properties. - pub fn get_health_manager(&self) -> HealthClient { - HealthClient::from_com(self.com_health_client.clone()) + pub fn get_health_manager(&self) -> &HealthClient { + &self.health_client } } +#[derive(Debug, Clone)] pub struct PropertyManagementClient { - _com: IFabricPropertyManagementClient2, + com: IFabricPropertyManagementClient2, +} + +impl PropertyManagementClient { + /// Get a copy of COM object + pub fn get_com(&self) -> IFabricPropertyManagementClient2 { + self.com.clone() + } + + fn from_com(com: IFabricPropertyManagementClient2) -> Self { + Self { com } + } } diff --git a/crates/libs/core/src/client/query_client.rs b/crates/libs/core/src/client/query_client.rs index 0129823..680f9e8 100644 --- a/crates/libs/core/src/client/query_client.rs +++ b/crates/libs/core/src/client/query_client.rs @@ -2,7 +2,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // ------------------------------------------------------------ - +#![cfg_attr( + not(feature = "tokio_async"), + allow(unused_imports) // reason = "code configured out" +)] use std::{ffi::c_void, time::Duration}; use mssf_com::{ @@ -19,9 +22,10 @@ use mssf_com::{ }, }; +#[cfg(feature = "tokio_async")] +use crate::sync::{fabric_begin_end_proxy2, CancellationToken, FabricReceiver2}; use crate::{ strings::get_pcwstr_from_opt, - sync::{fabric_begin_end_proxy2, CancellationToken, FabricReceiver2}, types::{ NodeList, NodeQueryDescription, PartitionLoadInformation, PartitionLoadInformationQueryDescription, ServicePartitionList, @@ -37,6 +41,7 @@ pub struct QueryClient { // Internal implementation block // Internal functions focuses on changing SF callback to async future, // while the public apis impl focuses on type conversion. +#[cfg(feature = "tokio_async")] impl QueryClient { pub fn get_node_list_internal( &self, @@ -109,10 +114,17 @@ impl QueryClient { } impl QueryClient { + pub fn get_com(&self) -> IFabricQueryClient10 { + self.com.clone() + } + pub fn from_com(com: IFabricQueryClient10) -> Self { Self { com: com.clone() } } +} +#[cfg(feature = "tokio_async")] +impl QueryClient { // List nodes in the cluster pub async fn get_node_list( &self, diff --git a/crates/libs/core/src/client/svc_mgmt_client.rs b/crates/libs/core/src/client/svc_mgmt_client.rs index 3107251..85c8c41 100644 --- a/crates/libs/core/src/client/svc_mgmt_client.rs +++ b/crates/libs/core/src/client/svc_mgmt_client.rs @@ -2,7 +2,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // ------------------------------------------------------------ - +#![cfg_attr( + not(feature = "tokio_async"), + allow(unused_imports) // reason = "code configured out" +)] use std::{ffi::c_void, time::Duration}; use mssf_com::{ @@ -22,10 +25,12 @@ use mssf_com::{ }; use windows_core::{WString, PCWSTR}; +#[cfg(feature = "tokio_async")] +use crate::sync::{fabric_begin_end_proxy2, CancellationToken, FabricReceiver2}; + use crate::{ iter::{FabricIter, FabricListAccessor}, strings::WStringWrap, - sync::{fabric_begin_end_proxy2, CancellationToken, FabricReceiver2}, types::{ RemoveReplicaDescription, RestartReplicaDescription, ServiceNotificationFilterDescription, }, @@ -37,7 +42,13 @@ pub struct ServiceManagementClient { com: IFabricServiceManagementClient6, } +impl ServiceManagementClient { + pub fn get_com(&self) -> IFabricServiceManagementClient6 { + self.com.clone() + } +} // internal implementation block +#[cfg(feature = "tokio_async")] impl ServiceManagementClient { fn resolve_service_partition_internal( &self, @@ -144,7 +155,11 @@ impl ServiceManagementClient { pub fn from_com(com: IFabricServiceManagementClient6) -> Self { Self { com: com.clone() } } +} +// public implementation block - tokio required +#[cfg(feature = "tokio_async")] +impl ServiceManagementClient { // Resolve service partition pub async fn resolve_service_partition( &self, diff --git a/crates/libs/core/src/lib.rs b/crates/libs/core/src/lib.rs index 7a075cb..0a59239 100644 --- a/crates/libs/core/src/lib.rs +++ b/crates/libs/core/src/lib.rs @@ -22,7 +22,6 @@ // SF lib entrypoint apis. pub mod api; pub use api::API_TABLE; -#[cfg(feature = "tokio_async")] pub mod client; #[cfg(feature = "config_source")] pub mod conf;