Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Digital Twin Graph #110

Merged
merged 115 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
48d8c10
Digital Twin Graph
ashbeitz Mar 24, 2024
2f2a748
Improved seat massager sample
ashbeitz Mar 25, 2024
eebe5bd
Digital Twin Graph
ashbeitz Mar 25, 2024
42a3230
Digital Twin Graph
ashbeitz Mar 25, 2024
9fa461d
Digital Twin Graph
ashbeitz Mar 25, 2024
41f3e7f
Digital Twin Graph
ashbeitz Mar 26, 2024
6a448bb
Digital Twin Graph
ashbeitz Apr 18, 2024
3144fec
Digital Twin Graph
ashbeitz Apr 18, 2024
2cdc650
Digital Twin Graph
ashbeitz Apr 21, 2024
084f896
Digital Twin Graph
ashbeitz Apr 21, 2024
bbab189
Digital Twin Graph
ashbeitz Apr 22, 2024
30bdb56
Digital Twin Graph
ashbeitz Apr 22, 2024
ace163d
Digital Twin Graph
ashbeitz Apr 22, 2024
2852951
Digital Twin Graph
ashbeitz Apr 23, 2024
0e267fb
Digital Twin Graph
ashbeitz Apr 23, 2024
1bfd6f9
Digital Twin Graph
ashbeitz Apr 23, 2024
5baf3ce
Digital Twin Graph
ashbeitz Apr 23, 2024
3001f7e
Digital Twin Graph
ashbeitz Apr 23, 2024
ec8b1bb
Digital Twin Graph
ashbeitz Apr 24, 2024
30c43e3
Digital Twin Graph
ashbeitz Apr 24, 2024
0f104dd
Digital Twin Graph
ashbeitz Apr 24, 2024
e1bcafb
Digital Twin Graph
ashbeitz Apr 24, 2024
0ba7580
Digital Twin Graph
ashbeitz Apr 24, 2024
788f4d0
Digital Twin Graph
ashbeitz Apr 25, 2024
1950d82
Digital Twin Graph
ashbeitz Apr 25, 2024
f02a537
Digital Twin Graph
ashbeitz Apr 26, 2024
2d8f2da
Generate PlantUML Diagrams
eclipse-ibeji-bot Apr 26, 2024
4390681
Digital Twin Graph
ashbeitz Apr 26, 2024
565a983
Merge branch 'ashbeitz/digitalTwinGraph' of https://github.com/eclips…
ashbeitz Apr 26, 2024
1581377
Generate PlantUML Diagrams
eclipse-ibeji-bot Apr 26, 2024
b304cd0
Digital Twin Graph
ashbeitz Apr 26, 2024
a7652e5
Merge branch 'ashbeitz/digitalTwinGraph' of https://github.com/eclips…
ashbeitz Apr 26, 2024
282012c
Digital Twin Graph
ashbeitz Apr 29, 2024
0b9bc6a
Generate PlantUML Diagrams
eclipse-ibeji-bot Apr 29, 2024
72067f7
Digital Twin Graph
ashbeitz Apr 29, 2024
07ca7c0
Merge branch 'ashbeitz/digitalTwinGraph' of https://github.com/eclips…
ashbeitz Apr 29, 2024
80c53c5
Digital Twin Graph
ashbeitz Apr 29, 2024
efea9e8
Digital Twin Graph
ashbeitz Apr 29, 2024
57942c5
Digital Twin Graph
ashbeitz Apr 29, 2024
3881c10
Digital Twin Graph
ashbeitz Apr 29, 2024
9d5404d
Digital Twin Graph
ashbeitz Apr 29, 2024
2aed358
Digital Twin Graph
ashbeitz Apr 30, 2024
0a881d4
Generate PlantUML Diagrams
eclipse-ibeji-bot Apr 30, 2024
8c60c7c
Digital Twin Graph
ashbeitz Apr 30, 2024
23cdfc3
Generate PlantUML Diagrams
eclipse-ibeji-bot Apr 30, 2024
243e057
Digital Twin Graph
ashbeitz Apr 30, 2024
a2d05f8
Generate PlantUML Diagrams
eclipse-ibeji-bot Apr 30, 2024
26088cb
Digital Twin Graph
ashbeitz Apr 30, 2024
6a5cab1
Merge branch 'ashbeitz/digitalTwinGraph' of https://github.com/eclips…
ashbeitz Apr 30, 2024
66693e2
Digital Twin Graph
ashbeitz Apr 30, 2024
a51723d
Digital Twin Graph
ashbeitz Apr 30, 2024
3b3f331
Digital Twin Graph
ashbeitz May 1, 2024
0aa2baf
Digital Twin Graph
ashbeitz May 1, 2024
c663f87
Digital Twin Graph
ashbeitz May 1, 2024
de66a57
Digital Twin Graph
ashbeitz May 1, 2024
7b2bb16
Digital Twin Graph
ashbeitz May 1, 2024
8afdd76
Digital Twin Graph
ashbeitz May 1, 2024
68f1124
Digital Twin Graph
ashbeitz May 1, 2024
7b9b4d6
Digital Twin Graph
ashbeitz May 2, 2024
05345ab
Digital Twin Graph
ashbeitz May 2, 2024
1807489
Digital Twin Graph
ashbeitz May 2, 2024
5ae74c4
Digital Twin Graph
ashbeitz May 2, 2024
22a6f4c
Digital Twin Graph
ashbeitz May 2, 2024
4a590fb
Digital Twin Graph
ashbeitz May 3, 2024
532a84e
Digital Twin Graph
ashbeitz May 3, 2024
f3b11fd
Digital Twin Graph
ashbeitz May 3, 2024
1f132a8
Digital Twin Graph
ashbeitz May 4, 2024
cc4a5be
Digital Twin Graph
ashbeitz May 4, 2024
21735bf
Digital Twin Graph
ashbeitz May 5, 2024
84369e9
Digital Twin Graph
ashbeitz May 5, 2024
dba0a31
Digital Twin Graph
ashbeitz May 5, 2024
4506ec0
Digital Twin Graph
ashbeitz May 5, 2024
ef9ced4
Digital Twin Graph
ashbeitz May 5, 2024
ce9f992
Digital Twin Graph
ashbeitz May 6, 2024
66f2c0f
Digital Twin Graph
ashbeitz May 6, 2024
d10a7dd
Digital Twin Graph
ashbeitz May 6, 2024
4608cf2
Digital Twin Graph
ashbeitz May 6, 2024
837c383
Digital Twin Graph
ashbeitz May 6, 2024
bdb67ac
Digital Twin Graph
ashbeitz May 6, 2024
7fc6ff1
Digital Twin Graph
ashbeitz May 6, 2024
7a97fc3
Digital Twin Graph
ashbeitz May 6, 2024
f5bfaee
Digital Twin Graph
ashbeitz May 6, 2024
f502fac
Digital Twin Graph
ashbeitz May 6, 2024
40293c0
Digital Twin Graph
ashbeitz May 6, 2024
57b2534
Digital Twin Graph
ashbeitz May 6, 2024
edde513
Digital Twin Graph
ashbeitz May 7, 2024
2ad820e
Generate PlantUML Diagrams
eclipse-ibeji-bot May 7, 2024
61de269
Digital Twin Graph
ashbeitz May 7, 2024
11bda50
Digital Twin Graph
ashbeitz May 7, 2024
2cb4bce
Digital Twin Graph
ashbeitz May 7, 2024
7e637c3
Digital Twin Graph
ashbeitz May 7, 2024
07d51b2
Digital Twin Graph
ashbeitz May 7, 2024
0b5b675
Digital Twin Graph
ashbeitz May 8, 2024
56ab4b9
Digital Twin Graph
ashbeitz May 8, 2024
b116968
Digital Twin Graph
ashbeitz May 9, 2024
ca47575
Digital Twin Graph
ashbeitz May 9, 2024
a0ce789
Digital Twin Graph
ashbeitz May 9, 2024
e32c6d7
Digital Twin Graph
ashbeitz May 9, 2024
8b12825
Digital Twin Graph
ashbeitz May 9, 2024
1a17ea6
Digital Twin Graph
ashbeitz May 9, 2024
0043b28
Digital Twin Graph
ashbeitz May 10, 2024
e0eb9b8
Generate PlantUML Diagrams
eclipse-ibeji-bot May 10, 2024
9bd59df
Digital Twin Graph
ashbeitz May 10, 2024
984c072
Digital Twin Graph
ashbeitz May 10, 2024
8138699
Generate PlantUML Diagrams
eclipse-ibeji-bot May 10, 2024
4d14d0e
Digital Twin Graph
ashbeitz May 10, 2024
98541b6
Merge branch 'ashbeitz/digitalTwinGraph' of https://github.com/eclips…
ashbeitz May 10, 2024
a0568fe
Digital Twin Graph
ashbeitz May 10, 2024
d0ca2ce
Generate PlantUML Diagrams
eclipse-ibeji-bot May 10, 2024
9dca7ff
Digital Twin Graph
ashbeitz May 10, 2024
6e90503
Merge branch 'ashbeitz/digitalTwinGraph' of https://github.com/eclips…
ashbeitz May 10, 2024
7ed2c96
Digital Twin Graph
ashbeitz May 10, 2024
b7a4580
Generate PlantUML Diagrams
eclipse-ibeji-bot May 10, 2024
951fa26
Digital Twin Graph
ashbeitz May 10, 2024
d0d1161
Digital Twin Graph
ashbeitz May 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ jobs:
- name: Cache Dependencies
uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build
# Build the project with the `managed_subscribe`, `digital_twin_graph` and `digital_twin_registry` features enabled.
run: cargo build --features "managed_subscribe,digital_twin_graph,digital_twin_registry"
- name: Test
run: cargo test
# Test the project with the `managed_subscribe`, `digital_twin_graph` and `digital_twin_registry` features enabled.
run: cargo test --features "managed_subscribe,digital_twin_graph,digital_twin_registry"
6 changes: 5 additions & 1 deletion .github/workflows/security-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
# Ignored advisories:
# - https://rustsec.org/advisories/RUSTSEC-2024-0320 : yaml-rust is unmaintained
# - This is a dependency of the config crate, which does not have a version without yaml-rust.
# See https://github.com/mehcode/config-rs/issues/473
- run: |
cargo audit --deny warnings
cargo audit --deny warnings --ignore RUSTSEC-2024-0320
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ members = [

# extension
"core/module/managed_subscribe",
"core/module/digital_twin_graph",
"core/module/digital_twin_registry",

# DTDL tools
"dtdl-tools",
Expand All @@ -27,6 +29,7 @@ members = [
"samples/common",
"samples/protobuf_data_access",
"samples/command",
"samples/digital_twin_graph",
"samples/managed_subscribe",
"samples/mixed",
"samples/property",
Expand Down Expand Up @@ -67,6 +70,7 @@ strum = "0.26.1"
strum_macros = "0.26.1"
tokio = "1.29.1"
tokio-console-subscriber = { version = "0.2.0", package = "console-subscriber" }
tokio-retry = "0.3"
tokio-stream = "0.1.14"
tonic = "0.11.0"
tonic-build = "0.11.0"
Expand Down
200 changes: 31 additions & 169 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
- [Tokio Console Support](#tokio-console-support)
- [Running the Tests](#running-the-tests)
- [Running the Samples](#running-the-samples)
- [Property Sample](#property-sample)
- [Command Sample](#command-sample)
- [Mixed Sample](#mixed-sample)
- [Seat Massager Sample](#seat-massager-sample)
- [Streaming Sample](#streaming-sample)
- [Using Chariott](#using-chariott)
- [Using Chariott](#using-chariott)
- [Running in a Container](#running-in-a-container)
- [Trademarks](#trademarks)

Expand Down Expand Up @@ -95,24 +90,33 @@ Instructions for installing Mosquitto can be found [here](https://github.com/ecl

## <a name="cloning-the-repo">Cloning the Repo</a>

The repo has two submodules [opendigitaltwins-dtdl](https://github.com/Azure/opendigitaltwins-dtdl) and [iot-plugandplay-models](https://github.com/Azure/iot-plugandplay-models) that provide DTDL context files
and DTDL samples file. To ensure that these are included, please use the following command when cloning Ibeji's github repo:
The repo has two submodules [opendigitaltwins-dtdl](https://github.com/Azure/opendigitaltwins-dtdl) and [iot-plugandplay-models](https://github.com/Azure/iot-plugandplay-models) that provide DTDL context files and DTDL samples file. To ensure that these are included, please use the following command when cloning Ibeji's github repo:

`git clone --recurse-submodules https://github.com/eclipse-ibeji/ibeji`
````shell
git clone --recurse-submodules https://github.com/eclipse-ibeji/ibeji`
````

## <a name="building">Building</a>

Once you have installed the prerequisites, go to your enlistment's root directory and run:

`cargo build`
````shell
cargo build
````

This should build all of the libraries and executables.
This will build all of the foundation libraries and executables.

Ibeji also has add-on modules that rely on feature flags to include them in the build. For example, to build Ibeji with the Digital Twin Graph and the Digital Twin Registry modules run:

````shell
cargo build --features "digital_twin_graph,digital_twin_registry"
````

### <a name="tokio-console-support">Tokio Console Support</a>

Ibeji has support for using the [tokio console](https://github.com/tokio-rs/console) for advanced debugging. To enable this support, you need to build with the `tokio_console` feature enabled and with the `tokio_unstable` config flag for the rust compiler:

```bash
```shell
RUSTFLAGS="--cfg tokio_unstable" cargo build --features tokio_console
```

Expand All @@ -124,178 +128,36 @@ Note that the tokio console will intercept trace-level logs, so these will not b

After successfully building Ibeji, you can run all of the unit tests. To do this go to the enlistment's root directory and run:

`cargo test`
````shell
cargo test
````

Currently, we have no integration tests or end-to-end tests.

## <a name="running-the-samples">Running the Samples</a>

There are currently four samples: one that demonstrates the use of a property, one that demonstrates the use of a command, one that
demonstrates the mixed use of properties and commands and one that demonstrates the use of get/set for a seat massager.
There are currently six samples:

The demos use config files and we have provided a templated version of each config file. These templates can be found in:
- [Property Sample](docs/samples/property/README.md) - demonstrates the use of a property
- [Command Sample](docs/samples/command/README.md) - demonstrates the use of a command
- [Mixed Sample](docs/samples/mixed/README.md) - demonstrates the mixed use of properties and commands
- [Seat Massager Sample](docs/samples/seat_massager/README.md) - demonstrates the use of get/set for a seat massager
- [Streaming Sample](docs/samples/streaming/README.md) - demonstrates the use of streaming
- [Digital Twin Graph Sample](docs/samples/digital_twin_graph/README.md) - demonstrates the use of the Digital Twin Graph Service

- {repo-root-dir}/core/invehicle-digital-twin/template
- {repo-root-dir}/samples/common/template

Configuration files will be loaded from the current working directory by default
The samples' configuration files will be loaded from the current working directory by default,
but an `IBEJI_HOME` environment variable can be used to change the base configuration directory to a different one:

```bash
```shell
IBEJI_HOME=/etc/ibeji ./invehicle-digital-twin
```

The above example tells `invehicle-digital-twin` to load configuration files from `/etc/ibeji` instead of using
the current working directory.

Chariott may be used to discover the in-vehicle digital twin service. We will discuss how to enable this feature.

### <a name="property-sample">Property Sample</a>

The following instructions are for the demo for the use of a property. This sample uses a MQTT Broker; please make sure that it is running.

Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Digital Twin Provider and one running the Digital Twin Consumer.
Orientate the three windows so that they are lined up in a column. The top window can be used for the In-Vehicle Digital Twin.
The middle window can be used for the Digital Twin Provider. The bottom window can be used for the Digital Twin Consumer.<br>
1. In each window, change directory to the directory containing the build artifacts.
Make sure that you replace "{repo-root-dir}" with the repository root directory on the machine where you are running the demo.<br><br>
`cd {repo-root-dir}/target/debug`<br>
1. Create the three config files with the following contents, if they are not already there:<br><br>
---- consumer_settings.yaml ----<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
---- invehicle_digital_twin_settings.yaml ----<br>
`invehicle_digital_twin_authority: "0.0.0.0:5010"`<br><br>
---- provider_settings.yaml ----<br>
`provider_authority: "0.0.0.0:1883"`<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
1. In the top window, run:<br><br>
`./invehicle-digital-twin`<br>
1. In the middle window, run:<br><br>
`./property-provider`<br>
1. In the bottom window, run:<br><br>
`./property-consumer`<br>
1. Use control-c in each of the windows when you wish to stop the demo.

### <a name="command-sample">Command Sample</a>

The following instructions are for the demo for the use of a command.

Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Digital Twin Provider and one running the Digital Twin Consumer.
Orientate the three windows so that they are lined up in a column. The top window can be used for the In-Vehicle Digital Twin.
The middle window can be used for the Digital Twin Provider. The bottom window can be used for the Digital Twin Consumer.<br>
1. In each window, change directory to the directory containing the build artifacts.
Make sure that you replace "{repo-root-dir}" with the repository root directory on the machine where you are running the demo.<br><br>
`cd {repo-root-dir}/target/debug`<br>
1. Create the three config files with the following contents, if they are not already there:<br><br>
---- consumer_settings.yaml ----<br>
`consumer_authority: "0.0.0.0:6010"`<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
---- invehicle_digital_twin_settings.yaml ----<br>
`invehicle_digital_twin_authority: "0.0.0.0:5010"`<br><br>
---- provider_settings.yaml ----<br>
`provider_authority: "0.0.0.0:4010"`<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
1. In the top window, run:<br><br>
`./invehicle-digital-twin`<br>
1. In the middle window, run:<br><br>
`./command-provider`<br>
1. In the bottom window, run:<br><br>
`./command-consumer`<br>
1. Use control-c in each of the windows when you wish to stop the demo.

### <a name="mixed-sample">Mixed Sample</a>

The following instructions are for the demo for the mixed use of commands and properties.

Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Digital Twin Provider and one running the Digital Twin Consumer.
Orientate the three windows so that they are lined up in a column. The top window can be used for the In-Vehicle Digital Twin.
The middle window can be used for the Digital Twin Provider. The bottom window can be used for the Digital Twin Consumer.<br>
1. In each window, change directory to the directory containing the build artifacts.
Make sure that you replace "{repo-root-dir}" with the repository root directory on the machine where you are running the demo.<br><br>
`cd {repo-root-dir}/target/debug`<br>
1. Create the three config files with the following contents, if they are not already there:<br><br>
---- consumer_settings.yaml ----<br>
`consumer_authority: "0.0.0.0:6010"`<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
---- invehicle_digital_twin_settings.yaml ----<br>
`invehicle_digital_twin_authority: "0.0.0.0:5010"`<br><br>
---- provider_settings.yaml ----<br>
`provider_authority: "0.0.0.0:4010"`<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
1. In the top window, run:<br><br>
`./invehicle-digital-twin`<br>
1. In the middle window, run:<br><br>
`./mixed-provider`<br>
1. In the bottom window, run:<br><br>
`./mixed-consumer`<br>
1. Use control-c in each of the windows when you wish to stop the demo.

### <a name="seat-massager-sample">Seat Massager Sample</a>

The following instructions are for the demo for a seat massager.

Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Digital Twin Provider and one running the Digital Twin Consumer.
Orientate the three windows so that they are lined up in a column. The top window can be used for the In-Vehicle Digital Twin.
The middle window can be used for the Digital Twin Provider. The bottom window can be used for the Digital Twin Consumer.<br>
1. In each window, change directory to the directory containing the build artifacts.
Make sure that you replace "{repo-root-dir}" with the repository root directory on the machine where you are running the demo.<br><br>
`cd {repo-root-dir}/target/debug`<br>
1. Create the three config files with the following contents, if they are not already there:<br><br>
---- consumer_settings.yaml ----<br>
`consumer_authority: "0.0.0.0:6010"`<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
---- invehicle_digital_twin_settings.yaml ----<br>
`invehicle_digital_twin_authority: "0.0.0.0:5010"`<br><br>
---- provider_settings.yaml ----<br>
`provider_authority: "0.0.0.0:4010"`<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
1. In the top window, run:<br><br>
`./invehicle-digital-twin`<br>
1. In the middle window, run:<br><br>
`./seat-massager-provider`<br>
1. In the bottom window, run:<br><br>
`./seat-massager-consumer`<br>
1. Use control-c in each of the windows when you wish to stop the demo.

### <a name="streaming-sample">Streaming Sample</a>

The following instructions are for the demo for streaming.

Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Digital Twin Provider and one running the Digital Twin Consumer.
Orientate the three windows so that they are lined up in a column. The top window can be used for the In-Vehicle Digital Twin.
The middle window can be used for the Digital Twin Provider. The bottom window can be used for the Digital Twin Consumer.<br>
1. In each window, change directory to the directory containing the build artifacts.
Make sure that you replace "{repo-root-dir}" with the repository root directory on the machine where you are running the demo.<br><br>
`cd {repo-root-dir}/target/debug`<br>
1. Create the three config files with the following contents, if they are not already there:<br><br>
---- streaming_consumer_settings.yaml ----<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
`number_of_images: 20`<br><br>
---- invehicle_digital_twin_settings.yaml ----<br>
`invehicle_digital_twin_authority: "0.0.0.0:5010"`<br><br>
---- streaming_provider_settings.yaml ----<br>
`provider_authority: "0.0.0.0:4010"`<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
`image_directory: "<<chariott-repo-root>>/examples/applications/simulated-camera/images"`
1. In the top window, run:<br><br>
`./invehicle-digital-twin`<br>
1. In the middle window, run:<br><br>
`./streaming-provider`<br>
1. In the bottom window, run:<br><br>
`./streaming-consumer`<br>
1. Use control-c in each of the windows when you wish to stop the demo.

### <a name="using-chariott">Using Chariott</a>
With the samples, Chariott may be used to discover the in-vehicle digital twin service. We will discuss how to enable this feature in the section on [Using Chariott](#using-chariott).

## <a name="using-chariott">Using Chariott</a>

If you want the digital twin consumers and digital twin providers for each demo to use Chariott to discover the URI for the In-Vehicle Digital Twin Service,
rather than having it statically provided in their respective config file, then do the following before starting each demo:
Expand Down
33 changes: 33 additions & 0 deletions core/common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ pub async fn get_service_uri(
Ok(result)
}

/// Is the provided subset a subset of the provided superset?
///
/// # Arguments
/// * `subset` - The provided subset.
/// * `superset` - The provided superset.
pub fn is_subset(subset: &[String], superset: &[String]) -> bool {
subset.iter().all(|subset_member| {
superset.iter().any(|supserset_member| subset_member == supserset_member)
})
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -228,4 +239,26 @@ mod tests {
.await;
assert!(result.is_err());
}

#[test]
fn is_subset_test() {
assert!(is_subset(&[], &[]));
assert!(is_subset(&[], &["one".to_string()]));
assert!(is_subset(&[], &["one".to_string(), "two".to_string()]));
assert!(is_subset(&["one".to_string()], &["one".to_string()]));
assert!(is_subset(&["one".to_string()], &["one".to_string(), "two".to_string()]));
assert!(is_subset(
&["one".to_string(), "two".to_string()],
&["one".to_string(), "two".to_string()]
));
assert!(!is_subset(
&["one".to_string(), "two".to_string(), "three".to_string()],
&["one".to_string(), "two".to_string()]
));
assert!(!is_subset(
&["one".to_string(), "two".to_string(), "three".to_string()],
&["one".to_string()]
));
assert!(!is_subset(&["one".to_string(), "two".to_string(), "three".to_string()], &[]));
}
}
4 changes: 4 additions & 0 deletions core/invehicle-digital-twin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ http = { workspace = true }
iref = { workspace = true }
log = { workspace = true }
common = { path = "../common" }
digital_twin_graph = { path = "../module/digital_twin_graph", optional = true }
digital_twin_registry = { path = "../module/digital_twin_registry", optional = true }
managed_subscribe = { path = "../module/managed_subscribe", optional = true }
parking_lot = { workspace = true }
prost = { workspace = true }
Expand All @@ -38,5 +40,7 @@ yaml-rust = { workspace = true }
tonic-build = { workspace = true }

[features]
digital_twin_graph = ["dep:digital_twin_graph"]
digital_twin_registry = ["dep:digital_twin_registry"]
managed_subscribe = ["dep:managed_subscribe"]
tokio_console = ["dep:tokio-console-subscriber", "tokio/tracing"]
Loading
Loading