From 385d0dc1055cbbabe90773ec6c9a8b34897a05c9 Mon Sep 17 00:00:00 2001 From: William Lyles <26171886+wilyle@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:14:51 -0700 Subject: [PATCH 1/4] config updates for ibeji adapter --- Cargo.lock | 1 + Cargo.toml | 1 + .../digital_twin/ibeji_adapter/Cargo.toml | 5 ++- .../digital_twin/ibeji_adapter/README.md | 34 +++++++------- .../digital_twin/ibeji_adapter/build.rs | 29 +++++------- ...ibeji_adapter_config.chariott_sample.json} | 4 +- ...json => ibeji_adapter_config.default.json} | 2 +- .../digital_twin/ibeji_adapter/src/config.rs | 41 +++++++++++------ .../ibeji_adapter/src/ibeji_adapter.rs | 45 +++++++++++-------- tools/cg/about.toml | 8 ++-- 10 files changed, 98 insertions(+), 72 deletions(-) rename freyja_adapters/digital_twin/ibeji_adapter/res/{ibeji_adapter_config_with_chariott.sample.json => ibeji_adapter_config.chariott_sample.json} (69%) rename freyja_adapters/digital_twin/ibeji_adapter/res/{ibeji_adapter_config.sample.json => ibeji_adapter_config.default.json} (63%) diff --git a/Cargo.lock b/Cargo.lock index 99b4653..a5d7940 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -921,6 +921,7 @@ version = "0.1.0" dependencies = [ "async-trait", "core-protobuf-data-access", + "freyja-build-common", "freyja-common", "freyja-contracts", "futures", diff --git a/Cargo.toml b/Cargo.toml index 1e5c202..cab2d66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ ibeji-adapter = { path = "freyja_adapters/digital_twin/ibeji_adapter" } # Versioning is managed by the Cargo.lock file rather than copying rev properties to all of these core-protobuf-data-access = { git = "https://github.com/eclipse-ibeji/ibeji" } freyja = { git = "https://github.com/eclipse-ibeji/freyja" } +freyja-build-common = { git = "https://github.com/eclipse-ibeji/freyja" } freyja-common = { git = "https://github.com/eclipse-ibeji/freyja" } freyja-contracts = { git = "https://github.com/eclipse-ibeji/freyja" } in-memory-mock-cloud-adapter = { git = "https://github.com/eclipse-ibeji/freyja" } diff --git a/freyja_adapters/digital_twin/ibeji_adapter/Cargo.toml b/freyja_adapters/digital_twin/ibeji_adapter/Cargo.toml index 95da418..4f97adc 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/Cargo.toml +++ b/freyja_adapters/digital_twin/ibeji_adapter/Cargo.toml @@ -25,4 +25,7 @@ tempfile = { workspace = true } tokio = { workspace = true } tokio-stream = { workspace = true, features = ["net"] } tonic = { workspace = true } -tower = { workspace = true } \ No newline at end of file +tower = { workspace = true } + +[build-dependencies] +freyja-build-common = { workspace = true } \ No newline at end of file diff --git a/freyja_adapters/digital_twin/ibeji_adapter/README.md b/freyja_adapters/digital_twin/ibeji_adapter/README.md index c38d148..5050472 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/README.md +++ b/freyja_adapters/digital_twin/ibeji_adapter/README.md @@ -4,28 +4,32 @@ The Ibeji Adapter is used to integrate with the [Ibeji In-Vehicle Digital Twin S ## Configuration -The `res` directory contains two sample config files. The `ibeji_adapter_config.sample.json` will be copied to the build output, so you can edit this file to configure the adapter. +This adapter supports two different configuration schemas depending on how you want to discover the In-Vehicle Digital Twin Service: -### Common Configuration Fields +### Without Chariott -Whether or not you are using Chariott, the following config values are required: +To bypass Chariott and use a configuration value to specify the In-Vehicle Digital Twin Service URI, you must specify the following configuration: -- `service_type`: Specifies whether to call Ibeji directly or use Chariott's Service Discovery system to find it. Valid values are `"ChariottDiscoveryService"` and `"InVehicleDigitalTwinService"`. -- `uri`: The URI for the selected service. -- `max_retries`: The maximum number of times to retry failed attempts to communicate with the digital twin service. +- `service_discovery_method`: Set this value to `"Config"`. +- `uri`: The URI for the In-Vehicle Digital Twin Service. +- `max_retries`: The maximum number of times to retry failed attempts to communicate with the In-Vehicle Digital Twin Service. - `retry_interval_ms`: The duration between retries in milliseconds. -### Ibeji Without Chariott +### Using Chariott -To use Ibeji without Chariott, the `service_type` must be `"InVehicleDigitalTwinService"`. No additional configuration is needed to use Ibeji without Chariott. +To use Chariott to discover the In-Vehicle Digital Twin Service, you must specify the following configuration: -### Ibeji With Chariott +- `service_discovery_method`: Set this value to `"ChariottServiceDiscovery"` to use Chariott. +- `uri`: The URI for Chariott's Service Discovery system. +- `max_retries`: The maximum number of times to retry failed attempts to communicate with Chariott or the In-Vehicle Digital Twin Service. +- `retry_interval_ms`: The duration between retries in milliseconds. +- `metadata`: Metadata for the discovery operation: + - `namespace`: The namespace for the In-Vehicle Digital Twin Service. + - `name`: The service name for the In-Vehicle Digital Twin Service. + - `version`: The version of the In-Vehicle Digital Twin Service to query for. -To use Ibeji with [Chariott's Service Discovery system](https://github.com/eclipse-chariott/chariott/blob/main/service_discovery/README.md), the `service_type` must be `"ChariottDiscoveryService"` and you must specify the following additional config for the adapter: +An example of a configuration file that uses Chariott can be found at `res/ibeji_adapter_config.chariott_sample.json`. -- `metadata`: Information used to query Chariott's Service Discovery system. This is an object with the following properties: - - `namespace`: The service namespace for Ibeji. - - `name`: The service name for Ibeji. - - `version`: The service version for Ibeji. +### Configuration Overrides -Ibeji must also be configured to use Chariott to use this feature. +This adapter supports the same [config overrides](../../docs/config-overrides.md) as the Freyja mocks. The override filename is `ibeji_adapter_config.json`, and the default config is located at `res/ibeji_adapter_config.default.json`. \ No newline at end of file diff --git a/freyja_adapters/digital_twin/ibeji_adapter/build.rs b/freyja_adapters/digital_twin/ibeji_adapter/build.rs index 871645b..70ec9dc 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/build.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/build.rs @@ -2,24 +2,19 @@ // Licensed under the MIT license. // SPDX-License-Identifier: MIT -use std::{env, fs, path::Path}; +use std::env; -const OUT_DIR: &str = "OUT_DIR"; -const SAMPLE_CONFIG_FILE: &str = "res/ibeji_adapter_config.sample.json"; -const CONFIG_FILE: &str = "ibeji_adapter_config.json"; +use freyja_build_common::copy_to_build_out_dir; -fn main() { - // The current directory of the build script is the package's root directory - let config_path = env::current_dir().unwrap().join(SAMPLE_CONFIG_FILE); - - let target_dir = env::var(OUT_DIR).unwrap(); - let dest_path = Path::new(&target_dir).join(CONFIG_FILE); +const RES_DIR_NAME: &str = "res"; +const DEFAULT_CONFIG_FILE: &str = "ibeji_adapter_config.default.json"; - fs::copy(&config_path, dest_path).unwrap(); +fn main() { + // Current directory of the build script is the package's root directory + let config_path = env::current_dir() + .unwrap() + .join(RES_DIR_NAME) + .join(DEFAULT_CONFIG_FILE); - println!( - "The config ibeji_adapter_config.json is located in the {} directory", - target_dir - ); - println!("cargo:rerun-if-changed={}", config_path.to_str().unwrap()); -} + copy_to_build_out_dir(config_path, DEFAULT_CONFIG_FILE); +} \ No newline at end of file diff --git a/freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config_with_chariott.sample.json b/freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config.chariott_sample.json similarity index 69% rename from freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config_with_chariott.sample.json rename to freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config.chariott_sample.json index 66a983b..ad8c6cd 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config_with_chariott.sample.json +++ b/freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config.chariott_sample.json @@ -1,9 +1,9 @@ { - "service_type": "ChariottDiscoveryService", + "service_discovery_method": "ChariottServiceDiscovery", "uri": "http://0.0.0.0:50000", "max_retries": 5, "retry_interval_ms": 1000, - "metadata": { + "discover_request": { "namespace": "sdv.ibeji", "name": "invehicle_digital_twin", "version": "1.0" diff --git a/freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config.sample.json b/freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config.default.json similarity index 63% rename from freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config.sample.json rename to freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config.default.json index b013929..1314afc 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config.sample.json +++ b/freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config.default.json @@ -1,5 +1,5 @@ { - "service_type": "InVehicleDigitalTwinService", + "service_discovery_method": "Config", "uri": "http://0.0.0.0:5010", "max_retries": 5, "retry_interval_ms": 1000 diff --git a/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs b/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs index 82a8c33..e0269e0 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs @@ -4,33 +4,48 @@ use serde::{Deserialize, Serialize}; -pub(crate) const CONFIG_FILE: &str = "ibeji_adapter_config.json"; - -/// Configuration setting variants for selecting the service -/// that the Ibeji Adapter should communicate with to interact with Ibeji +/// Configuration for the Ibeji Adapter. +/// Supports two different schemas based on the service discovery method. #[derive(Clone, Serialize, Deserialize)] -#[serde(tag = "service_type")] -pub enum Settings { - /// In-Vehicle Digital Twin Service - InVehicleDigitalTwinService { +#[serde(tag = "service_discovery_method")] +pub enum Config { + /// Use a URI from the config for the In-Vehicle Digital Twin Service + Config { + /// The URI for the In-Vehicle Digital Twin Service uri: String, + + /// The maximum number of retries for communication attempts max_retries: u32, + + /// The duration between retries in milliseconds retry_interval_ms: u64, }, - /// Chariott's Service Discovery to discover Ibeji - ChariottDiscoveryService { + /// Use Chariott's Service Discovery system to discover the In-Vehicle Digital Twin Service + ChariottServiceDiscovery { + /// The URI for the Chariott Discovery Service uri: String, + + /// The maximum number of retries for communication attempts max_retries: u32, + + /// The duration between retries in milliseconds retry_interval_ms: u64, - metadata: IbejiDiscoveryMetadata, + + /// The request to send to Chariott + discover_request: ChariottDiscoverRequest, }, } -/// Configuration metadata for discovering Ibeji using Chariott +/// A Chariott Service Discovery request #[derive(Clone, Serialize, Deserialize)] -pub struct IbejiDiscoveryMetadata { +pub struct ChariottDiscoverRequest { + /// The service namespace pub namespace: String, + + /// The service name pub name: String, + + /// The service version pub version: String, } diff --git a/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs b/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs index 3055e02..8fadca3 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs @@ -2,7 +2,7 @@ // Licensed under the MIT license. // SPDX-License-Identifier: MIT -use std::{fs, path::Path, str::FromStr, time::Duration}; +use std::{str::FromStr, time::Duration}; use async_trait::async_trait; use core_protobuf_data_access::invehicle_digital_twin::v1::{ @@ -13,8 +13,7 @@ use service_discovery_proto::service_registry::v1::service_registry_client::Serv use service_discovery_proto::service_registry::v1::DiscoverRequest; use tonic::{transport::Channel, Request}; -use crate::config::{IbejiDiscoveryMetadata, Settings, CONFIG_FILE}; -use freyja_common::retry_utils::execute_with_retry; +use freyja_common::{retry_utils::execute_with_retry, config_utils, out_dir}; use freyja_contracts::{ digital_twin_adapter::{ DigitalTwinAdapter, DigitalTwinAdapterError, GetDigitalTwinProviderRequest, @@ -24,6 +23,9 @@ use freyja_contracts::{ provider_proxy::OperationKind, }; +use crate::config::{ChariottDiscoverRequest, Config}; + +const CONFIG_FILE_STEM: &str = "ibeji_adapter_config"; const GET_OPERATION: &str = "Get"; const SUBSCRIBE_OPERATION: &str = "Subscribe"; @@ -36,11 +38,11 @@ impl IbejiAdapter { /// Retrieves Ibeji's In-Vehicle Digital Twin URI from Chariott /// /// # Arguments - /// - `chariott_service_discovery_uri`: the uri for Chariott's service discovery + /// - `chariott_discovery_request`: the uri for Chariott's service discovery /// - `metadata`: optional configuration metadata for discovering Ibeji using Chariott async fn retrieve_ibeji_invehicle_digital_twin_uri_from_chariott( chariott_service_discovery_uri: &str, - chariott_ibeji_config: IbejiDiscoveryMetadata, + chariott_discovery_request: ChariottDiscoverRequest, ) -> Result { let mut service_registry_client = ServiceRegistryClient::connect(String::from(chariott_service_discovery_uri)) @@ -48,9 +50,9 @@ impl IbejiAdapter { .map_err(DigitalTwinAdapterError::communication)?; let discover_request = Request::new(DiscoverRequest { - namespace: chariott_ibeji_config.namespace, - name: chariott_ibeji_config.name, - version: chariott_ibeji_config.version, + namespace: chariott_discovery_request.namespace, + name: chariott_discovery_request.name, + version: chariott_discovery_request.version, }); let service = service_registry_client @@ -73,21 +75,25 @@ impl IbejiAdapter { impl DigitalTwinAdapter for IbejiAdapter { /// Creates a new instance of a DigitalTwinAdapter with default settings fn create_new() -> Result { - let settings_content = - fs::read_to_string(Path::new(env!("OUT_DIR")).join(CONFIG_FILE)).unwrap(); - let settings: Settings = serde_json::from_str(settings_content.as_str()).unwrap(); - - let (invehicle_digital_twin_service_uri, max_retries, retry_interval_ms) = match settings { - Settings::InVehicleDigitalTwinService { + let config = config_utils::read_from_files( + CONFIG_FILE_STEM, + config_utils::JSON_EXT, + out_dir!(), + DigitalTwinAdapterError::io, + DigitalTwinAdapterError::deserialize, + )?; + + let (invehicle_digital_twin_service_uri, max_retries, retry_interval_ms) = match config { + Config::Config { uri, max_retries, retry_interval_ms, } => (uri, max_retries, retry_interval_ms), - Settings::ChariottDiscoveryService { + Config::ChariottServiceDiscovery { uri, max_retries, retry_interval_ms, - metadata, + discover_request, } => { let invehicle_digital_twin_service_uri = futures::executor::block_on(async { execute_with_retry( @@ -96,14 +102,15 @@ impl DigitalTwinAdapter for IbejiAdapter { || { Self::retrieve_ibeji_invehicle_digital_twin_uri_from_chariott( &uri, - metadata.clone(), + discover_request, ) }, Some(String::from("Connection retry for connecting to Chariott")), ) .await }) - .unwrap(); + .map_err(DigitalTwinAdapterError::communication)?; + info!("Discovered the uri of the In-Vehicle Digital Twin Service via Chariott: {invehicle_digital_twin_service_uri}"); ( @@ -124,7 +131,7 @@ impl DigitalTwinAdapter for IbejiAdapter { .await .map_err(DigitalTwinAdapterError::communication) }) - .unwrap(); + .map_err(DigitalTwinAdapterError::communication)?; Ok(Self { client }) } diff --git a/tools/cg/about.toml b/tools/cg/about.toml index 354f3e4..72369a2 100644 --- a/tools/cg/about.toml +++ b/tools/cg/about.toml @@ -1,11 +1,11 @@ accepted = [ - "MIT", "Apache-2.0", + "BSD-2-Clause", + "BSD-3-Clause", + "CC0-1.0", "EPL-1.0", "EPL-2.0", + "MIT", "Unicode-DFS-2016", - "BSD-2-Clause", - "BSD-3-Clause", "Zlib", - "CC0-1.0", ] \ No newline at end of file From fef3535e7a60d2254a4dddbe38b0a67b15381d61 Mon Sep 17 00:00:00 2001 From: William Lyles <26171886+wilyle@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:39:51 -0700 Subject: [PATCH 2/4] port over config improvements for migrated adapters --- Cargo.lock | 31 +++++++++++-------- Cargo.toml | 6 ++++ .../azure_cloud_connector_adapter/Cargo.toml | 5 ++- .../azure_cloud_connector_adapter/README.md | 12 +++---- .../azure_cloud_connector_adapter/build.rs | 25 +++++++-------- ...loud_connector_adapter_config.default.json | 5 +++ ...cloud_connector_adapter_config.sample.json | 5 --- .../src/azure_cloud_connector_adapter.rs | 22 +++++++------ ..._connector_adapter_config.rs => config.rs} | 6 ++-- .../azure_cloud_connector_adapter/src/lib.rs | 2 +- .../digital_twin/ibeji_adapter/README.md | 2 +- .../res/ibeji_adapter_config.default.json | 2 +- .../digital_twin/ibeji_adapter/src/config.rs | 2 +- .../ibeji_adapter/src/ibeji_adapter.rs | 4 +-- 14 files changed, 72 insertions(+), 57 deletions(-) create mode 100644 freyja_adapters/cloud/azure_cloud_connector_adapter/res/azure_cloud_connector_adapter_config.default.json delete mode 100644 freyja_adapters/cloud/azure_cloud_connector_adapter/res/azure_cloud_connector_adapter_config.sample.json rename freyja_adapters/cloud/azure_cloud_connector_adapter/src/{azure_cloud_connector_adapter_config.rs => config.rs} (72%) diff --git a/Cargo.lock b/Cargo.lock index a5d7940..c2aca53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -126,6 +126,7 @@ version = "0.1.0" dependencies = [ "async-trait", "azure-cloud-connector-proto", + "freyja-build-common", "freyja-common", "freyja-contracts", "futures", @@ -534,7 +535,7 @@ dependencies = [ [[package]] name = "freyja" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#71841353eaa1fba745447911e05dba6ce890ca69" +source = "git+https://github.com/eclipse-ibeji/freyja#4dac9b13fc0c5b11056ffe1ecdee2cffadc3f7b0" dependencies = [ "async-trait", "crossbeam", @@ -551,12 +552,12 @@ dependencies = [ [[package]] name = "freyja-build-common" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#71841353eaa1fba745447911e05dba6ce890ca69" +source = "git+https://github.com/eclipse-ibeji/freyja#4dac9b13fc0c5b11056ffe1ecdee2cffadc3f7b0" [[package]] name = "freyja-common" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#71841353eaa1fba745447911e05dba6ce890ca69" +source = "git+https://github.com/eclipse-ibeji/freyja#4dac9b13fc0c5b11056ffe1ecdee2cffadc3f7b0" dependencies = [ "config", "freyja-contracts", @@ -570,7 +571,7 @@ dependencies = [ [[package]] name = "freyja-contracts" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#71841353eaa1fba745447911e05dba6ce890ca69" +source = "git+https://github.com/eclipse-ibeji/freyja#4dac9b13fc0c5b11056ffe1ecdee2cffadc3f7b0" dependencies = [ "async-trait", "crossbeam", @@ -730,7 +731,7 @@ checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] name = "grpc-provider-proxy-v1" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#71841353eaa1fba745447911e05dba6ce890ca69" +source = "git+https://github.com/eclipse-ibeji/freyja#4dac9b13fc0c5b11056ffe1ecdee2cffadc3f7b0" dependencies = [ "async-trait", "crossbeam", @@ -830,11 +831,13 @@ dependencies = [ [[package]] name = "http-mock-provider-proxy" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#71841353eaa1fba745447911e05dba6ce890ca69" +source = "git+https://github.com/eclipse-ibeji/freyja#4dac9b13fc0c5b11056ffe1ecdee2cffadc3f7b0" dependencies = [ "async-trait", "axum", "crossbeam", + "freyja-build-common", + "freyja-common", "freyja-contracts", "log", "mock-digital-twin", @@ -952,7 +955,7 @@ dependencies = [ [[package]] name = "in-memory-mock-cloud-adapter" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#71841353eaa1fba745447911e05dba6ce890ca69" +source = "git+https://github.com/eclipse-ibeji/freyja#4dac9b13fc0c5b11056ffe1ecdee2cffadc3f7b0" dependencies = [ "async-trait", "freyja-contracts", @@ -966,7 +969,7 @@ dependencies = [ [[package]] name = "in-memory-mock-digital-twin-adapter" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#71841353eaa1fba745447911e05dba6ce890ca69" +source = "git+https://github.com/eclipse-ibeji/freyja#4dac9b13fc0c5b11056ffe1ecdee2cffadc3f7b0" dependencies = [ "async-trait", "freyja-contracts", @@ -978,7 +981,7 @@ dependencies = [ [[package]] name = "in-memory-mock-mapping-client" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#71841353eaa1fba745447911e05dba6ce890ca69" +source = "git+https://github.com/eclipse-ibeji/freyja#4dac9b13fc0c5b11056ffe1ecdee2cffadc3f7b0" dependencies = [ "async-trait", "freyja-build-common", @@ -992,10 +995,12 @@ dependencies = [ [[package]] name = "in-memory-mock-provider-proxy" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#71841353eaa1fba745447911e05dba6ce890ca69" +source = "git+https://github.com/eclipse-ibeji/freyja#4dac9b13fc0c5b11056ffe1ecdee2cffadc3f7b0" dependencies = [ "async-trait", "crossbeam", + "freyja-build-common", + "freyja-common", "freyja-contracts", "log", "proc-macros", @@ -1164,7 +1169,7 @@ dependencies = [ [[package]] name = "mock-digital-twin" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#71841353eaa1fba745447911e05dba6ce890ca69" +source = "git+https://github.com/eclipse-ibeji/freyja#4dac9b13fc0c5b11056ffe1ecdee2cffadc3f7b0" dependencies = [ "async-trait", "axum", @@ -1449,7 +1454,7 @@ dependencies = [ [[package]] name = "proc-macros" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#71841353eaa1fba745447911e05dba6ce890ca69" +source = "git+https://github.com/eclipse-ibeji/freyja#4dac9b13fc0c5b11056ffe1ecdee2cffadc3f7b0" dependencies = [ "convert_case", "proc-macro2", @@ -1514,7 +1519,7 @@ dependencies = [ [[package]] name = "provider-proxy-selector" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#71841353eaa1fba745447911e05dba6ce890ca69" +source = "git+https://github.com/eclipse-ibeji/freyja#4dac9b13fc0c5b11056ffe1ecdee2cffadc3f7b0" dependencies = [ "async-trait", "crossbeam", diff --git a/Cargo.toml b/Cargo.toml index cab2d66..fe600b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,11 @@ ibeji-adapter = { path = "freyja_adapters/digital_twin/ibeji_adapter" } # ESDV dependencies # Versioning is managed by the Cargo.lock file rather than copying rev properties to all of these + +## Ibeji core-protobuf-data-access = { git = "https://github.com/eclipse-ibeji/ibeji" } + +## Freyja freyja = { git = "https://github.com/eclipse-ibeji/freyja" } freyja-build-common = { git = "https://github.com/eclipse-ibeji/freyja" } freyja-common = { git = "https://github.com/eclipse-ibeji/freyja" } @@ -31,6 +35,8 @@ in-memory-mock-cloud-adapter = { git = "https://github.com/eclipse-ibeji/freyja" in-memory-mock-digital-twin-adapter = { git = "https://github.com/eclipse-ibeji/freyja" } in-memory-mock-mapping-client = { git = "https://github.com/eclipse-ibeji/freyja" } proc-macros = { git = "https://github.com/eclipse-ibeji/freyja" } + +## Chariott service_discovery_proto = { git = "https://github.com/eclipse-chariott/chariott" } # Cargo dependencies diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/Cargo.toml b/freyja_adapters/cloud/azure_cloud_connector_adapter/Cargo.toml index 9a4bfeb..ede60d9 100644 --- a/freyja_adapters/cloud/azure_cloud_connector_adapter/Cargo.toml +++ b/freyja_adapters/cloud/azure_cloud_connector_adapter/Cargo.toml @@ -21,4 +21,7 @@ tempfile = { workspace = true } tonic = { workspace = true } tokio = { workspace = true } tokio-stream = { workspace = true } -tower = { workspace = true } \ No newline at end of file +tower = { workspace = true } + +[build-dependencies] +freyja-build-common = { workspace = true } \ No newline at end of file diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/README.md b/freyja_adapters/cloud/azure_cloud_connector_adapter/README.md index 26f4416..0abd31d 100644 --- a/freyja_adapters/cloud/azure_cloud_connector_adapter/README.md +++ b/freyja_adapters/cloud/azure_cloud_connector_adapter/README.md @@ -1,8 +1,6 @@ # Azure Cloud Connector Adapter -This is an example implementation of an adapter for the [Azure Cloud Connectors](../../../cloud_connectors/azure/README.md). - -This adapter is used to communicate with an Azure Cloud Connector to synchronize in-vehicle signals with the cloud. +The Azure Cloud Connector Adapter is used to communicate with the [Azure Cloud Connectors](../../../cloud_connectors/azure/README.md) to synchronize in-vehicle signals with the cloud. ## Prerequisites @@ -12,8 +10,10 @@ You will need to either have the [Azure Digital Twins Connector](../../../cloud_ ## Configuration -This cloud adapter can be configured using the `res/azure_cloud_connector_adapter_config.json` file. This file is automatically copied to the build output and contains the following properties: +This adapter supports the following configuration settings: -- `cloud_connector_url`: The URL of the cloud connector. This should match the configuration for your cloud connector. +- `cloud_connector_uri`: The URI of the cloud connector. This should match the configuration for your cloud connector. - `max_retries`: The maximum number of times to retry failed attempts to send data to the cloud connector. -- `retry_interval_ms`: The duration between retries. +- `retry_interval_ms`: The duration between retries in milliseconds. + +This adapter supports the same [config override method](../../docs/config-overrides.md) as the Freyja mocks. The override filename is `azure_cloud_connector_adapter_config.json`, and the default config is located at `res/azure_cloud_connector_adapter_config.default.json`. diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/build.rs b/freyja_adapters/cloud/azure_cloud_connector_adapter/build.rs index 9b75cf8..ff1d1e6 100644 --- a/freyja_adapters/cloud/azure_cloud_connector_adapter/build.rs +++ b/freyja_adapters/cloud/azure_cloud_connector_adapter/build.rs @@ -2,20 +2,19 @@ // Licensed under the MIT license. // SPDX-License-Identifier: MIT -use std::{env, fs, path::Path}; +use std::env; -const OUT_DIR: &str = "OUT_DIR"; -const SAMPLE_CONFIG_FILE: &str = "res/azure_cloud_connector_adapter_config.sample.json"; -const CONFIG_FILE: &str = "azure_cloud_connector_adapter_config.json"; +use freyja_build_common::copy_to_build_out_dir; -fn main() { - // The current directory of the build script is the package's root directory - let config_path = env::current_dir().unwrap().join(SAMPLE_CONFIG_FILE); - - let target_dir = env::var(OUT_DIR).unwrap(); - let dest_path = Path::new(&target_dir).join(CONFIG_FILE); +const RES_DIR_NAME: &str = "res"; +const DEFAULT_CONFIG_FILE: &str = "azure_cloud_connector_adapter_config.default.json"; - fs::copy(&config_path, dest_path).unwrap(); +fn main() { + // Current directory of the build script is the package's root directory + let config_path = env::current_dir() + .unwrap() + .join(RES_DIR_NAME) + .join(DEFAULT_CONFIG_FILE); - println!("cargo:rerun-if-changed={}", config_path.to_str().unwrap()); -} + copy_to_build_out_dir(config_path, DEFAULT_CONFIG_FILE); +} \ No newline at end of file diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/res/azure_cloud_connector_adapter_config.default.json b/freyja_adapters/cloud/azure_cloud_connector_adapter/res/azure_cloud_connector_adapter_config.default.json new file mode 100644 index 0000000..f56dc84 --- /dev/null +++ b/freyja_adapters/cloud/azure_cloud_connector_adapter/res/azure_cloud_connector_adapter_config.default.json @@ -0,0 +1,5 @@ +{ + "cloud_connector_uri": "http://[::1]:8890", + "max_retries": 5, + "retry_interval_ms": 1000 +} \ No newline at end of file diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/res/azure_cloud_connector_adapter_config.sample.json b/freyja_adapters/cloud/azure_cloud_connector_adapter/res/azure_cloud_connector_adapter_config.sample.json deleted file mode 100644 index 71a7c2c..0000000 --- a/freyja_adapters/cloud/azure_cloud_connector_adapter/res/azure_cloud_connector_adapter_config.sample.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "max_retries": 5, - "retry_interval_ms": 1000, - "cloud_connector_url": "http://[::1]:8890" -} \ No newline at end of file diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter.rs b/freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter.rs index cb9b904..ad7f275 100644 --- a/freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter.rs +++ b/freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter.rs @@ -2,7 +2,7 @@ // Licensed under the MIT license. // SPDX-License-Identifier: MIT -use std::{env, fs, path::Path, time::Duration}; +use std::{env, time::Duration}; use async_trait::async_trait; use azure_cloud_connector_proto::azure_cloud_connector::{ @@ -12,12 +12,14 @@ use log::debug; use serde::{Deserialize, Serialize}; use tonic::transport::Channel; -use crate::azure_cloud_connector_adapter_config::{Config, CONFIG_FILE}; -use freyja_common::retry_utils::execute_with_retry; +use freyja_common::{retry_utils::execute_with_retry, config_utils, out_dir}; use freyja_contracts::cloud_adapter::{ CloudAdapter, CloudAdapterError, CloudMessageRequest, CloudMessageResponse, }; +use crate::config::Config; + +const CONFIG_FILE_STEM: &str = "azure_cloud_connector_adapter_config"; const MODEL_ID_KEY: &str = "model_id"; const INSTANCE_ID_KEY: &str = "instance_id"; const INSTANCE_PROPERTY_PATH_KEY: &str = "instance_property_path"; @@ -82,16 +84,18 @@ impl CloudAdapter for AzureCloudConnectorAdapter { /// Creates a new instance of a CloudAdapter with default settings fn create_new() -> Result { 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)?; - // Load the config - let config: Config = - serde_json::from_str(&config_file).map_err(CloudAdapterError::deserialize)?; + let config: Config = config_utils::read_from_files( + CONFIG_FILE_STEM, + config_utils::JSON_EXT, + out_dir!(), + CloudAdapterError::io, + CloudAdapterError::deserialize, + )?; execute_with_retry( config.max_retries, Duration::from_millis(config.retry_interval_ms), - || AzureCloudConnectorClient::connect(config.cloud_connector_url.clone()), + || AzureCloudConnectorClient::connect(config.cloud_connector_uri.clone()), Some(String::from( "Connection retry for connecting to Azure Cloud Connector", )), diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter_config.rs b/freyja_adapters/cloud/azure_cloud_connector_adapter/src/config.rs similarity index 72% rename from freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter_config.rs rename to freyja_adapters/cloud/azure_cloud_connector_adapter/src/config.rs index 3e985fd..7101fb0 100644 --- a/freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter_config.rs +++ b/freyja_adapters/cloud/azure_cloud_connector_adapter/src/config.rs @@ -4,8 +4,6 @@ use serde::{Deserialize, Serialize}; -pub(crate) const CONFIG_FILE: &str = "azure_cloud_connector_adapter_config.json"; - /// A config entry for the Azure Cloud Connector Adapter #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Config { @@ -15,6 +13,6 @@ pub struct Config { /// Retry interval in milliseconds pub retry_interval_ms: u64, - /// The url for the cloud connector server - pub cloud_connector_url: String, + /// The uri for the cloud connector server + pub cloud_connector_uri: String, } diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/src/lib.rs b/freyja_adapters/cloud/azure_cloud_connector_adapter/src/lib.rs index 26ee911..e95d15b 100644 --- a/freyja_adapters/cloud/azure_cloud_connector_adapter/src/lib.rs +++ b/freyja_adapters/cloud/azure_cloud_connector_adapter/src/lib.rs @@ -3,4 +3,4 @@ // SPDX-License-Identifier: MIT pub mod azure_cloud_connector_adapter; -mod azure_cloud_connector_adapter_config; +mod config; diff --git a/freyja_adapters/digital_twin/ibeji_adapter/README.md b/freyja_adapters/digital_twin/ibeji_adapter/README.md index 5050472..79f7ab8 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/README.md +++ b/freyja_adapters/digital_twin/ibeji_adapter/README.md @@ -32,4 +32,4 @@ An example of a configuration file that uses Chariott can be found at `res/ibeji ### Configuration Overrides -This adapter supports the same [config overrides](../../docs/config-overrides.md) as the Freyja mocks. The override filename is `ibeji_adapter_config.json`, and the default config is located at `res/ibeji_adapter_config.default.json`. \ No newline at end of file +This adapter supports the same [config override method](../../docs/config-overrides.md) as the Freyja mocks. The override filename is `ibeji_adapter_config.json`, and the default config is located at `res/ibeji_adapter_config.default.json`. diff --git a/freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config.default.json b/freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config.default.json index 1314afc..1c7f507 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config.default.json +++ b/freyja_adapters/digital_twin/ibeji_adapter/res/ibeji_adapter_config.default.json @@ -1,5 +1,5 @@ { - "service_discovery_method": "Config", + "service_discovery_method": "FromConfig", "uri": "http://0.0.0.0:5010", "max_retries": 5, "retry_interval_ms": 1000 diff --git a/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs b/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs index e0269e0..7c476e0 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; #[serde(tag = "service_discovery_method")] pub enum Config { /// Use a URI from the config for the In-Vehicle Digital Twin Service - Config { + FromConfig { /// The URI for the In-Vehicle Digital Twin Service uri: String, diff --git a/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs b/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs index 8fadca3..77d7dbb 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs @@ -84,7 +84,7 @@ impl DigitalTwinAdapter for IbejiAdapter { )?; let (invehicle_digital_twin_service_uri, max_retries, retry_interval_ms) = match config { - Config::Config { + Config::FromConfig { uri, max_retries, retry_interval_ms, @@ -102,7 +102,7 @@ impl DigitalTwinAdapter for IbejiAdapter { || { Self::retrieve_ibeji_invehicle_digital_twin_uri_from_chariott( &uri, - discover_request, + discover_request.clone(), ) }, Some(String::from("Connection retry for connecting to Chariott")), From 10cb2ab093103fd69a69b36f5808ac243ffc8361 Mon Sep 17 00:00:00 2001 From: William Lyles <26171886+wilyle@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:45:31 -0700 Subject: [PATCH 3/4] fix build issues --- freyja_adapters/cloud/azure_cloud_connector_adapter/README.md | 2 +- freyja_adapters/cloud/azure_cloud_connector_adapter/build.rs | 2 +- .../src/azure_cloud_connector_adapter.rs | 2 +- freyja_adapters/digital_twin/ibeji_adapter/README.md | 2 +- freyja_adapters/digital_twin/ibeji_adapter/build.rs | 2 +- freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/README.md b/freyja_adapters/cloud/azure_cloud_connector_adapter/README.md index 0abd31d..e610061 100644 --- a/freyja_adapters/cloud/azure_cloud_connector_adapter/README.md +++ b/freyja_adapters/cloud/azure_cloud_connector_adapter/README.md @@ -16,4 +16,4 @@ This adapter supports the following configuration settings: - `max_retries`: The maximum number of times to retry failed attempts to send data to the cloud connector. - `retry_interval_ms`: The duration between retries in milliseconds. -This adapter supports the same [config override method](../../docs/config-overrides.md) as the Freyja mocks. The override filename is `azure_cloud_connector_adapter_config.json`, and the default config is located at `res/azure_cloud_connector_adapter_config.default.json`. +This adapter supports the same [config override method](https://github.com/eclipse-ibeji/freyja/blob/main/docs/config-overrides.md) as the Freyja mocks. The override filename is `azure_cloud_connector_adapter_config.json`, and the default config is located at `res/azure_cloud_connector_adapter_config.default.json`. diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/build.rs b/freyja_adapters/cloud/azure_cloud_connector_adapter/build.rs index ff1d1e6..3ee420a 100644 --- a/freyja_adapters/cloud/azure_cloud_connector_adapter/build.rs +++ b/freyja_adapters/cloud/azure_cloud_connector_adapter/build.rs @@ -17,4 +17,4 @@ fn main() { .join(DEFAULT_CONFIG_FILE); copy_to_build_out_dir(config_path, DEFAULT_CONFIG_FILE); -} \ No newline at end of file +} diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter.rs b/freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter.rs index ad7f275..976a0a6 100644 --- a/freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter.rs +++ b/freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter.rs @@ -12,7 +12,7 @@ use log::debug; use serde::{Deserialize, Serialize}; use tonic::transport::Channel; -use freyja_common::{retry_utils::execute_with_retry, config_utils, out_dir}; +use freyja_common::{config_utils, out_dir, retry_utils::execute_with_retry}; use freyja_contracts::cloud_adapter::{ CloudAdapter, CloudAdapterError, CloudMessageRequest, CloudMessageResponse, }; diff --git a/freyja_adapters/digital_twin/ibeji_adapter/README.md b/freyja_adapters/digital_twin/ibeji_adapter/README.md index 79f7ab8..8779a11 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/README.md +++ b/freyja_adapters/digital_twin/ibeji_adapter/README.md @@ -32,4 +32,4 @@ An example of a configuration file that uses Chariott can be found at `res/ibeji ### Configuration Overrides -This adapter supports the same [config override method](../../docs/config-overrides.md) as the Freyja mocks. The override filename is `ibeji_adapter_config.json`, and the default config is located at `res/ibeji_adapter_config.default.json`. +This adapter supports the same [config override method](https://github.com/eclipse-ibeji/freyja/blob/main/docs/config-overrides.md) as the Freyja mocks. The override filename is `ibeji_adapter_config.json`, and the default config is located at `res/ibeji_adapter_config.default.json`. diff --git a/freyja_adapters/digital_twin/ibeji_adapter/build.rs b/freyja_adapters/digital_twin/ibeji_adapter/build.rs index 70ec9dc..e93e689 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/build.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/build.rs @@ -17,4 +17,4 @@ fn main() { .join(DEFAULT_CONFIG_FILE); copy_to_build_out_dir(config_path, DEFAULT_CONFIG_FILE); -} \ No newline at end of file +} diff --git a/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs b/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs index 77d7dbb..4fb43b5 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs @@ -13,7 +13,7 @@ use service_discovery_proto::service_registry::v1::service_registry_client::Serv use service_discovery_proto::service_registry::v1::DiscoverRequest; use tonic::{transport::Channel, Request}; -use freyja_common::{retry_utils::execute_with_retry, config_utils, out_dir}; +use freyja_common::{config_utils, out_dir, retry_utils::execute_with_retry}; use freyja_contracts::{ digital_twin_adapter::{ DigitalTwinAdapter, DigitalTwinAdapterError, GetDigitalTwinProviderRequest, From 570448fbffa92040443eb73bdd532842631597fc Mon Sep 17 00:00:00 2001 From: William Lyles <26171886+wilyle@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:47:20 -0700 Subject: [PATCH 4/4] fix a test issue --- freyja_adapters/cloud/azure_cloud_connector_adapter/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/Cargo.toml b/freyja_adapters/cloud/azure_cloud_connector_adapter/Cargo.toml index ede60d9..bb70667 100644 --- a/freyja_adapters/cloud/azure_cloud_connector_adapter/Cargo.toml +++ b/freyja_adapters/cloud/azure_cloud_connector_adapter/Cargo.toml @@ -20,7 +20,7 @@ serde_json = { workspace = true } tempfile = { workspace = true } tonic = { workspace = true } tokio = { workspace = true } -tokio-stream = { workspace = true } +tokio-stream = { workspace = true, features = ["net"] } tower = { workspace = true } [build-dependencies]