Commit f12dffc0 authored by mhellka's avatar mhellka
Browse files

Added APIs and SNAPSHOT permission to work with snapshots.

parent e09495d0
......@@ -2,11 +2,14 @@ package de.gwdg.cdstar.runtime.client;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import de.gwdg.cdstar.runtime.client.auth.ArchivePermission;
import de.gwdg.cdstar.runtime.client.exc.AccessError;
import de.gwdg.cdstar.runtime.client.exc.FileExists;
import de.gwdg.cdstar.runtime.client.exc.FileNotFound;
import de.gwdg.cdstar.runtime.client.exc.InvalidFileName;
import de.gwdg.cdstar.runtime.client.exc.InvalidSnapshotName;
import de.gwdg.cdstar.runtime.listener.ArchiveListener;
public interface CDStarArchive extends CDStarAnnotateable {
......@@ -212,4 +215,33 @@ public interface CDStarArchive extends CDStarAnnotateable {
*/
void setProperty(String name, String value);
/**
* Return a list of snapshots that exist for this archvie, ordered by the time
* they were created (old to new).
*/
List<CDStarSnapshot> getSnapshots();
/**
* Return a specific named snapshot, if it exists.
*/
default Optional<CDStarSnapshot> getSnapshot(String name) {
return getSnapshots().stream().filter(s -> s.getName().equals(name)).findFirst();
}
/**
* Create a new snapshot. This is only possible on archives with unmodified
* content ({@link #isContentModified()} must return false) and requires
* {@link ArchivePermission#SNAPSHOT} permissions. The snapshot name must be
* unique and should be short and simple (like a version number). Only ASCII
* letters, numbers, '-' and '.' are allowed for now.
*
* Note that this operation may block for a while if a large snapshot is
* created, depending on the backing storage.
*
* @throws InvalidSnapshotName if the supplied name contains invalid
* charakters or is already taken
* @throws IllegalStateException if the archive is modified
*/
CDStarSnapshot createSnapshot(String name) throws InvalidSnapshotName;
}
package de.gwdg.cdstar.runtime.client;
import java.util.Date;
import java.util.List;
import java.util.Optional;
public interface CDStarSnapshot extends CDStarAnnotateable {
/**
* Return the archive this snapshot was created from.
*/
CDStarArchive getSource();
/**
* Return the revision this snapshot is based on.
*/
String getRevision();
/**
* Return the name of this snapshot.
*/
String getName();
/**
* Return true if the snapshot is currently available and all content can be
* read, false otherwise.
*/
boolean isAvailable();
/**
* Return the date the snapshot was created.
*/
Date getCreated();
/**
* Return the name of the suer that created this snapshot.
*/
String getCreator();
/**
* Get a list of all files in this snapshot.
*
* @throws IllegalStateException if the snapshot was removed.
*/
List<CDStarFile> getFiles();
/**
* Return true if the file exists.
*/
boolean hasFile(String name);
/**
* Get an existing file with the given name, if it exists.
*/
Optional<CDStarFile> getFile(String name);
/**
* Remove this snapshot.
*/
void remove();
/**
* Return true if this snapshot no longer exists.
*/
boolean isRemoved();
}
......@@ -6,6 +6,7 @@ public enum ArchivePermission {
/* Basic archive access */
LOAD,
DELETE,
SNAPSHOT,
/* Access control */
READ_ACL,
CHANGE_ACL,
......
......@@ -62,10 +62,10 @@ public enum ArchivePermissionSet implements Iterable<ArchivePermission> {
READ(LIST, ArchivePermission.READ_FILES, ArchivePermission.READ_META),
WRITE(READ, ArchivePermission.CHANGE_FILES, ArchivePermission.CHANGE_META),
OWNER(WRITE, ArchivePermission.READ_ACL, ArchivePermission.CHANGE_ACL, ArchivePermission.DELETE,
ArchivePermission.CHANGE_PROFILE),
ArchivePermission.CHANGE_PROFILE, ArchivePermission.SNAPSHOT),
/* System account permission sets */
MANAGE(LIST, ArchivePermission.CHANGE_OWNER, ArchivePermission.READ_ACL, ArchivePermission.CHANGE_ACL,
ArchivePermission.CHANGE_PROFILE),
ArchivePermission.CHANGE_PROFILE),
ADMIN(ArchivePermission.values());
final EnumSet<ArchivePermission> permissions = EnumSet.noneOf(ArchivePermission.class);
......
package de.gwdg.cdstar.runtime.client.exc;
public class InvalidSnapshotName extends ClientError {
private static final long serialVersionUID = 894470101513996640L;
public InvalidSnapshotName(String name, String reason) {
super("Invalid snapshot name: " + name + " (" + reason + ")");
}
}
package de.gwdg.cdstar.runtime.client.exc;
/**
* This unchecked exception is thrown if an operation tries to modify a
* snapshot. Snapshots are always read-only.
*/
public class SnapshotLocked extends IllegalStateException {
private static final long serialVersionUID = -8102695906202684177L;
public SnapshotLocked() {
super("Snapshots are read-only");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment