@Test @RunWithCustomExecutor public void reconstructCollectionOnAllVitamTenantsOK() throws Exception { Optional<CollectionBackupModel> backupCollection0 = getBackupCollection(TENANT_ID_0); Optional<CollectionBackupModel> backupCollection1 = getBackupCollection(TENANT_ID_1); Optional<CollectionBackupModel> backupCollection2 = getBackupCollection(TENANT_ID_2); when(recoverBuckupService.readLatestSavedFile(STRATEGY_ID, FunctionalAdminCollections.RULES)) .thenReturn(backupCollection0); when(recoverBuckupService.readLatestSavedFile(STRATEGY_ID, FunctionalAdminCollections.RULES)) .thenReturn(backupCollection1); when(recoverBuckupService.readLatestSavedFile(STRATEGY_ID, FunctionalAdminCollections.RULES)) .thenReturn(backupCollection2); when(repositoryFactory.getVitamMongoRepository(FunctionalAdminCollections.VITAM_SEQUENCE.getVitamCollection())) .thenReturn(multiTenantMongoRepository); LOGGER.debug(String.format("Reconstruction of Vitam tenants.")); VitamConfiguration.setTenants(Arrays.asList(0, 1, 2)); reconstructionService.reconstruct(FunctionalAdminCollections.RULES); verify(reconstructionService, times(1)) .reconstruct(any(), tenantCaptor.capture()); }
@Override public void reconstruct(FunctionalAdminCollections collection, Integer... tenants) throws DatabaseException { ParametersChecker.checkParameter("All parameters [%s, %s] are required.", collection, tenants); LOGGER.debug(String .format("Start reconstruction of the %s collection on the Vitam tenant %s.", collection.getName(), tenants)); Integer originalTenant = VitamThreadUtils.getVitamSession().getTenantId(); final VitamMongoRepository mongoRepository = vitamRepositoryProvider.getVitamMongoRepository(collection.getVitamCollection()); final VitamElasticsearchRepository elasticsearchRepository = vitamRepositoryProvider.getVitamESRepository(collection.getVitamCollection()); final VitamMongoRepository sequenceRepository = vitamRepositoryProvider .getVitamMongoRepository(FunctionalAdminCollections.VITAM_SEQUENCE.getVitamCollection()); switch (collection) { case CONTEXT: case FORMATS: case SECURITY_PROFILE: case VITAM_SEQUENCE: tenants = new Integer[] {ADMIN_TENANT}; break; } try { for (Integer tenant : tenants) { VitamThreadUtils.getVitamSession().setTenantId(tenant); Optional<CollectionBackupModel> collectionBackup = recoverBuckupService.readLatestSavedFile(VitamConfiguration.getDefaultStrategy(), collection); if (collectionBackup.isPresent()) { LOGGER.debug(String.format("Last backup copy version : %s", collectionBackup)); if (collection.isMultitenant()) { mongoRepository.purge(tenant); elasticsearchRepository.purge(tenant); } else { mongoRepository.purge(); elasticsearchRepository.purge(); } restoreSequence(sequenceRepository, collectionBackup.get().getSequence()); restoreSequence(sequenceRepository, collectionBackup.get().getBackupSequence()); mongoRepository.save(collectionBackup.get().getDocuments()); elasticsearchRepository.save(collectionBackup.get().getDocuments()); LOGGER.debug(String .format( "[Reconstruction]: the collection {%s} has been reconstructed on the tenants {%s} at %s", collectionBackup, tenants, LocalDateUtil.now())); } } } finally { VitamThreadUtils.getVitamSession().setTenantId(originalTenant); } }
ReconstructionServiceImpl implements ReconstructionService { @Override public void reconstruct(FunctionalAdminCollections collection, Integer... tenants) throws DatabaseException { ParametersChecker.checkParameter("All parameters [%s, %s] are required.", collection, tenants); LOGGER.debug(String .format("Start reconstruction of the %s collection on the Vitam tenant %s.", collection.getName(), tenants)); Integer originalTenant = VitamThreadUtils.getVitamSession().getTenantId(); final VitamMongoRepository mongoRepository = vitamRepositoryProvider.getVitamMongoRepository(collection.getVitamCollection()); final VitamElasticsearchRepository elasticsearchRepository = vitamRepositoryProvider.getVitamESRepository(collection.getVitamCollection()); final VitamMongoRepository sequenceRepository = vitamRepositoryProvider .getVitamMongoRepository(FunctionalAdminCollections.VITAM_SEQUENCE.getVitamCollection()); switch (collection) { case CONTEXT: case FORMATS: case SECURITY_PROFILE: case VITAM_SEQUENCE: tenants = new Integer[] {ADMIN_TENANT}; break; } try { for (Integer tenant : tenants) { VitamThreadUtils.getVitamSession().setTenantId(tenant); Optional<CollectionBackupModel> collectionBackup = recoverBuckupService.readLatestSavedFile(VitamConfiguration.getDefaultStrategy(), collection); if (collectionBackup.isPresent()) { LOGGER.debug(String.format("Last backup copy version : %s", collectionBackup)); if (collection.isMultitenant()) { mongoRepository.purge(tenant); elasticsearchRepository.purge(tenant); } else { mongoRepository.purge(); elasticsearchRepository.purge(); } restoreSequence(sequenceRepository, collectionBackup.get().getSequence()); restoreSequence(sequenceRepository, collectionBackup.get().getBackupSequence()); mongoRepository.save(collectionBackup.get().getDocuments()); elasticsearchRepository.save(collectionBackup.get().getDocuments()); LOGGER.debug(String .format( "[Reconstruction]: the collection {%s} has been reconstructed on the tenants {%s} at %s", collectionBackup, tenants, LocalDateUtil.now())); } } } finally { VitamThreadUtils.getVitamSession().setTenantId(originalTenant); } } }
ReconstructionServiceImpl implements ReconstructionService { @Override public void reconstruct(FunctionalAdminCollections collection, Integer... tenants) throws DatabaseException { ParametersChecker.checkParameter("All parameters [%s, %s] are required.", collection, tenants); LOGGER.debug(String .format("Start reconstruction of the %s collection on the Vitam tenant %s.", collection.getName(), tenants)); Integer originalTenant = VitamThreadUtils.getVitamSession().getTenantId(); final VitamMongoRepository mongoRepository = vitamRepositoryProvider.getVitamMongoRepository(collection.getVitamCollection()); final VitamElasticsearchRepository elasticsearchRepository = vitamRepositoryProvider.getVitamESRepository(collection.getVitamCollection()); final VitamMongoRepository sequenceRepository = vitamRepositoryProvider .getVitamMongoRepository(FunctionalAdminCollections.VITAM_SEQUENCE.getVitamCollection()); switch (collection) { case CONTEXT: case FORMATS: case SECURITY_PROFILE: case VITAM_SEQUENCE: tenants = new Integer[] {ADMIN_TENANT}; break; } try { for (Integer tenant : tenants) { VitamThreadUtils.getVitamSession().setTenantId(tenant); Optional<CollectionBackupModel> collectionBackup = recoverBuckupService.readLatestSavedFile(VitamConfiguration.getDefaultStrategy(), collection); if (collectionBackup.isPresent()) { LOGGER.debug(String.format("Last backup copy version : %s", collectionBackup)); if (collection.isMultitenant()) { mongoRepository.purge(tenant); elasticsearchRepository.purge(tenant); } else { mongoRepository.purge(); elasticsearchRepository.purge(); } restoreSequence(sequenceRepository, collectionBackup.get().getSequence()); restoreSequence(sequenceRepository, collectionBackup.get().getBackupSequence()); mongoRepository.save(collectionBackup.get().getDocuments()); elasticsearchRepository.save(collectionBackup.get().getDocuments()); LOGGER.debug(String .format( "[Reconstruction]: the collection {%s} has been reconstructed on the tenants {%s} at %s", collectionBackup, tenants, LocalDateUtil.now())); } } } finally { VitamThreadUtils.getVitamSession().setTenantId(originalTenant); } } ReconstructionServiceImpl(VitamRepositoryProvider vitamRepositoryProvider,
        OffsetRepository offsetRepository); @VisibleForTesting  ReconstructionServiceImpl(VitamRepositoryProvider vitamRepositoryProvider,
        RestoreBackupService recoverBuckupService, OffsetRepository offsetRepository); }
ReconstructionServiceImpl implements ReconstructionService { @Override public void reconstruct(FunctionalAdminCollections collection, Integer... tenants) throws DatabaseException { ParametersChecker.checkParameter("All parameters [%s, %s] are required.", collection, tenants); LOGGER.debug(String .format("Start reconstruction of the %s collection on the Vitam tenant %s.", collection.getName(), tenants)); Integer originalTenant = VitamThreadUtils.getVitamSession().getTenantId(); final VitamMongoRepository mongoRepository = vitamRepositoryProvider.getVitamMongoRepository(collection.getVitamCollection()); final VitamElasticsearchRepository elasticsearchRepository = vitamRepositoryProvider.getVitamESRepository(collection.getVitamCollection()); final VitamMongoRepository sequenceRepository = vitamRepositoryProvider .getVitamMongoRepository(FunctionalAdminCollections.VITAM_SEQUENCE.getVitamCollection()); switch (collection) { case CONTEXT: case FORMATS: case SECURITY_PROFILE: case VITAM_SEQUENCE: tenants = new Integer[] {ADMIN_TENANT}; break; } try { for (Integer tenant : tenants) { VitamThreadUtils.getVitamSession().setTenantId(tenant); Optional<CollectionBackupModel> collectionBackup = recoverBuckupService.readLatestSavedFile(VitamConfiguration.getDefaultStrategy(), collection); if (collectionBackup.isPresent()) { LOGGER.debug(String.format("Last backup copy version : %s", collectionBackup)); if (collection.isMultitenant()) { mongoRepository.purge(tenant); elasticsearchRepository.purge(tenant); } else { mongoRepository.purge(); elasticsearchRepository.purge(); } restoreSequence(sequenceRepository, collectionBackup.get().getSequence()); restoreSequence(sequenceRepository, collectionBackup.get().getBackupSequence()); mongoRepository.save(collectionBackup.get().getDocuments()); elasticsearchRepository.save(collectionBackup.get().getDocuments()); LOGGER.debug(String .format( "[Reconstruction]: the collection {%s} has been reconstructed on the tenants {%s} at %s", collectionBackup, tenants, LocalDateUtil.now())); } } } finally { VitamThreadUtils.getVitamSession().setTenantId(originalTenant); } } ReconstructionServiceImpl(VitamRepositoryProvider vitamRepositoryProvider,
        OffsetRepository offsetRepository); @VisibleForTesting  ReconstructionServiceImpl(VitamRepositoryProvider vitamRepositoryProvider,
        RestoreBackupService recoverBuckupService, OffsetRepository offsetRepository); @Override void reconstruct(FunctionalAdminCollections collection, Integer... tenants); ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem); @Override void reconstruct(FunctionalAdminCollections collection); void computeAccessionRegisterSummary(String originatingAgency, Integer tenant); void computeAccessionRegisterSummary(Set<String> originatingAgencies, Integer tenant); @Override List<Document> agregateAccessionRegisterSummary(Set<String> originatingAgencies, Integer tenant); }
ReconstructionServiceImpl implements ReconstructionService { @Override public void reconstruct(FunctionalAdminCollections collection, Integer... tenants) throws DatabaseException { ParametersChecker.checkParameter("All parameters [%s, %s] are required.", collection, tenants); LOGGER.debug(String .format("Start reconstruction of the %s collection on the Vitam tenant %s.", collection.getName(), tenants)); Integer originalTenant = VitamThreadUtils.getVitamSession().getTenantId(); final VitamMongoRepository mongoRepository = vitamRepositoryProvider.getVitamMongoRepository(collection.getVitamCollection()); final VitamElasticsearchRepository elasticsearchRepository = vitamRepositoryProvider.getVitamESRepository(collection.getVitamCollection()); final VitamMongoRepository sequenceRepository = vitamRepositoryProvider .getVitamMongoRepository(FunctionalAdminCollections.VITAM_SEQUENCE.getVitamCollection()); switch (collection) { case CONTEXT: case FORMATS: case SECURITY_PROFILE: case VITAM_SEQUENCE: tenants = new Integer[] {ADMIN_TENANT}; break; } try { for (Integer tenant : tenants) { VitamThreadUtils.getVitamSession().setTenantId(tenant); Optional<CollectionBackupModel> collectionBackup = recoverBuckupService.readLatestSavedFile(VitamConfiguration.getDefaultStrategy(), collection); if (collectionBackup.isPresent()) { LOGGER.debug(String.format("Last backup copy version : %s", collectionBackup)); if (collection.isMultitenant()) { mongoRepository.purge(tenant); elasticsearchRepository.purge(tenant); } else { mongoRepository.purge(); elasticsearchRepository.purge(); } restoreSequence(sequenceRepository, collectionBackup.get().getSequence()); restoreSequence(sequenceRepository, collectionBackup.get().getBackupSequence()); mongoRepository.save(collectionBackup.get().getDocuments()); elasticsearchRepository.save(collectionBackup.get().getDocuments()); LOGGER.debug(String .format( "[Reconstruction]: the collection {%s} has been reconstructed on the tenants {%s} at %s", collectionBackup, tenants, LocalDateUtil.now())); } } } finally { VitamThreadUtils.getVitamSession().setTenantId(originalTenant); } } ReconstructionServiceImpl(VitamRepositoryProvider vitamRepositoryProvider,
        OffsetRepository offsetRepository); @VisibleForTesting  ReconstructionServiceImpl(VitamRepositoryProvider vitamRepositoryProvider,
        RestoreBackupService recoverBuckupService, OffsetRepository offsetRepository); @Override void reconstruct(FunctionalAdminCollections collection, Integer... tenants); ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem); @Override void reconstruct(FunctionalAdminCollections collection); void computeAccessionRegisterSummary(String originatingAgency, Integer tenant); void computeAccessionRegisterSummary(Set<String> originatingAgencies, Integer tenant); @Override List<Document> agregateAccessionRegisterSummary(Set<String> originatingAgencies, Integer tenant);  }