From 358c2d84ca092cad5df69ac19cc6acbfb85ee8d7 Mon Sep 17 00:00:00 2001 From: Noor Date: Mon, 20 Jan 2025 16:57:47 +0530 Subject: [PATCH] Add proto for daemon renamed to shared proto update build configuration changed exports for both protos in lib new rust structures for daemon types --- build.rs | 5 ++- proto/daemon.proto | 23 ++++++++++++++ .../{manager_protobuf.proto => shared.proto} | 19 ++++++++++-- src/lib.rs | 31 ++++++++++++++++++- 4 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 proto/daemon.proto rename proto/{manager_protobuf.proto => shared.proto} (79%) diff --git a/build.rs b/build.rs index 3a993c7..173750b 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,8 @@ fn main() -> Result<(), Box> { - tonic_build::compile_protos("proto/manager_protobuf.proto")?; + tonic_build::configure() + .build_server(true) + .protoc_arg("--experimental_allow_proto3_optional") + .compile_protos(&["proto/daemon.proto", "proto/shared.proto"], &["proto"])?; Ok(()) } diff --git a/proto/daemon.proto b/proto/daemon.proto new file mode 100644 index 0000000..d8f21e6 --- /dev/null +++ b/proto/daemon.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; + +package deamon; + +import "shared.proto"; + +message Empty { +} + +message NewContainerReq { + repeated string port = 1; +} + +message NewContainerRes { + string status = 1; +} + +service DaemonService { + // rpc CreateContainer (NewContainerReq) returns (NewContainerRes); + rpc CreateContainer (shared.Container) returns (NewContainerRes); + // rpc ListContainer (NodeFilters) returns (stream NodeListResp); + +} diff --git a/proto/manager_protobuf.proto b/proto/shared.proto similarity index 79% rename from proto/manager_protobuf.proto rename to proto/shared.proto index fc73a9c..cdadd52 100644 --- a/proto/manager_protobuf.proto +++ b/proto/shared.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package dtpm_proto; +package shared; message SetConfigResponse { string status = 1; @@ -13,6 +13,7 @@ message ManagerConfigPB { repeated FileEntry filesystem = 1; repeated EnvironmentEntry environment = 2; repeated ChildProcess child_processes = 3; + Container container = 4; } // Represents a file entry with a path and content @@ -49,4 +50,18 @@ message ChildProcess { service ConfigManager { rpc SetConfig(ManagerConfigPB) returns (SetConfigResponse) {} rpc GetConfig(Empty) returns (ManagerConfigPB) {} -} \ No newline at end of file +} + + +message Container { + optional string package_url = 1; + string node = 2; + Resource resource = 3; +} + +message Resource { + uint32 memory_mb = 1; + uint32 disk_mb = 2; + uint32 vcpu = 3; + repeated uint32 ports = 4; +} diff --git a/src/lib.rs b/src/lib.rs index 4149163..bff93db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,10 @@ pub mod pb { - tonic::include_proto!("dtpm_proto"); + pub mod shared { + tonic::include_proto!("shared"); + } + pub mod daemon { + tonic::include_proto!("deamon"); + } } pub mod config { @@ -71,6 +76,28 @@ pub mod config { pub restart: Option, } + #[derive(Clone, Serialize, Deserialize, prost::Message)] + pub struct Container { + #[prost(string, optional, tag = "1")] + pub package_url: Option, + #[prost(string, tag = "2")] + pub node: String, + #[prost(message, optional, tag = "3")] + pub resource: Option, + } + + #[derive(Clone, Serialize, Deserialize, PartialEq, prost::Message)] + pub struct Resource { + #[prost(uint32, tag = "1")] + memory_mb: u32, + #[prost(uint32, tag = "2")] + disk_mb: u32, + #[prost(uint32, tag = "3")] + vcpu: u32, + #[prost(uint32, repeated, tag = "4")] + port: Vec, + } + #[derive(Clone, Serialize, Deserialize, prost::Message)] pub struct Config { #[prost(message, repeated, tag = "1")] @@ -79,6 +106,8 @@ pub mod config { pub environment: Vec, #[prost(message, repeated, tag = "3")] pub child_processes: Vec, + #[prost(message, optional, tag = "4")] + pub container: Option, } impl Config {