Skip to content

Commit

Permalink
refac: proto definitions (#41)
Browse files Browse the repository at this point in the history
Co-authored-by: Luiz Felipe Gonçalves <[email protected]>
  • Loading branch information
lemosep and lffg authored Jun 7, 2024
1 parent 78409b6 commit f672383
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 157 deletions.
18 changes: 0 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ setup.path = "crates/setup"
worker.path = "worker"
# External deps (keep alphabetically sorted)
axum = "0.7"
bty = { version = "0.2", features = ["uuid-v7"] }
clap = { version = "4.5", features = ["derive"] }
chrono = { version = "0.4", default-features = false, features = [
"std",
Expand Down
3 changes: 2 additions & 1 deletion ctl/src/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use proto::{
};
use tokio::sync::{mpsc, oneshot};
use tracing::{debug, instrument};
use uuid::Uuid;

pub struct Discovery {
rx: mpsc::Receiver<Msg>,
Expand Down Expand Up @@ -55,7 +56,7 @@ impl Discovery {
_ = reply.send(entries);
}
Msg::DeploySchedule(revision_id, reply) => {
let deploy_id = DeployId::now_v7();
let deploy_id = DeployId(Uuid::now_v7());
assert!(!self.deploys.contains_key(&deploy_id));
self.deploys.insert(
deploy_id,
Expand Down
3 changes: 2 additions & 1 deletion ctl/src/http/deployer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use axum::{extract::State, Json};
use proto::ctl::deployer::{DeployId, DeployReq, DeployRes, RevisionId};
use uuid::Uuid;

use crate::http::HttpState;

pub async fn deploy(
State(state): State<HttpState>,
Json(payload): Json<DeployReq>,
) -> Json<DeployRes> {
let revision_id = RevisionId::now_v7();
let revision_id = RevisionId(Uuid::now_v7());

let mut deploys_id: Vec<DeployId> = Vec::new();
for _ in 0..payload.service_spec.concurrency {
Expand Down
1 change: 0 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
text = ''cargo fmt "$@"'';
})
cargo-nextest
cargo-llvm-cov

gnumake

Expand Down
1 change: 0 additions & 1 deletion proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition.workspace = true
workspace = true

[dependencies]
bty.workspace = true
chrono.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand Down
5 changes: 0 additions & 5 deletions proto/src/common/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ use std::net::SocketAddr;

use serde::{Deserialize, Serialize};

bty::brand!(
pub type NodeName = String;
);

#[derive(Debug, Serialize, Deserialize)]
pub struct Node {
pub name: NodeName,
pub addr: SocketAddr,
pub kind: NodeKind,
}
Expand Down
47 changes: 16 additions & 31 deletions proto/src/common/service.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,29 @@
use std::fmt;

use serde::{Deserialize, Serialize};

bty::brand!(
pub type ServiceName = String;
);

#[derive(Debug, Serialize, Deserialize)]
pub struct NetworkSpec {
/// If `None`, won't expose any port.
pub expose_port: Option<u16>,
pub expose_ports: Vec<u16>,
}

/// The service domain.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct ServiceId(pub String);

/// The service image.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct ServiceImage(pub String);

#[derive(Debug, Serialize, Deserialize)]
pub struct ServiceSpec {
pub name: ServiceName,
/// The service domain.
pub id: ServiceId,
pub image: ServiceImage,
pub network: NetworkSpec,
pub scripts: Scripts,
/// Whether this service is visible to the public load balancer.
///
/// Only for port 80 (HTTP traffic).
pub public: bool,
/// The maximum number of instances that Tucano is allowed to run for this
/// service.
pub concurrency: u32,
}

#[derive(Serialize, Deserialize)]
pub struct Scripts {
/// The script that is used to build a new instance of this service.
pub build_script: String,
/// The script that is used to run an instance of this service.
pub runtime_script: String,
/// An optional string that is used to remove files associated with this
/// service from a given worker node.
pub teardown_script: Option<String>,
}

impl fmt::Debug for Scripts {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Scripts")
.field("build", &"<...>")
.field("runtime", &"<...>")
.field("teardown", &self.teardown_script.as_ref().map(|_| "<...>"))
.finish_non_exhaustive()
}
}
39 changes: 0 additions & 39 deletions proto/src/ctl/config.rs

This file was deleted.

12 changes: 6 additions & 6 deletions proto/src/ctl/deployer.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::common::service::{ServiceName, ServiceSpec};
use crate::common::service::ServiceSpec;

bty::brand!(
pub type RevisionId = Uuid;
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct RevisionId(pub Uuid);

pub type DeployId = Uuid;
);
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct DeployId(pub Uuid);

#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub enum DeployStatus {
Expand Down Expand Up @@ -39,7 +39,7 @@ pub struct DeployRes {
/// Stops a given service from running in the system.
#[derive(Debug, Serialize, Deserialize)]
pub struct StopReq {
pub service_name: ServiceName,
pub service_name: String,
/// Whether to completely remove the service from the system, calling the
/// teardown script, if any.
pub remove: bool,
Expand Down
36 changes: 0 additions & 36 deletions proto/src/ctl/inspector.rs

This file was deleted.

10 changes: 0 additions & 10 deletions proto/src/ctl/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
/// Agent manager.
pub mod agent;

/// System inspector, used to introspect the system and its nodes.
pub mod inspector;

/// Configuration manager.
pub mod config;

/// Deployer.
pub mod deployer;
7 changes: 2 additions & 5 deletions proto/src/ctl/agent.rs → proto/src/ctl/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use std::collections::HashMap;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

use crate::common::{
node::{Metrics, NodeName},
service::ServiceName,
};
use crate::common::node::{Metrics, NodeName};

/// Pushes new metrics of a given **worker** node.
///
Expand All @@ -20,7 +17,7 @@ pub struct PushWorkerMetricsReq {
pub node_name: NodeName,
pub metrics: Metrics,
/// The number of services that are being executed on the node.
pub services: HashMap<ServiceName, u32 /* todo: more info? */>,
pub services: HashMap<String, u32 /* todo: more info? */>,
pub recorded_at: DateTime<Utc>,
}

Expand Down
4 changes: 2 additions & 2 deletions proto/src/worker/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use serde::{Deserialize, Serialize};

use crate::common::service::{ServiceName, ServiceSpec};
use crate::common::service::ServiceSpec;

/// Starts a **single** deploy of the given service spec.
///
Expand All @@ -24,7 +24,7 @@ pub struct DeployRes {
/// Stops a given service from running in the system.
#[derive(Debug, Serialize, Deserialize)]
pub struct StopReq {
pub service_name: ServiceName,
pub service_name: String,
/// Whether to completely remove the service from the node, calling the
/// teardown script, if any.
pub remove: bool,
Expand Down

0 comments on commit f672383

Please sign in to comment.