Skip to content

Commit

Permalink
Store number is specific if all storages are synchronized.
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmajchrak committed Dec 18, 2023
1 parent 9275741 commit 5828022
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions dspace/config/clarin-dspace.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5828022

Please sign in to comment.