Skip to content

Commit

Permalink
fix fabric client role
Browse files Browse the repository at this point in the history
  • Loading branch information
youyuanwu committed Oct 1, 2024
1 parent 286e70d commit 6785118
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 26 deletions.
41 changes: 26 additions & 15 deletions crates/libs/core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use connection::{ClientConnectionEventHandlerBridge, LambdaClientConnectionNotificationHandler};
use mssf_com::FabricClient::{
FabricCreateLocalClient4, IFabricClientConnectionEventHandler,
FabricCreateLocalClient3, FabricCreateLocalClient4, IFabricClientConnectionEventHandler,
IFabricPropertyManagementClient2, IFabricQueryClient10, IFabricServiceManagementClient6,
IFabricServiceNotificationEventHandler,
};
Expand Down Expand Up @@ -37,19 +37,25 @@ fn create_local_client_internal<T: Interface>(
client_connection_handler: Option<&IFabricClientConnectionEventHandler>,
client_role: Option<ClientRole>,
) -> T {
let role = client_role.unwrap_or(ClientRole::User);
assert_ne!(
role,
ClientRole::Unknown,
"Unknown role should not be used."
);
let raw = unsafe {
FabricCreateLocalClient4(
service_notification_handler,
client_connection_handler,
role.into(),
&T::IID,
)
let role = client_role.unwrap_or(ClientRole::Unknown);
let raw = if role == ClientRole::Unknown {
// unknown role should use the SF function without role param.
unsafe {
FabricCreateLocalClient3(
service_notification_handler,
client_connection_handler,
&T::IID,
)
}
} else {
unsafe {
FabricCreateLocalClient4(
service_notification_handler,
client_connection_handler,
role.into(),
&T::IID,
)
}
}
.expect("failed to create fabric client");
// if params are right, client should be created. There is no network call involved during obj creation.
Expand All @@ -75,7 +81,7 @@ impl FabricClientBuilder {
Self {
sn_handler: None,
cc_handler: None,
client_role: ClientRole::User,
client_role: ClientRole::Unknown,
}
}

Expand Down Expand Up @@ -168,6 +174,11 @@ pub struct FabricClient {
}

impl FabricClient {
/// Get a builder
pub fn builder() -> FabricClientBuilder {
FabricClientBuilder::new()
}

// Get a copy of COM object
pub fn get_com(&self) -> IFabricPropertyManagementClient2 {
self.com_property_client.clone()
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/core/src/client/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use tokio_util::sync::CancellationToken;
use windows_core::HSTRING;

use crate::{
client::{svc_mgmt_client::PartitionKeyType, FabricClientBuilder},
client::{svc_mgmt_client::PartitionKeyType, FabricClient},
error::FabricErrorCode,
types::{NodeQueryDescription, NodeStatusFilter, PagedQueryDescription},
};

#[tokio::test]
async fn test_fabric_client() {
let c = FabricClientBuilder::new().build();
let c = FabricClient::builder().build();
let qc = c.get_query_manager();
let timeout = Duration::from_secs(1);
let paging_status;
Expand Down
5 changes: 2 additions & 3 deletions crates/libs/core/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ mod tests {
impl FabricQueryClient {
pub fn new() -> FabricQueryClient {
FabricQueryClient {
com: crate::client::FabricClientBuilder::new()
.build_interface::<IFabricQueryClient>(),
com: crate::client::FabricClient::builder().build_interface::<IFabricQueryClient>(),
}
}

Expand Down Expand Up @@ -511,7 +510,7 @@ mod tests {

#[test]
fn local_client_create() {
let _mgmt = crate::client::FabricClientBuilder::new()
let _mgmt = crate::client::FabricClient::builder()
.build_interface::<IFabricClusterManagementClient3>();
}

Expand Down
4 changes: 2 additions & 2 deletions crates/libs/core/src/types/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ impl From<&ServiceNotificationFilterDescription>
// FABRIC_CLIENT_ROLE
#[derive(Debug, PartialEq, Clone)]
pub enum ClientRole {
Unknown, // Do not pass this in SF api, use User instead.
User,
Unknown, // Default client role.
User, // User client role. Must set client certificate for tls endpoints.
Admin,
// ElevatedAdmin not supported by SF 6.x sdk yet.
}
Expand Down
4 changes: 2 additions & 2 deletions crates/samples/echomain-stateful2/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use mssf_core::{
PartitionKeyType, ResolvedServiceEndpoint, ResolvedServicePartition,
ServiceEndpointRole, ServicePartitionKind,
},
FabricClient, FabricClientBuilder,
FabricClient,
},
error::FabricErrorCode,
types::{
Expand Down Expand Up @@ -233,7 +233,7 @@ impl TestClient {
// Uses fabric client to perform various actions for this service.
#[tokio::test]
async fn test_partition_info() {
let fc = FabricClientBuilder::new().build();
let fc = FabricClient::builder().build();
let tc = TestClient::new(fc.clone());
let timeout = Duration::from_secs(1);

Expand Down
4 changes: 2 additions & 2 deletions crates/samples/echomain/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use mssf_core::{
PartitionKeyType, ResolvedServiceEndpoint, ResolvedServicePartitionInfo,
ServiceEndpointRole, ServicePartitionKind,
},
FabricClient, FabricClientBuilder, GatewayInformationResult, ServiceNotification,
FabricClient, GatewayInformationResult, ServiceNotification,
},
error::FabricErrorCode,
types::{
Expand Down Expand Up @@ -120,7 +120,7 @@ async fn test_fabric_client() {
let (sn_tx, mut sn_rx) = tokio::sync::mpsc::channel::<ServiceNotification>(1);
// channel for client connection notification
let (cc_tx, mut cc_rx) = tokio::sync::mpsc::channel::<GatewayInformationResult>(1);
let fc = FabricClientBuilder::new()
let fc = FabricClient::builder()
.with_on_service_notification(move |notification| {
sn_tx
.blocking_send(notification.clone())
Expand Down

0 comments on commit 6785118

Please sign in to comment.