修复POJ问题 同时优化VJ重判
This commit is contained in:
parent
5f3a2532e7
commit
dbfd29ea78
|
@ -2,6 +2,7 @@ package top.hcode.hoj.controller.admin;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import io.swagger.models.auth.In;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
|
@ -21,6 +22,7 @@ import top.hcode.hoj.pojo.entity.*;
|
|||
import top.hcode.hoj.service.impl.*;
|
||||
import top.hcode.hoj.utils.Constants;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -83,6 +85,8 @@ public class AdminJudgeController {
|
|||
judgeCaseQueryWrapper.eq("submit_id", submitId);
|
||||
judgeCaseService.remove(judgeCaseQueryWrapper);
|
||||
|
||||
boolean hasSubmitIdRemoteRejudge = isHasSubmitIdRemoteRejudge(judge.getVjudgeSubmitId(), judge.getStatus());
|
||||
|
||||
// 设置默认值
|
||||
judge.setStatus(Constants.Judge.STATUS_PENDING.getStatus()); // 开始进入判题队列
|
||||
judge.setVersion(judge.getVersion() + 1);
|
||||
|
@ -98,7 +102,7 @@ public class AdminJudgeController {
|
|||
Problem problem = problemService.getById(judge.getPid());
|
||||
if (problem.getIsRemote()) { // 如果是远程oj判题
|
||||
remoteJudgeDispatcher.sendTask(judge, judgeToken, problem.getProblemId(),
|
||||
judge.getCid() != 0, 1);
|
||||
judge.getCid() != 0, 1, hasSubmitIdRemoteRejudge);
|
||||
} else {
|
||||
judgeDispatcher.sendTask(judge, judgeToken, judge.getCid() != 0, 1);
|
||||
}
|
||||
|
@ -124,8 +128,10 @@ public class AdminJudgeController {
|
|||
return CommonResult.errorResponse("当前该题目无提交,不可重判!");
|
||||
}
|
||||
List<Long> submitIdList = new LinkedList<>();
|
||||
HashMap<Long, Integer> idMapStatus = new HashMap<>();
|
||||
// 全部设置默认值
|
||||
for (Judge judge : rejudgeList) {
|
||||
idMapStatus.put(judge.getSubmitId(), judge.getStatus());
|
||||
judge.setStatus(Constants.Judge.STATUS_PENDING.getStatus()); // 开始进入判题队列
|
||||
judge.setVersion(judge.getVersion() + 1);
|
||||
judge.setJudger(null)
|
||||
|
@ -153,7 +159,8 @@ public class AdminJudgeController {
|
|||
for (Judge judge : rejudgeList) {
|
||||
// 进入重判队列,等待调用判题服务
|
||||
remoteJudgeDispatcher.sendTask(judge, judgeToken, problem.getProblemId(),
|
||||
judge.getCid() != 0, 1);
|
||||
judge.getCid() != 0, 1,
|
||||
isHasSubmitIdRemoteRejudge(judge.getVjudgeSubmitId(), idMapStatus.get(judge.getSubmitId())));
|
||||
}
|
||||
} else {
|
||||
for (Judge judge : rejudgeList) {
|
||||
|
@ -168,4 +175,17 @@ public class AdminJudgeController {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isHasSubmitIdRemoteRejudge(Long vjudgeSubmitId, int status) {
|
||||
boolean isHasSubmitIdRemoteRejudge = false;
|
||||
if (vjudgeSubmitId != null &&
|
||||
(status == Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus()
|
||||
|| status == Constants.Judge.STATUS_COMPILING.getStatus()
|
||||
|| status == Constants.Judge.STATUS_PENDING.getStatus()
|
||||
|| status == Constants.Judge.STATUS_JUDGING.getStatus()
|
||||
|| status == Constants.Judge.STATUS_SYSTEM_ERROR.getStatus())) {
|
||||
isHasSubmitIdRemoteRejudge = true;
|
||||
}
|
||||
return isHasSubmitIdRemoteRejudge;
|
||||
}
|
||||
}
|
|
@ -209,7 +209,8 @@ public class JudgeController {
|
|||
|
||||
// 将提交加入任务队列
|
||||
if (judgeDto.getIsRemote()) { // 如果是远程oj判题
|
||||
remoteJudgeDispatcher.sendTask(judge, judgeToken, judge.getDisplayPid(), judge.getCid() != 0, 1);
|
||||
remoteJudgeDispatcher.sendTask(judge, judgeToken, judge.getDisplayPid(), judge.getCid() != 0,
|
||||
1, false);
|
||||
|
||||
} else {
|
||||
judgeDispatcher.sendTask(judge, judgeToken, judge.getCid() == 0, 1);
|
||||
|
@ -265,15 +266,28 @@ public class JudgeController {
|
|||
}
|
||||
}
|
||||
|
||||
boolean isHasSubmitIdRemoteRejudge = false;
|
||||
if (judge.getVjudgeSubmitId() != null &&
|
||||
(judge.getStatus().intValue() == Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus()
|
||||
|| judge.getStatus().intValue() == Constants.Judge.STATUS_PENDING.getStatus()
|
||||
|| judge.getStatus().intValue() == Constants.Judge.STATUS_JUDGING.getStatus()
|
||||
|| judge.getStatus().intValue() == Constants.Judge.STATUS_COMPILING.getStatus()
|
||||
|| judge.getStatus().intValue() == Constants.Judge.STATUS_SYSTEM_ERROR.getStatus())) {
|
||||
isHasSubmitIdRemoteRejudge = true;
|
||||
}
|
||||
|
||||
// 重新进入等待队列
|
||||
judge.setStatus(Constants.Judge.STATUS_PENDING.getStatus());
|
||||
judge.setVersion(judge.getVersion() + 1);
|
||||
judge.setErrorMessage(null);
|
||||
judgeService.updateById(judge);
|
||||
|
||||
|
||||
// 将提交加入任务队列
|
||||
if (problem.getIsRemote()) { // 如果是远程oj判题
|
||||
|
||||
remoteJudgeDispatcher.sendTask(judge, judgeToken, problem.getProblemId(),
|
||||
judge.getCid() != 0, 1);
|
||||
judge.getCid() != 0, 1, isHasSubmitIdRemoteRejudge);
|
||||
} else {
|
||||
judgeDispatcher.sendTask(judge, judgeToken, judge.getCid() != 0, 1);
|
||||
}
|
||||
|
@ -317,12 +331,12 @@ public class JudgeController {
|
|||
// 如果不是本人或者并未分享代码,则不可查看
|
||||
// 当此次提交代码不共享
|
||||
// 比赛提交只有比赛创建者和root账号可看代码
|
||||
if (judge.getCid() != 0){
|
||||
if (judge.getCid() != 0) {
|
||||
|
||||
Contest contest = contestService.getById(judge.getCid());
|
||||
if (!root&&!userRolesVo.getUid().equals(contest.getUid())) {
|
||||
if (!root && !userRolesVo.getUid().equals(contest.getUid())) {
|
||||
// 如果是比赛,那么还需要判断是否为封榜,比赛管理员和超级管理员可以有权限查看(ACM题目除外)
|
||||
if(contest.getSealRank()
|
||||
if (contest.getSealRank()
|
||||
&& contest.getType().intValue() == Constants.Contest.TYPE_OI.getCode()
|
||||
&& contest.getStatus().intValue() == Constants.Contest.STATUS_RUNNING.getCode()
|
||||
&& contest.getSealRankTime().before(new Date())) {
|
||||
|
@ -331,7 +345,7 @@ public class JudgeController {
|
|||
}
|
||||
judge.setCode(null);
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
boolean admin = SecurityUtils.getSubject().hasRole("problem_admin");// 是否为题目管理员
|
||||
if (!judge.getShare() && !root && !admin) {
|
||||
if (userRolesVo != null) { // 当前是登陆状态
|
||||
|
|
|
@ -50,7 +50,7 @@ public class Dispatcher {
|
|||
switch (type) {
|
||||
case "judge":
|
||||
ToJudge judgeData = (ToJudge) data;
|
||||
toJudge(path, judgeData, judgeData.getJudge().getSubmitId(), judgeData.getRemoteJudge() != null);
|
||||
toJudge(path, judgeData, judgeData.getJudge().getSubmitId(), judgeData.getRemoteJudgeProblem() != null);
|
||||
break;
|
||||
case "compile":
|
||||
CompileSpj compileSpj = (CompileSpj) data;
|
||||
|
@ -76,7 +76,7 @@ public class Dispatcher {
|
|||
try {
|
||||
result = restTemplate.postForObject("http://" + judgeServer.getUrl() + path, data, CommonResult.class);
|
||||
} catch (Exception e) {
|
||||
log.error("调用判题服务器[" + judgeServer.getUrl() + "]发送异常-------------->{}", e.getMessage());
|
||||
log.error("调用判题服务器[" + judgeServer.getUrl() + "]发送异常-------------->{}", e);
|
||||
} finally {
|
||||
checkResult(result, submitId);
|
||||
// 无论成功与否,都要将对应的当前判题机当前判题数减1
|
||||
|
|
|
@ -62,7 +62,7 @@ public class JudgeServerUtils {
|
|||
switch (type) {
|
||||
case "judge":
|
||||
ToJudge judgeData = (ToJudge) data;
|
||||
toJudge(path, judgeData, judgeData.getJudge().getSubmitId(), judgeData.getRemoteJudge() != null);
|
||||
toJudge(path, judgeData, judgeData.getJudge().getSubmitId(), judgeData.getRemoteJudgeProblem() != null);
|
||||
break;
|
||||
case "compile":
|
||||
CompileSpj compileSpj = (CompileSpj) data;
|
||||
|
|
|
@ -25,13 +25,15 @@ public class RemoteJudgeDispatcher {
|
|||
@Autowired
|
||||
private RemoteJudgeReceiver remoteJudgeReceiver;
|
||||
|
||||
public void sendTask(Judge judge, String token, String remoteJudge, Boolean isContest, Integer tryAgainNum) {
|
||||
public void sendTask(Judge judge, String token, String remoteJudgeProblem, Boolean isContest,
|
||||
Integer tryAgainNum, Boolean isHasSubmitIdRemoteReJudge) {
|
||||
JSONObject task = new JSONObject();
|
||||
task.set("judge", judge);
|
||||
task.set("remoteJudge", remoteJudge);
|
||||
task.set("remoteJudgeProblem", remoteJudgeProblem);
|
||||
task.set("token", token);
|
||||
task.set("isContest", isContest);
|
||||
task.set("tryAgainNum", tryAgainNum);
|
||||
task.set("isHasSubmitIdRemoteReJudge", isHasSubmitIdRemoteReJudge);
|
||||
try {
|
||||
boolean isOk = redisUtils.llPush(Constants.Judge.STATUS_REMOTE_JUDGE_WAITING_HANDLE.getName(), JSONUtil.toJsonStr(task));
|
||||
if (!isOk) {
|
||||
|
@ -40,7 +42,7 @@ public class RemoteJudgeDispatcher {
|
|||
.setStatus(Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus())
|
||||
.setErrorMessage("Please try to submit again!")
|
||||
);
|
||||
}else{
|
||||
} else {
|
||||
remoteJudgeReceiver.processWaitingTask();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -55,11 +55,12 @@ public class RemoteJudgeReceiver {
|
|||
|
||||
Judge judge = task.get("judge", Judge.class);
|
||||
String token = task.getStr("token");
|
||||
String remoteJudge = task.getStr("remoteJudge");
|
||||
String remoteJudgeProblem = task.getStr("remoteJudgeProblem");
|
||||
Boolean isContest = task.getBool("isContest");
|
||||
Integer tryAgainNum = task.getInt("tryAgainNum");
|
||||
Boolean isHasSubmitIdRemoteReJudge = task.getBool("isHasSubmitIdRemoteReJudge");
|
||||
|
||||
String remoteOJName = remoteJudge.split("-")[0].toUpperCase();
|
||||
String remoteOJName = remoteJudgeProblem.split("-")[0].toUpperCase();
|
||||
|
||||
// 过滤出当前远程oj可用的账号列表
|
||||
QueryWrapper<RemoteJudgeAccount> remoteJudgeAccountQueryWrapper = new QueryWrapper<>();
|
||||
|
@ -69,23 +70,66 @@ public class RemoteJudgeReceiver {
|
|||
|
||||
List<RemoteJudgeAccount> remoteJudgeAccountList = remoteJudgeAccountService.list(remoteJudgeAccountQueryWrapper);
|
||||
|
||||
boolean isNeedAccountRejudge = remoteOJName.equals(Constants.RemoteOJ.POJ.getName());
|
||||
|
||||
boolean isHasAccountRejudge = false;
|
||||
|
||||
if (remoteJudgeAccountList.size() > 0) {
|
||||
RemoteJudgeAccount account = null;
|
||||
for (RemoteJudgeAccount remoteJudgeAccount : remoteJudgeAccountList) {
|
||||
remoteJudgeAccount.setStatus(false);
|
||||
boolean isOk = remoteJudgeAccountService.updateById(remoteJudgeAccount);
|
||||
if (isOk) {
|
||||
account = remoteJudgeAccount;
|
||||
break;
|
||||
// 已有submitId的重判不需要在获取账号(除POJ外)
|
||||
if (isHasSubmitIdRemoteReJudge) {
|
||||
// POJ已有submitId的重判需要使用原来的账号获取结果
|
||||
if (isNeedAccountRejudge) {
|
||||
if (remoteJudgeAccount.getUsername().equals(judge.getVjudgeUsername())) {
|
||||
isHasAccountRejudge = true;
|
||||
remoteJudgeAccount.setStatus(false);
|
||||
boolean isOk = remoteJudgeAccountService.updateById(remoteJudgeAccount);
|
||||
if (isOk) {
|
||||
account = remoteJudgeAccount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
remoteJudgeAccount.setStatus(false);
|
||||
boolean isOk = remoteJudgeAccountService.updateById(remoteJudgeAccount);
|
||||
if (isOk) {
|
||||
account = remoteJudgeAccount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (account != null) { // 如果获取到账号
|
||||
if (isHasSubmitIdRemoteReJudge) {
|
||||
ToJudge toJudge = new ToJudge();
|
||||
toJudge.setJudge(judge)
|
||||
.setToken(token)
|
||||
.setRemoteJudgeProblem(remoteJudgeProblem)
|
||||
.setIsHasSubmitIdRemoteReJudge(true)
|
||||
.setTryAgainNum(tryAgainNum);
|
||||
if (isNeedAccountRejudge) {
|
||||
if (account != null) {
|
||||
toJudge.setUsername(account.getUsername())
|
||||
.setPassword(account.getPassword());
|
||||
} else if (!isHasAccountRejudge) { // poj以往的账号丢失了,那么只能重新从头到尾提交
|
||||
remoteJudgeDispatcher.sendTask(judge, token, remoteJudgeProblem, isContest,
|
||||
tryAgainNum + 1, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 调用判题服务
|
||||
dispatcher.dispatcher("judge", "/remote-judge", toJudge);
|
||||
// 如果队列中还有任务,则继续处理
|
||||
processWaitingTask();
|
||||
} else if (account != null) { // 如果获取到账号
|
||||
// 调用判题服务
|
||||
dispatcher.dispatcher("judge", "/remote-judge", new ToJudge()
|
||||
.setJudge(judge)
|
||||
.setToken(token)
|
||||
.setRemoteJudge(remoteJudge)
|
||||
.setRemoteJudgeProblem(remoteJudgeProblem)
|
||||
.setIsHasSubmitIdRemoteReJudge(false)
|
||||
.setUsername(account.getUsername())
|
||||
.setPassword(account.getPassword())
|
||||
.setTryAgainNum(tryAgainNum));
|
||||
|
@ -98,7 +142,8 @@ public class RemoteJudgeReceiver {
|
|||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
remoteJudgeDispatcher.sendTask(judge, token, remoteJudge, isContest, tryAgainNum + 1);
|
||||
remoteJudgeDispatcher.sendTask(judge, token, remoteJudgeProblem, isContest,
|
||||
tryAgainNum + 1, false);
|
||||
}
|
||||
} else {
|
||||
if (tryAgainNum >= 30) {
|
||||
|
@ -113,7 +158,8 @@ public class RemoteJudgeReceiver {
|
|||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
remoteJudgeDispatcher.sendTask(judge, token, remoteJudge, isContest, tryAgainNum + 1);
|
||||
remoteJudgeDispatcher.sendTask(judge, token, remoteJudgeProblem, isContest,
|
||||
tryAgainNum + 1, isHasSubmitIdRemoteReJudge);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public class JudgeReceiver {
|
|||
dispatcher.dispatcher("judge", "/judge", new ToJudge()
|
||||
.setJudge(judge)
|
||||
.setToken(token)
|
||||
.setRemoteJudge(null)
|
||||
.setRemoteJudgeProblem(null)
|
||||
.setTryAgainNum(tryAgainNum));
|
||||
// 接着处理任务
|
||||
processWaitingTask();
|
||||
|
|
|
@ -16,10 +16,12 @@ import top.hcode.hoj.common.exception.CompileError;
|
|||
import top.hcode.hoj.common.exception.SystemError;
|
||||
import top.hcode.hoj.judge.SandboxRun;
|
||||
import top.hcode.hoj.pojo.entity.*;
|
||||
import top.hcode.hoj.remoteJudge.RemoteJudgeGetResult;
|
||||
import top.hcode.hoj.remoteJudge.RemoteJudgeToSubmit;
|
||||
import top.hcode.hoj.service.impl.*;
|
||||
import top.hcode.hoj.util.Constants;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
@ -43,6 +45,9 @@ public class JudgeController {
|
|||
@Autowired
|
||||
private RemoteJudgeToSubmit remoteJudgeToSubmit;
|
||||
|
||||
@Resource
|
||||
private RemoteJudgeGetResult remoteJudgeGetResult;
|
||||
|
||||
|
||||
@Value("${hoj.judge.token}")
|
||||
private String judgeToken;
|
||||
|
@ -68,7 +73,7 @@ public class JudgeController {
|
|||
|
||||
HashMap<String, Object> res = new HashMap<>();
|
||||
|
||||
res.put("version", "1.3.0");
|
||||
res.put("version", "1.5.0");
|
||||
res.put("currentTime", new Date());
|
||||
res.put("judgeServerName", name);
|
||||
res.put("cpu", Runtime.getRuntime().availableProcessors());
|
||||
|
@ -184,14 +189,29 @@ public class JudgeController {
|
|||
Long pid = toJudge.getJudge().getPid();
|
||||
String username = toJudge.getUsername();
|
||||
String password = toJudge.getPassword();
|
||||
String[] source = toJudge.getRemoteJudge().split("-");
|
||||
Boolean isHasSubmitIdRemoteReJudge = toJudge.getIsHasSubmitIdRemoteReJudge();
|
||||
String[] source = toJudge.getRemoteJudgeProblem().split("-");
|
||||
String remotePid = source[1];
|
||||
String remoteJudge = source[0];
|
||||
String userCode = toJudge.getJudge().getCode();
|
||||
String language = toJudge.getJudge().getLanguage();
|
||||
|
||||
// 调用远程判题
|
||||
remoteJudgeToSubmit.sendTask(username, password, remoteJudge, remotePid, submitId, uid, cid, pid, language, userCode);
|
||||
// 拥有远程oj的submitId远程判题的重判
|
||||
if (isHasSubmitIdRemoteReJudge != null && isHasSubmitIdRemoteReJudge) {
|
||||
Long vjudgeSubmitId = toJudge.getJudge().getVjudgeSubmitId();
|
||||
remoteJudgeGetResult.sendTask(remoteJudge,
|
||||
username,
|
||||
password,
|
||||
submitId,
|
||||
uid,
|
||||
cid,
|
||||
pid,
|
||||
vjudgeSubmitId,
|
||||
null);
|
||||
} else {
|
||||
// 调用远程判题
|
||||
remoteJudgeToSubmit.sendTask(username, password, remoteJudge, remotePid, submitId, uid, cid, pid, language, userCode);
|
||||
}
|
||||
return CommonResult.successResponse(null, "提交成功");
|
||||
}
|
||||
}
|
|
@ -9,9 +9,11 @@ import org.springframework.stereotype.Component;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.hcode.hoj.pojo.entity.Judge;
|
||||
|
||||
import top.hcode.hoj.pojo.entity.RemoteJudgeAccount;
|
||||
import top.hcode.hoj.remoteJudge.task.RemoteJudgeFactory;
|
||||
import top.hcode.hoj.remoteJudge.task.RemoteJudgeStrategy;
|
||||
import top.hcode.hoj.service.impl.JudgeServiceImpl;
|
||||
import top.hcode.hoj.service.impl.RemoteJudgeAccountServiceImpl;
|
||||
import top.hcode.hoj.util.Constants;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -30,8 +32,11 @@ public class RemoteJudgeGetResult {
|
|||
@Autowired
|
||||
private JudgeServiceImpl judgeService;
|
||||
|
||||
@Autowired
|
||||
private RemoteJudgeAccountServiceImpl remoteJudgeAccountService;
|
||||
|
||||
@Transactional
|
||||
public void sendTask(String remoteJudge, String username, Long submitId, String uid,
|
||||
public void sendTask(String remoteJudge, String username, String password, Long submitId, String uid,
|
||||
Long cid, Long pid, Long resultSubmitId, String cookies) {
|
||||
|
||||
RemoteJudgeStrategy remoteJudgeStrategy = RemoteJudgeFactory.selectJudge(remoteJudge);
|
||||
|
@ -43,13 +48,31 @@ public class RemoteJudgeGetResult {
|
|||
@Override
|
||||
@Transactional
|
||||
public void run() {
|
||||
|
||||
if (count.get() > 60) { // 超过60次失败则判为提交失败
|
||||
// 更新此次提交状态为提交失败!
|
||||
UpdateWrapper<Judge> judgeUpdateWrapper = new UpdateWrapper<>();
|
||||
judgeUpdateWrapper.set("status", Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus())
|
||||
.eq("submit_id", submitId);
|
||||
judgeService.update(judgeUpdateWrapper);
|
||||
|
||||
changePOJAccountStatus(remoteJudge, username, password);
|
||||
|
||||
scheduler.shutdown();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
count.getAndIncrement();
|
||||
try {
|
||||
Map<String, Object> result = remoteJudgeStrategy.result(resultSubmitId, username, cookies);
|
||||
Map<String, Object> result = remoteJudgeStrategy.result(resultSubmitId, username, password, cookies);
|
||||
Integer status = (Integer) result.getOrDefault("status", Constants.Judge.STATUS_SYSTEM_ERROR.getStatus());
|
||||
if (status.intValue() != Constants.Judge.STATUS_PENDING.getStatus() &&
|
||||
status.intValue() != Constants.Judge.STATUS_JUDGING.getStatus()) {
|
||||
|
||||
// 由于POJ特殊 之前获取提交ID未释放账号,所以在此需要将账号变为可用
|
||||
changePOJAccountStatus(remoteJudge, username, password);
|
||||
|
||||
Integer time = (Integer) result.getOrDefault("time", null);
|
||||
Integer memory = (Integer) result.getOrDefault("memory", null);
|
||||
String CEInfo = (String) result.getOrDefault("CEInfo", null);
|
||||
|
@ -81,7 +104,6 @@ public class RemoteJudgeGetResult {
|
|||
judgeService.updateOtherTable(submitId, status, cid, uid, pid, score, judge.getTime());
|
||||
|
||||
} else {
|
||||
|
||||
judgeService.updateById(judge);
|
||||
// 同步其它表
|
||||
judgeService.updateOtherTable(submitId, status, cid, uid, pid, null, null);
|
||||
|
@ -92,15 +114,6 @@ public class RemoteJudgeGetResult {
|
|||
|
||||
} catch (Exception ignored) {
|
||||
|
||||
} finally {
|
||||
if (count.get() == 60) { // 60次失败则判为提交失败
|
||||
// 更新此次提交状态为提交失败!
|
||||
UpdateWrapper<Judge> judgeUpdateWrapper = new UpdateWrapper<>();
|
||||
judgeUpdateWrapper.set("status", Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus())
|
||||
.eq("submit_id", submitId);
|
||||
judgeService.update(judgeUpdateWrapper);
|
||||
scheduler.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -110,4 +123,19 @@ public class RemoteJudgeGetResult {
|
|||
|
||||
}
|
||||
|
||||
public void changePOJAccountStatus(String remoteJudge, String username, String password) {
|
||||
// 由于POJ特殊 之前获取提交ID未释放账号,所以在此需要将账号变为可用
|
||||
if (remoteJudge.equals(Constants.RemoteJudge.POJ_JUDGE.getName())) {
|
||||
UpdateWrapper<RemoteJudgeAccount> remoteJudgeAccountUpdateWrapper = new UpdateWrapper<>();
|
||||
remoteJudgeAccountUpdateWrapper.set("status", true)
|
||||
.eq("oj", remoteJudge)
|
||||
.eq("username", username)
|
||||
.eq("password", password);
|
||||
boolean isOk = remoteJudgeAccountService.update(remoteJudgeAccountUpdateWrapper);
|
||||
if (!isOk) {
|
||||
log.error("远程判题:修正账号为可用状态失败----------->{}", "username:" + username + ",password:" + password);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,10 +54,12 @@ public class RemoteJudgeToSubmit {
|
|||
try {
|
||||
submitResult = remoteJudgeStrategy.submit(username, password, remotePid, language, userCode);
|
||||
} catch (Exception e) {
|
||||
log.error(remoteJudge + "的远程提交发生异常---------->{}", e.getMessage());
|
||||
} finally {
|
||||
// 将使用的账号放回对应列表
|
||||
log.error(remoteJudge + "的远程提交发生异常---------->{}", e);
|
||||
}
|
||||
|
||||
// 提交失败 前端手动按按钮再次提交 修改状态 STATUS_SUBMITTED_FAILED
|
||||
if (submitResult == null || (Long) submitResult.getOrDefault("runId", -1L) == -1L) {
|
||||
// 将使用的账号放回对应列表
|
||||
UpdateWrapper<RemoteJudgeAccount> remoteJudgeAccountUpdateWrapper = new UpdateWrapper<>();
|
||||
remoteJudgeAccountUpdateWrapper.set("status", true)
|
||||
.eq("oj", remoteJudge)
|
||||
|
@ -68,10 +70,6 @@ public class RemoteJudgeToSubmit {
|
|||
log.error("远程判题:修正账号为可用状态失败----------->{}", "username:" + username + ",password:" + password);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TODO 提交失败 前端手动按按钮再次提交 修改状态 STATUS_SUBMITTED_FAILED
|
||||
if (submitResult == null || (Long) submitResult.getOrDefault("runId", -1L) == -1L) {
|
||||
// 更新此次提交状态为提交失败!
|
||||
UpdateWrapper<Judge> judgeUpdateWrapper = new UpdateWrapper<>();
|
||||
judgeUpdateWrapper.set("status", Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus())
|
||||
|
@ -87,18 +85,36 @@ public class RemoteJudgeToSubmit {
|
|||
null);
|
||||
log.error("网络错误---------------->获取不到提交ID");
|
||||
return;
|
||||
}else {
|
||||
// 由于POJ特殊 需要一直保持提交和获取结果时账号唯一,所以需要特别过滤
|
||||
if (!remoteJudge.equals(Constants.RemoteJudge.POJ_JUDGE.getName())) {
|
||||
UpdateWrapper<RemoteJudgeAccount> remoteJudgeAccountUpdateWrapper = new UpdateWrapper<>();
|
||||
remoteJudgeAccountUpdateWrapper.set("status", true)
|
||||
.eq("oj", remoteJudge)
|
||||
.eq("username", username)
|
||||
.eq("password", password);
|
||||
boolean isOk = remoteJudgeAccountService.update(remoteJudgeAccountUpdateWrapper);
|
||||
if (!isOk) {
|
||||
log.error("远程判题:修正账号为可用状态失败----------->{}", "username:" + username + ",password:" + password);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 提交成功顺便更新状态为-->STATUS_JUDGING 判题中...
|
||||
Long vjudgeSubmitId = (Long) submitResult.get("runId");
|
||||
|
||||
// 提交成功顺便更新状态为-->STATUS_PENDING 等待判题中...
|
||||
judgeService.updateById(new Judge()
|
||||
.setSubmitId(submitId)
|
||||
.setStatus(Constants.Judge.STATUS_JUDGING.getStatus())
|
||||
.setStatus(Constants.Judge.STATUS_PENDING.getStatus())
|
||||
.setVjudgeSubmitId(vjudgeSubmitId)
|
||||
.setVjudgeUsername(username)
|
||||
.setVjudgePassword(password)
|
||||
.setJudger(name)
|
||||
);
|
||||
|
||||
// 调用获取远程判题结果
|
||||
remoteJudgeGetResult.sendTask(remoteJudge, username, submitId, uid, cid, pid,
|
||||
(Long) submitResult.get("runId"), (String) submitResult.get("cookies"));
|
||||
remoteJudgeGetResult.sendTask(remoteJudge, username, password, submitId, uid, cid, pid,
|
||||
vjudgeSubmitId, (String) submitResult.get("cookies"));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ public class CodeForcesJudge implements RemoteJudgeStrategy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> result(Long submitId, String username, String cookies) {
|
||||
public Map<String, Object> result(Long submitId, String username, String password, String cookies) {
|
||||
|
||||
String url = HOST + String.format(SUBMISSION_RESULT_URL, username);
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ public class HduJudge implements RemoteJudgeStrategy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> result(Long submitId, String username, String cookies) throws Exception {
|
||||
public Map<String, Object> result(Long submitId, String username, String password, String cookies) throws Exception {
|
||||
String url = HOST + String.format(QUERY_URL, submitId);
|
||||
HttpRequest request = HttpUtil.createGet(url)
|
||||
.cookie(cookies)
|
||||
|
@ -168,7 +168,7 @@ public class HduJudge implements RemoteJudgeStrategy {
|
|||
put("Wrong Answer", Constants.Judge.STATUS_WRONG_ANSWER);
|
||||
put("Compilation Error", Constants.Judge.STATUS_COMPILE_ERROR);
|
||||
put("Queuing", Constants.Judge.STATUS_PENDING);
|
||||
put("Compiling", Constants.Judge.STATUS_PENDING);
|
||||
put("Compiling", Constants.Judge.STATUS_COMPILING);
|
||||
put("Time Limit Exceeded", Constants.Judge.STATUS_TIME_LIMIT_EXCEEDED);
|
||||
put("Presentation Error", Constants.Judge.STATUS_PRESENTATION_ERROR);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import cn.hutool.core.map.MapUtil;
|
|||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.http.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.hcode.hoj.remoteJudge.task.RemoteJudgeStrategy;
|
||||
import top.hcode.hoj.util.Constants;
|
||||
|
||||
|
@ -79,7 +80,11 @@ public class POJJudge implements RemoteJudgeStrategy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> result(Long submitId, String username, String cookies) {
|
||||
public Map<String, Object> result(Long submitId, String username, String password, String cookies) {
|
||||
if (StringUtils.isEmpty(cookies)) {
|
||||
Map<String, Object> loginUtils = getLoginUtils(username, password);
|
||||
cookies = (String) loginUtils.get("cookie");
|
||||
}
|
||||
String url = HOST + String.format(QUERY_URL, submitId);
|
||||
HttpRequest request = HttpUtil.createGet(url)
|
||||
.cookie(cookies)
|
||||
|
@ -170,6 +175,7 @@ public class POJJudge implements RemoteJudgeStrategy {
|
|||
{
|
||||
put("Compiling", Constants.Judge.STATUS_COMPILING);
|
||||
put("Accepted", Constants.Judge.STATUS_ACCEPTED);
|
||||
put("Running & Judging", Constants.Judge.STATUS_JUDGING);
|
||||
put("Presentation Error", Constants.Judge.STATUS_PRESENTATION_ERROR);
|
||||
put("Time Limit Exceeded", Constants.Judge.STATUS_TIME_LIMIT_EXCEEDED);
|
||||
put("Memory Limit Exceeded", Constants.Judge.STATUS_MEMORY_LIMIT_EXCEEDED);
|
||||
|
|
|
@ -22,7 +22,7 @@ public interface RemoteJudgeStrategy {
|
|||
* @param username 题库的提交者的账号
|
||||
* @return 返回结果
|
||||
*/
|
||||
Map<String, Object> result(Long submitId, String username, String cookies) throws Exception;
|
||||
Map<String, Object> result(Long submitId, String username, String password, String cookies) throws Exception;
|
||||
|
||||
Map<String, Object> getLoginUtils(String username, String password) throws Exception;
|
||||
|
||||
|
|
|
@ -114,9 +114,6 @@ public class JudgeServerApplicationTests {
|
|||
POJJudge pojJudge = new POJJudge();
|
||||
Map<String, Object> loginUtils = pojJudge.getLoginUtils("账号", "密码");
|
||||
|
||||
Map<String, Object> result = pojJudge.result(22716128L, "账号", (String) loginUtils.get("cookies"));
|
||||
System.out.println(result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -92,6 +92,15 @@ public class Judge implements Serializable {
|
|||
@ApiModelProperty(value = "该题在OI排行榜的分数")
|
||||
private Integer oiRankScore;
|
||||
|
||||
@ApiModelProperty(value = "vjudge判题在其它oj的提交id")
|
||||
private Long vjudgeSubmitId;
|
||||
|
||||
@ApiModelProperty(value = "vjudge判题在其它oj的提交用户名")
|
||||
private String vjudgeUsername;
|
||||
|
||||
@ApiModelProperty(value = "vjudge判题在其它oj的提交账号密码")
|
||||
private String vjudgePassword;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date gmtCreate;
|
||||
|
||||
|
|
|
@ -28,7 +28,10 @@ public class ToJudge implements Serializable {
|
|||
private String token;
|
||||
|
||||
@ApiModelProperty("远程判题不为空,hoj判题为null,例如HDU-1000")
|
||||
private String remoteJudge;
|
||||
private String remoteJudgeProblem;
|
||||
|
||||
@ApiModelProperty("是否为远程判题重判,仅限于已有远程OJ的提交id的重判")
|
||||
private Boolean isHasSubmitIdRemoteReJudge;
|
||||
|
||||
@ApiModelProperty("远程判题所用账号")
|
||||
private String username;
|
||||
|
|
Loading…
Reference in New Issue