From fef705361e1ddf49ccad3ef372f4add421e9ae6c Mon Sep 17 00:00:00 2001 From: Claudio Cicconetti Date: Mon, 11 Sep 2023 10:11:18 +0200 Subject: [PATCH] CLI: use newly-added InstanceId::none() Also: improve readability of "function invoke" --- edgeless_api/src/function_instance/mod.rs | 9 +++++++++ edgeless_cli/src/edgeless_cli.rs | 10 ++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/edgeless_api/src/function_instance/mod.rs b/edgeless_api/src/function_instance/mod.rs index 69aae6f6..a418d424 100644 --- a/edgeless_api/src/function_instance/mod.rs +++ b/edgeless_api/src/function_instance/mod.rs @@ -2,6 +2,9 @@ pub type NodeId = uuid::Uuid; pub type NodeLocalComponentId = uuid::Uuid; +const NODE_ID_NONE: uuid::Uuid = uuid::uuid!("00000000-0000-0000-0000-fffe00000000"); +const FUNCTION_ID_NONE: uuid::Uuid = uuid::uuid!("00000000-0000-0000-0000-fffd00000000"); + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct InstanceId { pub node_id: NodeId, @@ -15,6 +18,12 @@ impl InstanceId { function_id: uuid::Uuid::new_v4(), } } + pub fn none() -> Self { + Self { + node_id: NODE_ID_NONE, + function_id: FUNCTION_ID_NONE, + } + } } #[derive(Debug, Clone)] diff --git a/edgeless_cli/src/edgeless_cli.rs b/edgeless_cli/src/edgeless_cli.rs index b7bb9a56..7ff6210a 100644 --- a/edgeless_cli/src/edgeless_cli.rs +++ b/edgeless_cli/src/edgeless_cli.rs @@ -229,19 +229,13 @@ async fn main() -> anyhow::Result<()> { node_id: uuid::Uuid::parse_str(&node_id)?, function_id: uuid::Uuid::parse_str(&function_id)?, }, - source: edgeless_api::function_instance::InstanceId { - node_id: uuid::uuid!("00000000-0000-0000-0000-ffff00000000"), - function_id: uuid::uuid!("00000000-0000-0000-0000-ffff00000000"), - }, + source: edgeless_api::function_instance::InstanceId::none(), stream_id: 0, data: match event_type.as_str() { "cast" => edgeless_api::invocation::EventData::Cast(payload), - _ => edgeless_api::invocation::EventData::Err, + _ => return Err(anyhow::anyhow!("invalid event type: {}", event_type)), }, }; - if let edgeless_api::invocation::EventData::Err = event.data { - return Err(anyhow::anyhow!("invalid event type: {}", event_type)); - } match edgeless_api::invocation::InvocationAPI::handle(&mut client, event).await { Ok(_) => println!("event casted"), Err(err) => return Err(anyhow::anyhow!("error casting the event: {}", err)),