Skip to content

Commit

Permalink
migrate ibeji adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
wilyle committed Feb 6, 2024
1 parent 6c3db75 commit b64b782
Show file tree
Hide file tree
Showing 10 changed files with 515 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"adapters/data/in_memory_mock_data_adapter",
"adapters/data/managed_subscribe_data_adapter",
"adapters/data/mqtt_data_adapter",
"adapters/digital_twin/ibeji_adapter",
"adapters/digital_twin/in_memory_mock_digital_twin_adapter",
"adapters/digital_twin/mock_digital_twin_adapter",
"adapters/mapping/in_memory_mock_mapping_adapter",
Expand Down
31 changes: 31 additions & 0 deletions adapters/digital_twin/ibeji_adapter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
# SPDX-License-Identifier: MIT

[package]
name = "ibeji-adapter"
version = "0.1.0"
edition = "2021"
license = "MIT"

[dependencies]
async-trait = { workspace = true }
core-protobuf-data-access = { workspace = true }
freyja-build-common = { workspace = true }
freyja-common = { workspace = true }
futures = { workspace = true }
log = { workspace = true }
proc-macros = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
service_discovery_proto = { workspace = true }
strum = { workspace = true }
strum_macros = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true }
tokio-stream = { workspace = true, features = ["net"] }
tonic = { workspace = true }
tower = { workspace = true }

[build-dependencies]
freyja-build-common = { workspace = true }
35 changes: 35 additions & 0 deletions adapters/digital_twin/ibeji_adapter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Ibeji Adapter

The Ibeji Adapter is used to integrate with the [Ibeji In-Vehicle Digital Twin Service](https://github.com/eclipse-ibeji/ibeji), and optionally [Chariott](https://github.com/eclipse-chariott/chariott) to discover Ibeji.

## Configuration

This adapter supports two different configuration schemas depending on how you want to discover the In-Vehicle Digital Twin Service:

### Without Chariott

To bypass Chariott and use a configuration value to specify the In-Vehicle Digital Twin Service URI, you must specify the following configuration:

- `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.

### Using Chariott

To use Chariott to discover the In-Vehicle Digital Twin Service, you must specify the following configuration:

- `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.

An example of a configuration file that uses Chariott can be found at `res/ibeji_adapter_config.chariott_sample.json`.

### Configuration Overrides

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`.
11 changes: 11 additions & 0 deletions adapters/digital_twin/ibeji_adapter/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

use freyja_build_common::copy_config;

const CONFIG_FILE_STEM: &str = "ibeji_adapter_config";

fn main() {
copy_config(CONFIG_FILE_STEM);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"service_discovery_method": "ChariottServiceDiscovery",
"uri": "http://0.0.0.0:50000",
"max_retries": 5,
"retry_interval_ms": 1000,
"discover_request": {
"namespace": "sdv.ibeji",
"name": "invehicle_digital_twin",
"version": "1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"service_discovery_method": "FromConfig",
"uri": "http://0.0.0.0:5010",
"max_retries": 5,
"retry_interval_ms": 1000
}
51 changes: 51 additions & 0 deletions adapters/digital_twin/ibeji_adapter/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

use serde::{Deserialize, Serialize};

/// Configuration for the Ibeji Adapter.
/// Supports two different schemas based on the service discovery method.
#[derive(Clone, Serialize, Deserialize)]
#[serde(tag = "service_discovery_method")]
pub enum Config {
/// Use a URI from the config for the In-Vehicle Digital Twin Service
FromConfig {
/// 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,
},

/// 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,

/// The request to send to Chariott
discover_request: ChariottDiscoverRequest,
},
}

/// A Chariott Service Discovery request
#[derive(Clone, Serialize, Deserialize)]
pub struct ChariottDiscoverRequest {
/// The service namespace
pub namespace: String,

/// The service name
pub name: String,

/// The service version
pub version: String,
}
Loading

0 comments on commit b64b782

Please sign in to comment.