Skip to content

Commit

Permalink
(feat) add log (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengjiachun authored Sep 3, 2019
1 parent 49a7e9a commit 6cb5feb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,25 @@ public NodeRequestProcessor(Executor executor) {
super(executor);
}

protected abstract Message processRequest0(RaftServerService serviceService, T request, RpcRequestClosure done);
protected abstract Message processRequest0(final RaftServerService serviceService, final T request,
final RpcRequestClosure done);

protected abstract String getPeerId(T request);
protected abstract String getPeerId(final T request);

protected abstract String getGroupId(T request);
protected abstract String getGroupId(final T request);

@Override
public Message processRequest(T request, RpcRequestClosure done) {
PeerId peer = new PeerId();
String peerIdStr = getPeerId(request);
final PeerId peer = new PeerId();
final String peerIdStr = getPeerId(request);
if (peer.parse(peerIdStr)) {
Node node = NodeManager.getInstance().get(getGroupId(request), peer);
final String groupId = getGroupId(request);
final Node node = NodeManager.getInstance().get(groupId, peer);
if (node != null) {
return processRequest0((RaftServerService) node, request, done);
} else {
return RpcResponseFactory.newResponse(RaftError.ENOENT, "Peer id not found: %s", peerIdStr);
return RpcResponseFactory.newResponse(RaftError.ENOENT, "Peer id not found: %s, group: %s", peerIdStr,
groupId);
}
} else {
return RpcResponseFactory.newResponse(RaftError.EINVAL, "Fail to parse peerId: %s", peerIdStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ public void testPeerIdNotFound() {
ErrorResponse resp = (ErrorResponse) asyncContext.getResponseObject();
assertNotNull(resp);
assertEquals(RaftError.ENOENT.getNumber(), resp.getErrorCode());
assertEquals("Peer id not found: localhost:8081", resp.getErrorMsg());
assertEquals("Peer id not found: localhost:8081, group: test", resp.getErrorMsg());
}
}

0 comments on commit 6cb5feb

Please sign in to comment.