diff --git a/Cargo.lock b/Cargo.lock index 09be75d..76558c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -176,17 +176,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" -[[package]] -name = "bty" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e4b083c3c82ce9b5927af9bed28c6085d824d6b9a789cccfd6af2bb4fdde3d1" -dependencies = [ - "paste", - "serde", - "uuid", -] - [[package]] name = "bumpalo" version = "3.16.0" @@ -830,12 +819,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" -[[package]] -name = "paste" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" - [[package]] name = "percent-encoding" version = "2.3.1" @@ -893,7 +876,6 @@ dependencies = [ name = "proto" version = "0.1.0" dependencies = [ - "bty", "chrono", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 86a7ad4..1a74590 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", diff --git a/ctl/src/discovery/mod.rs b/ctl/src/discovery/mod.rs index 15ce6a8..c79e0ae 100644 --- a/ctl/src/discovery/mod.rs +++ b/ctl/src/discovery/mod.rs @@ -6,6 +6,7 @@ use proto::{ }; use tokio::sync::{mpsc, oneshot}; use tracing::{debug, instrument}; +use uuid::Uuid; pub struct Discovery { rx: mpsc::Receiver, @@ -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, diff --git a/ctl/src/http/deployer/mod.rs b/ctl/src/http/deployer/mod.rs index 20fbf3c..f07969c 100644 --- a/ctl/src/http/deployer/mod.rs +++ b/ctl/src/http/deployer/mod.rs @@ -1,5 +1,6 @@ use axum::{extract::State, Json}; use proto::ctl::deployer::{DeployId, DeployReq, DeployRes, RevisionId}; +use uuid::Uuid; use crate::http::HttpState; @@ -7,7 +8,7 @@ pub async fn deploy( State(state): State, Json(payload): Json, ) -> Json { - let revision_id = RevisionId::now_v7(); + let revision_id = RevisionId(Uuid::now_v7()); let mut deploys_id: Vec = Vec::new(); for _ in 0..payload.service_spec.concurrency { diff --git a/flake.nix b/flake.nix index 5da3925..0c43925 100644 --- a/flake.nix +++ b/flake.nix @@ -40,7 +40,6 @@ text = ''cargo fmt "$@"''; }) cargo-nextest - cargo-llvm-cov gnumake diff --git a/proto/Cargo.toml b/proto/Cargo.toml index 6b9f23b..50c2bd8 100644 --- a/proto/Cargo.toml +++ b/proto/Cargo.toml @@ -7,7 +7,6 @@ edition.workspace = true workspace = true [dependencies] -bty.workspace = true chrono.workspace = true serde.workspace = true serde_json.workspace = true diff --git a/proto/src/common/node.rs b/proto/src/common/node.rs index aeea744..02fff68 100644 --- a/proto/src/common/node.rs +++ b/proto/src/common/node.rs @@ -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, } diff --git a/proto/src/common/service.rs b/proto/src/common/service.rs index 009d52b..109702b 100644 --- a/proto/src/common/service.rs +++ b/proto/src/common/service.rs @@ -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, + pub expose_ports: Vec, } +/// 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, -} - -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() - } -} diff --git a/proto/src/ctl/config.rs b/proto/src/ctl/config.rs deleted file mode 100644 index 6ed3617..0000000 --- a/proto/src/ctl/config.rs +++ /dev/null @@ -1,39 +0,0 @@ -use serde::{Deserialize, Serialize}; -use uuid::Uuid; - -bty::brand!( - pub type ConfigVersion = Uuid; -); - -/// Controller configuration. -#[derive(Debug, Serialize, Deserialize)] -pub struct Config { - // TODO: Define configuration values. -} - -/// Returns the current configuration. -pub struct GetConfigurationReq {} - -/// Response for [`GetConfigurationReq`]. -pub struct GetConfigurationRes { - pub version: ConfigVersion, - pub config: Config, -} - -/// Defines a new configuration for the controller. -/// -/// Implementors must implement optimistic locking. -#[derive(Debug, Serialize, Deserialize)] -pub struct PutConfigurationReq { - /// The previous configuration version. - pub version: ConfigVersion, - /// The new configuration (will override the current one). - pub config: Config, -} - -/// Response for [`PutConfigurationReq`]. -#[derive(Debug, Serialize, Deserialize)] -pub struct PutConfigurationRes { - /// The new configuration version. - pub version: ConfigVersion, -} diff --git a/proto/src/ctl/deployer.rs b/proto/src/ctl/deployer.rs index 202f3f5..575f5e3 100644 --- a/proto/src/ctl/deployer.rs +++ b/proto/src/ctl/deployer.rs @@ -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 { @@ -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, diff --git a/proto/src/ctl/inspector.rs b/proto/src/ctl/inspector.rs deleted file mode 100644 index 733c1ce..0000000 --- a/proto/src/ctl/inspector.rs +++ /dev/null @@ -1,36 +0,0 @@ -use std::{collections::HashMap, os::unix::net::SocketAddr}; - -use serde::{Deserialize, Serialize}; - -use crate::common::{ - node::{Metrics, Node}, - service::ServiceName, -}; - -/// Returns the current system's topological information (regarding its nodes). -#[derive(Debug, Serialize, Deserialize)] -pub struct InspectTopologyReq {} - -/// Response for [`InspectTopologyReq`]. -#[derive(Debug, Serialize, Deserialize)] -pub struct InspectTopologyRes { - pub nodes: Vec<(Node, Metrics)>, - // More stuff? -} - -/// Returns information about the **services** that are being executed on the -/// system. -pub struct InspectServicesReq {} - -/// Response for [`InspectServicesReq`]. -pub struct InspectServicesRes { - pub services: HashMap, -} - -pub struct ServiceInfo { - /// The current number of service instances that are running. - pub total: u32, - /// Maps the node address to the number of instances that are executing on - /// it. - pub nodes: HashMap, -} diff --git a/proto/src/ctl/mod.rs b/proto/src/ctl/mod.rs index 876f383..0fa4d83 100644 --- a/proto/src/ctl/mod.rs +++ b/proto/src/ctl/mod.rs @@ -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; diff --git a/proto/src/ctl/agent.rs b/proto/src/ctl/worker.rs similarity index 83% rename from proto/src/ctl/agent.rs rename to proto/src/ctl/worker.rs index d6caffc..1788e7e 100644 --- a/proto/src/ctl/agent.rs +++ b/proto/src/ctl/worker.rs @@ -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. /// @@ -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, + pub services: HashMap, pub recorded_at: DateTime, } diff --git a/proto/src/worker/runner.rs b/proto/src/worker/runner.rs index a1d85f6..cee45c0 100644 --- a/proto/src/worker/runner.rs +++ b/proto/src/worker/runner.rs @@ -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. /// @@ -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,