Skip to content

Commit

Permalink
Merge pull request #282 from northwesternfintech/sandbox
Browse files Browse the repository at this point in the history
Updat to enable sandbox
  • Loading branch information
stevenewald authored Oct 6, 2024
2 parents 2935b5e + 71ad802 commit 49b3c71
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 164 deletions.
2 changes: 1 addition & 1 deletion docker/dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
image: nutc-webserver
build:
context: ../..
dockerfile: webserver/WebserverDockerfile
dockerfile: webserver/Dockerfile
restart: unless-stopped

linter:
Expand Down
71 changes: 0 additions & 71 deletions docker/prod/docker-compose.yml

This file was deleted.

43 changes: 0 additions & 43 deletions docker/prod/nginx.conf

This file was deleted.

Binary file modified exchange/docker/dev/grafana_data/grafana.db
Binary file not shown.
12 changes: 11 additions & 1 deletion exchange/src/exchange/sandbox_server/crow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,20 @@ CrowServer::CrowServer() :
: common::AlgoLanguage::cpp;
std::string algorithm_data = req.body;
add_pending_trader_(algo_id, language_enum, algorithm_data);
crow::json::wvalue response_json({
{"success", true},
{"message", "Algorithm Successfully Submitted" }
});
res.body = response_json.dump();
return res;
} catch (const std::exception& e) {
log_e(sandbox_server, "Failed to spawn algorithm: {}", e.what());
return crow::response(500);
crow::json::wvalue response_json({
{"success", false },
{"message", e.what()}
});
res.body = response_json.dump();
return crow::response(500, e.what());
}
}
);
Expand Down
6 changes: 3 additions & 3 deletions exchange/src/linter/crow/crow.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "crow.hpp"

#include "linter/fetching/fetching.hpp"
#include "common/logging/logging.hpp"
#include "linter/fetching/fetching.hpp"
#include "linter/spawning/spawning.hpp"

namespace nutc {
Expand Down Expand Up @@ -59,7 +59,7 @@ get_server_thread()
auto algo_code = client::storage_request(algo_url);
if (!algo_code.has_value()) {
crow::json::wvalue response = crow::json::wvalue({
{"lint_success", false },
{"success", false },
{"message", "Algo file not found"}
});

Expand All @@ -72,7 +72,7 @@ get_server_thread()
auto lint_res =
spawner_manager.spawn_client(algo_code.value(), algo_language);
crow::json::wvalue response({
{"lint_success", lint_res.success },
{"success", lint_res.success },
{"message", client::replaceDisallowedValues(lint_res.message)}
});

Expand Down
8 changes: 4 additions & 4 deletions web/app/api/protected/db/user/createAlgo/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export async function POST(req: Request) {
});

const url = `${process.env.WEBSERVER_INTERNAL_ENDPOINT}/submit/${algo.algoFileS3Key}/${algo.language}`;
console.log("Fetching " + url);
const submission_response = await fetch(
url,
{
Expand All @@ -60,10 +59,11 @@ export async function POST(req: Request) {
if (!submission_response.ok) {
console.log("Failed to lint/sandbox");
}
const resp = await submission_response.text();
console.log(resp);
const { success, message } = await submission_response.json();
console.log("Success state: " + success);
console.log("Lint message: " + message);
return NextResponse.json({
message: "Linter response: " + resp
success, message
}, { status: 200 });
} catch (error) {
console.log(error);
Expand Down
17 changes: 8 additions & 9 deletions web/app/dash/submissions/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ export default async function SubmissionPage(props: {
notFound();
}

const formatNewLines = (str: string) => {
const LINES = str.split("\n");
return LINES.map((line: string, index: number) => (
<React.Fragment key={`line_${index}`}>
<p>{line}</p>
{index < LINES.length - 1 && <br />}
</React.Fragment>
));
function formatNewLines(str: string): TrustedHTML {
return str.replace(/\\n/g, "<br />");
};

const lintFailureMessage = algo?.lintFailureMessage;
Expand Down Expand Up @@ -69,6 +63,11 @@ export default async function SubmissionPage(props: {
</div>
);
} else {
return formatNewLines(stringToRender);
return <div className="flex flex-col items-center pt-12">
<h1 className="text-3xl font-bold mb-12">Error Log</h1>
<div className="bg-gray-800 p-6 rounded-lg">
<div dangerouslySetInnerHTML={{ __html: formatNewLines(stringToRender) }} />
</div>
</div>
}
}
31 changes: 13 additions & 18 deletions web/app/dash/submit/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export default function SubmissionForm(props: { user: any }) {
});

const onSubmit: SubmitHandler<Inputs> = async data => {
Swal.fire({ title: "Submissions not yet open", text: "Check back October 6th" });
return;
// Swal.fire({ title: "Submissions not yet open", text: "Check back October 6th" });
// return;
const responsePromise = fetch("/api/protected/db/user/createAlgo", {
method: "POST",
body: JSON.stringify(data),
Expand All @@ -78,24 +78,21 @@ export default function SubmissionForm(props: { user: any }) {
Swal.showLoading();

const response = await responsePromise;
Swal.close();
if (!response.ok) {
Swal.fire({ title: "Error", icon: "error", text: "Server error. Please contact the nuft team in the piazza" });
return;
}
Swal.close();
var { success, message } = await response.json();
message = message.replace(/\\n/g, "<br />");
if (!success) {
Swal.fire({
title: "Error",
title: "Compilation/Linting Error",
icon: "error",
text: "An error occurred",
toast: true,
position: "top-end",
showConfirmButton: false,
timer: 4000,
timerProgressBar: true,
didOpen: toast => {
toast.addEventListener("mouseenter", Swal.stopTimer);
toast.addEventListener("mouseleave", Swal.resumeTimer);
},
html: message,
width: 800,
showConfirmButton: true,
});
const errMsg = await response.text();
alert(errMsg);
} else {
Swal.fire({
title: "Linting complete!",
Expand Down Expand Up @@ -179,8 +176,6 @@ export default function SubmissionForm(props: { user: any }) {
handleAlgoChange(files[0]);
};

console.log("key", algoFileS3Key);

return (
<div className="mx-auto max-w-7xl px-4 pb-24 pt-12 sm:px-6 sm:pb-32 sm:pt-16 lg:px-8">
<div className="mx-auto max-w-2xl">
Expand Down
2 changes: 1 addition & 1 deletion webserver/WebserverDockerfile → webserver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ COPY webserver/src src

RUN cargo build --release

COPY web/.env .env
COPY webserver/.env .env

EXPOSE 16124

Expand Down
28 changes: 15 additions & 13 deletions webserver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct LinterResponse {

#[derive(Deserialize, Debug)]
struct LintResult {
lint_success: bool,
success: bool,
message: String,
}

Expand Down Expand Up @@ -62,8 +62,8 @@ async fn handle_algo_submission(

let (algo_id, language) = data.into_inner();

let s3_endpoint = std::env::var("INTERNAL_S3_ENDPOINT")
.expect("env variable `INTERNAL_S3_ENDPOINT` should be set");
let s3_endpoint =
std::env::var("S3_ENDPOINT").expect("env variable `S3_ENDPOINT` should be set");
let algo_url = format!("{}/nutc/{}", s3_endpoint, algo_id);

let linter_url = format!(
Expand Down Expand Up @@ -94,14 +94,14 @@ async fn handle_algo_submission(
tracing::error!("failed to update linter status in database, {:?}", e);
return HttpResponse::BadGateway().finish();
}
if linter_response.lint_success {
tracing::info!("linting success now requesting sandbox");
if linter_response.success {
tracing::info!("Linting succeeded, now requesting sandbox");
} else {
// forward the error message from the linter, and add something in the response
// to indicate that the linter Failed
tracing::error!("linting failed: {}", linter_response.message);
return HttpResponse::Ok()
.json(json!({"status": "lint failure", "message": linter_response.message}));
.json(json!({"success": false, "message": linter_response.message}));
}

// todo: this function shouldnt return a http request
Expand Down Expand Up @@ -132,17 +132,19 @@ async fn request_sandbox(algo_id: String, algo_url: String, language: String) ->

match sandbox_response {
Ok(response) => {
let body = response.text().await;
tracing::info!(
"sandbox response: {}",
body.unwrap_or("failed to decode sandbox response".into())
);
return HttpResponse::Ok().finish();
let text_body = response.text().await;
let text = text_body.unwrap();
tracing::info!("sandbox response: {}", text);
return HttpResponse::Ok()
.content_type("application/json")
.body(text);
}
Err(err) => {
tracing::error!("failed to request sandbox {:#?}", err);
tracing::error!("someting went wrong requesting to sandbox");
return HttpResponse::BadGateway().finish();
return HttpResponse::BadGateway()
.content_type("application/json")
.body("{\"success\": false}");
}
}
}
Expand Down

0 comments on commit 49b3c71

Please sign in to comment.