From 28e84ff43bbdc6c8190d901a84ff28991a3b9327 Mon Sep 17 00:00:00 2001 From: Jason Klotzer Date: Fri, 10 Feb 2023 03:00:18 +0000 Subject: [PATCH] Adjusted fileName creation, fixes #159 --- .../cstore/backup/BackupUploadService.java | 10 +++++----- .../multipledest/MultipleDestinationUploadService.java | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/import/src/main/java/com/google/cloud/healthcare/imaging/dicomadapter/cstore/backup/BackupUploadService.java b/import/src/main/java/com/google/cloud/healthcare/imaging/dicomadapter/cstore/backup/BackupUploadService.java index 324757d..e755720 100644 --- a/import/src/main/java/com/google/cloud/healthcare/imaging/dicomadapter/cstore/backup/BackupUploadService.java +++ b/import/src/main/java/com/google/cloud/healthcare/imaging/dicomadapter/cstore/backup/BackupUploadService.java @@ -228,7 +228,7 @@ public void run() { } } else { MonitoringService.addEvent(Event.CSTORE_ERROR); - throwOnHttpFilterFail(dwe, dwe.getHttpStatus()); + throwOnHttpFilterFail(dwe, dwe.getHttpStatus(), uniqueFileName); } } } @@ -256,9 +256,9 @@ private boolean filterHttpCode(Integer actualHttpStatus) { return actualHttpStatus >= 500 || httpErrorCodesToRetry.contains(actualHttpStatus); } - private void throwOnHttpFilterFail(DicomWebException dwe, int httpCode) throws CompletionException { - String errorMessage = "Not retried due to HTTP code=" + httpCode; - log.debug(errorMessage); + private void throwOnHttpFilterFail(DicomWebException dwe, int httpCode, String uniqueFileName) throws CompletionException { + String errorMessage = "filename=" + uniqueFileName + ". Not retried due to HTTP code=" + httpCode; + log.error(errorMessage); throw new CompletionException(new BackupException(dwe.getStatus(), dwe, errorMessage)); } @@ -268,7 +268,7 @@ private void throwOnNoResendAttemptsLeft(DicomWebException dwe, String uniqueFil private BackupException getNoResendAttemptLeftException(DicomWebException dwe, String uniqueFileName) { String errorMessage = "fileName=" + uniqueFileName + ". No upload attempt left."; - log.debug(errorMessage); + log.error(errorMessage); if (dwe != null) { return new BackupException(dwe.getStatus(), dwe, errorMessage); } else { diff --git a/import/src/main/java/com/google/cloud/healthcare/imaging/dicomadapter/cstore/multipledest/MultipleDestinationUploadService.java b/import/src/main/java/com/google/cloud/healthcare/imaging/dicomadapter/cstore/multipledest/MultipleDestinationUploadService.java index d92154b..3747652 100644 --- a/import/src/main/java/com/google/cloud/healthcare/imaging/dicomadapter/cstore/multipledest/MultipleDestinationUploadService.java +++ b/import/src/main/java/com/google/cloud/healthcare/imaging/dicomadapter/cstore/multipledest/MultipleDestinationUploadService.java @@ -14,7 +14,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.UUID; +import java.util.Random; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; @@ -23,6 +23,7 @@ public class MultipleDestinationUploadService implements IMultipleDestinationUploadService { + private static Random rand = new Random(); private Logger log = LoggerFactory.getLogger(MultipleDestinationUploadService.class); private CStoreSenderFactory cStoreSenderFactory; @@ -57,7 +58,7 @@ public void start( } List asyncUploadProcessingExceptions = new ArrayList<>(); - String uniqueFileName = UUID.randomUUID().toString() + ".dcm"; + String uniqueFileName = String.format("%s_%s.dcm", sopInstanceUID, rand.nextInt(1000)); try { backupUploadService.createBackup(inputStream, uniqueFileName);