Skip to content
Snippets Groups Projects
Commit 8d44542c authored by buczekp's avatar buczekp
Browse files

[LMS-2106] implement deletion from archive and simple existence test

SVN: 20296
parent 7007539e
No related branches found
No related tags found
No related merge requests found
......@@ -27,8 +27,8 @@ import ch.systemsx.cisd.openbis.dss.generic.server.plugins.tasks.ArchiverTaskCon
import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription;
/**
* Archiver plugin which copies data sets to a destination folder using rsync (if it is remote).
* The destination can be
* Archiver plugin which copies data sets to a destination folder using rsync (if it is remote). The
* destination can be
* <ul>
* <li>on the local file system,
* <li>a mounted remote folder,
......@@ -62,39 +62,16 @@ public class RsyncArchiver extends AbstractArchiverProcessingPlugin
this.sshCommandExecutorFactory = sshCommandExecutorFactory;
}
private boolean isInitialized()
{
return copier != null;
}
private void init()
{
this.copier =
new RsyncDataSetCopier(properties, pathCopierFactory, sshCommandExecutorFactory);
}
private Status doArchive(DatasetDescription dataset, File originalData)
{
return copier.copyToDestination(originalData, dataset);
}
private Status doUnarchive(DatasetDescription dataset, File originalData)
{
return copier.retrieveFromDestination(originalData, dataset);
}
@Override
protected DatasetProcessingStatuses doArchive(List<DatasetDescription> datasets,
ArchiverTaskContext context) throws UserFailureException
{
if (isInitialized() == false)
{
init();
}
initIfNecessary();
DatasetProcessingStatuses statuses = new DatasetProcessingStatuses();
for (DatasetDescription dataset : datasets)
{
File originalData = context.getDirectoryProvider().getDataSetDirectory(dataset);
File originalData = getDatasetDirectory(context, dataset);
Status status = doArchive(dataset, originalData);
statuses.addResult(dataset.getDatasetCode(), status, true);
}
......@@ -106,36 +83,77 @@ public class RsyncArchiver extends AbstractArchiverProcessingPlugin
protected DatasetProcessingStatuses doUnarchive(List<DatasetDescription> datasets,
ArchiverTaskContext context) throws UserFailureException
{
if (isInitialized() == false)
{
init();
}
initIfNecessary();
// no need to lock - this is processing task
DatasetProcessingStatuses statuses = new DatasetProcessingStatuses();
for (DatasetDescription dataset : datasets)
{
File originalData = context.getDirectoryProvider().getDataSetDirectory(dataset);
File originalData = getDatasetDirectory(context, dataset);
Status status = doUnarchive(dataset, originalData);
statuses.addResult(dataset.getDatasetCode(), status, false);
}
return createStatusesFrom(Status.OK, datasets, false);
return statuses;
}
// TODO do we really need the status?
protected DatasetProcessingStatuses doDeleteFromArchive(List<DatasetDescription> datasets,
ArchiverTaskContext context)
{
initIfNecessary();
// no need to lock - this is processing task
DatasetProcessingStatuses statuses = new DatasetProcessingStatuses();
for (DatasetDescription dataset : datasets)
{
File originalData = getDatasetDirectory(context, dataset);
Status status = doDeleteFromArchive(dataset, originalData);
statuses.addResult(dataset.getDatasetCode(), status, false); // false -> deletion
}
return statuses;
}
protected boolean isProperlyArchived() throws UserFailureException
/**
* @return <code>true</code> if the dataset is present in the archive, <code>false</code>
* otherwise.
*/
protected boolean isDataSetPresentInArchive(DatasetDescription dataset,
ArchiverTaskContext context)
{
return true;
initIfNecessary();
File originalData = getDatasetDirectory(context, dataset);
return copier.isPresentInDestination(originalData, dataset);
}
protected void doDeleteFromArchive() throws UserFailureException
private void initIfNecessary()
{
if (copier == null)
{
this.copier =
new RsyncDataSetCopier(properties, pathCopierFactory, sshCommandExecutorFactory);
}
}
private Status doArchive(DatasetDescription dataset, File originalData)
{
return copier.copyToDestination(originalData, dataset);
}
protected void doDeleteFromDss() throws UserFailureException
private Status doUnarchive(DatasetDescription dataset, File originalData)
{
return copier.retrieveFromDestination(originalData, dataset);
}
private Status doDeleteFromArchive(DatasetDescription dataset, File originalData)
{
return copier.deleteFromDestination(originalData, dataset);
}
private File getDatasetDirectory(ArchiverTaskContext context, DatasetDescription dataset)
{
return context.getDirectoryProvider().getDataSetDirectory(dataset);
}
}
......@@ -44,7 +44,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription;
*
* @author Piotr Buczek
*/
public class RsyncDataSetCopier
public class RsyncDataSetCopier // TODO rename to DataSetFileOperationsManager
{
private static final String DESTINATION_KEY = "destination";
......@@ -101,8 +101,8 @@ public class RsyncDataSetCopier
}
/**
* Copies specified data file/folder to destination specified in constructor. The path of the
* file/folder at the destination is defined by the original location of the data set.
* Copies specified dataset's data to destination specified in constructor. The path at the
* destination is defined by the original location of the data set.
*/
public Status copyToDestination(File originalData, DatasetDescription dataset)
{
......@@ -121,8 +121,8 @@ public class RsyncDataSetCopier
}
/**
* Retrieves specified data file/folder from the destination specified in constructor. The path
* at the destination is defined by original location of the data set.
* Retrieves specified datases's data from the destination specified in constructor. The path at
* the destination is defined by original location of the data set.
*/
public Status retrieveFromDestination(File originalData, DatasetDescription dataset)
{
......@@ -140,6 +140,51 @@ public class RsyncDataSetCopier
}
}
/**
* Deletes specified datases's data from the destination specified in constructor. The path at
* the destination is defined by original location of the data set.
*/
public Status deleteFromDestination(File originalData, DatasetDescription dataset)
{
try
{
File destinationFolder = new File(destination, dataset.getDataSetLocation());
BooleanStatus destinationExists = destinationExists(destinationFolder);
if (destinationExists.isSuccess())
{
executor.deleteFolder(destinationFolder);
} else
{
operationLog.info("Data of data set '" + dataset.getDatasetCode()
+ "' don't exist in the destination '" + destinationFolder.getPath()
+ "'. There is nothing to delete.");
}
return Status.OK;
} catch (ExceptionWithStatus ex)
{
return ex.getStatus();
}
}
/**
* Checks if specified dataset's data are present in the destination specified in constructor.
* The path at the destination is defined by original location of the data set.
*/
public boolean isPresentInDestination(File originalData, DatasetDescription dataset)
{
try
{
File destinationFolder = new File(destination, dataset.getDataSetLocation());
BooleanStatus destinationExists = destinationExists(destinationFolder);
// TODO check file sizes
return destinationExists.isSuccess();
} catch (ExceptionWithStatus ex)
{
// TODO?
return false; // ex.getStatus();
}
}
private void checkDestinationExists(File destinationFolder)
{
BooleanStatus destinationExists = destinationExists(destinationFolder);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment