Skip to content

Commit

Permalink
Mount udev devpath in Akri brokers (#534)
Browse files Browse the repository at this point in the history
* Mount udev devpath in Akri brokers

Signed-off-by: Kate Goldenring <[email protected]>

* Update minor version

Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

Signed-off-by: Kate Goldenring <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
kate-goldenring and github-actions[bot] authored Dec 7, 2022
1 parent 6a2ba06 commit 2efb89e
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 52 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion agent/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "agent"
version = "0.8.27"
version = "0.9.0"
authors = ["Kate Goldenring <[email protected]>", "<[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
2 changes: 1 addition & 1 deletion controller/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "controller"
version = "0.8.27"
version = "0.9.0"
authors = ["<[email protected]>", "<[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
4 changes: 2 additions & 2 deletions deployment/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.8.27
version: 0.9.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 0.8.27
appVersion: 0.9.0
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "debug-echo-discovery-handler"
version = "0.8.27"
version = "0.9.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "onvif-discovery-handler"
version = "0.8.27"
version = "0.9.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opcua-discovery-handler"
version = "0.8.27"
version = "0.9.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "udev-discovery-handler"
version = "0.8.27"
version = "0.9.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/debug-echo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-debug-echo"
version = "0.8.27"
version = "0.9.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/onvif/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-onvif"
version = "0.8.27"
version = "0.9.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/opcua/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-opcua"
version = "0.8.27"
version = "0.9.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/udev/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-udev"
version = "0.8.27"
version = "0.9.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
14 changes: 10 additions & 4 deletions discovery-handlers/udev/src/discovery_handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use super::{discovery_impl::do_parse_and_find, wrappers::udev_enumerator};
use super::{
discovery_impl::{do_parse_and_find, DeviceProperties},
wrappers::udev_enumerator,
};
use akri_discovery_utils::discovery::{
discovery_handler::{deserialize_discovery_details, DISCOVERED_DEVICES_CHANNEL_CAPACITY},
v0::{
Expand Down Expand Up @@ -65,7 +68,7 @@ impl DiscoveryHandler for DiscoveryHandlerImpl {
}
break;
}
let mut devpaths: HashSet<String> = HashSet::new();
let mut devpaths: HashSet<DeviceProperties> = HashSet::new();
udev_rules.iter().for_each(|rule| {
let enumerator = udev_enumerator::create_enumerator();
let paths = do_parse_and_find(enumerator, rule).unwrap();
Expand All @@ -79,9 +82,12 @@ impl DiscoveryHandler for DiscoveryHandlerImpl {
);
let discovered_devices = devpaths
.into_iter()
.map(|path| {
.map(|(path, node)| {
let mut properties = std::collections::HashMap::new();
properties.insert(super::UDEV_DEVNODE_LABEL_ID.to_string(), path.clone());
if let Some(devnode) = node {
properties.insert(super::UDEV_DEVNODE_LABEL_ID.to_string(), devnode);
}
properties.insert(super::UDEV_DEVPATH_LABEL_ID.to_string(), path.clone());
let mount = Mount {
container_path: path.clone(),
host_path: path.clone(),
Expand Down
30 changes: 14 additions & 16 deletions discovery-handlers/udev/src/discovery_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@ pub struct UdevFilter<'a> {
value: String,
}

/// A udev device is defined by its devpath and devnode (if exists)
pub(crate) type DeviceProperties = (String, Option<String>);

/// This parses the udev rule into UdevFilters and finds all devices that match those filters
pub fn do_parse_and_find(
enumerator: impl Enumerator,
udev_rule_string: &str,
) -> Result<Vec<String>, anyhow::Error> {
) -> Result<Vec<DeviceProperties>, anyhow::Error> {
let udev_filters = parse_udev_rule(udev_rule_string)?;
let devpaths = find_devices(enumerator, udev_filters)?;
let devices = find_devices(enumerator, udev_filters)?;
trace!(
"do_parse_and_find - returning discovered devices with devpaths: {:?}",
devpaths
devices
);
Ok(devpaths)
Ok(devices)
}

/// This parses a udev rule and returns a list of UdevFilter objects that specify which devices to search for.
Expand Down Expand Up @@ -103,7 +106,7 @@ fn parse_udev_rule(udev_rule_string: &str) -> Result<Vec<UdevFilter>, anyhow::Er
fn find_devices(
enumerator: impl Enumerator,
udev_filters: Vec<UdevFilter>,
) -> std::io::Result<Vec<String>> {
) -> std::io::Result<Vec<DeviceProperties>> {
let mut enumerator = enumerator;
trace!("find_devices - enter with udev_filters {:?}", udev_filters);

Expand Down Expand Up @@ -147,18 +150,13 @@ fn find_devices(
let devices: Vec<udev::Device> = enumerator.scan_devices()?.collect();
let final_devices = filter_by_remaining_udev_filters(devices, remaining_udev_filters);

let device_devpaths: Vec<String> = final_devices
let device_devpaths: Vec<DeviceProperties> = final_devices
.into_iter()
.filter_map(|device| {
if let Some(devnode) = get_devnode(&device) {
Some(devnode.to_str().unwrap().to_string())
} else {
trace!(
"find_devices - ignoring device with devpath {:?} due to having no devnode",
get_devpath(&device)
);
None
}
.map(|device| {
(
get_devpath(&device).to_str().unwrap().to_string(),
get_devnode(&device).map(|devnode| devnode.to_str().unwrap().to_string()),
)
})
.collect();

Expand Down
5 changes: 4 additions & 1 deletion discovery-handlers/udev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ mod discovery_impl;
mod wrappers;

/// Name of environment variable that is set in udev brokers. Contains devnode for udev device
/// the broker should connect to.
/// the broker should use.
pub const UDEV_DEVNODE_LABEL_ID: &str = "UDEV_DEVNODE";
/// Name of environment variable that is set in udev brokers. Contains devpath for udev device
/// the broker should connect to.
pub const UDEV_DEVPATH_LABEL_ID: &str = "UDEV_DEVPATH";
/// Name that udev discovery handlers use when registering with the Agent
pub const DISCOVERY_HANDLER_NAME: &str = "udev";
/// Defines whether this discovery handler discovers local devices on nodes rather than ones visible to multiple nodes
Expand Down
2 changes: 1 addition & 1 deletion discovery-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-discovery-utils"
version = "0.8.27"
version = "0.9.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
2 changes: 1 addition & 1 deletion samples/brokers/udev-video-broker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "udev-video-broker"
version = "0.8.27"
version = "0.9.0"
authors = ["Kate Goldenring <[email protected]>", "<[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
2 changes: 1 addition & 1 deletion shared/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-shared"
version = "0.8.27"
version = "0.9.0"
authors = ["<[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.27
0.9.0
2 changes: 1 addition & 1 deletion webhooks/validating/configuration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "webhook-configuration"
version = "0.8.27"
version = "0.9.0"
authors = ["DazWilkin <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down

0 comments on commit 2efb89e

Please sign in to comment.