Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
gen_http_client:
echo "Running demo server..."
- kill $(lsof -ti :3000)
- pkill reactor_nctrl
# - kill $(lsof -ti :3000)
cargo run --features swagger --bin reactor_nctrl -- --port 3000 /tmp &
SERVER_PID=$!
sleep 5
echo "Generating client"
# docker run --rm --network=host -v $PWD:/local -u $(id -u):$(id -g) \
# openapitools/openapi-generator-cli generate -i http://host.docker.internal:3000/api-doc/openapi.json \
# -g rust -o /local/rpc_client/ --additional-properties=packageName=reactor-client
docker run --rm --network=host -v $PWD:/local -u $(id -u):$(id -g) \
openapitools/openapi-generator-cli generate -i http://host.docker.internal:3000/api-doc/openapi.json \
openapitools/openapi-generator-cli generate -i http://localhost:3000/api-doc/openapi.json \
-g rust -o /local/rpc_client/ --additional-properties=packageName=reactor-client
kill ${SERVER_PID}
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ thiserror.workspace = true

tracing = "0.1.41"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tower-http = { version = "0.6.4", features = ["trace"] }
tower-http = { version = "0.6.4", features = ["trace", "cors"] }
tracing-log = "0.2.0"
tracing-shared = "0.1.5"
utoipa = {version="5.3.1", features=["axum_extras"], optional = true}
Expand Down
18 changes: 18 additions & 0 deletions node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ pub(crate) struct SpawnResult {
#[derive(Debug)]
pub(crate) struct RegisterResult {}

#[derive(Debug)]
pub(crate) struct NodeStatus {
actors: Vec<String>,
loaded_libs: Vec<String>,
}

/// Global Controller
pub(crate) enum JobControllerReq {
#[cfg(feature = "dynop")]
Expand All @@ -65,6 +71,9 @@ pub(crate) enum JobControllerReq {
sock_addr: SocketAddr,
},
StopAllActors,
GetStatus {
resp_tx: oneshot::Sender<NodeStatus>,
},
}

struct LocalActor {
Expand Down Expand Up @@ -229,6 +238,15 @@ async fn handle_job_req(
actor.handle.send(ControlInst::Stop).await.unwrap();
}
}
JobControllerReq::GetStatus { resp_tx } => {
event!(target: "serving get status", Level::INFO, total_actors=local_actors.len());
resp_tx
.send(NodeStatus {
actors: local_actors.keys().cloned().collect(),
loaded_libs: op_lib.lib_names(),
})
.unwrap();
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions node/src/op_lib_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ impl OpLibrary {
pub(crate) fn num_libs(&self) -> usize {
self.container.len()
}

pub(crate) fn lib_names(&self) -> Vec<LibName> {
self.container.keys().cloned().collect()
}
}
40 changes: 38 additions & 2 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ use axum::{
extract::{MatchedPath, State},
http::{HeaderMap, Request},
response::{IntoResponse, Response},
routing::post,
routing::{get, post},
};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use tokio::sync::mpsc::UnboundedSender;
use tower_http::cors::{Any, CorsLayer};
use tower_http::{classify::ServerErrorsFailureClass, trace::TraceLayer};
use tracing::{Span, info_span};
#[cfg(feature = "swagger")]
Expand Down Expand Up @@ -211,18 +212,53 @@ async fn stop_all_actors(State(state): State<Arc<AppState>>) -> impl IntoRespons
(axum::http::StatusCode::OK, "Actors Stopped!")
}

#[derive(Serialize, ToSchema)]
struct StatusResponse {
actors: Vec<String>,
loaded_libs: Vec<String>,
}
#[cfg_attr(feature="swagger", utoipa::path(
get,
path = "/status",
responses(
(status = 200, description = "Status of the node", body = StatusResponse)
)
))]
async fn get_status(State(state): State<Arc<AppState>>) -> impl IntoResponse {
let (tx, rx) = tokio::sync::oneshot::channel();
state
.tx
.send(JobControllerReq::GetStatus { resp_tx: tx })
.unwrap();
let result = rx.await.unwrap();
(
axum::http::StatusCode::OK,
Json(StatusResponse {
actors: result.actors,
loaded_libs: result.loaded_libs,
}),
)
}

#[cfg(feature = "swagger")]
#[derive(OpenApi)]
#[openapi(paths(start_actor, actor_added, register_lib, stop_all_actors))]
#[openapi(paths(start_actor, actor_added, register_lib, stop_all_actors, get_status))]
struct ApiDoc;

pub async fn webserver(job_control_tx: UnboundedSender<JobControllerReq>, port: u16) {
let state = Arc::new(AppState { tx: job_control_tx });
let app = Router::new()
.route("/status", get(get_status))
.route("/start_actor", post(start_actor))
.route("/actor_added", post(actor_added))
.route("/register_lib", post(register_lib))
.route("/stop_all_actors", post(stop_all_actors))
.layer(
CorsLayer::new()
.allow_origin(Any) // allow all origins
.allow_methods(Any) // allow all methods (GET, POST, etc.)
.allow_headers(Any), // allow all headers
)
.with_state(state)
.layer(
TraceLayer::new_for_http()
Expand Down
52 changes: 52 additions & 0 deletions reactor-dashboard/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Node modules
node_modules/
**/node_modules/

# Logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Build outputs
dist/
build/
out/

# TypeScript
*.tsbuildinfo

# Vite / React / JSX caches
.vite/
.vscode/
*.env.local
*.env.*.local

# Tailwind cache
.tailwind-cache/

# OS files
.DS_Store
Thumbs.db

# IDE / editor configs
.idea/
*.sublime-project
*.sublime-workspace

# npm package lock
package-lock.json
yarn.lock
pnpm-lock.yaml

# Optional: coverage reports
coverage/
*.lcov

# Optional: storybook
storybook-static/

# Optional: temporary files
*.tmp
*.temp

4 changes: 4 additions & 0 deletions reactor-dashboard/api-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
wwwroot/*.js
node_modules
typings
dist
1 change: 1 addition & 0 deletions reactor-dashboard/api-client/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
23 changes: 23 additions & 0 deletions reactor-dashboard/api-client/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
14 changes: 14 additions & 0 deletions reactor-dashboard/api-client/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.gitignore
.npmignore
.openapi-generator-ignore
api.ts
base.ts
common.ts
configuration.ts
docs/DefaultApi.md
docs/RegistrationArgs.md
docs/RemoteActorInfo.md
docs/SpawnArgs.md
docs/StatusResponse.md
git_push.sh
index.ts
1 change: 1 addition & 0 deletions reactor-dashboard/api-client/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.14.0
16 changes: 16 additions & 0 deletions reactor-dashboard/api-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@reactor/api-client",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc -b",
"prepare": "npm run build"
},
"devDependencies": {
"typescript": "~5.8.3"
},
"dependencies": {
"axios": "^1.11.0"
}
}
Loading