diff --git a/dspace-api/src/main/java/org/dspace/storage/bitstore/BitstreamStorageServiceImpl.java b/dspace-api/src/main/java/org/dspace/storage/bitstore/BitstreamStorageServiceImpl.java index b8a1a2e96ad4..f86296383dba 100644 --- a/dspace-api/src/main/java/org/dspace/storage/bitstore/BitstreamStorageServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/storage/bitstore/BitstreamStorageServiceImpl.java @@ -28,6 +28,7 @@ import org.dspace.content.service.BitstreamService; import org.dspace.core.Context; import org.dspace.core.Utils; +import org.dspace.services.ConfigurationService; import org.dspace.storage.bitstore.service.BitstreamStorageService; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; @@ -64,11 +65,14 @@ public class BitstreamStorageServiceImpl implements BitstreamStorageService, Ini * log4j log */ private static final Logger log = LogManager.getLogger(); + private static final int SYNCHRONIZED_STORES_NUMBER = 77; @Autowired(required = true) protected BitstreamService bitstreamService; @Autowired(required = true) protected ChecksumHistoryService checksumHistoryService; + @Autowired(required = true) + protected ConfigurationService configurationService; /** * asset stores @@ -107,10 +111,17 @@ public UUID store(Context context, Bitstream bitstream, InputStream is) throws S * other method of working out where to put a new bitstream, here's * where it should go */ + boolean isEnabled = configurationService.getBooleanProperty("sync.storage.service.enabled", false); + if (isEnabled) { + bitstream.setStoreNumber(SYNCHRONIZED_STORES_NUMBER); + } else { + bitstream.setStoreNumber(incoming); + } bitstream.setStoreNumber(incoming); bitstream.setDeleted(true); bitstream.setInternalId(id); + BitStoreService store = this.getStore(incoming); //For efficiencies sake, PUT is responsible for setting bitstream size_bytes, checksum, and checksum_algorithm store.put(bitstream, is); diff --git a/dspace-api/src/main/java/org/dspace/storage/bitstore/ClarinS3BitStoreService.java b/dspace-api/src/main/java/org/dspace/storage/bitstore/ClarinS3BitStoreService.java index 8aeef77ae6fd..85bbc72a1ea5 100644 --- a/dspace-api/src/main/java/org/dspace/storage/bitstore/ClarinS3BitStoreService.java +++ b/dspace-api/src/main/java/org/dspace/storage/bitstore/ClarinS3BitStoreService.java @@ -17,6 +17,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.dspace.content.Bitstream; +import org.dspace.services.ConfigurationService; import org.springframework.beans.factory.annotation.Autowired; /** @@ -30,14 +31,23 @@ public class ClarinS3BitStoreService extends S3BitStoreService { * log4j log */ private static final Logger log = LogManager.getLogger(ClarinS3BitStoreService.class); + private boolean syncEnabled = false; @Autowired(required = true) DSBitStoreService dsBitStoreService; + @Autowired(required = true) + ConfigurationService configurationService; + public ClarinS3BitStoreService() { super(); } + public void init() throws IOException { + super.init(); + syncEnabled = configurationService.getBooleanProperty("sync.storage.service.enabled", false); + } + @Override public void put(Bitstream bitstream, InputStream in) throws IOException { String key = getFullKey(bitstream.getInternalId()); @@ -58,10 +68,11 @@ public void put(Bitstream bitstream, InputStream in) throws IOException { bitstream.setChecksum(localChecksum); bitstream.setChecksumAlgorithm(CSA); - // Upload file into local assetstore - File localFile = dsBitStoreService.getFile(bitstream); - FileUtils.copyFile(scratchFile, localFile); - + if (syncEnabled) { + // Upload file into local assetstore + File localFile = dsBitStoreService.getFile(bitstream); + FileUtils.copyFile(scratchFile, localFile); + } } catch (AmazonClientException | IOException | InterruptedException e) { log.error("put(" + bitstream.getInternalId() + ", is)", e); throw new IOException(e); @@ -78,8 +89,10 @@ public void remove(Bitstream bitstream) throws IOException { try { // Remove file from S3 s3Service.deleteObject(getBucketName(), key); - // Remove file from local assetstore - dsBitStoreService.remove(bitstream); + if (syncEnabled) { + // Remove file from local assetstore + dsBitStoreService.remove(bitstream); + } } catch (AmazonClientException e) { log.error("remove(" + key + ")", e); throw new IOException(e); diff --git a/dspace/config/clarin-dspace.cfg b/dspace/config/clarin-dspace.cfg index 0064162af6ad..86cd4ea11448 100644 --- a/dspace/config/clarin-dspace.cfg +++ b/dspace/config/clarin-dspace.cfg @@ -238,3 +238,7 @@ shibboleth.name.conversion.outputEncoding = UTF-8 ### File preview ### # File preview is enabled by default file.preview.enabled = false + +### Storage service ### +# Synchronization is NOT enabled by default +sync.storage.service.enabled = true