From 2e71c4e8ed5ddf2fe62289d42f81d6cbe4a19bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Henrique?= Date: Thu, 26 Oct 2023 22:33:28 -0300 Subject: [PATCH] adding nginx page & simulation endpoint --- ASP.NET/Controllers/SimulationController.cs | 26 +++++++++++++++++++++ ASP.NET/Dockerfile | 4 +++- ActixAPI/Dockerfile | 4 +++- ActixAPI/src/main.rs | 15 ++++++++++++ FlaskAPI/Dockerfile | 4 +++- FlaskAPI/app.py | 2 ++ FlaskAPI/controllers/simulation.py | 23 ++++++++++++++++++ scripts/graph.py | 2 ++ 8 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 ASP.NET/Controllers/SimulationController.cs create mode 100644 FlaskAPI/controllers/simulation.py diff --git a/ASP.NET/Controllers/SimulationController.cs b/ASP.NET/Controllers/SimulationController.cs new file mode 100644 index 0000000..ed8f445 --- /dev/null +++ b/ASP.NET/Controllers/SimulationController.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Mvc; +using TCC.Services; + +namespace TCC.Controllers +{ + [ApiController] + [Route("simulation")] + public class SimulationController : ControllerBase + { + public SimulationController() + { + } + + [HttpGet("harmonic-progression")] + public async Task GetHarmonicProgression([FromQuery] int n) + { + float sum = 0; + for (int i = 1; i <= n; i++) + { + sum += 1.0f / i; + } + + return Ok(sum); + } + } +} diff --git a/ASP.NET/Dockerfile b/ASP.NET/Dockerfile index eed04b1..daacbbe 100644 --- a/ASP.NET/Dockerfile +++ b/ASP.NET/Dockerfile @@ -15,11 +15,13 @@ RUN cd out && \ wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \ wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \ wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 && \ + wget https://files.ivanch.me/api/public/dl/RzXwJG7o/nginx.html && \ rm -rf runtimes && \ mkdir -p ./static && \ mv small-image.png ./static && \ mv big-image.png ./static && \ - mv video.mp4 ./static + mv video.mp4 ./static && \ + mv nginx.html ./static # Build runtime image FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim diff --git a/ActixAPI/Dockerfile b/ActixAPI/Dockerfile index aa2f7da..0558dd5 100644 --- a/ActixAPI/Dockerfile +++ b/ActixAPI/Dockerfile @@ -18,7 +18,8 @@ WORKDIR /app RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \ wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \ - wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 + wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 && \ + wget https://files.ivanch.me/api/public/dl/RzXwJG7o/nginx.html COPY . . @@ -27,6 +28,7 @@ RUN cargo build --release && \ mv small-image.png ./static && \ mv big-image.png ./static && \ mv video.mp4 ./static && \ + mv nginx.html ./static && \ ldconfig /usr/local/lib ENV LD_LIBRARY_PATH=/usr/local/lib diff --git a/ActixAPI/src/main.rs b/ActixAPI/src/main.rs index 878169d..8e13c71 100644 --- a/ActixAPI/src/main.rs +++ b/ActixAPI/src/main.rs @@ -15,6 +15,20 @@ async fn static_serve(req: HttpRequest) -> Result { Ok(NamedFile::open(real_path)?) } +#[get("/simulation/harmonic-progression")] +async fn simulation_harmonic_progression(req: HttpRequest) -> impl Responder { + let query_str = req.query_string(); + let qs = QString::from(query_str); + let radius = qs.get("n").unwrap_or("1").parse::().unwrap_or(1.0); + + let mut sum = 0.0; + for i in 1..=radius as i32 { + sum += 1.0 / i as f64; + } + + HttpResponse::Ok().body(format!("{}", sum)) +} + #[get("/image/load-small-image")] async fn load_small_image() -> Result { let real_path = "static/small-image.png"; @@ -74,6 +88,7 @@ async fn main() -> std::io::Result<()> { .service(load_big_image) .service(save_big_image) .service(blur_image) + .service(simulation_harmonic_progression) .app_data(web::PayloadConfig::new(1024 * 1024 * 1024)) }) .bind(("0.0.0.0", 5000))? diff --git a/FlaskAPI/Dockerfile b/FlaskAPI/Dockerfile index 2a22885..d0caa71 100644 --- a/FlaskAPI/Dockerfile +++ b/FlaskAPI/Dockerfile @@ -11,11 +11,13 @@ RUN apt-get update && apt-get install -y imagemagick && apt-get install -y wget RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \ wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \ wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 && \ + wget https://files.ivanch.me/api/public/dl/RzXwJG7o/nginx.html && \ rm -rf runtimes && \ mkdir -p ./static && \ mv small-image.png ./static && \ mv big-image.png ./static && \ - mv video.mp4 ./static + mv video.mp4 ./static && \ + mv nginx.html ./static COPY . . diff --git a/FlaskAPI/app.py b/FlaskAPI/app.py index c63e1c6..9451d0f 100644 --- a/FlaskAPI/app.py +++ b/FlaskAPI/app.py @@ -1,11 +1,13 @@ from flask import Flask from controllers.status import status_blueprint +from controllers.simulation import simulation_blueprint from controllers.image import image_blueprint app = Flask(__name__) # app.register_blueprint(status_blueprint) +app.register_blueprint(simulation_blueprint) app.register_blueprint(image_blueprint) if __name__ == '__main__': diff --git a/FlaskAPI/controllers/simulation.py b/FlaskAPI/controllers/simulation.py new file mode 100644 index 0000000..40e3716 --- /dev/null +++ b/FlaskAPI/controllers/simulation.py @@ -0,0 +1,23 @@ +from flask import request, Blueprint + +simulation_blueprint = Blueprint('simulation_blueprint', __name__) + +class SimulationController: + def __init__(self): + pass + + def harmonic_progression(self, n): + sum = 0 + for i in range(1, n): + sum += 1/i + + return sum + +simulation_controller = SimulationController() + +@simulation_blueprint.route('/simulation/harmonic-progression', methods=['GET']) +def return_ok(): + n = int(request.args.get('n')) + sum = simulation_controller.harmonic_progression(n) + + return str(sum), 200 diff --git a/scripts/graph.py b/scripts/graph.py index 9e058a9..a468ec0 100644 --- a/scripts/graph.py +++ b/scripts/graph.py @@ -126,7 +126,9 @@ if __name__ == '__main__': endpoint_file = endpoint_name.replace('/', '') filename = f'data/resource_ASP.NET_{endpoint_file}.csv' + filename = filename.replace("?", "_") generate_resource_graph(filename, framework_name, endpoint_name) filename = f'data/req_ASP.NET_{endpoint_file}.csv' + filename = filename.replace("?", "_") generate_req_graph(filename, framework_name, endpoint_name)