From 597534445173a3a822c2cd11019ed2e56a006142 Mon Sep 17 00:00:00 2001 From: ppom Date: Mon, 20 Oct 2025 12:00:00 +0200 Subject: [PATCH] Add cluster plugin skeleton --- Cargo.lock | 9 +++ Cargo.toml | 2 +- TODO | 12 ++++ plugins/reaction-plugin-cluster/Cargo.toml | 9 +++ plugins/reaction-plugin-cluster/src/main.rs | 58 +++++++++++++++++ tests/test-conf/test-cluster.jsonnet | 72 +++++++++++++++++++++ 6 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 plugins/reaction-plugin-cluster/Cargo.toml create mode 100644 plugins/reaction-plugin-cluster/src/main.rs create mode 100644 tests/test-conf/test-cluster.jsonnet diff --git a/Cargo.lock b/Cargo.lock index 9ea2963..8a63b3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1071,6 +1071,15 @@ dependencies = [ "tokio", ] +[[package]] +name = "reaction-plugin-cluster" +version = "0.1.0" +dependencies = [ + "reaction-plugin", + "remoc", + "tokio", +] + [[package]] name = "reaction-plugin-virtual" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index b504b22..fcec4c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,7 +75,7 @@ assert_cmd = "2.0.17" predicates = "3.1.3" [workspace] -members = ["plugins/reaction-plugin", "plugins/reaction-plugin-virtual"] +members = ["plugins/reaction-plugin", "plugins/reaction-plugin-cluster", "plugins/reaction-plugin-virtual"] [workspace.dependencies] remoc = { version = "0.18.3" } diff --git a/TODO b/TODO index e01932a..b81282c 100644 --- a/TODO +++ b/TODO @@ -2,3 +2,15 @@ Test what happens when a Filter's pattern Set changes (I think it's shitty) DB: add tests on stress testing (lines should always be in order) plugins: pipe stderr too and wrap errors in logs plugins: provide tree storage? omg + +questionnements: +- quelle cli pour les plugins ? + - Directement en appelant le plugin ? reaction-plugin-cluster gen-id ? 🟢 + → Demande de savoir où stocker tout ça + - Via moult IPC ? reaction plugin cluster gen-id ? 🔴 + → Mais du coup c'est l'oeuf ou la poule entre avoir un serveur qui fonctionne et avoir un +- Stockage ? + - uniquement dans la db reaction + → Faut pas que ce soit trop gros, un peu d'overhead, risque de perdre la donnée + - à part dans le configuration directory + → Pas mal en vrai diff --git a/plugins/reaction-plugin-cluster/Cargo.toml b/plugins/reaction-plugin-cluster/Cargo.toml new file mode 100644 index 0000000..4eb351e --- /dev/null +++ b/plugins/reaction-plugin-cluster/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "reaction-plugin-cluster" +version = "0.1.0" +edition = "2024" + +[dependencies] +tokio = { workspace = true, features = ["rt-multi-thread"] } +remoc.workspace = true +reaction-plugin.path = "../reaction-plugin" diff --git a/plugins/reaction-plugin-cluster/src/main.rs b/plugins/reaction-plugin-cluster/src/main.rs new file mode 100644 index 0000000..cae9109 --- /dev/null +++ b/plugins/reaction-plugin-cluster/src/main.rs @@ -0,0 +1,58 @@ +use std::collections::BTreeSet; + +use reaction_plugin::{ + ActionImpl, Hello, Manifest, PersistData, PluginInfo, RemoteResult, StreamImpl, Value, + main_loop, +}; +use remoc::rtc; + +#[tokio::main] +async fn main() { + let plugin = Plugin::default(); + main_loop(plugin).await; +} + +#[derive(Default)] +struct Plugin { + data: Option, +} + +impl PluginInfo for Plugin { + async fn manifest(&mut self, data: PersistData) -> Result { + self.data = Some(data); + Ok(Manifest { + hello: Hello::hello(), + streams: BTreeSet::from(["cluster".into()]), + actions: BTreeSet::from(["cluster_send".into()]), + }) + } + + async fn stream_impl( + &mut self, + stream_name: String, + stream_type: String, + config: Value, + ) -> RemoteResult { + todo!() + } + + async fn action_impl( + &mut self, + stream_name: String, + filter_name: String, + action_name: String, + action_type: String, + config: Value, + patterns: Vec, + ) -> RemoteResult { + todo!() + } + + async fn finish_setup(&mut self) -> RemoteResult<()> { + todo!() + } + + async fn close(self) -> RemoteResult<()> { + todo!() + } +} diff --git a/tests/test-conf/test-cluster.jsonnet b/tests/test-conf/test-cluster.jsonnet new file mode 100644 index 0000000..9ec8f32 --- /dev/null +++ b/tests/test-conf/test-cluster.jsonnet @@ -0,0 +1,72 @@ +{ + patterns: { + num: { + regex: @"[0-9]+", + }, + all: { + regex: @".*", + }, + }, + + plugins: { + cluster: { + path: "./target/debug/reaction-plugin-cluster", + check_root: false, + systemd_options: { + DynamicUser: ["false"], + }, + options: { + clusters: { + org1: { + listen_port: 9000, + bootstrap_nodes: { + "public_key": ["127.0.0.1:9001"], + }, + }, + }, + }, + }, + }, + + streams: { + s0: { + cmd: ["bash", "-c", "for i in $(seq 4); do echo $i; sleep 0.1; done; sleep 1.2"], + filters: { + f0: { + regex: ["^$"], + actions: { + a0: { + type: "virtual", + options: { + send: "a0 ", + to: "s1", + } + }, + b0: { + type: "virtual", + options: { + send: "b0 ", + to: "s1", + }, + after: "600ms", + }, + }, + }, + }, + }, + s1: { + type: "cluster", + options: {}, + filters: { + f1: { + regex: ["^$"], + actions: { + a1: { + cmd: ['sh', '-c', 'echo >>./log'], + }, + }, + }, + }, + }, + }, +}