@Test public void should_fail_when_saving_collection() throws Exception { final FunctionalAdminCollections agencies = FunctionalAdminCollections.AGENCIES; GUID guid = newEventGUID(0); willThrow(new BackupServiceException("Error Message")).given(backupService).backup(any(), any(), any()); VitamThreadUtils.getVitamSession().setTenantId(0); assertThatThrownBy(() -> functionalBackupService .saveCollectionAndSequence(guid, "STP_TEST", agencies, guid.toString())) .isInstanceOf(FunctionalBackupServiceException.class) .withFailMessage("Error Message"); verify(backupLogbookManager).logError(guid, "STP_TEST", "Error Message"); }
public void saveCollectionAndSequence(GUID eipMaster, String eventCode, FunctionalAdminCollections collection, String objectIdentifier) throws VitamException { try { int initialTenant = ParameterHelper.getTenantParameter(); int storageTenant = getStorageTenant(collection, initialTenant); VitamSequence backupSequence = vitamCounterService .getNextBackupSequenceDocument(storageTenant, fromFunctionalAdminCollections(collection)); String fileName = getBackupFileName(collection, storageTenant, backupSequence.getCounter()); String digestStr; File file = null; try { VitamThreadUtils.getVitamSession().setTenantId(storageTenant); file = saveFunctionalCollectionToTempFile(collection, storageTenant, backupSequence); digestStr = storeBackupFileInStorage(fileName, file); } finally { VitamThreadUtils.getVitamSession().setTenantId(initialTenant); deleteTmpFile(file); } backupLogbookManager.logEventSuccess(eipMaster, eventCode, digestStr, fileName, objectIdentifier); } catch (ReferentialException | IOException | BackupServiceException e) { try { backupLogbookManager.logError(eipMaster, eventCode, e.getMessage()); } catch (VitamException | RuntimeException logbookErrorException) { LOGGER.error("Could not persist backup error in logbook operation", logbookErrorException); } throw new FunctionalBackupServiceException("Could not backup collection " + collection.toString(), e); } catch (Exception e) { try { backupLogbookManager.logError(eipMaster, eventCode, e.getMessage()); } catch (VitamException | RuntimeException logbookErrorException) { LOGGER.error("Could not persist backup error in logbook operation", logbookErrorException); } throw new FunctionalBackupServiceException("Could not backup collection " + collection.toString(), e); } }
FunctionalBackupService { public void saveCollectionAndSequence(GUID eipMaster, String eventCode, FunctionalAdminCollections collection, String objectIdentifier) throws VitamException { try { int initialTenant = ParameterHelper.getTenantParameter(); int storageTenant = getStorageTenant(collection, initialTenant); VitamSequence backupSequence = vitamCounterService .getNextBackupSequenceDocument(storageTenant, fromFunctionalAdminCollections(collection)); String fileName = getBackupFileName(collection, storageTenant, backupSequence.getCounter()); String digestStr; File file = null; try { VitamThreadUtils.getVitamSession().setTenantId(storageTenant); file = saveFunctionalCollectionToTempFile(collection, storageTenant, backupSequence); digestStr = storeBackupFileInStorage(fileName, file); } finally { VitamThreadUtils.getVitamSession().setTenantId(initialTenant); deleteTmpFile(file); } backupLogbookManager.logEventSuccess(eipMaster, eventCode, digestStr, fileName, objectIdentifier); } catch (ReferentialException | IOException | BackupServiceException e) { try { backupLogbookManager.logError(eipMaster, eventCode, e.getMessage()); } catch (VitamException | RuntimeException logbookErrorException) { LOGGER.error("Could not persist backup error in logbook operation", logbookErrorException); } throw new FunctionalBackupServiceException("Could not backup collection " + collection.toString(), e); } catch (Exception e) { try { backupLogbookManager.logError(eipMaster, eventCode, e.getMessage()); } catch (VitamException | RuntimeException logbookErrorException) { LOGGER.error("Could not persist backup error in logbook operation", logbookErrorException); } throw new FunctionalBackupServiceException("Could not backup collection " + collection.toString(), e); } } }
FunctionalBackupService { public void saveCollectionAndSequence(GUID eipMaster, String eventCode, FunctionalAdminCollections collection, String objectIdentifier) throws VitamException { try { int initialTenant = ParameterHelper.getTenantParameter(); int storageTenant = getStorageTenant(collection, initialTenant); VitamSequence backupSequence = vitamCounterService .getNextBackupSequenceDocument(storageTenant, fromFunctionalAdminCollections(collection)); String fileName = getBackupFileName(collection, storageTenant, backupSequence.getCounter()); String digestStr; File file = null; try { VitamThreadUtils.getVitamSession().setTenantId(storageTenant); file = saveFunctionalCollectionToTempFile(collection, storageTenant, backupSequence); digestStr = storeBackupFileInStorage(fileName, file); } finally { VitamThreadUtils.getVitamSession().setTenantId(initialTenant); deleteTmpFile(file); } backupLogbookManager.logEventSuccess(eipMaster, eventCode, digestStr, fileName, objectIdentifier); } catch (ReferentialException | IOException | BackupServiceException e) { try { backupLogbookManager.logError(eipMaster, eventCode, e.getMessage()); } catch (VitamException | RuntimeException logbookErrorException) { LOGGER.error("Could not persist backup error in logbook operation", logbookErrorException); } throw new FunctionalBackupServiceException("Could not backup collection " + collection.toString(), e); } catch (Exception e) { try { backupLogbookManager.logError(eipMaster, eventCode, e.getMessage()); } catch (VitamException | RuntimeException logbookErrorException) { LOGGER.error("Could not persist backup error in logbook operation", logbookErrorException); } throw new FunctionalBackupServiceException("Could not backup collection " + collection.toString(), e); } } FunctionalBackupService(
        VitamCounterService vitamCounterService); @VisibleForTesting  FunctionalBackupService(BackupService backupService,
        VitamCounterService vitamCounterService, BackupLogbookManager backupLogbookManager); }
FunctionalBackupService { public void saveCollectionAndSequence(GUID eipMaster, String eventCode, FunctionalAdminCollections collection, String objectIdentifier) throws VitamException { try { int initialTenant = ParameterHelper.getTenantParameter(); int storageTenant = getStorageTenant(collection, initialTenant); VitamSequence backupSequence = vitamCounterService .getNextBackupSequenceDocument(storageTenant, fromFunctionalAdminCollections(collection)); String fileName = getBackupFileName(collection, storageTenant, backupSequence.getCounter()); String digestStr; File file = null; try { VitamThreadUtils.getVitamSession().setTenantId(storageTenant); file = saveFunctionalCollectionToTempFile(collection, storageTenant, backupSequence); digestStr = storeBackupFileInStorage(fileName, file); } finally { VitamThreadUtils.getVitamSession().setTenantId(initialTenant); deleteTmpFile(file); } backupLogbookManager.logEventSuccess(eipMaster, eventCode, digestStr, fileName, objectIdentifier); } catch (ReferentialException | IOException | BackupServiceException e) { try { backupLogbookManager.logError(eipMaster, eventCode, e.getMessage()); } catch (VitamException | RuntimeException logbookErrorException) { LOGGER.error("Could not persist backup error in logbook operation", logbookErrorException); } throw new FunctionalBackupServiceException("Could not backup collection " + collection.toString(), e); } catch (Exception e) { try { backupLogbookManager.logError(eipMaster, eventCode, e.getMessage()); } catch (VitamException | RuntimeException logbookErrorException) { LOGGER.error("Could not persist backup error in logbook operation", logbookErrorException); } throw new FunctionalBackupServiceException("Could not backup collection " + collection.toString(), e); } } FunctionalBackupService(
        VitamCounterService vitamCounterService); @VisibleForTesting  FunctionalBackupService(BackupService backupService,
        VitamCounterService vitamCounterService, BackupLogbookManager backupLogbookManager); void saveCollectionAndSequence(GUID eipMaster, String eventCode,
        FunctionalAdminCollections collection, String objectIdentifier); void saveDocument(FunctionalAdminCollections collection, Document document); static String getBackupFileName(FunctionalAdminCollections functionalAdminCollections, int tenant,
        Integer sequence); void saveFile(InputStream inputStream, GUID eipMaster, String eventCode,
        DataCategory dataCategory, String fileName); String getName(DataCategory dataCategory, int tenant, String fileName); MongoCursor getCurrentCollection(FunctionalAdminCollections collections, int tenant); ArrayNode getCollectionInJson(MongoCursor mongoCursor); }
FunctionalBackupService { public void saveCollectionAndSequence(GUID eipMaster, String eventCode, FunctionalAdminCollections collection, String objectIdentifier) throws VitamException { try { int initialTenant = ParameterHelper.getTenantParameter(); int storageTenant = getStorageTenant(collection, initialTenant); VitamSequence backupSequence = vitamCounterService .getNextBackupSequenceDocument(storageTenant, fromFunctionalAdminCollections(collection)); String fileName = getBackupFileName(collection, storageTenant, backupSequence.getCounter()); String digestStr; File file = null; try { VitamThreadUtils.getVitamSession().setTenantId(storageTenant); file = saveFunctionalCollectionToTempFile(collection, storageTenant, backupSequence); digestStr = storeBackupFileInStorage(fileName, file); } finally { VitamThreadUtils.getVitamSession().setTenantId(initialTenant); deleteTmpFile(file); } backupLogbookManager.logEventSuccess(eipMaster, eventCode, digestStr, fileName, objectIdentifier); } catch (ReferentialException | IOException | BackupServiceException e) { try { backupLogbookManager.logError(eipMaster, eventCode, e.getMessage()); } catch (VitamException | RuntimeException logbookErrorException) { LOGGER.error("Could not persist backup error in logbook operation", logbookErrorException); } throw new FunctionalBackupServiceException("Could not backup collection " + collection.toString(), e); } catch (Exception e) { try { backupLogbookManager.logError(eipMaster, eventCode, e.getMessage()); } catch (VitamException | RuntimeException logbookErrorException) { LOGGER.error("Could not persist backup error in logbook operation", logbookErrorException); } throw new FunctionalBackupServiceException("Could not backup collection " + collection.toString(), e); } } FunctionalBackupService(
        VitamCounterService vitamCounterService); @VisibleForTesting  FunctionalBackupService(BackupService backupService,
        VitamCounterService vitamCounterService, BackupLogbookManager backupLogbookManager); void saveCollectionAndSequence(GUID eipMaster, String eventCode,
        FunctionalAdminCollections collection, String objectIdentifier); void saveDocument(FunctionalAdminCollections collection, Document document); static String getBackupFileName(FunctionalAdminCollections functionalAdminCollections, int tenant,
        Integer sequence); void saveFile(InputStream inputStream, GUID eipMaster, String eventCode,
        DataCategory dataCategory, String fileName); String getName(DataCategory dataCategory, int tenant, String fileName); MongoCursor getCurrentCollection(FunctionalAdminCollections collections, int tenant); ArrayNode getCollectionInJson(MongoCursor mongoCursor); static final String FIELD_COLLECTION; static final String FIELD_SEQUENCE; static final String FIELD_BACKUP_SEQUENCE; static final String DEFAULT_EXTENSION; }