From 56ab4b95774984a678cf867fb0903716507478da Mon Sep 17 00:00:00 2001 From: Ash Beitz <8304894+ashbeitz@users.noreply.github.com> Date: Wed, 8 May 2024 16:39:10 -0700 Subject: [PATCH] Digital Twin Graph --- .../src/digital_twin_graph_impl.rs | 52 +++++---- .../src/digital_twin_registry_impl.rs | 108 +++++++----------- .../v1/digital_twin_graph.proto | 18 +++ .../v1/digital_twin_registry.proto | 34 ++++-- .../seat_massager_provider/src/main.rs | 33 +++--- .../src/request_impl.rs | 2 - .../vehicle_core_provider/src/main.rs | 41 +++---- .../vehicle_core_provider/src/request_impl.rs | 2 - 8 files changed, 147 insertions(+), 143 deletions(-) diff --git a/core/module/digital_twin_graph/src/digital_twin_graph_impl.rs b/core/module/digital_twin_graph/src/digital_twin_graph_impl.rs index 2ee0bb4b..341ecf7e 100644 --- a/core/module/digital_twin_graph/src/digital_twin_graph_impl.rs +++ b/core/module/digital_twin_graph/src/digital_twin_graph_impl.rs @@ -13,7 +13,7 @@ use core_protobuf_data_access::module::digital_twin_graph::v1::{ }; use core_protobuf_data_access::module::digital_twin_registry::v1::digital_twin_registry_client::DigitalTwinRegistryClient; use core_protobuf_data_access::module::digital_twin_registry::v1::{ - EndpointInfo, FindByInstanceIdRequest, FindByInstanceIdResponse, FindByModelIdRequest, + EntityAccessInfo, FindByInstanceIdRequest, FindByInstanceIdResponse, FindByModelIdRequest, FindByModelIdResponse, }; use log::{debug, warn}; @@ -76,7 +76,7 @@ impl DigitalTwinGraphImpl { model_id: &str, protocol: &str, operations: &[String], - ) -> Result, tonic::Status> { + ) -> Result, tonic::Status> { // Define the retry strategy. let retry_strategy = ExponentialBackoff::from_millis(Self::BACKOFF_BASE_DURATION_IN_MILLIS) .map(jitter) // add jitter to delays @@ -99,11 +99,11 @@ impl DigitalTwinGraphImpl { Ok(response .entity_access_info_list .iter() - .flat_map(|entity_access_info| entity_access_info.endpoint_info_list.clone()) - .filter(|endpoint_info| { - endpoint_info.protocol == protocol - && is_subset(operations, &endpoint_info.operations) + .filter(|entity_access_info| { + entity_access_info.protocol == protocol + && is_subset(operations, &entity_access_info.operations) }) + .cloned() .collect()) } @@ -118,7 +118,7 @@ impl DigitalTwinGraphImpl { instance_id: &str, protocol: &str, operations: &[String], - ) -> Result, tonic::Status> { + ) -> Result, tonic::Status> { // Define the retry strategy. let retry_strategy = ExponentialBackoff::from_millis(Self::BACKOFF_BASE_DURATION_IN_MILLIS) .map(jitter) // add jitter to delays @@ -142,11 +142,11 @@ impl DigitalTwinGraphImpl { Ok(response .entity_access_info_list .iter() - .flat_map(|entity_access_info| entity_access_info.endpoint_info_list.clone()) - .filter(|endpoint_info| { - endpoint_info.protocol == protocol - && is_subset(operations, &endpoint_info.operations) + .filter(|entity_access_info| { + entity_access_info.protocol == protocol + && is_subset(operations, &entity_access_info.operations) }) + .cloned() .collect()) } @@ -243,7 +243,7 @@ impl DigitalTwinGraph for DigitalTwinGraphImpl { debug!("Received a find request for model id {model_id}"); // Retrieve the provider details. - let provider_endpoint_info_list = self + let provider_entity_access_info_list = self .find_digital_twin_providers_with_model_id( model_id.as_str(), digital_twin_protocol::GRPC, @@ -252,17 +252,23 @@ impl DigitalTwinGraph for DigitalTwinGraphImpl { .await?; // Build a map of instance id to its associated endpoint infos. - let instance_provider_map: std::collections::HashMap> = - provider_endpoint_info_list + let instance_provider_map: std::collections::HashMap> = + provider_entity_access_info_list .iter() - .map(|provider_endpoint_info| { - (provider_endpoint_info.context.clone(), provider_endpoint_info.clone()) + .map(|provider_entity_access_info| { + ( + provider_entity_access_info.instance_id.clone(), + provider_entity_access_info.clone(), + ) }) .fold( // fold is used to group the endpoint infos by instance id. std::collections::HashMap::new(), - |mut accumulator, (instance_id, endpoint_info)| { - accumulator.entry(instance_id).or_insert_with(Vec::new).push(endpoint_info); + |mut accumulator, (instance_id, entity_access_info)| { + accumulator + .entry(instance_id) + .or_insert_with(Vec::new) + .push(entity_access_info); accumulator }, ); @@ -271,10 +277,10 @@ impl DigitalTwinGraph for DigitalTwinGraphImpl { for instance_id in instance_provider_map.keys() { // We will only use the first provider. For a high availability scenario, we can try multiple providers. - let provider_endpoint_info = &instance_provider_map[instance_id][0]; + let provider_entity_access_info = &instance_provider_map[instance_id][0]; - let provider_uri = provider_endpoint_info.uri.clone(); - let instance_id = provider_endpoint_info.context.clone(); + let provider_uri = provider_entity_access_info.uri.clone(); + let instance_id = provider_entity_access_info.instance_id.clone(); let tx = self.tx.clone(); let mut rx = tx.subscribe(); @@ -347,7 +353,7 @@ impl DigitalTwinGraph for DigitalTwinGraphImpl { let provider_endpoint_info = &provider_endpoint_info_list[0]; let provider_uri = provider_endpoint_info.uri.clone(); - let instance_id = provider_endpoint_info.context.clone(); + let instance_id = provider_endpoint_info.instance_id.clone(); let tx = self.tx.clone(); let mut rx = tx.subscribe(); @@ -429,7 +435,7 @@ impl DigitalTwinGraph for DigitalTwinGraphImpl { let provider_endpoint_info = &provider_endpoint_info_list[0]; let provider_uri = provider_endpoint_info.uri.clone(); - let instance_id = provider_endpoint_info.context.clone(); + let instance_id = provider_endpoint_info.instance_id.clone(); let tx = self.tx.clone(); let mut rx = tx.subscribe(); diff --git a/core/module/digital_twin_registry/src/digital_twin_registry_impl.rs b/core/module/digital_twin_registry/src/digital_twin_registry_impl.rs index 955a7642..73f7d31e 100644 --- a/core/module/digital_twin_registry/src/digital_twin_registry_impl.rs +++ b/core/module/digital_twin_registry/src/digital_twin_registry_impl.rs @@ -6,8 +6,8 @@ extern crate iref; use core_protobuf_data_access::module::digital_twin_registry::v1::digital_twin_registry_server::DigitalTwinRegistry; use core_protobuf_data_access::module::digital_twin_registry::v1::{ - EndpointInfo, EntityAccessInfo, FindByInstanceIdRequest, FindByInstanceIdResponse, - FindByModelIdRequest, FindByModelIdResponse, RegisterRequest, RegisterResponse, + EntityAccessInfo, FindByInstanceIdRequest, FindByInstanceIdResponse, FindByModelIdRequest, + FindByModelIdResponse, RegisterRequest, RegisterResponse, }; use log::{debug, info}; use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; @@ -69,7 +69,7 @@ impl DigitalTwinRegistry for DigitalTwinRegistryImpl { debug!("Received a find_by_instance_id request for instance id {instance_id}"); - let mut new_entity_access_info_list = Vec::::new(); + let mut matching_entity_access_info_list = Vec::::new(); // This block controls the lifetime of the lock. { @@ -77,35 +77,21 @@ impl DigitalTwinRegistry for DigitalTwinRegistryImpl { self.entity_access_info_map.read(); for entity_access_info_list in lock.values() { for entity_access_info in entity_access_info_list { - let mut instance_found: bool = false; - let mut new_endpoint_info_list: Vec = Vec::new(); - for endpoint_info_ in entity_access_info.endpoint_info_list.iter() { - if endpoint_info_.context == instance_id { - instance_found = true; - } - new_endpoint_info_list.push(endpoint_info_.clone()); - } - if instance_found { - let new_entity_access_info = EntityAccessInfo { - name: entity_access_info.name.clone(), - id: entity_access_info.id.clone(), - description: entity_access_info.description.clone(), - endpoint_info_list: new_endpoint_info_list, - }; - new_entity_access_info_list.push(new_entity_access_info); + if entity_access_info.instance_id == instance_id { + matching_entity_access_info_list.push(entity_access_info.clone()); } } } } - if new_entity_access_info_list.is_empty() { + if matching_entity_access_info_list.is_empty() { return Err(Status::not_found( "Unable to find any entities with instance id {instance_id}", )); } let response = - FindByInstanceIdResponse { entity_access_info_list: new_entity_access_info_list }; + FindByInstanceIdResponse { entity_access_info_list: matching_entity_access_info_list }; debug!("Completed the find_by_instance_id request."); @@ -125,11 +111,14 @@ impl DigitalTwinRegistry for DigitalTwinRegistryImpl { for entity_access_info in &request_inner.entity_access_info_list { self.register_entity(entity_access_info.clone()).map_err(|e| { Status::internal(format!( - "Failed to register the entity: {}, error: {}", - entity_access_info.id, e + "Failed to register the entity with instance id: {}, error: {}", + entity_access_info.instance_id, e )) })?; - info!("Registered the entity: {}", entity_access_info.id); + info!( + "Registered the entity with model id: {} and instance id: {}", + entity_access_info.model_id, entity_access_info.instance_id + ); } let response = RegisterResponse {}; @@ -150,18 +139,23 @@ impl DigitalTwinRegistryImpl { { let mut lock: RwLockWriteGuard>> = self.entity_access_info_map.write(); - let get_result = lock.get(&entity_access_info.id); + let get_result = lock.get(&entity_access_info.model_id); match get_result { Some(_) => { info!( "Registered another entity access info for entity {}", - &entity_access_info.id + &entity_access_info.model_id ); - lock.get_mut(&entity_access_info.id).unwrap().push(entity_access_info.clone()); + lock.get_mut(&entity_access_info.model_id) + .unwrap() + .push(entity_access_info.clone()); } None => { - info!("Registered entity {}", &entity_access_info.id); - lock.insert(entity_access_info.id.clone(), vec![entity_access_info.clone()]); + info!("Registered entity {}", &entity_access_info.model_id); + lock.insert( + entity_access_info.model_id.clone(), + vec![entity_access_info.clone()], + ); } }; } @@ -178,20 +172,16 @@ mod digital_twin_registry_impl_tests { async fn find_by_model_id_test() { let operations = vec![String::from("Subscribe"), String::from("Unsubscribe")]; - let endpoint_info = EndpointInfo { + let entity_access_info = EntityAccessInfo { + provider_id: String::from("test-provider"), + instance_id: String::from("1234567890"), + model_id: String::from("dtmi:sdv:hvac:ambient_air_temperature;1"), protocol: String::from("grpc"), uri: String::from("http://[::1]:40010"), // Devskim: ignore DS137138 - context: String::from("1234567890"), + context: String::from(""), operations, }; - let entity_access_info = EntityAccessInfo { - name: String::from("AmbientAirTemperature"), - id: String::from("dtmi:sdv:hvac:ambient_air_temperature;1"), - description: String::from("Ambient air temperature"), - endpoint_info_list: vec![endpoint_info], - }; - let entity_access_info_map = Arc::new(RwLock::new(HashMap::new())); let digital_twin_registry_impl = @@ -201,7 +191,7 @@ mod digital_twin_registry_impl_tests { { let mut lock: RwLockWriteGuard>> = entity_access_info_map.write(); - lock.insert(entity_access_info.id.clone(), vec![entity_access_info.clone()]); + lock.insert(entity_access_info.model_id.clone(), vec![entity_access_info.clone()]); } let request = tonic::Request::new(FindByModelIdRequest { @@ -216,10 +206,9 @@ mod digital_twin_registry_impl_tests { let response_entity_access_info = response_inner.entity_access_info_list[0].clone(); - assert_eq!(response_entity_access_info.id, "dtmi:sdv:hvac:ambient_air_temperature;1"); - assert_eq!(response_entity_access_info.endpoint_info_list.len(), 1); + assert_eq!(response_entity_access_info.model_id, "dtmi:sdv:hvac:ambient_air_temperature;1"); assert_eq!( - response_entity_access_info.endpoint_info_list[0].uri, + response_entity_access_info.uri, "http://[::1]:40010" // Devskim: ignore DS137138 ); } @@ -228,20 +217,16 @@ mod digital_twin_registry_impl_tests { async fn find_by_instance_id_test() { let operations = vec![String::from("Subscribe"), String::from("Unsubscribe")]; - let endpoint_info = EndpointInfo { + let entity_access_info = EntityAccessInfo { + provider_id: String::from("test-provider"), + instance_id: String::from("1234567890"), + model_id: String::from("dtmi:sdv:hvac:ambient_air_temperature;1"), protocol: String::from("grpc"), uri: String::from("http://[::1]:40010"), // Devskim: ignore DS137138 - context: String::from("1234567890"), + context: String::from(""), operations, }; - let entity_access_info = EntityAccessInfo { - name: String::from("AmbientAirTemperature"), - id: String::from("dtmi:sdv:hvac:ambient_air_temperature;1"), - description: String::from("Ambient air temperature"), - endpoint_info_list: vec![endpoint_info], - }; - let entity_access_info_map = Arc::new(RwLock::new(HashMap::new())); let digital_twin_registry_impl = @@ -251,7 +236,7 @@ mod digital_twin_registry_impl_tests { { let mut lock: RwLockWriteGuard>> = entity_access_info_map.write(); - lock.insert(entity_access_info.id.clone(), vec![entity_access_info.clone()]); + lock.insert(entity_access_info.model_id.clone(), vec![entity_access_info.clone()]); } let request = tonic::Request::new(FindByInstanceIdRequest { @@ -266,30 +251,25 @@ mod digital_twin_registry_impl_tests { let response_entity_access_info = response_inner.entity_access_info_list[0].clone(); - assert_eq!(response_entity_access_info.endpoint_info_list[0].context, "1234567890"); - assert_eq!(response_entity_access_info.endpoint_info_list.len(), 1); + assert_eq!(response_entity_access_info.instance_id, "1234567890"); assert_eq!( - response_entity_access_info.endpoint_info_list[0].uri, + response_entity_access_info.uri, "http://[::1]:40010" // Devskim: ignore DS137138 ); } #[tokio::test] async fn register_test() { - let endpoint_info = EndpointInfo { + let entity_access_info = EntityAccessInfo { + provider_id: String::from("test-provider"), + instance_id: String::from("1234567890"), + model_id: String::from("dtmi:sdv:hvac:ambient_air_temperature;1"), protocol: String::from("grpc"), uri: String::from("http://[::1]:40010"), // Devskim: ignore DS137138 - context: String::from("1234567890"), + context: String::from(""), operations: vec![String::from("Subscribe"), String::from("Unsubscribe")], }; - let entity_access_info = EntityAccessInfo { - name: String::from("AmbientAirTemperature"), - id: String::from("dtmi:sdv:hvac:ambient_air_temperature;1"), - description: String::from("Ambient air temperature"), - endpoint_info_list: vec![endpoint_info], - }; - let entity_access_info_map = Arc::new(RwLock::new(HashMap::new())); let digital_twin_registry_impl = diff --git a/interfaces/module/digital_twin_graph/v1/digital_twin_graph.proto b/interfaces/module/digital_twin_graph/v1/digital_twin_graph.proto index 9b48eed1..642c7daf 100644 --- a/interfaces/module/digital_twin_graph/v1/digital_twin_graph.proto +++ b/interfaces/module/digital_twin_graph/v1/digital_twin_graph.proto @@ -7,32 +7,46 @@ syntax = "proto3"; package digital_twin_graph.v1.digital_twin_graph; service DigitalTwinGraph { + // Find the values of all instances that have the provided model id. rpc Find (FindRequest) returns (FindResponse); + // Get an instance or an instance's member's value. rpc Get (GetRequest) returns (GetResponse); + // Set an instance's or an instance memeber's value. rpc Set (SetRequest) returns (SetResponse); + // Invoke an instance's command. rpc Invoke (InvokeRequest) returns (InvokeResponse); } message FindRequest { + // The model id. string model_id = 1; } message FindResponse { + // The JSON-LD string for each matching value. repeated string values = 1; } message GetRequest { + // The instance id. string instance_id = 1; + // Scopes the request to a specific instance member located at the provided path. + // An empty string means the entire instance. string member_path = 2; } message GetResponse { + // The JSON-LD string for the retieved value. string value = 1; } message SetRequest { + // The instance id. string instance_id = 1; + // Scopes the request to a specific instance member located at the provided path. + // An empty string means the entire instance. string member_path = 2; + // The JSON-LD string for the value to be set. string value = 3; } @@ -40,11 +54,15 @@ message SetResponse { } message InvokeRequest { + // The instance id. string instance_id = 1; + // The instance's command that is to be invoked. string member_path = 2; + // The JSON-LD string for the command's request payload. string request_payload = 3; } message InvokeResponse { + // The JSON-LD string for the command's response payload. string response_payload = 1; } \ No newline at end of file diff --git a/interfaces/module/digital_twin_registry/v1/digital_twin_registry.proto b/interfaces/module/digital_twin_registry/v1/digital_twin_registry.proto index 4953a39b..1b79c533 100644 --- a/interfaces/module/digital_twin_registry/v1/digital_twin_registry.proto +++ b/interfaces/module/digital_twin_registry/v1/digital_twin_registry.proto @@ -7,42 +7,54 @@ syntax = "proto3"; package digital_twin_registry.v1.digital_twin_registry; service DigitalTwinRegistry { + // Find the access details that have the provided model id. rpc FindByModelId (FindByModelIdRequest) returns (FindByModelIdResponse); + // Find the access details that have the provided instance id. rpc FindByInstanceId (FindByInstanceIdRequest) returns (FindByInstanceIdResponse); + // Register access details. rpc Register (RegisterRequest) returns (RegisterResponse); } -message EndpointInfo { - string protocol = 1; - repeated string operations = 2; - string uri = 3; - string context = 4; -} - message EntityAccessInfo { - string name = 1; - string id = 2; - string description = 3; - repeated EndpointInfo endpointInfoList = 4; + // The id of the provider that registered these access details. + string provider_id = 1; + // The provider id. + string instance_id = 2; + // The model id. + string model_id = 3; + // The protocol that should be used to access the instance. + string protocol = 4; + // The URI speific to the protocol that should be used to access the instance. + string uri = 5; + // Additional context specific tp the protocol that should be used to acess the instance. + // For example, with MQTT the URI will represent the address of the MQTT provider and the context will represent the topic name. + string context = 6; + // The names of the operations that are available at this endpoint. + repeated string operations = 7; } message FindByModelIdRequest { + // The model id. string model_id = 1; } message FindByModelIdResponse { + // The matching entries. repeated EntityAccessInfo entityAccessInfoList = 1; } message FindByInstanceIdRequest { + // The instance id. string instance_id = 1; } message FindByInstanceIdResponse { + // The matching entries. repeated EntityAccessInfo entityAccessInfoList = 1; } message RegisterRequest { + // The entries to register. repeated EntityAccessInfo entityAccessInfoList = 1; } diff --git a/samples/digital_twin_graph/seat_massager_provider/src/main.rs b/samples/digital_twin_graph/seat_massager_provider/src/main.rs index f244f994..d14c20e0 100644 --- a/samples/digital_twin_graph/seat_massager_provider/src/main.rs +++ b/samples/digital_twin_graph/seat_massager_provider/src/main.rs @@ -14,7 +14,7 @@ use samples_common::utils::retrieve_invehicle_digital_twin_uri; use samples_protobuf_data_access::async_rpc::v1::request::request_server::RequestServer; use samples_protobuf_data_access::digital_twin_registry::v1::digital_twin_registry::digital_twin_registry_client::DigitalTwinRegistryClient; use samples_protobuf_data_access::digital_twin_registry::v1::digital_twin_registry::{ - EndpointInfo, EntityAccessInfo, RegisterRequest, RegisterResponse, + EntityAccessInfo, RegisterRequest, RegisterResponse, }; use std::collections::HashMap; use std::net::SocketAddr; @@ -31,21 +31,22 @@ const BACKOFF_BASE_DURATION_IN_MILLIS: u64 = 100; /// The maximum number of retries. const MAX_RETRIES: usize = 100; +/// The provider ID. +const PROVIDER_ID: &str = "seat_massager_provider"; + /// Add an entry to the instance map. /// # Arguments /// * `instance_map` - The instance map. /// * `instance_id` - The instance id. /// * `model_id` - The model id. -/// * `description` - The description. /// * `serialized_value` - The serialized value. fn add_entry_to_instance_map( instance_map: &mut HashMap, instance_id: String, model_id: String, - description: String, serialized_value: String, ) { - instance_map.insert(instance_id, InstanceData { model_id, description, serialized_value }); + instance_map.insert(instance_id, InstanceData { model_id, serialized_value }); } /// Create the provider's state. @@ -117,7 +118,6 @@ fn create_provider_state() -> ProviderState { &mut result.instance_map, front_left_airbag_seat_massager_instance_id.clone(), sdv::premium_airbag_seat_massager::ID.to_string(), - sdv::premium_airbag_seat_massager::DESCRIPTION.to_string(), serde_json::to_string(&front_left_airbag_seat_massager).unwrap(), ); @@ -125,7 +125,6 @@ fn create_provider_state() -> ProviderState { &mut result.instance_map, front_right_airbag_seat_massager_instance_id.clone(), sdv::premium_airbag_seat_massager::ID.to_string(), - sdv::premium_airbag_seat_massager::DESCRIPTION.to_string(), serde_json::to_string(&front_right_airbag_seat_massager).unwrap(), ); @@ -133,7 +132,6 @@ fn create_provider_state() -> ProviderState { &mut result.instance_map, back_left_airbag_seat_massager_instance_id.clone(), sdv::basic_airbag_seat_massager::ID.to_string(), - sdv::basic_airbag_seat_massager::DESCRIPTION.to_string(), serde_json::to_string(&back_left_airbag_seat_massager).unwrap(), ); @@ -141,7 +139,6 @@ fn create_provider_state() -> ProviderState { &mut result.instance_map, back_center_airbag_seat_massager_instance_id.clone(), sdv::basic_airbag_seat_massager::ID.to_string(), - sdv::basic_airbag_seat_massager::DESCRIPTION.to_string(), serde_json::to_string(&back_center_airbag_seat_massager).unwrap(), ); @@ -149,7 +146,6 @@ fn create_provider_state() -> ProviderState { &mut result.instance_map, back_right_airbag_seat_massager_instance_id.clone(), sdv::basic_airbag_seat_massager::ID.to_string(), - sdv::basic_airbag_seat_massager::DESCRIPTION.to_string(), serde_json::to_string(&back_right_airbag_seat_massager).unwrap(), ); @@ -159,10 +155,12 @@ fn create_provider_state() -> ProviderState { /// Register the seat massagers. /// /// # Arguments +/// * `provider_id` - The provider's ID. /// * `invehicle_digital_twin_uri` - The In-Vehicle Digital Twin URI. /// * `provider_uri` - The provider's URI. /// * `provider_state` - The provider's state. async fn register_seat_massagers( + provider_id: &str, invehicle_digital_twin_uri: &str, provider_uri: &str, provider_state: Arc>, @@ -175,21 +173,17 @@ async fn register_seat_massagers( instance_id, instance_data.model_id ); - let endpoint_info = EndpointInfo { + let entity_access_info = EntityAccessInfo { + provider_id: provider_id.to_string(), + instance_id: instance_id.to_string(), + model_id: instance_data.model_id.to_string(), protocol: digital_twin_protocol::GRPC.to_string(), operations: vec![ digital_twin_operation::GET.to_string(), digital_twin_operation::INVOKE.to_string(), ], uri: provider_uri.to_string(), - context: instance_id.to_string(), // the context holds te - }; - - let entity_access_info = EntityAccessInfo { - name: String::new(), // no name, so we will use an empty name - id: instance_data.model_id.to_string(), - description: instance_data.description.to_string(), - endpoint_info_list: vec![endpoint_info], + context: "".to_string(), }; entity_access_info_list.push(entity_access_info); @@ -253,7 +247,8 @@ async fn main() -> Result<(), Box> { let server_future = Server::builder().add_service(RequestServer::new(request_impl)).serve(addr); info!("The HTTP server is listening on address '{provider_authority}'"); - register_seat_massagers(&invehicle_digital_twin_uri, &provider_uri, state.clone()).await?; + register_seat_massagers(PROVIDER_ID, &invehicle_digital_twin_uri, &provider_uri, state.clone()) + .await?; server_future.await?; diff --git a/samples/digital_twin_graph/seat_massager_provider/src/request_impl.rs b/samples/digital_twin_graph/seat_massager_provider/src/request_impl.rs index 55929a59..71d345a9 100644 --- a/samples/digital_twin_graph/seat_massager_provider/src/request_impl.rs +++ b/samples/digital_twin_graph/seat_massager_provider/src/request_impl.rs @@ -23,8 +23,6 @@ use tokio_retry::Retry; pub struct InstanceData { /// Model Id. pub model_id: String, - /// Description. - pub description: String, /// Serialized value (using JSON-LD as a string). pub serialized_value: String, } diff --git a/samples/digital_twin_graph/vehicle_core_provider/src/main.rs b/samples/digital_twin_graph/vehicle_core_provider/src/main.rs index 7d388fc7..ba62682f 100644 --- a/samples/digital_twin_graph/vehicle_core_provider/src/main.rs +++ b/samples/digital_twin_graph/vehicle_core_provider/src/main.rs @@ -14,7 +14,7 @@ use samples_common::utils::retrieve_invehicle_digital_twin_uri; use samples_protobuf_data_access::async_rpc::v1::request::request_server::RequestServer; use samples_protobuf_data_access::digital_twin_registry::v1::digital_twin_registry::digital_twin_registry_client::DigitalTwinRegistryClient; use samples_protobuf_data_access::digital_twin_registry::v1::digital_twin_registry::{ - EndpointInfo, EntityAccessInfo, RegisterRequest, RegisterResponse, + EntityAccessInfo, RegisterRequest, RegisterResponse, }; use std::collections::HashMap; use std::net::SocketAddr; @@ -31,21 +31,22 @@ const BACKOFF_BASE_DURATION_IN_MILLIS: u64 = 100; /// The maximum number of retries. const MAX_RETRIES: usize = 100; +/// The provider ID. +const PROVIDER_ID: &str = "vehicle_provider"; + /// Add an entry to the instance map. /// # Arguments /// * `instance_map` - The instance map. /// * `instance_id` - The instance id. /// * `model_id` - The model id. -/// * `description` - The description. /// * `serialized_value` - The serialized value. fn add_entry_to_instance_map( instance_map: &mut HashMap, instance_id: String, model_id: String, - description: String, serialized_value: String, ) { - instance_map.insert(instance_id, InstanceData { model_id, description, serialized_value }); + instance_map.insert(instance_id, InstanceData { model_id, serialized_value }); } /// Create the provider's state. @@ -169,7 +170,6 @@ fn create_provider_state() -> ProviderState { &mut result.instance_map, front_left_seat_instance_id.clone(), sdv::seat::ID.to_string(), - sdv::seat::DESCRIPTION.to_string(), serde_json::to_string(&front_left_seat).unwrap(), ); @@ -177,7 +177,6 @@ fn create_provider_state() -> ProviderState { &mut result.instance_map, front_right_seat_instance_id.clone(), sdv::seat::ID.to_string(), - sdv::seat::DESCRIPTION.to_string(), serde_json::to_string(&front_right_seat).unwrap(), ); @@ -185,7 +184,6 @@ fn create_provider_state() -> ProviderState { &mut result.instance_map, back_left_seat_instance_id.clone(), sdv::seat::ID.to_string(), - sdv::seat::DESCRIPTION.to_string(), serde_json::to_string(&back_left_seat).unwrap(), ); @@ -193,7 +191,6 @@ fn create_provider_state() -> ProviderState { &mut result.instance_map, back_center_seat_instance_id.clone(), sdv::seat::ID.to_string(), - sdv::seat::DESCRIPTION.to_string(), serde_json::to_string(&back_center_seat).unwrap(), ); @@ -201,7 +198,6 @@ fn create_provider_state() -> ProviderState { &mut result.instance_map, back_right_seat_instance_id.clone(), sdv::seat::ID.to_string(), - sdv::seat::DESCRIPTION.to_string(), serde_json::to_string(&back_right_seat).unwrap(), ); @@ -209,7 +205,6 @@ fn create_provider_state() -> ProviderState { &mut result.instance_map, cabin_instance_id, sdv::cabin::ID.to_string(), - sdv::cabin::DESCRIPTION.to_string(), serde_json::to_string(&cabin_value).unwrap(), ); @@ -217,7 +212,6 @@ fn create_provider_state() -> ProviderState { &mut result.instance_map, vehicle_instance_id.clone(), sdv::vehicle::ID.to_string(), - sdv::vehicle::DESCRIPTION.to_string(), serde_json::to_string(&vehicle_value).unwrap(), ); @@ -227,10 +221,12 @@ fn create_provider_state() -> ProviderState { /// Register the vehicle parts. /// /// # Arguments +/// * `provider_id` - The provider's ID. /// * `invehicle_digital_twin_uri` - The In-Vehicle Digital Twin URI. /// * `provider_uri` - The provider's URI. /// * `provider_state` - The provider's state. async fn register_vehicle_parts( + provider_id: &str, invehicle_digital_twin_uri: &str, provider_uri: &str, provider_state: Arc>, @@ -243,18 +239,14 @@ async fn register_vehicle_parts( instance_id, instance_data.model_id ); - let endpoint_info = EndpointInfo { + let entity_access_info = EntityAccessInfo { + provider_id: provider_id.to_string(), + instance_id: instance_id.to_string(), + model_id: instance_data.model_id.to_string(), protocol: digital_twin_protocol::GRPC.to_string(), operations: vec![digital_twin_operation::GET.to_string()], uri: provider_uri.to_string(), - context: instance_id.to_string(), - }; - - let entity_access_info = EntityAccessInfo { - name: String::new(), // no name, so we will use an empty name - id: instance_data.model_id.to_string(), - description: instance_data.description.to_string(), - endpoint_info_list: vec![endpoint_info], + context: "".to_string(), }; entity_access_info_list.push(entity_access_info); @@ -317,8 +309,13 @@ async fn main() -> Result<(), Box> { let server_future = Server::builder().add_service(RequestServer::new(request_impl)).serve(addr); info!("The HTTP server is listening on address '{provider_authority}'"); - register_vehicle_parts(&invehicle_digital_twin_uri, &provider_uri, provider_state.clone()) - .await?; + register_vehicle_parts( + PROVIDER_ID, + &invehicle_digital_twin_uri, + &provider_uri, + provider_state.clone(), + ) + .await?; server_future.await?; diff --git a/samples/digital_twin_graph/vehicle_core_provider/src/request_impl.rs b/samples/digital_twin_graph/vehicle_core_provider/src/request_impl.rs index 387625b3..c56ba79f 100644 --- a/samples/digital_twin_graph/vehicle_core_provider/src/request_impl.rs +++ b/samples/digital_twin_graph/vehicle_core_provider/src/request_impl.rs @@ -22,8 +22,6 @@ use tokio_retry::Retry; pub struct InstanceData { /// Model Id. pub model_id: String, - /// Description. - pub description: String, /// Serialized value (using JSON-LD as a string). pub serialized_value: String, }