@Test public void outputObjectGetsStoredLocallyWhenCanStoreFails() throws StorageException, IOException { long jobId = 869; JsonOutputObject outputObject = mock(JsonOutputObject.class); when(outputObject.getJobId()) .thenReturn(jobId); SortedSet<JsonMediaIssue> warnings = setupWarnings(outputObject); doThrow(StorageException.class) .when(_mockNginxBackend).canStore(outputObject); when(_mockLocalBackend.store(outputObject)) .thenReturn(TEST_LOCAL_URI); var status = new MutableObject<>(BatchJobStatusType.COMPLETE); URI result = _storageService.store(outputObject, status); assertEquals(TEST_LOCAL_URI, result); assertEquals(BatchJobStatusType.COMPLETE_WITH_WARNINGS, status.getValue()); verifyJobWarning(jobId); verifySingleWarningAddedToOutputObject(0, warnings); verify(_mockNginxBackend, never()) .store(any(JsonOutputObject.class)); }
public URI store(JsonOutputObject outputObject, Mutable<BatchJobStatusType> jobStatus) throws IOException { Exception remoteException = null; try { for (StorageBackend remoteBackend : _remoteBackends) { if (remoteBackend.canStore(outputObject)) { return remoteBackend.store(outputObject); } } } catch (StorageException ex) { remoteException = ex; LOG.warn(String.format( "Failed to remotely store output object for job id %d. It will be stored locally instead.", outputObject.getJobId()), ex); _inProgressJobs.addJobWarning( outputObject.getJobId(), IssueCodes.REMOTE_STORAGE, "The output object was stored locally because storing it remotely failed due to: " + ex); outputObject.addWarnings(0, List.of(new JsonIssueDetails( IssueSources.WORKFLOW_MANAGER.toString(), IssueCodes.REMOTE_STORAGE.toString(), "This output object was stored locally because storing it remotely failed due to: " + ex))); JobStatusCalculator.checkErrorMessages(outputObject, jobStatus); } try { return _localBackend.store(outputObject); } catch (IOException localException) { if (remoteException != null) { localException.addSuppressed(remoteException); } throw localException; } }
StorageService { public URI store(JsonOutputObject outputObject, Mutable<BatchJobStatusType> jobStatus) throws IOException { Exception remoteException = null; try { for (StorageBackend remoteBackend : _remoteBackends) { if (remoteBackend.canStore(outputObject)) { return remoteBackend.store(outputObject); } } } catch (StorageException ex) { remoteException = ex; LOG.warn(String.format( "Failed to remotely store output object for job id %d. It will be stored locally instead.", outputObject.getJobId()), ex); _inProgressJobs.addJobWarning( outputObject.getJobId(), IssueCodes.REMOTE_STORAGE, "The output object was stored locally because storing it remotely failed due to: " + ex); outputObject.addWarnings(0, List.of(new JsonIssueDetails( IssueSources.WORKFLOW_MANAGER.toString(), IssueCodes.REMOTE_STORAGE.toString(), "This output object was stored locally because storing it remotely failed due to: " + ex))); JobStatusCalculator.checkErrorMessages(outputObject, jobStatus); } try { return _localBackend.store(outputObject); } catch (IOException localException) { if (remoteException != null) { localException.addSuppressed(remoteException); } throw localException; } } }
StorageService { public URI store(JsonOutputObject outputObject, Mutable<BatchJobStatusType> jobStatus) throws IOException { Exception remoteException = null; try { for (StorageBackend remoteBackend : _remoteBackends) { if (remoteBackend.canStore(outputObject)) { return remoteBackend.store(outputObject); } } } catch (StorageException ex) { remoteException = ex; LOG.warn(String.format( "Failed to remotely store output object for job id %d. It will be stored locally instead.", outputObject.getJobId()), ex); _inProgressJobs.addJobWarning( outputObject.getJobId(), IssueCodes.REMOTE_STORAGE, "The output object was stored locally because storing it remotely failed due to: " + ex); outputObject.addWarnings(0, List.of(new JsonIssueDetails( IssueSources.WORKFLOW_MANAGER.toString(), IssueCodes.REMOTE_STORAGE.toString(), "This output object was stored locally because storing it remotely failed due to: " + ex))); JobStatusCalculator.checkErrorMessages(outputObject, jobStatus); } try { return _localBackend.store(outputObject); } catch (IOException localException) { if (remoteException != null) { localException.addSuppressed(remoteException); } throw localException; } } @Inject  StorageService(
            InProgressBatchJobsService inProgressJobs,
            S3StorageBackend s3StorageBackend,
            CustomNginxStorageBackend nginxStorageBackend,
            LocalStorageBackend localStorageBackend); }
StorageService { public URI store(JsonOutputObject outputObject, Mutable<BatchJobStatusType> jobStatus) throws IOException { Exception remoteException = null; try { for (StorageBackend remoteBackend : _remoteBackends) { if (remoteBackend.canStore(outputObject)) { return remoteBackend.store(outputObject); } } } catch (StorageException ex) { remoteException = ex; LOG.warn(String.format( "Failed to remotely store output object for job id %d. It will be stored locally instead.", outputObject.getJobId()), ex); _inProgressJobs.addJobWarning( outputObject.getJobId(), IssueCodes.REMOTE_STORAGE, "The output object was stored locally because storing it remotely failed due to: " + ex); outputObject.addWarnings(0, List.of(new JsonIssueDetails( IssueSources.WORKFLOW_MANAGER.toString(), IssueCodes.REMOTE_STORAGE.toString(), "This output object was stored locally because storing it remotely failed due to: " + ex))); JobStatusCalculator.checkErrorMessages(outputObject, jobStatus); } try { return _localBackend.store(outputObject); } catch (IOException localException) { if (remoteException != null) { localException.addSuppressed(remoteException); } throw localException; } } @Inject  StorageService(
            InProgressBatchJobsService inProgressJobs,
            S3StorageBackend s3StorageBackend,
            CustomNginxStorageBackend nginxStorageBackend,
            LocalStorageBackend localStorageBackend); URI store(JsonOutputObject outputObject, Mutable<BatchJobStatusType> jobStatus); Table<Integer, Integer, URI> storeArtifacts(ArtifactExtractionRequest request); void store(MarkupResult markupResult); }
StorageService { public URI store(JsonOutputObject outputObject, Mutable<BatchJobStatusType> jobStatus) throws IOException { Exception remoteException = null; try { for (StorageBackend remoteBackend : _remoteBackends) { if (remoteBackend.canStore(outputObject)) { return remoteBackend.store(outputObject); } } } catch (StorageException ex) { remoteException = ex; LOG.warn(String.format( "Failed to remotely store output object for job id %d. It will be stored locally instead.", outputObject.getJobId()), ex); _inProgressJobs.addJobWarning( outputObject.getJobId(), IssueCodes.REMOTE_STORAGE, "The output object was stored locally because storing it remotely failed due to: " + ex); outputObject.addWarnings(0, List.of(new JsonIssueDetails( IssueSources.WORKFLOW_MANAGER.toString(), IssueCodes.REMOTE_STORAGE.toString(), "This output object was stored locally because storing it remotely failed due to: " + ex))); JobStatusCalculator.checkErrorMessages(outputObject, jobStatus); } try { return _localBackend.store(outputObject); } catch (IOException localException) { if (remoteException != null) { localException.addSuppressed(remoteException); } throw localException; } } @Inject  StorageService(
            InProgressBatchJobsService inProgressJobs,
            S3StorageBackend s3StorageBackend,
            CustomNginxStorageBackend nginxStorageBackend,
            LocalStorageBackend localStorageBackend); URI store(JsonOutputObject outputObject, Mutable<BatchJobStatusType> jobStatus); Table<Integer, Integer, URI> storeArtifacts(ArtifactExtractionRequest request); void store(MarkupResult markupResult);  }