Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #19

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
792d069
Add server snippet
tracy2811 Apr 13, 2021
a81c24e
Add .gitignore
tracy2811 Apr 13, 2021
880c9fc
Remove unnecessary files
tracy2811 Apr 13, 2021
84c8812
Add solution file upload
tracy2811 Apr 13, 2021
5892e6e
Added 2 problems
KerimKochekov Apr 14, 2021
67d3910
Added 3 more problems
KerimKochekov Apr 14, 2021
4eb91e0
Update README.md
tracy2811 Apr 14, 2021
e02cf65
Add documentation to README
peki453 Apr 14, 2021
d5c0336
Update README
tracy2811 Apr 14, 2021
9d7cf57
Update README
tracy2811 Apr 14, 2021
50b184f
Minor changes to README
khaledismaeel Apr 14, 2021
6b0aee4
Remove presentation slides
khaledismaeel Apr 14, 2021
339008d
Add server CI, tests, docs
tracy2811 Apr 23, 2021
558d897
Add badge
tracy2811 Apr 23, 2021
fd230a6
Connect to server, emit solution:create event
tracy2811 Apr 23, 2021
f9b9acd
Merge branch 'develop' of https://github.com/IU-MAP/project-distribut…
KerimKochekov Apr 25, 2021
2df7e44
Add docker files for server
tracy2811 Apr 25, 2021
0b2f301
Api docs added [GET only for now]
KerimKochekov Apr 26, 2021
fbfc3d5
Change tests to be more specific
tracy2811 Apr 26, 2021
825667e
Save downloaded file to directory
tracy2811 Apr 26, 2021
1451c69
Update .gitignore
tracy2811 Apr 26, 2021
2e9fb4c
Write remaining tests
khaledismaeel Apr 26, 2021
b15de34
Update README
tracy2811 Apr 26, 2021
5cfcf40
Full API Docs added
KerimKochekov Apr 26, 2021
5a73913
Documentation with Swagger
KerimKochekov Apr 26, 2021
9fcc1b2
Use up-to-date test script
KerimKochekov Apr 26, 2021
12793a1
Merge pull request #20 from IU-MAP/server/tests
khaledismaeel Apr 26, 2021
1f96c9c
Merge branch 'develop' into server/docs
khaledismaeel Apr 26, 2021
ab68412
*s added to the path
KerimKochekov Apr 26, 2021
de52ad0
*s added to the solution path
KerimKochekov Apr 26, 2021
369339a
Change image name
tracy2811 Apr 26, 2021
fcc9c18
Fix api routes
tracy2811 Apr 26, 2021
ae20b5b
Merge pull request #31 from IU-MAP/server/docs
tracy2811 Apr 26, 2021
b8917f9
Merge remote-tracking branch 'origin/develop' into client/connect-server
tracy2811 Apr 26, 2021
e489f24
Fix route, socket.io error
tracy2811 May 2, 2021
b37b415
Add update solution api
tracy2811 May 2, 2021
16b57e4
Add file upload when creating problem
tracy2811 May 2, 2021
54e42d2
Merge pull request #32 from IU-MAP/server/update-api
tracy2811 May 3, 2021
a210a3b
Merge pull request #21 from IU-MAP/client/connect-server
tracy2811 May 3, 2021
3d068c7
New checker and connect.js added for judging
KerimKochekov May 4, 2021
1162870
Tranformed database example problems testdata in zip format
KerimKochekov May 4, 2021
2b36fb3
updated out directory
KerimKochekov May 4, 2021
a79ddaf
Update api.js
KerimKochekov May 4, 2021
1af83f2
Update solution status when running checker
tracy2811 May 4, 2021
980d53e
Delete client/data directory
KerimKochekov May 5, 2021
239a7f2
Fix checker.sh, add logs
tracy2811 May 5, 2021
3bb5cbe
Merge branch 'client/volunteer_judge' of github.com:IU-MAP/project-di…
tracy2811 May 5, 2021
7b42590
Merge pull request #33 from IU-MAP/client/volunteer_judge
KerimKochekov May 5, 2021
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
29 changes: 29 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Node.js CI

on:
push:
branches: [main, master, develop]
pull_request:
branches: [main, master, develop]

jobs:
test-server:
runs-on: ubuntu-latest

defaults:
run:
working-directory: ./server

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run test
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
*/node_modules/
server/public/uploads/
client/data/
client/judge/
95 changes: 92 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# Distributed Online Judge

[![Tests](https://github.com/IU-MAP/project-distributed-online-judge/actions/workflows/node.js.yml/badge.svg)](https://github.com/IU-MAP/project-distributed-online-judge/actions/workflows/node.js.yml)

Distributed Online Judge is a distributed computing application for testing programs against test cases in programming competitions.

Table of contents:
- [Team members](#team-members)
- [Why yet another online judge?](#why-yet-another-online-judge)
- [Architecture](#architecture)
- [Technology stack](#technology-stack)
- [Documentation](#documentation)
- [Challenges](#challenges)

## Team members

- Khaled Ismaeel (BS18-SB)
Expand All @@ -26,7 +36,7 @@ The application cluster consists of 2 types of network nodes:

The server hosts the platform interface to contestants along with all units related to solution testing (test cases, checker, validator, interactor, etc). When the server accepts a solution from a user, it forwards this solution along with testing units (which could be cached) to a volunteer. The client performs the testing protocol and reports the results back to the server, which in turn reports the result back to the contestant. All communication channels (contestant-server, server-volunteer) are to be implemented on top of HTTPS.

![Test Image 1](images/structure.PNG)
![Structure image](images/structure.png)

## Technology stack

Expand All @@ -51,9 +61,88 @@ The server hosts the platform interface to contestants along with all units rela
- Swagger
- JSDoc

## Challenges
## Documentation

### Server

#### Setup

##### Run locally

To get this project up and running locally on your computer:

1. Set up a [Nodejs](https://wiki.developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/development_environment) development environment.
1. Once you have node setup, enter the following commands in the root of your clone of this repo:
```
#Go to server directory
cd server

#Install dependencies
npm install

#Start development server
DEBUG=distributed-online-judge:* npm run devstart
```
1. Open a browser to http://localhost:3000/ to open the site.

> **Note:** The library uses a default MongoDb database hosted on [MongoDB Atlas](https://www.mongodb.com/cloud/atlas). You should use a different database for your own code experiments.

##### Run on Docker

1. Make sure Docker and Docker Compose installed
1. Enter the following commands in the root of your clone of this repo:
```
#Go to server directory
cd server

#Run docker compose
docker-compose up
```
1. Open a browser to http://localhost/ to open the site.

#### APIs

Once you have the server run on your machine (locally or using Docker), APIs are documented under `/api-docs/` path using `Swagger`.

![API Docs Screenshot](images/api-docs-screenshot.png)

![API Test Screenshot](images/test-screenshot.png)

Following is the documentation for our server's frontend.

| HTML Verb | URL | Description |
|-----------|-----|-------------|
| GET | /ui/problems | Display all available problems |
| GET | /ui/problems/create | Show form to make new problem |
| POST | /ui/problems/create | Add new problem to database and redirect |
| GET | /ui/problems/:id | Show info about one problem |
| GET | /ui/solutions | Display all available solutions |
| GET | /ui/solutions/create | Show form to make new solution |
| POST | /ui/solutions/create | Add new solution to database and redirect |
| GET | /api-docs/ | Show API documentation|


### Client

#### Run locally

To get this project up and running locally on your computer:

1. Set up a [Nodejs](https://wiki.developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/development_environment) development environment.
1. Once you have node setup, enter the following commands in the root of your clone of this repo:
```
#Go to server directory
cd client

#Install dependencies
npm install

#Connect to server
npm start
```
#### Run on Docker

Yet to be written.
To be set up

## Project

Expand Down
29 changes: 29 additions & 0 deletions client/checker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

if ! [ -f "data/$2.zip" ]; then
wget $3/$2.zip -P data
echo "Downloading"
echo $3/$2.zip
fi

if ! [ -d "judge/$2" ]; then
echo "Directory not exist"
mkdir judge/$2
unzip data/$2.zip -d judge/$2
fi

cat data/$1 > judge/$2/solution.cpp && g++ -std=c++11 judge/$2/solution.cpp -o judge/$2/solution.out && for ((i=1;;i++))
do
INPUT=judge/$2/testdata/input/$i.in
OUTPUT=judge/$2/testdata/output/$i.out
if [ -f "$INPUT" ] && [ -f "$OUTPUT" ]; then
./judge/$2/solution.out < $INPUT > judge/$2/out
if ! diff -w judge/$2/out $OUTPUT
then
exit 1
fi
else
exit 0
fi
done

46 changes: 46 additions & 0 deletions client/connect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const io = require("socket.io-client");
const fs = require("fs");
const request = require("request");
const { exec } = require("child_process");
const axios = require("axios");

if (!fs.existsSync(`${__dirname}/data/`)) {
fs.mkdirSync(`${__dirname}/data/`);
}

if (!fs.existsSync(`${__dirname}/judge/`)) {
fs.mkdirSync(`${__dirname}/judge/`);
}

const host = process.env.DOJ_HOST || "http://localhost:3000";
const socket = io(host);

socket.on("solution:create", (data) => {
const writer = fs.createWriteStream(`data/${data._id}`);
request(`${host}/uploads/${data._id}`).pipe(writer);
writer.on("finish", async () => {
console.log(`Running solution ${data._id}...`);
await axios.put(`${host}/api/solutions/${data._id}`, {
problem: data.problem,
status: "running",
});
exec(
`./checker.sh ${data._id} ${data.problem} ${host}/uploads`,
async (err, stdout, stderr) => {
if (err) {
console.log(`Solution ${data._id} failed!`);
await axios.put(`${host}/api/solutions/${data._id}`, {
problem: data.problem,
status: "failed",
});
} else {
console.log(`Solution ${data._id} ok!`);
await axios.put(`${host}/api/solutions/${data._id}`, {
problem: data.problem,
status: "ok",
});
}
}
);
});
});
Loading