From 9aaf10ce37347b461e6b3bc5e43968d47eb2b680 Mon Sep 17 00:00:00 2001 From: Claudio Cicconetti Date: Wed, 20 Sep 2023 16:26:03 +0200 Subject: [PATCH] Refactor gRPC API Split proto file in services + messages. Rename package agent_api -> edgeless_api. --- edgeless_api/build.rs | 2 +- .../proto/{agent_api.proto => messages.proto} | 68 +------------------ edgeless_api/proto/services.proto | 64 +++++++++++++++++ edgeless_api/src/grpc_impl/mod.rs | 2 +- 4 files changed, 67 insertions(+), 69 deletions(-) rename edgeless_api/proto/{agent_api.proto => messages.proto} (67%) create mode 100644 edgeless_api/proto/services.proto diff --git a/edgeless_api/build.rs b/edgeless_api/build.rs index 1753a2e6..29fecc1f 100644 --- a/edgeless_api/build.rs +++ b/edgeless_api/build.rs @@ -1,7 +1,7 @@ fn main() -> Result<(), Box> { #[cfg(feature = "grpc_impl")] { - tonic_build::compile_protos("proto/agent_api.proto")?; + tonic_build::compile_protos("proto/services.proto")?; } Ok(()) } diff --git a/edgeless_api/proto/agent_api.proto b/edgeless_api/proto/messages.proto similarity index 67% rename from edgeless_api/proto/agent_api.proto rename to edgeless_api/proto/messages.proto index 11dd73bc..d3882c6d 100644 --- a/edgeless_api/proto/agent_api.proto +++ b/edgeless_api/proto/messages.proto @@ -1,10 +1,6 @@ syntax = "proto3"; -import "google/protobuf/empty.proto"; -package agent_api; -////////////////////////////////////////////////////////////////////////// -// Messages and data types -////////////////////////////////////////////////////////////////////////// +package edgeless_api; // Function instance identifier. message InstanceId { @@ -180,65 +176,3 @@ message ResourceInstanceSpecification { // Map between the callbacks and instances that will be called. map output_callback_definitions = 3; } - -////////////////////////////////////////////////////////////////////////// -// Services -////////////////////////////////////////////////////////////////////////// - -// API to manage the lifecycle of function instances (s07). -service FunctionInstance { - // Start a new function instance. - // Input: request containing the description of the function to create. - // Output: the function instance identifier assigned - rpc Start (SpawnFunctionRequest) returns (InstanceId); - - // Stop a running function instance. - // Input: the identifier of the function instance to tear down. - // Output: none. - rpc Stop (InstanceId) returns (google.protobuf.Empty ); - - // Update a running function instance by changing the mapping between the - // callback declarations and function instances. - // Input: the update mapping. - // Output: none. - rpc UpdateLinks (UpdateFunctionLinksRequest) returns (google.protobuf.Empty); -} - -// API to manage the lifecycle of workflow instances (s04). -service WorkflowInstance { - // Start a new workflow. - // Input: request containing the description of the workflow to create. - // Output: the status of workflow instance newly created. - rpc Start (SpawnWorkflowRequest) returns (WorkflowInstanceStatus); - - // Stop an active workflow. - // Input: the identifier of the workflow to tear down. - // Output: none. - - rpc Stop (WorkflowId) returns (google.protobuf.Empty); - // List the active workflows or shows the status of a given active workflow. - // Input: the identifier of the active workflow or a special value indicating all workflows. - // Output: the list of status of the active workflow instances. - rpc List (WorkflowId) returns (WorkflowInstanceList); -} - -// API to handle events (s01). -service FunctionInvocation { - // Handle an event. - // Input: event to be handled. - // Output: none. - rpc Handle (Event) returns (google.protobuf.Empty); -} - -// API to handle the lifecycle of resources (s06). -service ResourceConfiguration { - // Create a new resource. - // Input: specification of the resource to be created. - // Output: the identifier of the newly created resource. - rpc Start (ResourceInstanceSpecification) returns (InstanceId); - - // Terminate an existing resource. - // Input: the identifier of the resource to be terminated. - // Output: none. - rpc Stop (InstanceId) returns (google.protobuf.Empty); -} \ No newline at end of file diff --git a/edgeless_api/proto/services.proto b/edgeless_api/proto/services.proto new file mode 100644 index 00000000..5ef12d43 --- /dev/null +++ b/edgeless_api/proto/services.proto @@ -0,0 +1,64 @@ +syntax = "proto3"; + +import "google/protobuf/empty.proto"; +import "messages.proto"; + +package edgeless_api; + +// API to manage the lifecycle of function instances (s07). +service FunctionInstance { + // Start a new function instance. + // Input: request containing the description of the function to create. + // Output: the function instance identifier assigned + rpc Start (SpawnFunctionRequest) returns (InstanceId); + + // Stop a running function instance. + // Input: the identifier of the function instance to tear down. + // Output: none. + rpc Stop (InstanceId) returns (google.protobuf.Empty ); + + // Update a running function instance by changing the mapping between the + // callback declarations and function instances. + // Input: the update mapping. + // Output: none. + rpc UpdateLinks (UpdateFunctionLinksRequest) returns (google.protobuf.Empty); +} + +// API to manage the lifecycle of workflow instances (s04). +service WorkflowInstance { + // Start a new workflow. + // Input: request containing the description of the workflow to create. + // Output: the status of workflow instance newly created. + rpc Start (SpawnWorkflowRequest) returns (WorkflowInstanceStatus); + + // Stop an active workflow. + // Input: the identifier of the workflow to tear down. + // Output: none. + + rpc Stop (WorkflowId) returns (google.protobuf.Empty); + // List the active workflows or shows the status of a given active workflow. + // Input: the identifier of the active workflow or a special value indicating all workflows. + // Output: the list of status of the active workflow instances. + rpc List (WorkflowId) returns (WorkflowInstanceList); +} + +// API to handle events (s01). +service FunctionInvocation { + // Handle an event. + // Input: event to be handled. + // Output: none. + rpc Handle (Event) returns (google.protobuf.Empty); +} + +// API to handle the lifecycle of resources (s06). +service ResourceConfiguration { + // Create a new resource. + // Input: specification of the resource to be created. + // Output: the identifier of the newly created resource. + rpc Start (ResourceInstanceSpecification) returns (InstanceId); + + // Terminate an existing resource. + // Input: the identifier of the resource to be terminated. + // Output: none. + rpc Stop (InstanceId) returns (google.protobuf.Empty); +} \ No newline at end of file diff --git a/edgeless_api/src/grpc_impl/mod.rs b/edgeless_api/src/grpc_impl/mod.rs index 3778d18f..29db1620 100644 --- a/edgeless_api/src/grpc_impl/mod.rs +++ b/edgeless_api/src/grpc_impl/mod.rs @@ -13,5 +13,5 @@ pub mod invocation; pub mod resource_configuration; pub mod api { - tonic::include_proto!("agent_api"); + tonic::include_proto!("edgeless_api"); }