From c1306d87b6165d14658ef0b41dde3b62dee7e11b Mon Sep 17 00:00:00 2001 From: Eduardo Lemos Date: Tue, 23 Apr 2024 18:21:30 -0300 Subject: [PATCH 1/2] initial commit --- worker/src/runner/builder.rs | 1 + worker/src/runner/mod.rs | 1 + 2 files changed, 2 insertions(+) create mode 100644 worker/src/runner/builder.rs create mode 100644 worker/src/runner/mod.rs diff --git a/worker/src/runner/builder.rs b/worker/src/runner/builder.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/worker/src/runner/builder.rs @@ -0,0 +1 @@ + diff --git a/worker/src/runner/mod.rs b/worker/src/runner/mod.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/worker/src/runner/mod.rs @@ -0,0 +1 @@ + From f419794b7ee155bbbff7bdf3752cd480948f16d5 Mon Sep 17 00:00:00 2001 From: Eduardo Lemos Date: Fri, 7 Jun 2024 15:47:51 -0300 Subject: [PATCH 2/2] added blolb --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + proto/src/worker/runner.rs | 24 ++++++++++++------------ worker/Cargo.toml | 1 + worker/src/main.rs | 1 + worker/src/runner/mod.rs | 23 +++++++++++++++++++++++ 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5c3a7a..a733e6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -436,6 +436,12 @@ dependencies = [ "pin-utils", ] +[[package]] +name = "get-port" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "888123007db34fbff15b5a347d46364dfbad531d6cb43de52cc0b62558f570e2" + [[package]] name = "getrandom" version = "0.2.12" @@ -1724,6 +1730,7 @@ version = "0.1.0" dependencies = [ "clap", "eyre", + "get-port", "proto", "reqwest", "setup", diff --git a/Cargo.toml b/Cargo.toml index 0d73ef2..09aba26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ chrono = { version = "0.4", default-features = false, features = [ "serde", ] } eyre = "0.6" +get-port = "4.0.0" reqwest = { version = "0.12", features = ["json"] } serde = { version = "1", features = ["derive"] } serde_json = "1" diff --git a/proto/src/worker/runner.rs b/proto/src/worker/runner.rs index a1d85f6..71e75fc 100644 --- a/proto/src/worker/runner.rs +++ b/proto/src/worker/runner.rs @@ -3,28 +3,28 @@ //! service on a given worker node. use serde::{Deserialize, Serialize}; +use uuid::Uuid; -use crate::common::service::{ServiceName, ServiceSpec}; +/// Specification of a service's instance +#[derive(Debug, Serialize, Deserialize)] +pub struct InstanceSpec { + id: Uuid, + image: String, +} /// Starts a **single** deploy of the given service spec. /// /// The worker server doesn't follow the concurrency limit for the service as -/// defined in [`ServiceSpec`]. -#[derive(Debug, Serialize, Deserialize)] -pub struct DeployReq { - pub service_spec: ServiceSpec, -} - -/// Response for [`DeployReq`]. +/// defined in [`InstanceSpec`]. #[derive(Debug, Serialize, Deserialize)] -pub struct DeployRes { - // ??? +pub struct DeployInstanceReq { + pub instances: Vec, } -/// Stops a given service from running in the system. +/// Stops a given instance from running in the system. #[derive(Debug, Serialize, Deserialize)] pub struct StopReq { - pub service_name: ServiceName, + pub instance: InstanceSpec, /// Whether to completely remove the service from the node, calling the /// teardown script, if any. pub remove: bool, diff --git a/worker/Cargo.toml b/worker/Cargo.toml index 266ee19..70437a1 100644 --- a/worker/Cargo.toml +++ b/worker/Cargo.toml @@ -12,6 +12,7 @@ proto.workspace = true clap.workspace = true eyre.workspace = true +get-port.workspace = true reqwest.workspace = true sysinfo.workspace = true tokio.workspace = true diff --git a/worker/src/main.rs b/worker/src/main.rs index 7460120..f71e5c0 100644 --- a/worker/src/main.rs +++ b/worker/src/main.rs @@ -7,6 +7,7 @@ use crate::{args::WorkerArgs, monitor::pusher}; mod args; mod monitor; +mod runner; #[tokio::main] async fn main() -> Result<()> { diff --git a/worker/src/runner/mod.rs b/worker/src/runner/mod.rs index 8b13789..74ffd9c 100644 --- a/worker/src/runner/mod.rs +++ b/worker/src/runner/mod.rs @@ -1 +1,24 @@ +use std::collections::HashMap; +use proto::worker::runner; + +use get_port::{tcp::TcpPort, Range}; + +pub struct UsedPorts { + pub in_use: HashMap Result<()> { + let tcp_port = TcpPort::in_range( + "127.0.0.1", + Range { + min: 6000, + max: 7000, + }, + ) + .unwrap(); + + Ok(()) +} + +pub fn terminate(instance: &InstanceSpec) {}