complete refactor of brain proto format
This commit is contained in:
parent
7c9f66a739
commit
6e7a337709
9
build.rs
9
build.rs
@ -2,7 +2,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tonic_build::configure()
|
||||
.build_server(true)
|
||||
.protoc_arg("--experimental_allow_proto3_optional")
|
||||
.compile_protos(&["proto/daemon.proto", "proto/shared.proto"], &["proto"])?;
|
||||
.compile_protos(
|
||||
&[
|
||||
"proto/daemon.proto",
|
||||
"proto/shared.proto",
|
||||
"proto/brain.proto",
|
||||
],
|
||||
&["proto"],
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
110
proto/brain.proto
Normal file
110
proto/brain.proto
Normal file
@ -0,0 +1,110 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package brain;
|
||||
|
||||
message Empty {
|
||||
}
|
||||
|
||||
message AppContract {
|
||||
string uuid = 1;
|
||||
string package_url = 2;
|
||||
string admin_pubkey = 3;
|
||||
string node_pubkey = 4;
|
||||
string public_ipv4 = 5;
|
||||
AppResource resource = 6;
|
||||
repeated MappedPort exposed_ports = 7;
|
||||
string created_at = 8;
|
||||
string updated_at = 9;
|
||||
uint64 nano_per_minute = 10;
|
||||
uint64 locked_nano = 11;
|
||||
string collected_at = 12;
|
||||
}
|
||||
|
||||
message NewAppReq {
|
||||
string package_url = 1;
|
||||
string node_pubkey = 2;
|
||||
AppResource resource = 3;
|
||||
string uuid = 4;
|
||||
string admin_pubkey = 5;
|
||||
}
|
||||
|
||||
message AppResource {
|
||||
uint32 memory_mb = 1;
|
||||
uint32 disk_mb = 2;
|
||||
uint32 vcpu = 3;
|
||||
repeated uint32 ports = 4;
|
||||
}
|
||||
|
||||
message NewAppRes {
|
||||
string uuid = 1;
|
||||
string status = 2;
|
||||
string ip_address = 3;
|
||||
repeated MappedPort mapped_ports = 4;
|
||||
string error = 5;
|
||||
}
|
||||
|
||||
message MappedPort {
|
||||
uint32 host_port = 1;
|
||||
uint32 app_port = 2;
|
||||
}
|
||||
|
||||
message DelAppReq {
|
||||
string uuid= 1;
|
||||
}
|
||||
|
||||
message ListAppContractsReq {
|
||||
string uuid = 1;
|
||||
string admin_pubkey = 2;
|
||||
string node_pubkey = 3;
|
||||
}
|
||||
|
||||
service BrainAppCli {
|
||||
rpc CreateApp (NewAppReq) returns (NewAppRes);
|
||||
rpc DeleteApp (DelAppReq) returns (Empty);
|
||||
rpc ListAppContracts (ListAppContractsReq) returns (stream AppContract);
|
||||
}
|
||||
|
||||
message RegisterAppNodeReq {
|
||||
string node_pubkey = 1;
|
||||
string owner_pubkey = 2;
|
||||
string main_ip = 3;
|
||||
string country = 4;
|
||||
string region = 5;
|
||||
string city = 6;
|
||||
}
|
||||
|
||||
message AppNodeResources {
|
||||
string node_pubkey = 1;
|
||||
uint32 avail_ports = 2;
|
||||
uint32 avail_ipv4 = 3;
|
||||
uint32 avail_ipv6 = 4;
|
||||
uint32 avail_vcpus = 5;
|
||||
uint32 avail_memory_mb = 6;
|
||||
uint32 avail_storage_gb = 7;
|
||||
uint32 max_ports_per_vm = 8;
|
||||
}
|
||||
|
||||
message BrainMessageApp {
|
||||
oneof Msg {
|
||||
NewAppReq new_app_req = 1;
|
||||
DelAppReq delete_app_req = 2;
|
||||
// resource usage
|
||||
}
|
||||
}
|
||||
|
||||
message DaemonMessageApp {
|
||||
oneof Msg {
|
||||
string pubkey = 1;
|
||||
NewAppRes new_app_resp = 2;
|
||||
AppNodeResources app_node_resources = 3;
|
||||
}
|
||||
}
|
||||
message Pubkey {
|
||||
string pubkey = 1;
|
||||
}
|
||||
|
||||
service BrainAppDaemon {
|
||||
rpc RegisterNode (RegisterAppNodeReq) returns (stream AppContract);
|
||||
rpc BrainMessages (Pubkey) returns (stream BrainMessageApp);
|
||||
rpc DaemonMessages (stream DaemonMessageApp) returns (Empty);
|
||||
}
|
@ -5,6 +5,10 @@ pub mod pb {
|
||||
pub mod daemon {
|
||||
tonic::include_proto!("deamon");
|
||||
}
|
||||
|
||||
pub mod brain {
|
||||
tonic::include_proto!("brain");
|
||||
}
|
||||
}
|
||||
|
||||
pub mod types;
|
||||
|
@ -1 +1,2 @@
|
||||
pub mod brain;
|
||||
pub mod shared;
|
||||
|
66
src/types/brain.rs
Normal file
66
src/types/brain.rs
Normal file
@ -0,0 +1,66 @@
|
||||
use crate::pb::brain::{AppResource, NewAppReq};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
||||
pub struct Resource {
|
||||
pub memory_mb: u32,
|
||||
pub disk_mb: u32,
|
||||
pub vcpu: u32,
|
||||
pub port: Vec<u32>,
|
||||
}
|
||||
|
||||
impl From<AppResource> for Resource {
|
||||
fn from(pb_val: AppResource) -> Self {
|
||||
Self {
|
||||
memory_mb: pb_val.memory_mb,
|
||||
disk_mb: pb_val.disk_mb,
|
||||
vcpu: pb_val.vcpu,
|
||||
port: pb_val.ports,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<Resource> for AppResource {
|
||||
fn from(val: Resource) -> AppResource {
|
||||
AppResource {
|
||||
memory_mb: val.memory_mb,
|
||||
disk_mb: val.disk_mb,
|
||||
vcpu: val.vcpu,
|
||||
ports: val.port,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct AppDeployConfig {
|
||||
pub package_url: String,
|
||||
pub resource: Resource,
|
||||
#[serde(default)]
|
||||
pub uuid: String,
|
||||
// #[serde(default)]
|
||||
pub admin_pubkey: String,
|
||||
pub node_pubkey: String,
|
||||
}
|
||||
|
||||
impl From<NewAppReq> for AppDeployConfig {
|
||||
fn from(pb_val: NewAppReq) -> Self {
|
||||
Self {
|
||||
package_url: pb_val.package_url,
|
||||
resource: pb_val.resource.map(Resource::from).unwrap_or_default(),
|
||||
uuid: pb_val.uuid,
|
||||
admin_pubkey: pb_val.admin_pubkey,
|
||||
node_pubkey: pb_val.node_pubkey,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AppDeployConfig> for NewAppReq {
|
||||
fn from(val: AppDeployConfig) -> NewAppReq {
|
||||
NewAppReq {
|
||||
package_url: val.package_url,
|
||||
resource: Some(val.resource.into()),
|
||||
uuid: val.uuid,
|
||||
admin_pubkey: val.admin_pubkey,
|
||||
node_pubkey: val.node_pubkey,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user