Search in sources :

Example 1 with StorageLocatable

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());
    }
}
Also used : FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) ChimeraFsException(org.dcache.chimera.ChimeraFsException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) LockedCacheException(diskCacheV111.util.LockedCacheException) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) CacheException(diskCacheV111.util.CacheException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) StorageLocatable(org.dcache.chimera.StorageLocatable) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException)

Example 2 with StorageLocatable

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());
    }
}
Also used : FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) LockedCacheException(diskCacheV111.util.LockedCacheException) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) CacheException(diskCacheV111.util.CacheException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) StorageLocatable(org.dcache.chimera.StorageLocatable) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) ChimeraFsException(org.dcache.chimera.ChimeraFsException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) FsPath(diskCacheV111.util.FsPath)

Example 3 with StorageLocatable

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());
    }
}
Also used : ChimeraFsException(org.dcache.chimera.ChimeraFsException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) LockedCacheException(diskCacheV111.util.LockedCacheException) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) CacheException(diskCacheV111.util.CacheException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) ArrayList(java.util.ArrayList) StorageLocatable(org.dcache.chimera.StorageLocatable)

Aggregations

AttributeExistsCacheException (diskCacheV111.util.AttributeExistsCacheException)3 CacheException (diskCacheV111.util.CacheException)3 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)3 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)3 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)3 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)3 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)3 LockedCacheException (diskCacheV111.util.LockedCacheException)3 NoAttributeCacheException (diskCacheV111.util.NoAttributeCacheException)3 NotDirCacheException (diskCacheV111.util.NotDirCacheException)3 NotFileCacheException (diskCacheV111.util.NotFileCacheException)3 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)3 ChimeraFsException (org.dcache.chimera.ChimeraFsException)3 DirNotEmptyChimeraFsException (org.dcache.chimera.DirNotEmptyChimeraFsException)3 FileExistsChimeraFsException (org.dcache.chimera.FileExistsChimeraFsException)3 FileNotFoundChimeraFsException (org.dcache.chimera.FileNotFoundChimeraFsException)3 StorageLocatable (org.dcache.chimera.StorageLocatable)3 FsPath (diskCacheV111.util.FsPath)1 ArrayList (java.util.ArrayList)1 FileAttributes (org.dcache.vehicles.FileAttributes)1