Skip to content

Commit 662f9f9

Browse files
Merge pull request #48 from satyamjay-iitd/web-ui
Added web-ui
2 parents 7500065 + d52a256 commit 662f9f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+5506
-13
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
gen_http_client:
22
echo "Running demo server..."
3-
- kill $(lsof -ti :3000)
3+
- pkill reactor_nctrl
4+
# - kill $(lsof -ti :3000)
45
cargo run --features swagger --bin reactor_nctrl -- --port 3000 /tmp &
56
SERVER_PID=$!
67
sleep 5
78
echo "Generating client"
9+
# docker run --rm --network=host -v $PWD:/local -u $(id -u):$(id -g) \
10+
# openapitools/openapi-generator-cli generate -i http://host.docker.internal:3000/api-doc/openapi.json \
11+
# -g rust -o /local/rpc_client/ --additional-properties=packageName=reactor-client
812
docker run --rm --network=host -v $PWD:/local -u $(id -u):$(id -g) \
9-
openapitools/openapi-generator-cli generate -i http://host.docker.internal:3000/api-doc/openapi.json \
13+
openapitools/openapi-generator-cli generate -i http://localhost:3000/api-doc/openapi.json \
1014
-g rust -o /local/rpc_client/ --additional-properties=packageName=reactor-client
1115
kill ${SERVER_PID}

node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ thiserror.workspace = true
2121

2222
tracing = "0.1.41"
2323
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
24-
tower-http = { version = "0.6.4", features = ["trace"] }
24+
tower-http = { version = "0.6.4", features = ["trace", "cors"] }
2525
tracing-log = "0.2.0"
2626
tracing-shared = "0.1.5"
2727
utoipa = {version="5.3.1", features=["axum_extras"], optional = true}

node/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ pub(crate) struct SpawnResult {
4545
#[derive(Debug)]
4646
pub(crate) struct RegisterResult {}
4747

48+
#[derive(Debug)]
49+
pub(crate) struct NodeStatus {
50+
actors: Vec<String>,
51+
loaded_libs: Vec<String>,
52+
}
53+
4854
/// Global Controller
4955
pub(crate) enum JobControllerReq {
5056
#[cfg(feature = "dynop")]
@@ -65,6 +71,9 @@ pub(crate) enum JobControllerReq {
6571
sock_addr: SocketAddr,
6672
},
6773
StopAllActors,
74+
GetStatus {
75+
resp_tx: oneshot::Sender<NodeStatus>,
76+
},
6877
}
6978

7079
struct LocalActor {
@@ -229,6 +238,15 @@ async fn handle_job_req(
229238
actor.handle.send(ControlInst::Stop).await.unwrap();
230239
}
231240
}
241+
JobControllerReq::GetStatus { resp_tx } => {
242+
event!(target: "serving get status", Level::INFO, total_actors=local_actors.len());
243+
resp_tx
244+
.send(NodeStatus {
245+
actors: local_actors.keys().cloned().collect(),
246+
loaded_libs: op_lib.lib_names(),
247+
})
248+
.unwrap();
249+
}
232250
}
233251
}
234252

node/src/op_lib_manager.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ impl OpLibrary {
2121
pub(crate) fn num_libs(&self) -> usize {
2222
self.container.len()
2323
}
24+
25+
pub(crate) fn lib_names(&self) -> Vec<LibName> {
26+
self.container.keys().cloned().collect()
27+
}
2428
}

node/src/rpc.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ use axum::{
1111
extract::{MatchedPath, State},
1212
http::{HeaderMap, Request},
1313
response::{IntoResponse, Response},
14-
routing::post,
14+
routing::{get, post},
1515
};
1616
use serde::{Deserialize, Serialize};
1717
use serde_json::Value;
1818
use tokio::sync::mpsc::UnboundedSender;
19+
use tower_http::cors::{Any, CorsLayer};
1920
use tower_http::{classify::ServerErrorsFailureClass, trace::TraceLayer};
2021
use tracing::{Span, info_span};
2122
#[cfg(feature = "swagger")]
@@ -211,18 +212,53 @@ async fn stop_all_actors(State(state): State<Arc<AppState>>) -> impl IntoRespons
211212
(axum::http::StatusCode::OK, "Actors Stopped!")
212213
}
213214

215+
#[derive(Serialize, ToSchema)]
216+
struct StatusResponse {
217+
actors: Vec<String>,
218+
loaded_libs: Vec<String>,
219+
}
220+
#[cfg_attr(feature="swagger", utoipa::path(
221+
get,
222+
path = "/status",
223+
responses(
224+
(status = 200, description = "Status of the node", body = StatusResponse)
225+
)
226+
))]
227+
async fn get_status(State(state): State<Arc<AppState>>) -> impl IntoResponse {
228+
let (tx, rx) = tokio::sync::oneshot::channel();
229+
state
230+
.tx
231+
.send(JobControllerReq::GetStatus { resp_tx: tx })
232+
.unwrap();
233+
let result = rx.await.unwrap();
234+
(
235+
axum::http::StatusCode::OK,
236+
Json(StatusResponse {
237+
actors: result.actors,
238+
loaded_libs: result.loaded_libs,
239+
}),
240+
)
241+
}
242+
214243
#[cfg(feature = "swagger")]
215244
#[derive(OpenApi)]
216-
#[openapi(paths(start_actor, actor_added, register_lib, stop_all_actors))]
245+
#[openapi(paths(start_actor, actor_added, register_lib, stop_all_actors, get_status))]
217246
struct ApiDoc;
218247

219248
pub async fn webserver(job_control_tx: UnboundedSender<JobControllerReq>, port: u16) {
220249
let state = Arc::new(AppState { tx: job_control_tx });
221250
let app = Router::new()
251+
.route("/status", get(get_status))
222252
.route("/start_actor", post(start_actor))
223253
.route("/actor_added", post(actor_added))
224254
.route("/register_lib", post(register_lib))
225255
.route("/stop_all_actors", post(stop_all_actors))
256+
.layer(
257+
CorsLayer::new()
258+
.allow_origin(Any) // allow all origins
259+
.allow_methods(Any) // allow all methods (GET, POST, etc.)
260+
.allow_headers(Any), // allow all headers
261+
)
226262
.with_state(state)
227263
.layer(
228264
TraceLayer::new_for_http()

reactor-dashboard/.gitignore

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Node modules
2+
node_modules/
3+
**/node_modules/
4+
5+
# Logs
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
pnpm-debug.log*
10+
11+
# Build outputs
12+
dist/
13+
build/
14+
out/
15+
16+
# TypeScript
17+
*.tsbuildinfo
18+
19+
# Vite / React / JSX caches
20+
.vite/
21+
.vscode/
22+
*.env.local
23+
*.env.*.local
24+
25+
# Tailwind cache
26+
.tailwind-cache/
27+
28+
# OS files
29+
.DS_Store
30+
Thumbs.db
31+
32+
# IDE / editor configs
33+
.idea/
34+
*.sublime-project
35+
*.sublime-workspace
36+
37+
# npm package lock
38+
package-lock.json
39+
yarn.lock
40+
pnpm-lock.yaml
41+
42+
# Optional: coverage reports
43+
coverage/
44+
*.lcov
45+
46+
# Optional: storybook
47+
storybook-static/
48+
49+
# Optional: temporary files
50+
*.tmp
51+
*.temp
52+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
wwwroot/*.js
2+
node_modules
3+
typings
4+
dist
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.gitignore
2+
.npmignore
3+
.openapi-generator-ignore
4+
api.ts
5+
base.ts
6+
common.ts
7+
configuration.ts
8+
docs/DefaultApi.md
9+
docs/RegistrationArgs.md
10+
docs/RemoteActorInfo.md
11+
docs/SpawnArgs.md
12+
docs/StatusResponse.md
13+
git_push.sh
14+
index.ts

0 commit comments

Comments
 (0)