Search in sources :

Example 1 with SubmissionDetail

use of cn.edu.zjnu.acm.judge.domain.SubmissionDetail in project judge by zjnu-acm.

the class JudgeServiceImpl method execute.

@Override
public void execute(long submissionId) {
    Submission submission = submissionMapper.findOne(submissionId);
    if (submission == null) {
        throw new BusinessException(BusinessCode.SUBMISSION_NOT_FOUND, submissionId);
    }
    long problemId = submission.getProblem();
    Problem problem = problemService.findOneNoI18n(problemId);
    try {
        RunRecord runRecord = RunRecord.builder().language(languageService.getAvailableLanguage(submission.getLanguage())).source(submissionDetailMapper.findSourceById(submissionId)).memoryLimit(problem.getMemoryLimit()).timeLimit(problem.getTimeLimit()).build();
        Path dataDirectory = systemService.getDataDirectory(problemId);
        JudgeData judgeData = JudgeData.parse(dataDirectory);
        Path specialFile = systemService.getSpecialJudgeExecutable(problemId);
        boolean isSpecial = systemService.isSpecialJudge(problemId);
        // 建立临时文件
        Path work = systemService.getWorkDirectory(submissionId);
        final Validator validator = isSpecial ? new SpecialValidator(specialFile.toString(), work) : SimpleValidator.PE_AS_AC;
        boolean deleteTempFile = systemService.isDeleteTempFile();
        RunResult runResult = judgeRunner.run(runRecord, work, judgeData, validator, deleteTempFile);
        SubmissionDetail detail = SubmissionDetail.builder().id(submissionId).compileInfo(runResult.getCompileInfo()).detail(runResult.getDetail()).systemInfo(runResult.getSystemInfo()).build();
        if (runResult.getType() == Status.COMPILATION_ERROR) {
            submissionMapper.updateResult(submissionId, ResultType.COMPILE_ERROR, 0, 0);
        } else {
            int score = runResult.getScore();
            long time = runResult.getTime();
            long memory = runResult.getMemory();
            submissionMapper.updateResult(submissionId, score, time, memory);
        }
        // TODO return value not handled, we can do nothing for the record not exists in the table now.
        submissionDetailMapper.update(detail);
        updateSubmissionStatus(submission.getUser(), problemId);
    } catch (ThreadDeath | VirtualMachineError error) {
        throw error;
    } catch (JudgeException | IOException | Error ex) {
        log.error("got an exception when judging submission {}", submissionId, ex);
        submissionMapper.updateResult(submissionId, ResultType.SYSTEM_ERROR, 0, 0);
        StringWriter sw = new StringWriter();
        try (PrintWriter pw = new PrintWriter(sw)) {
            ex.printStackTrace(pw);
        }
        submissionDetailMapper.update(SubmissionDetail.builder().id(submissionId).systemInfo(sw.toString()).build());
    }
}
Also used : Path(java.nio.file.Path) Submission(cn.edu.zjnu.acm.judge.domain.Submission) IOException(java.io.IOException) RunRecord(cn.edu.zjnu.acm.judge.support.RunRecord) BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) JudgeData(cn.edu.zjnu.acm.judge.support.JudgeData) StringWriter(java.io.StringWriter) SubmissionDetail(cn.edu.zjnu.acm.judge.domain.SubmissionDetail) SpecialValidator(cn.edu.zjnu.acm.judge.sandbox.win32.SpecialValidator) Problem(cn.edu.zjnu.acm.judge.domain.Problem) JudgeException(cn.edu.zjnu.acm.judge.core.JudgeException) RunResult(cn.edu.zjnu.acm.judge.support.RunResult) Validator(cn.edu.zjnu.acm.judge.core.Validator) SpecialValidator(cn.edu.zjnu.acm.judge.sandbox.win32.SpecialValidator) SimpleValidator(cn.edu.zjnu.acm.judge.core.SimpleValidator) PrintWriter(java.io.PrintWriter)

Aggregations

JudgeException (cn.edu.zjnu.acm.judge.core.JudgeException)1 SimpleValidator (cn.edu.zjnu.acm.judge.core.SimpleValidator)1 Validator (cn.edu.zjnu.acm.judge.core.Validator)1 Problem (cn.edu.zjnu.acm.judge.domain.Problem)1 Submission (cn.edu.zjnu.acm.judge.domain.Submission)1 SubmissionDetail (cn.edu.zjnu.acm.judge.domain.SubmissionDetail)1 BusinessException (cn.edu.zjnu.acm.judge.exception.BusinessException)1 SpecialValidator (cn.edu.zjnu.acm.judge.sandbox.win32.SpecialValidator)1 JudgeData (cn.edu.zjnu.acm.judge.support.JudgeData)1 RunRecord (cn.edu.zjnu.acm.judge.support.RunRecord)1 RunResult (cn.edu.zjnu.acm.judge.support.RunResult)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Path (java.nio.file.Path)1