-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eldath
committed
Jul 23, 2017
1 parent
0e2bd35
commit 053d16f
Showing
18 changed files
with
243 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
sudo: required | ||
|
||
language: java | ||
|
||
jdk: | ||
- oraclejdk8 | ||
|
||
script: | ||
- "./gradlew build" | ||
|
||
before_install: | ||
- chmod a+x gradlew | ||
|
||
notifications: | ||
email: | ||
- ray.eldath@gmail.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/ray/eldath/avalon/executive/pool/ExecutableFilePool.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ray.eldath.avalon.executive.pool | ||
|
||
import java.io.File | ||
|
||
object ExecutableFilePool { | ||
private val executableFiles = new java.util.HashMap[Integer, File] | ||
|
||
def get(id: Int): File = executableFiles.get(id) | ||
|
||
def put(id: Int, executableFile: File): Unit = executableFiles.put(id, executableFile) | ||
|
||
def rm(id: Int): Unit = executableFiles.remove(id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/ray/eldath/avalon/executive/pool/SubmissionPool.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ray.eldath.avalon.executive.pool | ||
|
||
import java.util | ||
|
||
import ray.eldath.avalon.executive.model.Submission | ||
|
||
object SubmissionPool { | ||
private val submissions = new util.HashMap[Integer, Submission] | ||
|
||
def put(submission: Submission): Unit = SubmissionPool.submissions.put(submission.getId, submission) | ||
|
||
def rm(id: Int): Unit = SubmissionPool.submissions.remove(id) | ||
|
||
def getById(id: Int): Submission = SubmissionPool.submissions.get(id) | ||
|
||
def has(id: Int): Boolean = SubmissionPool.submissions.containsKey(id) | ||
} |
34 changes: 32 additions & 2 deletions
34
src/main/java/ray/eldath/avalon/executive/servlet/Compile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,66 @@ | ||
package ray.eldath.avalon.executive.servlet; | ||
|
||
import com.spotify.docker.client.exceptions.DockerException; | ||
import org.eclipse.jetty.util.UrlEncoded; | ||
import org.json.JSONObject; | ||
import org.json.JSONTokener; | ||
import ray.eldath.avalon.executive.core.Compiler; | ||
import ray.eldath.avalon.executive.exception.CompileErrorException; | ||
import ray.eldath.avalon.executive.model.Language; | ||
import ray.eldath.avalon.executive.model.Submission; | ||
import ray.eldath.avalon.executive.pool.ConstantPool; | ||
import ray.eldath.avalon.executive.pool.ExecutableFilePool; | ||
import ray.eldath.avalon.executive.pool.LanguagePool; | ||
import ray.eldath.avalon.executive.tool.ResponseErrorMessage; | ||
import ray.eldath.avalon.executive.pool.SubmissionPool; | ||
import ray.eldath.avalon.executive.tool.ResponseRequestUtils; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public class Compile extends HttpServlet { | ||
@Override | ||
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
req.setCharacterEncoding("UTF-8"); | ||
resp.setCharacterEncoding("UTF-8"); | ||
resp.setContentType("application/json"); | ||
JSONObject object = (JSONObject) new JSONTokener(req.getReader()).nextValue(); | ||
int id = object.getInt("id"); | ||
String encodedCode = object.getString("code"); | ||
String languageId = object.getString("lang"); | ||
Language language = LanguagePool.getById(languageId); | ||
if (language == null) { | ||
ResponseErrorMessage.response( | ||
ResponseRequestUtils.response( | ||
resp, | ||
HttpServletResponse.SC_BAD_REQUEST, | ||
"找不到id为" + languageId + "的语言!" | ||
); | ||
return; | ||
} | ||
Submission submission = new Submission(id, language, encodedCode); | ||
SubmissionPool.put(submission); | ||
JSONObject response = new JSONObject(); | ||
response.put("id", id); | ||
File executableFile; | ||
try { | ||
executableFile = Compiler.compile(ConstantPool._WORK_DIR(), submission); | ||
} catch (DockerException | InterruptedException e) { | ||
ResponseRequestUtils.responseDockerException(resp, e); | ||
return; | ||
} catch (CompileErrorException e) { | ||
response.put("out", UrlEncoded.encodeString(e.toString())); | ||
response.put("error", true); | ||
resp.getWriter().write(response.toString()); | ||
resp.getWriter().close(); | ||
return; | ||
} | ||
ExecutableFilePool.put(id, executableFile); | ||
response.put("out", ""); | ||
response.put("error", false); | ||
resp.getWriter().write(response.toString()); | ||
resp.getWriter().close(); | ||
} | ||
} |
Oops, something went wrong.