use of diskCacheV111.util.RetentionPolicy in project dcache by dCache.
the class ALRPStorageUnitQoSProvider method fetchRequirements.
@Override
public FileQoSRequirements fetchRequirements(FileQoSUpdate update) throws QoSException {
FileQoSRequirements descriptor = initialize(update);
if (descriptor == null) {
/*
* Should only happen when a CLEAR CACHE LOCATION finds no locations.
*/
return null;
}
FileAttributes attributes = descriptor.getAttributes();
AccessLatency accessLatency = attributes.getAccessLatency();
RetentionPolicy retentionPolicy = attributes.getRetentionPolicy();
String unitKey = attributes.getStorageClass() + "@" + attributes.getHsm();
SelectionUnit unit = poolSelectionUnit().getStorageUnit(unitKey);
if (!(unit instanceof StorageUnit)) {
throw new QoSException(unitKey + " does not correspond to a storage unit; " + "cannot retrieve requirements for " + descriptor.getPnfsId());
}
StorageUnit storageUnit = (StorageUnit) unit;
Integer required = storageUnit.getRequiredCopies();
List<String> onlyOneCopyPer = storageUnit.getOnlyOneCopyPer();
if (retentionPolicy == CUSTODIAL) {
/*
* REVISIT -- currently we support only one tape location.
*/
descriptor.setRequiredTape(1);
} else {
descriptor.setRequiredTape(0);
}
if (accessLatency == ONLINE) {
/*
* REVISIT -- current override of file AL based on storage unit
* REVISIT -- eventually we will want to override the storage unit default for a given file
*/
descriptor.setRequiredDisk(required == null ? 1 : required);
if (onlyOneCopyPer != null) {
descriptor.setPartitionKeys(new HashSet<>(onlyOneCopyPer));
}
} else {
descriptor.setRequiredDisk(0);
}
LOGGER.debug("fetchRequirements for {}, returning {}.", update, descriptor);
return descriptor;
}
use of diskCacheV111.util.RetentionPolicy in project dcache by dCache.
the class ChimeraNameSpaceProvider method createUploadPath.
@Override
public FsPath createUploadPath(Subject subject, FsPath path, FsPath rootPath, Long size, AccessLatency al, RetentionPolicy rp, String spaceToken, Set<CreateOption> options) throws CacheException {
checkState(_uploadDirectory != null, "Upload directory is not configured.");
try {
/* Parent directory must exist.
*/
ExtendedInode parentOfPath = options.contains(CreateOption.CREATE_PARENTS) ? installDirectory(subject, path.parent(), INHERIT_MODE) : lookupDirectory(subject, path.parent());
FileAttributes attributesOfParent = !Subjects.isExemptFromNamespaceChecks(subject) ? getFileAttributesForPermissionHandler(parentOfPath) : null;
/* File must not exist unless overwrite is enabled.
*/
try {
ExtendedInode inodeOfPath = parentOfPath.inodeOf(path.name(), STAT);
if (!options.contains(CreateOption.OVERWRITE_EXISTING) || (inodeOfPath.statCache().getMode() & UnixPermission.S_TYPE) != UnixPermission.S_IFREG) {
throw new FileExistsCacheException("File exists: " + path);
}
/* User must be authorized to delete existing file.
*/
if (!Subjects.isExemptFromNamespaceChecks(subject)) {
FileAttributes attributesOfPath = getFileAttributesForPermissionHandler(inodeOfPath);
if (_permissionHandler.canDeleteFile(subject, attributesOfParent, attributesOfPath) != ACCESS_ALLOWED) {
throw new PermissionDeniedCacheException("Access denied: " + path);
}
}
} catch (FileNotFoundChimeraFsException ignored) {
}
/* User must be authorized to create file.
*/
if (!Subjects.isExemptFromNamespaceChecks(subject)) {
if (_permissionHandler.canCreateFile(subject, attributesOfParent) != ACCESS_ALLOWED) {
throw new PermissionDeniedCacheException("Access denied: " + path);
}
}
/* Attributes are inherited from real parent directory.
*/
int mode = parentOfPath.statCache().getMode() & UnixPermission.S_PERMS;
int gid;
if ((mode & UnixPermission.S_ISGID) != 0) {
gid = parentOfPath.statCache().getGid();
} else if (Subjects.isNobody(subject) || _inheritFileOwnership) {
gid = parentOfPath.statCache().getGid();
} else {
gid = Ints.checkedCast(Subjects.getPrimaryGid(subject));
}
int uid;
if (Subjects.isNobody(subject) || _inheritFileOwnership) {
uid = parentOfPath.statCache().getUid();
} else {
uid = Ints.checkedCast(Subjects.getUid(subject));
}
/* ACLs are copied from real parent to the temporary upload directory
* such that the upload is allowed (in case write permissions rely
* on ACLs) and such that the file will inherit the correct ACLs.
*/
List<ACE> acl = _fs.getACL(parentOfPath);
/* The temporary upload directory has the same tags as the real parent,
* except target file specific properties are stored as tags local to
* the upload directory.
*/
Map<String, byte[]> tags = Maps.newHashMap(parentOfPath.getTags());
if (spaceToken != null) {
tags.put(TAG_WRITE_TOKEN, spaceToken.getBytes(UTF_8));
/* If client provides space token to upload to, the access latency and
* retention policy tags of the upload directory must be disregarded.
*/
tags.remove(TAG_ACCESS_LATENCY);
tags.remove(TAG_RETENTION_POLICY);
}
if (al != null) {
tags.put(TAG_ACCESS_LATENCY, al.toString().getBytes(UTF_8));
}
if (rp != null) {
tags.put(TAG_RETENTION_POLICY, rp.toString().getBytes(UTF_8));
}
if (size != null) {
tags.put(TAG_EXPECTED_SIZE, size.toString().getBytes(UTF_8));
}
tags.put(TAG_PATH, path.toString().getBytes(UTF_8));
/* Upload directory may optionally be relative to the user's root path. Whether
* that's the case depends on if the configured upload directory is an absolute
* or relative path.
*/
FsPath uploadDirectory = rootPath.resolve(_uploadDirectory);
if (_uploadSubDirectory != null) {
uploadDirectory = uploadDirectory.chroot(String.format(_uploadSubDirectory, threadId.get()));
}
/* Upload directory must exist and have the right permissions.
*/
ExtendedInode inodeOfUploadDir = installSystemDirectory(uploadDirectory, 0711, Collections.emptyList(), Collections.emptyMap());
if (inodeOfUploadDir.statCache().getUid() != 0) {
LOGGER.error("Owner must be root: {}", uploadDirectory);
throw new CacheException("Owner must be root: " + uploadDirectory);
}
if ((inodeOfUploadDir.statCache().getMode() & UnixPermission.S_PERMS) != 0711) {
LOGGER.error("File mode must be 0711: {}", uploadDirectory);
throw new CacheException("File mode must be 0711: " + uploadDirectory);
}
/* Use cryptographically strong pseudo random UUID to create temporary upload directory.
*/
UUID uuid = UUID.randomUUID();
_fs.mkdir(inodeOfUploadDir, uuid.toString(), uid, gid, mode, acl, tags);
return uploadDirectory.child(uuid.toString()).child(path.name());
} catch (ChimeraFsException e) {
LOGGER.error("Problem with database: {}", e.getMessage());
throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
}
}
use of diskCacheV111.util.RetentionPolicy in project dcache by dCache.
the class PerformanceTest method processOperation.
private void processOperation(Operation aOp, String path) {
try {
switch(aOp) {
case CREATE_ENTRY:
provider.createFile(Subjects.ROOT, path, FileAttributes.of().uid(UID).gid(GID).mode(0664).build(), EnumSet.noneOf(FileAttribute.class));
break;
case PATH_TO_PNFS_ID:
getPnfsid(path);
break;
case FILE_META_DATA:
provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.of(OWNER, OWNER_GROUP, MODE, TYPE, SIZE, CREATION_TIME, ACCESS_TIME, MODIFICATION_TIME, CHANGE_TIME));
break;
case DELETE_ENTRY:
provider.deleteEntry(Subjects.ROOT, EnumSet.allOf(FileType.class), path, EnumSet.noneOf(FileAttribute.class));
break;
case PNFS_ID_TO_PATH:
provider.pnfsidToPath(Subjects.ROOT, getPnfsid(path));
break;
case FIND:
provider.find(Subjects.ROOT, getPnfsid(path));
break;
case ADD_CHECKSUM:
provider.setFileAttributes(Subjects.ROOT, getPnfsid(path), FileAttributes.ofChecksum(CHECKSUM), EnumSet.noneOf(FileAttribute.class));
break;
case GET_CHECKSUMS:
provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.of(FileAttribute.CHECKSUM)).getChecksums();
break;
case SET_FILE_ATTR:
provider.setFileAttributes(Subjects.ROOT, getPnfsid(path), FileAttributes.of().accessLatency(ONLINE).retentionPolicy(REPLICA).build(), EnumSet.noneOf(FileAttribute.class));
break;
case GET_FILE_ATTR:
provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.allOf(FileAttribute.class));
break;
case ADD_CACHE_LOC:
provider.addCacheLocation(Subjects.ROOT, getPnfsid(path), CACHE_LOCATION);
break;
case GET_CACHE_LOC:
provider.getCacheLocation(Subjects.ROOT, getPnfsid(path));
break;
case STORAGE_INFO:
provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.of(FileAttribute.STORAGEINFO)).getStorageInfo();
break;
case SET_STORAGE_INFO:
StorageInfo info = provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.of(FileAttribute.STORAGEINFO)).getStorageInfo();
info.setHsm("hsm");
info.setKey("store", "test");
info.setKey("group", "disk");
info.addLocation(URI.create("osm://hsm/?store=test&group=disk&bdif=1234"));
provider.setFileAttributes(Subjects.ROOT, getPnfsid(path), FileAttributes.ofStorageInfo(info), EnumSet.noneOf(FileAttribute.class));
break;
case MKDIR:
provider.createDirectory(Subjects.ROOT, path, FileAttributes.of().uid(UID).gid(GID).mode(0755).build());
break;
case RMDIR:
provider.deleteEntry(Subjects.ROOT, EnumSet.of(FileType.DIR), path, EnumSet.noneOf(FileAttribute.class));
break;
default:
break;
}
} catch (CacheException e) {
System.err.println("Exception " + aOp.getUserInput() + " :" + e.getMessage());
}
}
use of diskCacheV111.util.RetentionPolicy in project dcache by dCache.
the class ChimeraHsmStorageInfoExtractor method getRetentionPolicy.
@Override
public RetentionPolicy getRetentionPolicy(ExtendedInode inode) throws CacheException {
try {
if (!inode.exists()) {
throw new FileNotFoundCacheException(inode.toString() + " does not exists");
}
ExtendedInode dirInode;
if (inode.isDirectory()) {
dirInode = inode;
} else {
if (inode.statCache().isDefined(Stat.StatAttributes.RETENTION_POLICY)) {
return inode.statCache().getRetentionPolicy();
}
dirInode = inode.getParent();
if (dirInode == null) {
throw new FileNotFoundCacheException("File " + inode + " has been deleted.");
}
}
Optional<String> retentionPolicy = getFirstLine(dirInode.getTag("RetentionPolicy"));
if (retentionPolicy.isPresent()) {
try {
return RetentionPolicy.getRetentionPolicy(retentionPolicy.get());
} catch (IllegalArgumentException e) {
LOGGER.error("Badly formatted RetentionPolicy tag in {}: {}", dirInode, e.getMessage());
}
}
Optional<String> spaceToken = getFirstLine(dirInode.getTag("WriteToken"));
if (spaceToken.isPresent()) {
return null;
}
return getDefaultRetentionPolicy();
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException(e.getMessage(), e);
} catch (ChimeraFsException e) {
throw new CacheException("Failed to obtain RetentionPolicy: " + e.getMessage(), e);
}
}
use of diskCacheV111.util.RetentionPolicy in project dcache by dCache.
the class PnfsManagerTest method testDefaultALandRP.
@Test
public void testDefaultALandRP() throws ChimeraFsException {
/*
* this test relays on the fact that default values in PnfsManager
* is CUSTODIAL/NEARLINE
*/
// use back door to create the tag
FsInode dirInode = _fs.path2inode("/pnfs/testRoot");
_fs.createTag(dirInode, "AccessLatency");
_fs.createTag(dirInode, "RetentionPolicy");
String al = "ONLINE";
String rp = "OUTPUT";
_fs.setTag(dirInode, "AccessLatency", al.getBytes(), 0, al.getBytes().length);
_fs.setTag(dirInode, "RetentionPolicy", rp.getBytes(), 0, rp.getBytes().length);
PnfsCreateEntryMessage pnfsCreateEntryMessage = new PnfsCreateEntryMessage("/pnfs/testRoot/testDefaultALandRP", FileAttributes.ofFileType(REGULAR));
_pnfsManager.createEntry(pnfsCreateEntryMessage);
FileAttributes fileAttributes = pnfsCreateEntryMessage.getFileAttributes();
assertEquals("AccessLatensy is not taken from the parent directory", AccessLatency.ONLINE, fileAttributes.getAccessLatency());
assertEquals("RetentionPolicy is not taken from the parent directory", RetentionPolicy.OUTPUT, fileAttributes.getRetentionPolicy());
}
Aggregations