diff --git a/zenoh-flow-commons/src/identifiers.rs b/zenoh-flow-commons/src/identifiers.rs index cefe66f9..a1c89a49 100644 --- a/zenoh-flow-commons/src/identifiers.rs +++ b/zenoh-flow-commons/src/identifiers.rs @@ -80,17 +80,8 @@ impl From<&str> for PortId { } } -/// A `PortId` identifies an `Input` or an `Output` of a Node. #[derive(Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize)] -pub struct RuntimeId(Arc); - -impl Deref for RuntimeId { - type Target = Arc; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} +pub struct RuntimeId(Arc); impl Display for RuntimeId { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -98,15 +89,17 @@ impl Display for RuntimeId { } } -impl From for RuntimeId { - fn from(value: String) -> Self { - Self(value.into()) +impl Deref for RuntimeId { + type Target = Uuid; + + fn deref(&self) -> &Self::Target { + &self.0 } } -impl From<&str> for RuntimeId { - fn from(value: &str) -> Self { - Self(value.into()) +impl From for RuntimeId { + fn from(value: Uuid) -> Self { + Self(Arc::new(value)) } } diff --git a/zenoh-flow-descriptors/Cargo.toml b/zenoh-flow-descriptors/Cargo.toml index 67ee669c..01ae9de9 100644 --- a/zenoh-flow-descriptors/Cargo.toml +++ b/zenoh-flow-descriptors/Cargo.toml @@ -11,6 +11,7 @@ # Contributors: # ZettaScale Zenoh Team, # + [package] authors = { workspace = true } categories = { workspace = true } @@ -30,6 +31,8 @@ serde_json = { workspace = true } serde_yaml = { workspace = true } tracing = { workspace = true } url = { workspace = true } -uuid = { workspace = true } zenoh-flow-commons = { workspace = true } zenoh-keyexpr = { workspace = true } + +[dev-dependencies] +uuid = { workspace = true } diff --git a/zenoh-flow-descriptors/src/dataflow.rs b/zenoh-flow-descriptors/src/dataflow.rs index 60f17fba..a8f7931d 100644 --- a/zenoh-flow-descriptors/src/dataflow.rs +++ b/zenoh-flow-descriptors/src/dataflow.rs @@ -64,7 +64,7 @@ use zenoh_flow_commons::{Configuration, NodeId, RuntimeId}; /// input : in-operator /// /// mapping: -/// Source-0: zenoh-flow-plugin-0 +/// Source-0: 10628aa2-66ca-4fda-8d5c-d7de63764bcc /// "#; /// /// let data_flow_yaml = serde_yaml::from_str::(yaml).unwrap(); @@ -131,7 +131,7 @@ use zenoh_flow_commons::{Configuration, NodeId, RuntimeId}; /// ], /// /// "mapping": { -/// "Source-0": "zenoh-flow-plugin-0" +/// "Source-0": "10628aa2-66ca-4fda-8d5c-d7de63764bcc" /// } /// } /// "#; diff --git a/zenoh-flow-descriptors/src/flattened/tests.rs b/zenoh-flow-descriptors/src/flattened/tests.rs index 2eef98b2..230ff863 100644 --- a/zenoh-flow-descriptors/src/flattened/tests.rs +++ b/zenoh-flow-descriptors/src/flattened/tests.rs @@ -22,8 +22,9 @@ use crate::{ OutputDescriptor, }; use serde_json::json; -use std::collections::HashMap; -use zenoh_flow_commons::Vars; +use std::{collections::HashMap, str::FromStr}; +use uuid::Uuid; +use zenoh_flow_commons::{RuntimeId, Vars}; const BASE_DIR: &str = "./tests/descriptors"; const SCHEME: &str = "file://"; @@ -298,27 +299,45 @@ fn test_flatten_descriptor() { }); assert_eq!(expected_links.len(), flatten.links.len()); + let runtime_1: RuntimeId = Uuid::from_str("10628aa2-66ca-4fda-8d5c-d7de63764bcc") + .unwrap() + .into(); + let runtime_2: RuntimeId = Uuid::from_str("5f7a170d-cfaf-4f7a-971e-6c3e63c50e1e") + .unwrap() + .into(); + let runtime_source_composite: RuntimeId = + Uuid::from_str("e051658a-0cd6-4cef-8b08-0d0f17d3cc5d") + .unwrap() + .into(); + let runtime_operator_composite: RuntimeId = + Uuid::from_str("6a16a7ba-ec2d-4bb8-b303-7683e5477900") + .unwrap() + .into(); + let runtime_sink_composite: RuntimeId = Uuid::from_str("25270228-9cb1-4e6e-988c-00769622359f") + .unwrap() + .into(); + let expected_mapping = HashMap::from([ - ("source-1".into(), "runtime-1".into()), - ("sink-2".into(), "runtime-2".into()), - ("source-composite".into(), "runtime-source".into()), + ("source-1".into(), runtime_1), + ("sink-2".into(), runtime_2), + ("source-composite".into(), runtime_source_composite), ( "operator-composite/sub-operator-1".into(), - "runtime-composite".into(), + runtime_operator_composite.clone(), ), ( "operator-composite/sub-operator-composite/sub-sub-operator-1".into(), - "runtime-composite".into(), + runtime_operator_composite.clone(), ), ( "operator-composite/sub-operator-composite/sub-sub-operator-2".into(), - "runtime-composite".into(), + runtime_operator_composite.clone(), ), ( "operator-composite/sub-operator-2".into(), - "runtime-composite".into(), + runtime_operator_composite, ), - ("sink-composite".into(), "runtime-sink".into()), + ("sink-composite".into(), runtime_sink_composite), ]); assert_eq!(expected_mapping, flatten.mapping); diff --git a/zenoh-flow-descriptors/tests/descriptors/data-flow.yml b/zenoh-flow-descriptors/tests/descriptors/data-flow.yml index 68a416a7..047e6308 100644 --- a/zenoh-flow-descriptors/tests/descriptors/data-flow.yml +++ b/zenoh-flow-descriptors/tests/descriptors/data-flow.yml @@ -99,8 +99,8 @@ links: mapping: - source-1: runtime-1 - sink-2: runtime-2 - source-composite: runtime-source - operator-composite: runtime-composite - sink-composite: runtime-sink + source-1: 10628aa2-66ca-4fda-8d5c-d7de63764bcc + sink-2: 5f7a170d-cfaf-4f7a-971e-6c3e63c50e1e + source-composite: e051658a-0cd6-4cef-8b08-0d0f17d3cc5d + operator-composite: 6a16a7ba-ec2d-4bb8-b303-7683e5477900 + sink-composite: 25270228-9cb1-4e6e-988c-00769622359f diff --git a/zenoh-flow-records/src/tests.rs b/zenoh-flow-records/src/tests.rs index 96caa2ac..0146e0be 100644 --- a/zenoh-flow-records/src/tests.rs +++ b/zenoh-flow-records/src/tests.rs @@ -14,7 +14,8 @@ use std::collections::HashMap; -use zenoh_flow_commons::{NodeId, Vars}; +use uuid::Uuid; +use zenoh_flow_commons::{NodeId, RuntimeId, Vars}; use zenoh_flow_descriptors::{ DataFlowDescriptor, FlattenedDataFlowDescriptor, InputDescriptor, LinkDescriptor, OutputDescriptor, @@ -76,13 +77,14 @@ fn test_success_no_runtime() { ) .unwrap(); - let record = DataFlowRecord::try_new(flat_desc, &"default".into()).unwrap(); + let default_runtime: RuntimeId = Uuid::new_v4().into(); + let record = DataFlowRecord::try_new(flat_desc, &default_runtime).unwrap(); assert_eq!( HashMap::from([ - ("source-0".into(), "default".into()), - ("operator-1".into(), "default".into()), - ("sink-2".into(), "default".into()) + ("source-0".into(), default_runtime.clone()), + ("operator-1".into(), default_runtime.clone()), + ("sink-2".into(), default_runtime) ]), record.mapping ); @@ -94,16 +96,17 @@ fn test_success_no_runtime() { #[test] fn test_success_same_runtime() { + let runtime: RuntimeId = Uuid::new_v4().into(); let desc = format!( r#" {} mapping: - source-0: thing - operator-1: thing - sink-2: thing + source-0: {1} + operator-1: {1} + sink-2: {1} "#, - BASE_FLOW + BASE_FLOW, runtime, ); let flat_desc = FlattenedDataFlowDescriptor::try_flatten( @@ -112,13 +115,13 @@ mapping: ) .unwrap(); - let record = DataFlowRecord::try_new(flat_desc, &"default".into()).unwrap(); + let record = DataFlowRecord::try_new(flat_desc, &Uuid::new_v4().into()).unwrap(); assert_eq!( HashMap::from([ - ("source-0".into(), "thing".into()), - ("operator-1".into(), "thing".into()), - ("sink-2".into(), "thing".into()) + ("source-0".into(), runtime.clone()), + ("operator-1".into(), runtime.clone()), + ("sink-2".into(), runtime) ]), record.mapping ); @@ -130,15 +133,19 @@ mapping: #[test] fn test_success_different_runtime() { + let runtime_thing: RuntimeId = Uuid::new_v4().into(); + let runtime_edge: RuntimeId = Uuid::new_v4().into(); + let default_runtime: RuntimeId = Uuid::new_v4().into(); + let desc = format!( r#" {} mapping: - source-0: thing - operator-1: edge + source-0: {} + operator-1: {} "#, - BASE_FLOW + BASE_FLOW, runtime_thing, runtime_edge ); let flat_desc = FlattenedDataFlowDescriptor::try_flatten( @@ -147,13 +154,13 @@ mapping: ) .unwrap(); - let record = DataFlowRecord::try_new(flat_desc, &"default".into()).unwrap(); + let record = DataFlowRecord::try_new(flat_desc, &default_runtime).unwrap(); assert_eq!( HashMap::from([ - ("source-0".into(), "thing".into()), - ("operator-1".into(), "edge".into()), - ("sink-2".into(), "default".into()) + ("source-0".into(), runtime_thing), + ("operator-1".into(), runtime_edge), + ("sink-2".into(), default_runtime) ]), record.mapping );