Skip to content

Commit

Permalink
Wrap ProcGetJobResponse in try/catch (#1384)
Browse files Browse the repository at this point in the history
Fix two issues on the ManageProc logic.

1- When a proc no longer exists and the jdbc query throws an unhandled EmptyResultDataAccess exception instead of returning a proper status to the requester.

2- Use the correct Id when redirecting a proc to a group.

Co-authored-by: Roula O'Regan <[email protected]>
  • Loading branch information
DiegoTavares and roulaoregan-spi authored Jun 20, 2024
1 parent 0523b2b commit be9c15e
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions cuebot/src/main/java/com/imageworks/spcue/servant/ManageProc.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.List;

import io.grpc.Status;
import io.grpc.stub.StreamObserver;
import org.springframework.dao.EmptyResultDataAccessException;

Expand Down Expand Up @@ -175,12 +176,20 @@ public void getHost(ProcGetHostRequest request, StreamObserver<ProcGetHostRespon

@Override
public void getJob(ProcGetJobRequest request, StreamObserver<ProcGetJobResponse> responseObserver) {
VirtualProc proc = getVirtualProc(request.getProc());
ProcGetJobResponse response = ProcGetJobResponse.newBuilder()
.setJob(whiteboard.getJob(procDao.getCurrentJobId(proc)))
.build();
responseObserver.onNext(response);
responseObserver.onCompleted();
try {
VirtualProc proc = getVirtualProc(request.getProc());
ProcGetJobResponse response = ProcGetJobResponse.newBuilder()
.setJob(whiteboard.getJob(procDao.getCurrentJobId(proc)))
.build();
responseObserver.onNext(response);
responseObserver.onCompleted();

} catch (EmptyResultDataAccessException e) {
responseObserver.onError(Status.NOT_FOUND
.withDescription(e.getMessage())
.withCause(e)
.asRuntimeException());
}
}

@Override
Expand Down Expand Up @@ -220,7 +229,7 @@ public void unbook(ProcUnbookRequest request, StreamObserver<ProcUnbookResponse>
public void redirectToGroup(ProcRedirectToGroupRequest request,
StreamObserver<ProcRedirectToGroupResponse> responseObserver) {
VirtualProc proc = getVirtualProc(request.getProc());
VirtualProc p = procDao.getVirtualProc(proc.getId());
VirtualProc p = procDao.getVirtualProc(proc.getProcId());
GroupInterface g = groupManager.getGroup(request.getGroupId());
String message = "redirectToGroup called on " + proc.getProcId() + " with Group " + g.getGroupId();
boolean value = redirectManager.addRedirect(p, g, request.getKill(), new Source(message));
Expand Down

0 comments on commit be9c15e

Please sign in to comment.