Skip to content

Commit

Permalink
Digital Twin Graph
Browse files Browse the repository at this point in the history
  • Loading branch information
ashbeitz committed Apr 26, 2024
1 parent 1950d82 commit f02a537
Show file tree
Hide file tree
Showing 15 changed files with 445 additions and 141 deletions.
20 changes: 10 additions & 10 deletions core/invehicle-digital-twin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async fn register_invehicle_digital_twin_service_with_chariott(
Ok(())
}

/// Builds the enabled modules for the grpc server and starts the server.
/// Builds the enabled modules for the app server and starts the app server.
///
/// # Arguments
/// * `addr` - The address the server will be hosted on.
Expand All @@ -98,7 +98,7 @@ async fn register_invehicle_digital_twin_service_with_chariott(
/// 5. Call and return from the block `.add_module()` on the server with the updated middleware and
/// module.
#[allow(unused_assignments, unused_mut)] // Necessary when no extra modules are built.
async fn build_server_and_serve<S>(
async fn build_app_server_and_serve<S>(
addr: SocketAddr,
base_service: S,
) -> Result<(), Box<dyn std::error::Error>>
Expand All @@ -113,15 +113,15 @@ where
let mut server: GrpcServer<Identity> = GrpcServer::new(addr);

#[cfg(feature = "managed_subscribe")]
// Adds the Managed Subscribe module to the service.
// Adds the Managed Subscribe module to the app server.
let mut server = {
// Initialize the Managed Subscribe module, which implements GrpcModule.
let managed_subscribe_module = ManagedSubscribeModule::new().await.map_err(|error| {
error!("Unable to create Managed Subscribe module.");
error
})?;

// Create interceptor layer to be added to the server.
// Create interceptor layer to be added to the app.
let managed_subscribe_layer =
GrpcInterceptorLayer::new(Box::new(managed_subscribe_module.create_interceptor()));

Expand All @@ -136,7 +136,7 @@ where
};

#[cfg(feature = "digital_twin_graph")]
// Adds the Digital Twin Graph module to the service.
// Adds the Digital Twin Graph module to the app server.
let mut server = {
// Initialize the Digital Twin Graph module, which implements GrpcModule.
let digital_twin_graph_module = DigitalTwinGraphModule::new().await.map_err(|error| {
Expand All @@ -151,7 +151,7 @@ where
};

#[cfg(feature = "digital_twin_registry")]
// Adds the Digital Twin Registry module to the service.
// Adds the Digital Twin Registry module to the app server.
let mut server = {
// Initialize the Digital Twin Registry module, which implements GrpcModule.
let digital_twin_registry_module =
Expand All @@ -166,10 +166,10 @@ where
server.add_module(server.middleware.clone(), Box::new(digital_twin_registry_module))
};

// Construct the server.
// Construct the app server.
let builder = server.construct_server().add_service(base_service);

// Start the server.
// Start the app server.
builder.serve(addr).await.map_err(|error| error.into())
}

Expand Down Expand Up @@ -243,8 +243,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let base_service = InvehicleDigitalTwinServer::new(invehicle_digital_twin_impl);

// Build and start the grpc server.
build_server_and_serve(addr, base_service).await?;
// Build and start the app server.
build_app_server_and_serve(addr, base_service).await?;

debug!("The Digital Twin Service has completed.");

Expand Down
1 change: 1 addition & 0 deletions core/module/digital_twin_graph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true , features = ["full"] }
tokio-retry = { workspace = true }
tonic = { workspace = true }
tower = { workspace = true }
yaml-rust = { workspace = true }
Expand Down
23 changes: 23 additions & 0 deletions core/module/digital_twin_graph/src/digital_twin_graph_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

use common::utils;
use serde_derive::Deserialize;

const DEFAULT_CONFIG_FILENAME: &str = "digital_twin_graph_settings";

#[derive(Debug, Deserialize)]
pub struct Settings {
pub base_authority: String,
}

/// Load the settings.
pub fn load_settings() -> Settings {
utils::load_settings(DEFAULT_CONFIG_FILENAME).unwrap()
}

/// Load the settings.
pub fn load_settings_with_config_filename(config_filename: &str) -> Settings {
utils::load_settings(config_filename).unwrap()
}
Loading

0 comments on commit f02a537

Please sign in to comment.