@Test @RunWithCustomExecutor public void testBulkCreateFromWorkspace() throws StorageException { int tenantId = 2; List<String> workspaceObjectURIs = Arrays.asList("uir1", "uri2"); List<String> objectNames = Arrays.asList("ob1", "ob2"); String workspaceContainer = "workspaceContainer"; String requester = "requester"; List<String> offers = Arrays.asList("default", "default2"); Map<String, String> digests = ImmutableMap.of("default", "digest1", "default2", "digest2"); VitamThreadUtils.getVitamSession().setTenantId(tenantId); doReturn(digests).when(bulkStorageDistribution).bulkCreateFromWorkspaceWithRetries( anyInt(),anyList(), anyMap(), anyMap(), any(), anyString(), anyList(), anyList(), anyString()); BulkObjectStoreRequest bulkObjectStoreRequest = new BulkObjectStoreRequest( workspaceContainer, workspaceObjectURIs, DataCategory.UNIT, objectNames ); BulkObjectStoreResponse bulkObjectStoreResponse = customDistribution.bulkCreateFromWorkspace(VitamConfiguration.getDefaultStrategy(), bulkObjectStoreRequest, requester); assertThat(bulkObjectStoreResponse.getDigestType()).isEqualTo(DigestType.SHA1.getName()); assertThat(bulkObjectStoreResponse.getObjectDigests()).isEqualTo(digests); assertThat(bulkObjectStoreResponse.getOfferIds()).isEqualTo(offers); ArgumentCaptor<Map<String, StorageOffer>> storageOfferCaptor = ArgumentCaptor.forClass(Map.class); ArgumentCaptor<Map<String, Driver>> storageDriverCaptor = ArgumentCaptor.forClass(Map.class); verify(bulkStorageDistribution).bulkCreateFromWorkspaceWithRetries( eq(tenantId), eq(offers), storageDriverCaptor.capture(), storageOfferCaptor.capture(), eq(DataCategory.UNIT), eq(workspaceContainer), eq(workspaceObjectURIs), eq(objectNames), eq(requester) ); assertThat(storageOfferCaptor.getValue().keySet()).containsExactlyInAnyOrderElementsOf(offers); assertThat(storageOfferCaptor.getValue().values()).noneMatch(Objects::isNull); assertThat(storageDriverCaptor.getValue().keySet()).containsExactlyInAnyOrderElementsOf(offers); assertThat(storageDriverCaptor.getValue().values()).noneMatch(Objects::isNull); }
@Override public BulkObjectStoreResponse bulkCreateFromWorkspace(String strategyId, BulkObjectStoreRequest bulkObjectStoreRequest, String requester) throws StorageException { Integer tenantId = ParameterHelper.getTenantParameter(); List<String> offerIds = getStorageOffers(strategyId).stream().map(StorageOffer::getId).collect(Collectors.toList()); Map<String, Driver> storageDrivers = new HashMap<>(); for (String offerId : offerIds) { storageDrivers.put(offerId, retrieveDriverInternal(offerId)); } Map<String, StorageOffer> storageOffers = new HashMap<>(); for (String offerId : offerIds) { storageOffers.put(offerId, OFFER_PROVIDER.getStorageOffer(offerId)); } Map<String, String> objectDigests = bulkStorageDistribution .bulkCreateFromWorkspaceWithRetries(tenantId, offerIds, storageDrivers, storageOffers, bulkObjectStoreRequest.getType(), bulkObjectStoreRequest.getWorkspaceContainerGUID(), bulkObjectStoreRequest.getWorkspaceObjectURIs(), bulkObjectStoreRequest.getObjectNames(), requester); return new BulkObjectStoreResponse(offerIds, digestType.getName(), objectDigests); }
StorageDistributionImpl implements StorageDistribution { @Override public BulkObjectStoreResponse bulkCreateFromWorkspace(String strategyId, BulkObjectStoreRequest bulkObjectStoreRequest, String requester) throws StorageException { Integer tenantId = ParameterHelper.getTenantParameter(); List<String> offerIds = getStorageOffers(strategyId).stream().map(StorageOffer::getId).collect(Collectors.toList()); Map<String, Driver> storageDrivers = new HashMap<>(); for (String offerId : offerIds) { storageDrivers.put(offerId, retrieveDriverInternal(offerId)); } Map<String, StorageOffer> storageOffers = new HashMap<>(); for (String offerId : offerIds) { storageOffers.put(offerId, OFFER_PROVIDER.getStorageOffer(offerId)); } Map<String, String> objectDigests = bulkStorageDistribution .bulkCreateFromWorkspaceWithRetries(tenantId, offerIds, storageDrivers, storageOffers, bulkObjectStoreRequest.getType(), bulkObjectStoreRequest.getWorkspaceContainerGUID(), bulkObjectStoreRequest.getWorkspaceObjectURIs(), bulkObjectStoreRequest.getObjectNames(), requester); return new BulkObjectStoreResponse(offerIds, digestType.getName(), objectDigests); } }
StorageDistributionImpl implements StorageDistribution { @Override public BulkObjectStoreResponse bulkCreateFromWorkspace(String strategyId, BulkObjectStoreRequest bulkObjectStoreRequest, String requester) throws StorageException { Integer tenantId = ParameterHelper.getTenantParameter(); List<String> offerIds = getStorageOffers(strategyId).stream().map(StorageOffer::getId).collect(Collectors.toList()); Map<String, Driver> storageDrivers = new HashMap<>(); for (String offerId : offerIds) { storageDrivers.put(offerId, retrieveDriverInternal(offerId)); } Map<String, StorageOffer> storageOffers = new HashMap<>(); for (String offerId : offerIds) { storageOffers.put(offerId, OFFER_PROVIDER.getStorageOffer(offerId)); } Map<String, String> objectDigests = bulkStorageDistribution .bulkCreateFromWorkspaceWithRetries(tenantId, offerIds, storageDrivers, storageOffers, bulkObjectStoreRequest.getType(), bulkObjectStoreRequest.getWorkspaceContainerGUID(), bulkObjectStoreRequest.getWorkspaceObjectURIs(), bulkObjectStoreRequest.getObjectNames(), requester); return new BulkObjectStoreResponse(offerIds, digestType.getName(), objectDigests); } StorageDistributionImpl(StorageConfiguration configuration, StorageLog storageLogService); @VisibleForTesting  StorageDistributionImpl(WorkspaceClientFactory workspaceClientFactory, DigestType digestType,
        StorageLog storageLogService,
        ExecutorService batchExecutorService, int batchDigestComputationTimeout,
        BulkStorageDistribution bulkStorageDistribution); }
StorageDistributionImpl implements StorageDistribution { @Override public BulkObjectStoreResponse bulkCreateFromWorkspace(String strategyId, BulkObjectStoreRequest bulkObjectStoreRequest, String requester) throws StorageException { Integer tenantId = ParameterHelper.getTenantParameter(); List<String> offerIds = getStorageOffers(strategyId).stream().map(StorageOffer::getId).collect(Collectors.toList()); Map<String, Driver> storageDrivers = new HashMap<>(); for (String offerId : offerIds) { storageDrivers.put(offerId, retrieveDriverInternal(offerId)); } Map<String, StorageOffer> storageOffers = new HashMap<>(); for (String offerId : offerIds) { storageOffers.put(offerId, OFFER_PROVIDER.getStorageOffer(offerId)); } Map<String, String> objectDigests = bulkStorageDistribution .bulkCreateFromWorkspaceWithRetries(tenantId, offerIds, storageDrivers, storageOffers, bulkObjectStoreRequest.getType(), bulkObjectStoreRequest.getWorkspaceContainerGUID(), bulkObjectStoreRequest.getWorkspaceObjectURIs(), bulkObjectStoreRequest.getObjectNames(), requester); return new BulkObjectStoreResponse(offerIds, digestType.getName(), objectDigests); } StorageDistributionImpl(StorageConfiguration configuration, StorageLog storageLogService); @VisibleForTesting  StorageDistributionImpl(WorkspaceClientFactory workspaceClientFactory, DigestType digestType,
        StorageLog storageLogService,
        ExecutorService batchExecutorService, int batchDigestComputationTimeout,
        BulkStorageDistribution bulkStorageDistribution); @Override StoredInfoResult copyObjectFromOfferToOffer(DataContext context, String sourceOffer, String destinationOffer); @Override StoredInfoResult storeDataInOffers(String strategyId, String objectId, DataCategory category,
        String requester,
        List<String> offerIds, Response response); @Override StoredInfoResult storeDataInOffers(String strategyId, StreamAndInfo streamAndInfo, String objectId,
        DataCategory category, String requester,
        List<String> offerIds); @Override StoredInfoResult storeDataInAllOffers(String strategyId, String objectId,
        ObjectDescription createObjectDescription, DataCategory category, String requester); @Override BulkObjectStoreResponse bulkCreateFromWorkspace(String strategyId,
        BulkObjectStoreRequest bulkObjectStoreRequest, String requester); @Override List<String> getOfferIds(String strategyId); @Override Map<String, StorageStrategy> getStrategies(); @Override JsonNode getContainerInformation(String strategyId); @Override CloseableIterator<ObjectEntry> listContainerObjects(String strategyId, DataCategory category); @Override CloseableIterator<ObjectEntry> listContainerObjectsForOffer(DataCategory category,
        String offerId, boolean includeDisabled); @Override RequestResponse<OfferLog> getOfferLogs(String strategyId, DataCategory category, Long offset, int limit,
        Order order); @Override RequestResponse<OfferLog> getOfferLogsByOfferId(String strategyId, String offerId,
        DataCategory category,
        Long offset, int limit, Order order); @Override Response getContainerByCategory(String strategyId, String objectId, DataCategory category,
        AccessLogInfoModel logInformation); @Override Response getContainerByCategory(String strategyId, String objectId, DataCategory category, String
        offerId); @Override JsonNode getContainerInformation(String strategyId, DataCategory type, String objectId,
        List<String> offerIds, boolean noCache); @Override Map<String, Boolean> checkObjectExisting(String strategyId, String objectId, DataCategory category,
        List<String> offerIds); @Override void deleteObjectInAllOffers(String strategyId, DataContext context); @Override void deleteObjectInOffers(String strategyId, DataContext context, List<String> offers); @Override List<BatchObjectInformationResponse> getBatchObjectInformation(String strategyId, DataCategory type,
        List<String> objectIds, List<String> offerIds); @Override void close(); }
StorageDistributionImpl implements StorageDistribution { @Override public BulkObjectStoreResponse bulkCreateFromWorkspace(String strategyId, BulkObjectStoreRequest bulkObjectStoreRequest, String requester) throws StorageException { Integer tenantId = ParameterHelper.getTenantParameter(); List<String> offerIds = getStorageOffers(strategyId).stream().map(StorageOffer::getId).collect(Collectors.toList()); Map<String, Driver> storageDrivers = new HashMap<>(); for (String offerId : offerIds) { storageDrivers.put(offerId, retrieveDriverInternal(offerId)); } Map<String, StorageOffer> storageOffers = new HashMap<>(); for (String offerId : offerIds) { storageOffers.put(offerId, OFFER_PROVIDER.getStorageOffer(offerId)); } Map<String, String> objectDigests = bulkStorageDistribution .bulkCreateFromWorkspaceWithRetries(tenantId, offerIds, storageDrivers, storageOffers, bulkObjectStoreRequest.getType(), bulkObjectStoreRequest.getWorkspaceContainerGUID(), bulkObjectStoreRequest.getWorkspaceObjectURIs(), bulkObjectStoreRequest.getObjectNames(), requester); return new BulkObjectStoreResponse(offerIds, digestType.getName(), objectDigests); } StorageDistributionImpl(StorageConfiguration configuration, StorageLog storageLogService); @VisibleForTesting  StorageDistributionImpl(WorkspaceClientFactory workspaceClientFactory, DigestType digestType,
        StorageLog storageLogService,
        ExecutorService batchExecutorService, int batchDigestComputationTimeout,
        BulkStorageDistribution bulkStorageDistribution); @Override StoredInfoResult copyObjectFromOfferToOffer(DataContext context, String sourceOffer, String destinationOffer); @Override StoredInfoResult storeDataInOffers(String strategyId, String objectId, DataCategory category,
        String requester,
        List<String> offerIds, Response response); @Override StoredInfoResult storeDataInOffers(String strategyId, StreamAndInfo streamAndInfo, String objectId,
        DataCategory category, String requester,
        List<String> offerIds); @Override StoredInfoResult storeDataInAllOffers(String strategyId, String objectId,
        ObjectDescription createObjectDescription, DataCategory category, String requester); @Override BulkObjectStoreResponse bulkCreateFromWorkspace(String strategyId,
        BulkObjectStoreRequest bulkObjectStoreRequest, String requester); @Override List<String> getOfferIds(String strategyId); @Override Map<String, StorageStrategy> getStrategies(); @Override JsonNode getContainerInformation(String strategyId); @Override CloseableIterator<ObjectEntry> listContainerObjects(String strategyId, DataCategory category); @Override CloseableIterator<ObjectEntry> listContainerObjectsForOffer(DataCategory category,
        String offerId, boolean includeDisabled); @Override RequestResponse<OfferLog> getOfferLogs(String strategyId, DataCategory category, Long offset, int limit,
        Order order); @Override RequestResponse<OfferLog> getOfferLogsByOfferId(String strategyId, String offerId,
        DataCategory category,
        Long offset, int limit, Order order); @Override Response getContainerByCategory(String strategyId, String objectId, DataCategory category,
        AccessLogInfoModel logInformation); @Override Response getContainerByCategory(String strategyId, String objectId, DataCategory category, String
        offerId); @Override JsonNode getContainerInformation(String strategyId, DataCategory type, String objectId,
        List<String> offerIds, boolean noCache); @Override Map<String, Boolean> checkObjectExisting(String strategyId, String objectId, DataCategory category,
        List<String> offerIds); @Override void deleteObjectInAllOffers(String strategyId, DataContext context); @Override void deleteObjectInOffers(String strategyId, DataContext context, List<String> offers); @Override List<BatchObjectInformationResponse> getBatchObjectInformation(String strategyId, DataCategory type,
        List<String> objectIds, List<String> offerIds); @Override void close(); static final String DIGEST; }