测试提交远程题库并修改bug
This commit is contained in:
parent
791970a177
commit
7c79bf01a5
|
@ -110,65 +110,39 @@ public class JudgeController {
|
|||
}
|
||||
|
||||
@PostMapping(value = "/remote-judge")
|
||||
public CommonResult remoteJudge() {
|
||||
public CommonResult remoteJudge(@RequestBody ToJudge toJudge) {
|
||||
|
||||
// if (!toJudge.getToken().equals(judgeToken)) {
|
||||
// return CommonResult.errorResponse("对不起!您使用的判题服务调用凭证不正确!访问受限!", CommonResult.STATUS_ACCESS_DENIED);
|
||||
// }
|
||||
if (!toJudge.getToken().equals(judgeToken)) {
|
||||
return CommonResult.errorResponse("对不起!您使用的判题服务调用凭证不正确!访问受限!", CommonResult.STATUS_ACCESS_DENIED);
|
||||
}
|
||||
|
||||
// Long submitId = toJudge.getJudge().getSubmitId();
|
||||
// String uid = toJudge.getJudge().getUid();
|
||||
// Long cid = toJudge.getJudge().getCid();
|
||||
// Long pid = toJudge.getJudge().getPid();
|
||||
Long submitId = 1L;
|
||||
String uid = "1";
|
||||
Long cid = 1L;
|
||||
Long pid = 1L;
|
||||
Long submitId = toJudge.getJudge().getSubmitId();
|
||||
String uid = toJudge.getJudge().getUid();
|
||||
Long cid = toJudge.getJudge().getCid();
|
||||
Long pid = toJudge.getJudge().getPid();
|
||||
// 发送消息
|
||||
try {
|
||||
// String[] source = toJudge.getRemoteJudge().split("-");
|
||||
// Long remotePid = Long.valueOf(source[1]);
|
||||
// String remoteJudge = source[0];
|
||||
// String userCode = toJudge.getJudge().getCode();
|
||||
// String language = toJudge.getJudge().getLanguage();
|
||||
Long remotePid = 1090L;
|
||||
String remoteJudge = "HDU";
|
||||
String userCode = "#include<iostream>\n" +
|
||||
"using namespace std;\n" +
|
||||
"\n" +
|
||||
"int main()\n" +
|
||||
"{\n" +
|
||||
"\tint t;\n" +
|
||||
"\tcin >> t;\n" +
|
||||
"\twhile (t--) {\n" +
|
||||
"\t\tint a, b;\n" +
|
||||
"\t\tcin >> a >> b;\n" +
|
||||
"\t\tcout << a + b;\n" +
|
||||
"\t\tif (t == 0){\n" +
|
||||
"\t\t\tcout << endl;\n" +
|
||||
"\t\t} else {\n" +
|
||||
"\t\t\tcout << endl;\n" +
|
||||
"\t\t}\n" +
|
||||
"\t}\n" +
|
||||
"\treturn 1;\n" +
|
||||
"}";
|
||||
String language = "G++";
|
||||
String[] source = toJudge.getRemoteJudge().split("-");
|
||||
Long remotePid = Long.valueOf(source[1]);
|
||||
String remoteJudge = source[0];
|
||||
String userCode = toJudge.getJudge().getCode();
|
||||
String language = toJudge.getJudge().getLanguage();
|
||||
remoteJudgeSubmitDispatcher.sendTask(remoteJudge, remotePid, submitId, uid, cid, pid, language, userCode);
|
||||
return CommonResult.successResponse(null, "提交成功");
|
||||
} catch (Exception e) {
|
||||
// TODO 如果为了测试是否可行,请把数据库更新注释掉,若正常运行,则需要保证数据一致性
|
||||
// Judge judge = new Judge();
|
||||
// judge.setSubmitId(submitId)
|
||||
// .setStatus(Constants.Judge.STATUS_SYSTEM_ERROR.getStatus())
|
||||
// .setErrorMessage("Oops, something has gone wrong with the judgeServer. Please report this to administrator.");
|
||||
// judgeService.updateById(judge);
|
||||
// // 更新其它表
|
||||
// judgeService.updateOtherTable(submitId,
|
||||
// Constants.Judge.STATUS_SYSTEM_ERROR.getStatus(),
|
||||
// cid,
|
||||
// uid,
|
||||
// pid,
|
||||
// null);
|
||||
Judge judge = new Judge();
|
||||
judge.setSubmitId(submitId)
|
||||
.setStatus(Constants.Judge.STATUS_SYSTEM_ERROR.getStatus())
|
||||
.setErrorMessage("Oops, something has gone wrong with the judgeServer. Please report this to administrator.");
|
||||
judgeService.updateById(judge);
|
||||
// 更新其它表
|
||||
judgeService.updateOtherTable(submitId,
|
||||
Constants.Judge.STATUS_SYSTEM_ERROR.getStatus(),
|
||||
cid,
|
||||
uid,
|
||||
pid,
|
||||
null);
|
||||
log.error("调用redis消息发布异常,此次远程判题任务判为系统错误--------------->{}", e.getMessage());
|
||||
return CommonResult.errorResponse(e.getMessage(), CommonResult.STATUS_ERROR);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ public class RemoteJudgeResultReceiver implements MessageListener {
|
|||
return;
|
||||
}
|
||||
JSONObject task = JSONUtil.parseObj(source);
|
||||
log.info(source);
|
||||
Long resultSubmitId = task.getLong("resultSubmitId");
|
||||
Long submitId = task.getLong("submitId");
|
||||
String uid = task.getStr("uid");
|
||||
|
@ -61,7 +60,6 @@ public class RemoteJudgeResultReceiver implements MessageListener {
|
|||
|
||||
// TODO 获取对应的result,修改到数据库
|
||||
try {
|
||||
log.info("resultSubmitId:" + resultSubmitId);
|
||||
Map<String, Object> result = remoteJudgeStrategy.result(resultSubmitId);
|
||||
Judge judge = new Judge();
|
||||
judge.setSubmitId(submitId);
|
||||
|
@ -79,31 +77,30 @@ public class RemoteJudgeResultReceiver implements MessageListener {
|
|||
Integer time = (Integer) result.getOrDefault("time", null);
|
||||
Integer memory = (Integer) result.getOrDefault("memory", null);
|
||||
String CEInfo = (String) result.getOrDefault("CEInfo", null);
|
||||
log.info(status.toString() + " " + time + " " + memory + " " + CEInfo);
|
||||
// judge.setStatus(status)
|
||||
// .setTime(time)
|
||||
// .setMemory(memory);
|
||||
//
|
||||
// // 获取当前判题系统所在ip写入数据库
|
||||
// if (ip.equals("-1")) {
|
||||
// judge.setJudger(IpUtils.getLocalIpv4Address());
|
||||
// } else {
|
||||
// judge.setJudger(ip);
|
||||
// }
|
||||
//
|
||||
// if (status.intValue() == Constants.Judge.STATUS_COMPILE_ERROR.getStatus()) {
|
||||
// judge.setErrorMessage(CEInfo);
|
||||
// } else if (status.intValue() == Constants.Judge.STATUS_SYSTEM_ERROR.getStatus()) {
|
||||
// judge.setErrorMessage("There is something wrong with the " + remoteJudge + ", please try again later");
|
||||
// }
|
||||
// 写回数据库
|
||||
// judgeService.updateById(judge);
|
||||
judge.setStatus(status)
|
||||
.setTime(time)
|
||||
.setMemory(memory);
|
||||
|
||||
// 获取当前判题系统所在ip写入数据库
|
||||
if (ip.equals("-1")) {
|
||||
judge.setJudger(IpUtils.getLocalIpv4Address());
|
||||
} else {
|
||||
judge.setJudger(ip);
|
||||
}
|
||||
|
||||
if (status.intValue() == Constants.Judge.STATUS_COMPILE_ERROR.getStatus()) {
|
||||
judge.setErrorMessage(CEInfo);
|
||||
} else if (status.intValue() == Constants.Judge.STATUS_SYSTEM_ERROR.getStatus()) {
|
||||
judge.setErrorMessage("There is something wrong with the " + remoteJudge + ", please try again later");
|
||||
}
|
||||
// 写回数据库
|
||||
judgeService.updateById(judge);
|
||||
|
||||
/**
|
||||
* @Description TODO 注意! 如果是OI题目肯定score得分,若不是则请传入null,该方法是为了更新关联表,保持数据一致!
|
||||
* @Since 2021/2/12
|
||||
**/
|
||||
// judgeService.updateOtherTable(submitId, status, cid, uid, pid, null);
|
||||
judgeService.updateOtherTable(submitId, status, cid, uid, pid, null);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("获取结果出错------------>{}", e.getMessage());
|
||||
|
|
|
@ -29,6 +29,5 @@ public class RemoteJudgeSubmitDispatcher {
|
|||
task.set("language", language);
|
||||
redisUtils.sendMessage(Constants.RemoteJudge.JUDGE_SUBMIT_HANDLER.getName(), "New Problem Added");
|
||||
redisUtils.lrPush(Constants.RemoteJudge.JUDGE_WAITING_SUBMIT_QUEUE.getName(), JSONUtil.toJsonStr(task));
|
||||
log.info("发送数据");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,12 +33,9 @@ public class RemoteJudgeSubmitReceiver implements MessageListener {
|
|||
@Override
|
||||
public void onMessage(Message message, byte[] bytes) {
|
||||
// log.debug("RemoteJudgeSubmitReceiver获取到消息{}", Arrays.toString(message.getBody()));
|
||||
log.info("开始竞争");
|
||||
String source = (String) redisUtils.lrPop(Constants.RemoteJudge.JUDGE_WAITING_SUBMIT_QUEUE.getName());
|
||||
// 如果竞争不到提交队列,结束
|
||||
log.info(source);
|
||||
if (source == null) {
|
||||
log.info("竞争不到");
|
||||
return;
|
||||
}
|
||||
JSONObject task = JSONUtil.parseObj(source);
|
||||
|
@ -65,19 +62,17 @@ public class RemoteJudgeSubmitReceiver implements MessageListener {
|
|||
// TODO 提交失败 前端手动按按钮再次提交 修改状态 STATUS_SUBMITTED_FAILED
|
||||
if (resultSubmitId < 0) {
|
||||
// 更新此次提交状态为提交失败!
|
||||
log.info("查询id失败");
|
||||
// UpdateWrapper<Judge> judgeUpdateWrapper = new UpdateWrapper<>();
|
||||
// judgeUpdateWrapper.set("status", Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus())
|
||||
// .eq("submit_id", submitId);
|
||||
// judgeService.update(judgeUpdateWrapper);
|
||||
UpdateWrapper<Judge> judgeUpdateWrapper = new UpdateWrapper<>();
|
||||
judgeUpdateWrapper.set("status", Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus())
|
||||
.eq("submit_id", submitId);
|
||||
judgeService.update(judgeUpdateWrapper);
|
||||
log.error("网络错误---------------->获取不到提交ID");
|
||||
return;
|
||||
}
|
||||
// 提交成功顺便更新状态为-->STATUS_JUDGING 判题中...
|
||||
// judgeService.updateById(new Judge().setSubmitId(submitId).setStatus(Constants.Judge.STATUS_JUDGING.getStatus()));
|
||||
judgeService.updateById(new Judge().setSubmitId(submitId).setStatus(Constants.Judge.STATUS_JUDGING.getStatus()));
|
||||
try {
|
||||
remoteJudgeResultDispatcher.sendTask(remoteJudge, submitId, uid, cid, pid, resultSubmitId);
|
||||
log.info("查询结果信息发送");
|
||||
} catch (Exception e) {
|
||||
log.error("调用redis消息发布异常,此次远程查询结果任务判为系统错误--------------->{}", e.getMessage());
|
||||
}
|
||||
|
|
|
@ -47,32 +47,27 @@ public class HduJudge implements RemoteJudgeStrategy {
|
|||
.put("problemid", String.valueOf(problemId))
|
||||
.put("usercode", userCode)
|
||||
.map());
|
||||
System.out.println("提交代码的状态码:-------" + response.statusCode());
|
||||
if (response.statusCode() != 200) {
|
||||
log.error("提交题目失败");
|
||||
return -1L;
|
||||
}
|
||||
// 获取提交的题目id
|
||||
Long maxRunId = getMaxRunId(connection, "2018030402055", problemId);
|
||||
System.out.println(maxRunId);
|
||||
return maxRunId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> result(Long submitId) throws Exception {
|
||||
String url = host + String.format(queryUrl, submitId);
|
||||
System.out.println(url);
|
||||
Connection connection = JsoupUtils.getConnectionFromUrl(url, null, null);
|
||||
Connection.Response response = JsoupUtils.getResponse(connection, null);
|
||||
// 1提交时间 2结果 3执行时间 4执行空间 5代码长度
|
||||
// 一般情况下 代码长度和提交时间不需要,想要也行,自行添加
|
||||
Pattern pattern = Pattern.compile(">" + submitId + "</td><td>([\\s\\S]*?)</td><td>([\\s\\S]*?)</td><td>[\\s\\S]*?</td><td>(\\d*?)MS</td><td>(\\d*?)K</td><td>(\\d*?)B</td>");
|
||||
Matcher matcher = pattern.matcher(response.body());
|
||||
// System.out.println(response.body());
|
||||
// 找到时
|
||||
Validate.isTrue(matcher.find());
|
||||
String rawStatus = matcher.group(2).replaceAll("<[\\s\\S]*?>", "").trim();
|
||||
System.out.println(rawStatus);
|
||||
Constants.Judge statusType = statusTypeMap.get(rawStatus);
|
||||
if (statusType == Constants.Judge.STATUS_PENDING) {
|
||||
return MapUtil.builder(new HashMap<String, Object>())
|
||||
|
|
Loading…
Reference in New Issue