Skip to content

Commit

Permalink
Cartographer + Emitter Reimplementation (#43)
Browse files Browse the repository at this point in the history
Reimplements the cartographer and emitter. Changes include:
- Switch from `Box<dyn Trait>` to generics for pluggable components
- Use a single shared signal store rather than separate shared components between each interface combo
- Move the `DigitalTwinAdapter::find_by_id` call to the cartographer, thereby eliminating the need for digital twin adapters to run a separate thread
- Update the API for providers and the provider proxy to use struct-like enum variants and return `Result` instead of panicking
- Utilize `mockall` for emitter tests instead of the in-memory mock
- Prevent errors on one signal in the cartographer and emitter from taking down the entire app
- Misc minor cleanup

This partially addresses #18, but more work is needed to get provider proxies integrated
  • Loading branch information
wilyle authored Sep 6, 2023
1 parent ddaa963 commit b38d4e4
Show file tree
Hide file tree
Showing 33 changed files with 1,667 additions and 1,457 deletions.
1 change: 1 addition & 0 deletions .accepted_words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ MappingClient
MappingClientImpl
md
microsoft
min
MockDigitalTwin
MockMappingService
MQTTProviderProxyImpl
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ members = [
"cloud_connectors/azure/mqtt_connector",
"cloud_connectors/azure/proto-build",
"common",
"contracts",
"digital_twin_adapters/ibeji_adapter",
"digital_twin_adapters/in_memory_mock_digital_twin_adapter",
"digital_twin_adapters/mock_digital_twin_adapter",
"freyja",
"mapping_clients/in_memory_mock_mapping_client",
"mapping_clients/mock_mapping_service_client",
Expand Down Expand Up @@ -48,6 +50,7 @@ env_logger = "0.10.0"
futures = "0.3.28"
httptest = "0.15.4"
log = "^0.4"
mockall = "0.11.4"
paho-mqtt = "0.12"
proc-macro2 = "1.0.52"
prost = "0.11.9"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl AzureCloudConnectorAdapter {
#[async_trait]
impl CloudAdapter for AzureCloudConnectorAdapter {
/// Creates a new instance of a CloudAdapter with default settings
fn create_new() -> Result<Box<dyn CloudAdapter + Send + Sync>, CloudAdapterError> {
fn create_new() -> Result<Self, CloudAdapterError> {
let cloud_connector_client = futures::executor::block_on(async {
let config_file = fs::read_to_string(Path::new(env!("OUT_DIR")).join(CONFIG_FILE))
.map_err(CloudAdapterError::io)?;
Expand All @@ -100,9 +100,9 @@ impl CloudAdapter for AzureCloudConnectorAdapter {
.map_err(CloudAdapterError::communication)
})?;

Ok(Box::new(Self {
Ok(Self {
cloud_connector_client,
}))
})
}

/// Sends the signal to the cloud
Expand Down
4 changes: 2 additions & 2 deletions cloud_adapters/in_memory_mock_cloud_adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ async-trait = { workspace = true }
freyja-contracts = { workspace = true }
log = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true}
tokio = { workspace = true}
serde_json = { workspace = true }
tokio = { workspace = true }
time = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ impl InMemoryMockCloudAdapter {
#[async_trait]
impl CloudAdapter for InMemoryMockCloudAdapter {
/// Creates a new instance of a CloudAdapter with default settings
fn create_new() -> Result<Box<dyn CloudAdapter + Send + Sync>, CloudAdapterError> {
fn create_new() -> Result<Self, CloudAdapterError> {
Self::from_config_file(Path::new(env!("OUT_DIR")).join(CONFIG_FILE))
.map(|r| Box::new(r) as _)
}

/// Sends the signal to the cloud
Expand Down
1 change: 1 addition & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ edition = "2021"
license = "MIT"

[dependencies]
freyja-contracts = { workspace = true }
log = { workspace = true }
tokio = { workspace = true }
1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

pub mod signal_store;
pub mod utils;
Loading

0 comments on commit b38d4e4

Please sign in to comment.