use of org.dcache.chimera.StorageLocatable in project dcache by dCache.
the class ChimeraNameSpaceProvider method clearCacheLocation.
@Override
public void clearCacheLocation(Subject subject, PnfsId pnfsId, String cacheLocation, boolean removeIfLast) throws CacheException {
LOGGER.debug("clearCacheLocation : {} for {}", cacheLocation, pnfsId);
try {
ExtendedInode inode = new ExtendedInode(_fs, pnfsId, NO_STAT);
_fs.clearInodeLocation(inode, StorageGenericLocation.DISK, cacheLocation);
if (removeIfLast) {
List<StorageLocatable> locations = _fs.getInodeLocations(inode, StorageGenericLocation.DISK);
if (locations.isEmpty()) {
LOGGER.debug("last location cleaned. removing file {}", inode);
_fs.remove(inode);
}
}
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file or directory: " + pnfsId, e);
} catch (ChimeraFsException e) {
LOGGER.error("Exception in clearCacheLocation for {} : {}", pnfsId, e);
throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
}
}
use of org.dcache.chimera.StorageLocatable in project dcache by dCache.
the class ChimeraNameSpaceProvider method commitUpload.
@Override
public FileAttributes commitUpload(Subject subject, FsPath temporaryPath, FsPath finalPath, Set<CreateOption> options, Set<FileAttribute> attributesToFetch) throws CacheException {
try {
FsPath temporaryDir = getParentOfFile(temporaryPath);
FsPath finalDir = getParentOfFile(finalPath);
checkIsTemporaryDirectory(temporaryPath, temporaryDir);
/* File must have been created...
*/
ExtendedInode uploadDirInode;
ExtendedInode temporaryDirInode;
ExtendedInode inodeOfFile;
try {
uploadDirInode = new ExtendedInode(_fs, _fs.path2inode(temporaryDir.parent().toString()));
temporaryDirInode = uploadDirInode.inodeOf(temporaryDir.name(), STAT);
inodeOfFile = temporaryDirInode.inodeOf(temporaryPath.name(), STAT);
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file or directory: " + temporaryPath, e);
}
/* ...and upload must have completed...
*/
ImmutableList<StorageLocatable> locations = inodeOfFile.getLocations();
if (locations.isEmpty()) {
throw new FileIsNewCacheException("Upload has not completed.");
}
/* ...and it must have the correct size.
*/
ImmutableList<String> size = inodeOfFile.getTag(TAG_EXPECTED_SIZE);
if (!size.isEmpty()) {
long expectedSize = Long.parseLong(size.get(0));
long actualSize = inodeOfFile.statCache().getSize();
if (expectedSize != actualSize) {
throw new FileCorruptedCacheException(expectedSize, actualSize);
}
}
/* Target directory must exist.
*/
ExtendedInode finalDirInode;
try {
finalDirInode = new ExtendedInode(_fs, _fs.path2inode(finalDir.toString()));
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file or directory: " + finalDir, e);
}
/* File must not exist unless overwrite is enabled.
*/
try {
ExtendedInode inodeOfExistingFile = finalDirInode.inodeOf(finalPath.name(), STAT);
if (!options.contains(CreateOption.OVERWRITE_EXISTING)) {
throw new FileExistsCacheException("File exists: " + finalPath);
}
/* User must be authorized to delete existing file.
*/
if (!Subjects.isExemptFromNamespaceChecks(subject)) {
FileAttributes attributesOfParent = getFileAttributesForPermissionHandler(finalDirInode);
FileAttributes attributesOfFile = getFileAttributesForPermissionHandler(inodeOfExistingFile);
if (_permissionHandler.canDeleteFile(subject, attributesOfParent, attributesOfFile) != ACCESS_ALLOWED) {
throw new PermissionDeniedCacheException("Overwrite denied: " + finalPath);
}
}
} catch (FileNotFoundChimeraFsException ignored) {
}
/* Read file attributes before moving the file. Otherwise the cached parent will
* be gone.
*/
FileAttributes attributes = getFileAttributes(inodeOfFile, attributesToFetch);
/* File is moved to correct directory.
*/
_fs.rename(inodeOfFile, temporaryDirInode, temporaryPath.name(), finalDirInode, finalPath.name());
/* Delete temporary upload directory and any files in it.
*/
removeRecursively(uploadDirInode, temporaryDir.name(), temporaryDirInode, i -> {
});
return attributes;
} catch (ChimeraFsException e) {
throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
} catch (NumberFormatException e) {
throw new FileCorruptedCacheException("Failed to commit file: " + e.getMessage());
}
}
use of org.dcache.chimera.StorageLocatable in project dcache by dCache.
the class ChimeraNameSpaceProvider method getCacheLocation.
@Override
public List<String> getCacheLocation(Subject subject, PnfsId pnfsId) throws CacheException {
try {
List<String> locations = new ArrayList<>();
ExtendedInode inode = new ExtendedInode(_fs, pnfsId, NO_STAT);
List<StorageLocatable> localyManagerLocations = _fs.getInodeLocations(inode, StorageGenericLocation.DISK);
for (StorageLocatable location : localyManagerLocations) {
locations.add(location.location());
}
return locations;
} catch (ChimeraFsException e) {
throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
}
}
Aggregations