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

Append hash of device usage id to device property key name #561

Merged
Merged
29 changes: 15 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.9.5"
version = "0.9.6"
authors = ["Kate Goldenring <[email protected]>", "<[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
19 changes: 17 additions & 2 deletions agent/src/util/device_plugin_service.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::constants::{
HEALTHY, KUBELET_UPDATE_CHANNEL_CAPACITY, LIST_AND_WATCH_SLEEP_SECS, UNHEALTHY,
};
use super::discovery_operator::generate_digest;
use super::v1beta1;
use super::v1beta1::{
device_plugin_server::DevicePlugin, AllocateRequest, AllocateResponse, DevicePluginOptions,
Expand Down Expand Up @@ -288,6 +289,7 @@ impl DevicePluginService {
request,
);
let mut akri_annotations = HashMap::new();
let mut akri_device_properties = HashMap::new();
for device_usage_id in request.devices_i_ds {
trace!(
"internal_allocate - for Instance {} processing request for device usage slot id {}",
Expand All @@ -300,6 +302,16 @@ impl DevicePluginService {
device_usage_id.clone(),
);

let hash_id_value = generate_digest(&device_usage_id, 3);
johnsonshih marked this conversation as resolved.
Show resolved Hide resolved
// add suffix _<usage_id> to each device property
let converted_properties = self
.device
.properties
.iter()
.map(|(key, value)| (format!("{}_{}", key, &hash_id_value), value.to_string()))
.collect::<HashMap<String, String>>();
akri_device_properties.extend(converted_properties);

if let Err(e) = try_update_instance_device_usage(
&device_usage_id,
&self.node_name,
Expand All @@ -324,7 +336,7 @@ impl DevicePluginService {
// Successfully reserved device_usage_slot[s] for this node.
// Add response to list of responses
let broker_properties =
get_all_broker_properties(&self.config.broker_properties, &self.device.properties);
get_all_broker_properties(&self.config.broker_properties, &akri_device_properties);
let response = build_container_allocate_response(
broker_properties,
akri_annotations,
Expand Down Expand Up @@ -1379,7 +1391,10 @@ mod device_plugin_service_tests {
assert_eq!(broker_envs.get("RESOLUTION_HEIGHT").unwrap(), "600");
// Check that Device properties are set as env vars by checking for
// property of device created in `create_device_plugin_service`
assert_eq!(broker_envs.get("DEVICE_LOCATION_INFO").unwrap(), "endpoint");
assert_eq!(
broker_envs.get("DEVICE_LOCATION_INFO_76cc26").unwrap(),
"endpoint"
);
assert!(device_plugin_service_receivers
.list_and_watch_message_receiver
.try_recv()
Expand Down
6 changes: 5 additions & 1 deletion agent/src/util/discovery_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,12 @@ pub fn inner_generate_instance_digest(
query.get_env_var("AGENT_NODE_NAME").unwrap()
);
}
generate_digest(&id_to_digest, 3)
}

pub fn generate_digest(id_to_digest: &str, output_size: usize) -> String {
johnsonshih marked this conversation as resolved.
Show resolved Hide resolved
let mut digest = String::new();
let mut hasher = VarBlake2b::new(3).unwrap();
let mut hasher = VarBlake2b::new(output_size).unwrap();
hasher.update(id_to_digest);
hasher.finalize_variable(|var| {
digest = var
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.9.5"
version = "0.9.6"
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.9.5
version: 0.9.6

# 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.9.5
appVersion: 0.9.6
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "debug-echo-discovery-handler"
version = "0.9.5"
version = "0.9.6"
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.9.5"
version = "0.9.6"
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.9.5"
version = "0.9.6"
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.9.5"
version = "0.9.6"
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.9.5"
version = "0.9.6"
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.9.5"
version = "0.9.6"
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.9.5"
version = "0.9.6"
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.9.5"
version = "0.9.6"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
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.9.5"
version = "0.9.6"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
30 changes: 29 additions & 1 deletion samples/brokers/onvif-video-broker/Akri.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.XPath;

Expand Down Expand Up @@ -38,6 +41,11 @@ private static string PostSoapRequest(String requestUri, String action, String s
private const String GET_PROFILES_SOAP = @"<soap:Envelope xmlns:soap=""http://www.w3.org/2003/05/soap-envelope"" xmlns:wsdl=""http://www.onvif.org/ver10/media/wsdl""><soap:Header/><soap:Body><wsdl:GetProfiles/></soap:Body></soap:Envelope>";
private const String GET_STREAMING_URI_SOAP_TEMPLATE = @"<soap:Envelope xmlns:soap=""http://www.w3.org/2003/05/soap-envelope"" xmlns:wsdl=""http://www.onvif.org/ver10/media/wsdl"" xmlns:sch=""http://www.onvif.org/ver10/schema""><soap:Header/><soap:Body><wsdl:GetStreamUri><wsdl:StreamSetup><sch:Stream>RTP-Unicast</sch:Stream><sch:Transport><sch:Protocol>RTSP</sch:Protocol></sch:Transport></wsdl:StreamSetup><wsdl:ProfileToken>{0}</wsdl:ProfileToken></wsdl:GetStreamUri></soap:Body></soap:Envelope>";

// Regular expression pattern of environment variables that hold OPC UA DiscoveryURL
// The pattern is ONVIF_DEVICE_SERVICE_URL_ followed by 6 digit digest. e.g.
// ONVIF_DEVICE_SERVICE_URL_123456, ONVIF_DEVICE_SERVICE_URL_abcdef
private const string OnvifDeviceServiceUrlLabelPattern = "ONVIF_DEVICE_SERVICE_URL_[a-fA-F0-9]{6,6}$";
johnsonshih marked this conversation as resolved.
Show resolved Hide resolved

private static string GetMediaUrl(String device_service_url)
{
var servicesResult = PostSoapRequest(
Expand Down Expand Up @@ -97,9 +105,29 @@ private static string GetStreamingUri(String media_url, String profile_token)
return streaming_uri;
}

private static List<string> GetDeviceServiceUrls()
{
var values = new List<string>();
foreach (DictionaryEntry de in Environment.GetEnvironmentVariables())
{
if (Regex.IsMatch(de.Key.ToString(), OnvifDeviceServiceUrlLabelPattern))
{
values.Add(de.Value.ToString());
}
}
return values;
}

public static string GetRtspUrl()
{
var device_service_url = Environment.GetEnvironmentVariable("ONVIF_DEVICE_SERVICE_URL");
// Get the first found Onvif device service url and use it
var device_service_urls = GetDeviceServiceUrls();
foreach(var url in device_service_urls)
{
Console.WriteLine("xxx url={0}", url);
}
return "";
var device_service_url = (device_service_urls.Count != 0) ? device_service_urls[0] : "";
if (string.IsNullOrEmpty(device_service_url))
{
throw new ArgumentNullException("ONVIF_DEVICE_SERVICE_URL undefined");
Expand Down
2 changes: 1 addition & 1 deletion samples/brokers/onvif-video-broker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ interface.
```
1. Run the broker, passing in the ONVIF service URL for the camera it should pull frames from.
```sh
ONVIF_DEVICE_SERVICE_URL=http://10.1.2.3:1000/onvif/device_service dotnet run
ONVIF_DEVICE_SERVICE_URL_abcdef=http://10.1.2.3:1000/onvif/device_service dotnet run
```
Loading