Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public class PeerController {

@PostMapping(value = "/registry")
public ResultInfo doRegistry( RegistryRequest req) {
ResultInfo res = null;
try {
return peerRegistryService.registryTask(req.getRawUrl(),
res = peerRegistryService.registryTask(req.getRawUrl(),
req.getTaskUrl(),
req.getMd5(),
req.getIdentifier(),
Expand All @@ -81,73 +82,80 @@ public ResultInfo doRegistry( RegistryRequest req) {
req.isDfdaemon());
} catch (ValidateException e) {
log.error("param is illegal", e);
return new ResultInfo(e.getCode(), e.getMessage(), null);
res = new ResultInfo(e.getCode(), e.getMessage(), null);
} catch (Exception e) {
log.error("E_registry", e);
return new ResultInfo(ResultCode.SYSTEM_ERROR, e.getMessage(), null);
res = new ResultInfo(ResultCode.SYSTEM_ERROR, e.getMessage(), null);
}
debug("doRegistry", req, res);
return res;
}

@GetMapping(value = "/task")
public ResultInfo pullPieceTask(PullPieceTaskRequest req) {
ResultInfo res = null;
long start = System.currentTimeMillis();
try {
ResultInfo processResult = commonPeerDispatcher.process(
res = commonPeerDispatcher.process(
req.getSrcCid(),
req.getDstCid(),
req.getTaskId(),
req.getRange(),
req.getResult(),
req.getStatus());
if (processResult == null) {
processResult = new ResultInfo(ResultCode.SYSTEM_ERROR, JSON.toJSONString(req), null);
if (res == null) {
res = new ResultInfo(ResultCode.SYSTEM_ERROR, JSON.toJSONString(req), null);
}
long end = System.currentTimeMillis();
if (end - start > 1000) {
log.warn("do peer task cost:{}ms", end - start);
}
return processResult;
} catch (ValidateException e) {
return new ResultInfo(e.getCode(), e.getMessage(), null);
res = new ResultInfo(e.getCode(), e.getMessage(), null);
} catch (Exception e) {
log.error("E_PeerTaskServlet", e);
return new ResultInfo(ResultCode.SYSTEM_ERROR, e.getMessage(), null);
res = new ResultInfo(ResultCode.SYSTEM_ERROR, e.getMessage(), null);
}
debug("pullPieceTask", req, res);
return res;
}

@GetMapping(value = "/piece/suc")
public ResultInfo reportPiece(ReportPieceRequest req) {
ResultInfo res = null;
try {
String taskId = req.getTaskId();
String cid = req.getCid();
String dstCid = req.getDstCid();
String range = req.getRange();
String range = req.getPieceRange();

if (StringUtils.isBlank(taskId) || StringUtils.isBlank(cid)
|| StringUtils.isBlank(range)) {
return new ResultInfo(ResultCode.PARAM_ERROR,
res = new ResultInfo(ResultCode.PARAM_ERROR,
"some param is empty", null);
}
int pieceNum = RangeParseUtil.calculatePieceNum(range);
ResultInfo resultInfo = null;
if (pieceNum >= 0) {
resultInfo = progressService.updateProgress(taskId, cid,
dstCid, pieceNum, PeerPieceStatus.SUCCESS);
} else {
log.error("do piece suc fail for cid:{} pieceNum:{}", cid,
pieceNum);
}
if (resultInfo == null) {
resultInfo = new ResultInfo(ResultCode.SYSTEM_ERROR);
int pieceNum = RangeParseUtil.calculatePieceNum(range);
if (pieceNum >= 0) {
res = progressService.updateProgress(taskId, cid,
dstCid, pieceNum, PeerPieceStatus.SUCCESS);
} else {
log.error("do piece suc fail for cid:{} pieceNum:{}", cid,
pieceNum);
}
if (res == null) {
res = new ResultInfo(ResultCode.SYSTEM_ERROR);
}
}
return resultInfo;
} catch (Exception e) {
return new ResultInfo(ResultCode.SYSTEM_ERROR, e.getMessage(), null);
res = new ResultInfo(ResultCode.SYSTEM_ERROR, e.getMessage(), null);
}
debug("reportPiece", req, res);
return res;
}

@GetMapping(value = "/service/down")
public ResultInfo reportServiceDown(ReportServiceDownRequest req) {
ResultInfo res = null;
try {
String cid = req.getCid();
String taskId = req.getTaskId();
Expand All @@ -158,9 +166,17 @@ public ResultInfo reportServiceDown(ReportServiceDownRequest req) {
lockService.unlockTaskOnRead(taskId);
}

return new ResultInfo(ResultCode.SUCCESS);
res = new ResultInfo(ResultCode.SUCCESS);
} catch (Exception e) {
return new ResultInfo(ResultCode.SYSTEM_ERROR, e.getMessage(), null);
res = new ResultInfo(ResultCode.SYSTEM_ERROR, e.getMessage(), null);
}
debug("reportServiceDown", req, res);
return res;
}

private void debug(String msg, Object req, ResultInfo res) {
if (log.isDebugEnabled()) {
log.debug("{}, req: {} res: {}", msg, JSON.toJSONString(req), JSON.toJSON(res));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public class ReportPieceRequest {
private String taskId;
private String cid;
private String dstCid;
private String range;
private String pieceRange;
}