Skip to content

Commit

Permalink
Merge pull request #4462 from IQSS/4460-dataset-storage-ids
Browse files Browse the repository at this point in the history
4460 dataset storage ids
  • Loading branch information
kcondon committed Feb 12, 2018
2 parents c6e1177 + 70efdf3 commit 6dd1fcb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ public void open (DataAccessOption... options) throws IOException {
} else if (isWriteAccess) {
//this checks whether a directory for a dataset exists
if (dataset.getFileSystemDirectory() != null && !Files.exists(dataset.getFileSystemDirectory())) {
Files.createDirectories(dataset.getFileSystemDirectory());
dataset.setStorageIdentifier("file://"+dataset.getAuthority()+dataset.getDoiSeparator()+dataset.getIdentifier());
Files.createDirectories(dataset.getFileSystemDirectory());
}
dataset.setStorageIdentifier("file://"+dataset.getAuthority()+dataset.getDoiSeparator()+dataset.getIdentifier());
}

} else if (dvObject instanceof Dataverse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ private String getDestinationKey(String auxItemTag) throws IOException {
if (dvObject instanceof DataFile) {
return getMainFileKey() + "." + auxItemTag;
} else if (dvObject instanceof Dataset) {
if (key == null) {
open();
}
return key + "/" + auxItemTag;
} else {
throw new IOException("S3AccessIO: This operation is only supported for Datasets and DataFiles.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public static Dataset persistDatasetLogoToStorageAndCreateThumbnail(Dataset data
StorageIO<Dataset> dataAccess = null;

try{
dataAccess = DataAccess.createNewStorageIO(dataset,"file");
dataAccess = DataAccess.createNewStorageIO(dataset,"placeholder");
}
catch(IOException ioex){
//TODO: Add a suitable waing message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import edu.harvard.iq.dataverse.api.imports.ImportUtil.ImportType;
import edu.harvard.iq.dataverse.authorization.Permission;
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
import edu.harvard.iq.dataverse.dataaccess.DataAccess;
import edu.harvard.iq.dataverse.datacapturemodule.DataCaptureModuleUtil;
import edu.harvard.iq.dataverse.datacapturemodule.ScriptRequestResponse;
import edu.harvard.iq.dataverse.engine.command.AbstractCommand;
Expand All @@ -15,6 +16,7 @@
import edu.harvard.iq.dataverse.engine.command.exception.CommandException;
import edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand Down Expand Up @@ -135,13 +137,15 @@ public Dataset execute(CommandContext ctxt) throws CommandException {
if (theDataset.getProtocol()==null) theDataset.setProtocol(protocol);
if (theDataset.getAuthority()==null) theDataset.setAuthority(authority);
if (theDataset.getDoiSeparator()==null) theDataset.setDoiSeparator(doiSeparator);
if(theDataset.getStorageIdentifier()==null) {
//FIXME: if the driver identifier is not set in the JVM options, should the storage identifier be set to file b default, or should an exception be thrown?
if(System.getProperty("dataverse.files.storage-driver-id")!=null){
theDataset.setStorageIdentifier(System.getProperty("dataverse.files.storage-driver-id")+"://"+theDataset.getAuthority()+theDataset.getDoiSeparator()+theDataset.getIdentifier());
}
else{
theDataset.setStorageIdentifier("file://"+theDataset.getAuthority()+theDataset.getDoiSeparator()+theDataset.getIdentifier());
if (theDataset.getStorageIdentifier() == null) {
try {
DataAccess.createNewStorageIO(theDataset, "placeholder");
} catch (IOException ioex) {
// if setting the storage identifier through createNewStorageIO fails, dataset creation
// does not have to fail. we just set the storage id to a default -SF
String storageDriver = (System.getProperty("dataverse.files.storage-driver-id") != null) ? System.getProperty("dataverse.files.storage-driver-id") : "file";
theDataset.setStorageIdentifier(storageDriver + "://" + theDataset.getAuthority()+theDataset.getDoiSeparator()+theDataset.getIdentifier());
logger.info("Failed to create StorageIO. StorageIdentifier set to default. Not fatal." + "(" + ioex.getMessage() + ")");
}
}
if (theDataset.getIdentifier()==null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private void cacheExport(DatasetVersion version, String format, JsonObject datas
Dataset dataset = version.getDataset();
StorageIO<Dataset> storageIO = null;
try {
storageIO = DataAccess.createNewStorageIO(dataset, "file");
storageIO = DataAccess.createNewStorageIO(dataset, "placeholder");
Channel outputChannel = storageIO.openAuxChannel("export_" + format + ".cached", DataAccessOption.WRITE_ACCESS);
outputStream = Channels.newOutputStream((WritableByteChannel) outputChannel);
} catch (IOException ioex) {
Expand Down

0 comments on commit 6dd1fcb

Please sign in to comment.