diff --git a/stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/FileTransferClientImpl.java b/stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/FileTransferClientImpl.java index 4780e76092..feb14223d1 100644 --- a/stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/FileTransferClientImpl.java +++ b/stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/FileTransferClientImpl.java @@ -91,6 +91,7 @@ public void storePart(final FileDescriptor fileDescriptor, } } } catch (final Exception e) { + LOGGER.error(e::getMessage, e); throw new RuntimeException(e.getMessage(), e); } } @@ -109,6 +110,7 @@ public void storePart(final FileDescriptor fileDescriptor, } } } catch (final IOException e) { + LOGGER.error(e::getMessage, e); throw new UncheckedIOException(e); } }); diff --git a/stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/FileTransferResourceImpl.java b/stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/FileTransferResourceImpl.java index 464d4fd3b8..f250a91d31 100644 --- a/stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/FileTransferResourceImpl.java +++ b/stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/FileTransferResourceImpl.java @@ -20,6 +20,7 @@ import stroom.event.logging.rs.api.AutoLogged.OperationType; import stroom.util.logging.LambdaLogger; import stroom.util.logging.LambdaLoggerFactory; +import stroom.util.logging.LogUtil; import stroom.util.shared.PermissionException; import jakarta.inject.Inject; @@ -31,6 +32,7 @@ import jakarta.ws.rs.core.StreamingOutput; import java.io.InputStream; +import java.util.function.Supplier; @AutoLogged(OperationType.UNLOGGED) public class FileTransferResourceImpl implements FileTransferResource { @@ -47,6 +49,7 @@ public FileTransferResourceImpl(final Provider fileTransfer @AutoLogged(OperationType.UNLOGGED) @Override public Response fetchSnapshot(final SnapshotRequest request) { + LOGGER.debug(() -> "Snapshot request: " + request); try { // Check the status before we start streaming snapshot data as it is hard to capture meaningful errors mid // stream. @@ -54,20 +57,26 @@ public Response fetchSnapshot(final SnapshotRequest request) { // Stream the snapshhot content to the client as ZIP data final StreamingOutput streamingOutput = output -> { - fileTransferServiceProvider.get().fetchSnapshot(request, output); + try { + fileTransferServiceProvider.get().fetchSnapshot(request, output); + } catch (final Exception e) { + LOGGER.error(e::getMessage, e); + throw e; + } }; + LOGGER.debug(() -> "Sending snapshot: " + request); return Response .ok(streamingOutput, MediaType.APPLICATION_OCTET_STREAM) .build(); } catch (final NotModifiedException e) { - LOGGER.debug(e::getMessage, e); + LOGGER.debug(() -> "Snapshot not modified: " + request + " " + e.getMessage(), e); throw new WebApplicationException(e.getMessage(), Status.NOT_MODIFIED); } catch (final PermissionException e) { - LOGGER.debug(e::getMessage, e); + LOGGER.error(() -> "Snapshot permission exception : " + request + " " + e.getMessage(), e); throw new WebApplicationException(e.getMessage(), Status.UNAUTHORIZED); } catch (final Exception e) { - LOGGER.debug(e::getMessage, e); + LOGGER.debug(() -> "Snapshot not found: " + request + " " + e.getMessage(), e); throw new WebApplicationException(e.getMessage(), Status.NOT_FOUND); } } @@ -79,18 +88,27 @@ public Response sendPart(final long createTime, final String fileHash, final String fileName, final InputStream inputStream) { + final Supplier messageDetail = () -> LogUtil.message( + "createTime={}, metaId={}, fileHash={}, fileName={}", + createTime, + metaId, + fileHash, + fileName); + try { + LOGGER.debug(() -> "Receiving part: " + messageDetail.get()); fileTransferServiceProvider.get().receivePart(createTime, metaId, fileHash, fileName, inputStream); + LOGGER.debug(() -> "Successfully received part: " + messageDetail.get()); return Response .ok() .build(); } catch (final PermissionException e) { - LOGGER.debug(e::getMessage, e); + LOGGER.error(LogUtil.message("Permission exception receiving part: " + messageDetail.get()), e); return Response .status(Status.UNAUTHORIZED.getStatusCode(), e.getMessage()) .build(); } catch (final Exception e) { - LOGGER.debug(e::getMessage, e); + LOGGER.error(LogUtil.message("Exception receiving part: " + messageDetail.get()), e); return Response .status(Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage()) .build(); diff --git a/stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/SnapshotRequest.java b/stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/SnapshotRequest.java index df4b6c9229..a8760a4d75 100644 --- a/stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/SnapshotRequest.java +++ b/stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/SnapshotRequest.java @@ -8,6 +8,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.Objects; + @JsonPropertyOrder(alphabetic = true) @JsonInclude(Include.NON_NULL) public class SnapshotRequest { @@ -22,7 +24,7 @@ public class SnapshotRequest { @JsonCreator public SnapshotRequest(@JsonProperty("planBDocRef") final DocRef planBDocRef, @JsonProperty("effectiveTime") final long effectiveTime, - @JsonProperty("currentSnapshotTime")final Long currentSnapshotTime) { + @JsonProperty("currentSnapshotTime") final Long currentSnapshotTime) { this.planBDocRef = planBDocRef; this.effectiveTime = effectiveTime; this.currentSnapshotTime = currentSnapshotTime; @@ -39,4 +41,32 @@ public long getEffectiveTime() { public Long getCurrentSnapshotTime() { return currentSnapshotTime; } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final SnapshotRequest request = (SnapshotRequest) o; + return effectiveTime == request.effectiveTime && + Objects.equals(planBDocRef, request.planBDocRef) && + Objects.equals(currentSnapshotTime, request.currentSnapshotTime); + } + + @Override + public int hashCode() { + return Objects.hash(planBDocRef, effectiveTime, currentSnapshotTime); + } + + @Override + public String toString() { + return "SnapshotRequest{" + + "planBDocRef=" + planBDocRef + + ", effectiveTime=" + effectiveTime + + ", currentSnapshotTime=" + currentSnapshotTime + + '}'; + } }