From d5988d42dc98c3aee6c7d60dbf1cbfa01d0f2c97 Mon Sep 17 00:00:00 2001 From: joschrew Date: Fri, 27 Oct 2023 15:27:30 +0200 Subject: [PATCH] Fix error handling with failing pid service Previously when updating a pid failed after uploading an archive, the error was basically ignored and not logged. --- .../controller/ImportController.java | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/main/java/ola/hd/longtermstorage/controller/ImportController.java b/src/main/java/ola/hd/longtermstorage/controller/ImportController.java index ecf0a37..8adf5a5 100644 --- a/src/main/java/ola/hd/longtermstorage/controller/ImportController.java +++ b/src/main/java/ola/hd/longtermstorage/controller/ImportController.java @@ -317,6 +317,7 @@ public void run() { IndexingConfig conf = readSearchindexFilegrps(destination, bagInfos, requestParams); sendToElastic(pid, conf); } catch (Exception ex) { + logger.error("Archive Import failed", ex); handleFailedImport(ex, pid, importResult, info); } finally { // Clean up the temp: Files are saved in CDStar and not needed any more @@ -324,26 +325,42 @@ public void run() { } } - private void handleFailedImport(Exception ex, String pid, ImportResult importResult, - TrackingInfo info) { + private void handleFailedImport( + Exception ex, String pid, ImportResult importResult,TrackingInfo info + ) { + // Delete the PID try { - // Delete the PID pidService.deletePid(pid); + } catch (Exception e) { + logger.error( + "error cleaning up. pid: '{}', online-id: '{}', offline-id: '{}' - {}", pid, + importResult.getOnlineId(), importResult.getOfflineId(), e, + "Deleting PID failed" + ); + } - // Delete the archive - if (importResult != null) { + // Delete the archives + if (importResult != null) { + try { archiveManagerService.deleteArchive(importResult.getOnlineId(), null); + } catch(Exception e) { + logger.error( + "error cleaning up. pid: '{}', online-id: '{}', offline-id: '{}' - {}", + pid, importResult.getOnlineId(), importResult.getOfflineId(), e, + "Deleting online archive failed" + ); + } + try { archiveManagerService.deleteArchive(importResult.getOfflineId(), null); + } catch (Exception e) { + logger.error( + "error cleaning up. pid: '{}', online-id: '{}', offline-id: '{}' - {}", + pid, importResult.getOnlineId(), importResult.getOfflineId(), e, + "Deleting offline archive failed" + ); } - - } catch (IOException e) { - // if cleaning fails, nothing can be done than manually clean up - logger.error("error cleaning up. pid: '{}', online-id: '{}', offline-id: '{}'", pid, - importResult.getOnlineId(), importResult.getOfflineId(), e); } - logger.error(ex.getMessage(), ex); - // Save the failure data to the tracking database info.setStatus(TrackingStatus.FAILED); info.setMessage(ex.getMessage());