Search in sources :

Example 1 with ChimeraFsException

use of org.dcache.chimera.ChimeraFsException 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 ChimeraFsException

use of org.dcache.chimera.ChimeraFsException in project dcache by dCache.

the class ChimeraNameSpaceProvider method cancelUpload.

@Override
public Collection<FileAttributes> cancelUpload(Subject subject, FsPath temporaryPath, FsPath finalPath, Set<FileAttribute> requested, String explanation) throws CacheException {
    List<FileAttributes> deleted = new ArrayList();
    try {
        FsPath temporaryDir = getParentOfFile(temporaryPath);
        checkIsTemporaryDirectory(temporaryPath, temporaryDir);
        /* Temporary upload directory must exist.
             */
        ExtendedInode uploadDirInode;
        try {
            uploadDirInode = new ExtendedInode(_fs, _fs.path2inode(temporaryDir.parent().toString()));
        } catch (FileNotFoundChimeraFsException e) {
            throw new FileNotFoundCacheException("No such file or directory: " + temporaryDir, e);
        }
        /* Delete temporary upload directory and any files in it.
             */
        String name = temporaryPath.parent().name();
        removeRecursively(uploadDirInode, name, uploadDirInode.inodeOf(name, STAT), i -> {
            try {
                if (i.getFileType() == FileType.REGULAR) {
                    deleted.add(getFileAttributes(i, requested));
                }
            } catch (CacheException | ChimeraFsException e) {
                LOGGER.info("Unable to identify deleted file for upload cancellation: {}", e.toString());
            }
        });
    } catch (ChimeraFsException e) {
        throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
    }
    return deleted;
}
Also used : 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) ChimeraFsException(org.dcache.chimera.ChimeraFsException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) ArrayList(java.util.ArrayList) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) FsPath(diskCacheV111.util.FsPath)

Example 3 with ChimeraFsException

use of org.dcache.chimera.ChimeraFsException in project dcache by dCache.

the class ChimeraNameSpaceProvider method writeExtendedAttribute.

public void writeExtendedAttribute(Subject subject, FsPath path, String name, byte[] value, SetExtendedAttributeMode mode) throws CacheException {
    try {
        ExtendedInode target = pathToInode(subject, path.toString());
        if (!Subjects.isExemptFromNamespaceChecks(subject)) {
            FileAttributes attributes = getFileAttributesForPermissionHandler(target);
            if (target.isDirectory()) {
                if (_permissionHandler.canCreateFile(subject, attributes) != ACCESS_ALLOWED) {
                    throw new PermissionDeniedCacheException("Access denied");
                }
            } else {
                if (_permissionHandler.canWriteFile(subject, attributes) != ACCESS_ALLOWED) {
                    throw new PermissionDeniedCacheException("Access denied");
                }
            }
        }
        FileSystemProvider.SetXattrMode m;
        switch(mode) {
            case CREATE:
                m = FileSystemProvider.SetXattrMode.CREATE;
                break;
            case REPLACE:
                m = FileSystemProvider.SetXattrMode.REPLACE;
                break;
            case EITHER:
                m = FileSystemProvider.SetXattrMode.EITHER;
                break;
            default:
                throw new RuntimeException();
        }
        _fs.setXattr(target, name, value, m);
    } catch (NoXdataChimeraException e) {
        throw new NoAttributeCacheException(e.getMessage(), e);
    } catch (FileExistsChimeraFsException e) {
        throw new AttributeExistsCacheException(e.getMessage(), e);
    } catch (FileNotFoundChimeraFsException e) {
        throw new FileNotFoundCacheException("No such file " + path);
    } catch (ChimeraFsException e) {
        throw new CacheException("Failed to list extended attributes: " + Exceptions.messageOrClassName(e), e);
    }
}
Also used : NoXdataChimeraException(org.dcache.chimera.NoXdataChimeraException) 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) SetXattrMode(org.dcache.chimera.FileSystemProvider.SetXattrMode) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) 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) FileSystemProvider(org.dcache.chimera.FileSystemProvider) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException)

Example 4 with ChimeraFsException

use of org.dcache.chimera.ChimeraFsException in project dcache by dCache.

the class ChimeraNameSpaceProvider method removeLabel.

/**
 * @param subject The user making the request. Remove a label from a file.
 * @param path    The file from which the label  is deleted.
 * @param label   The name of the label to remove.
 * @throws FileNotFoundCacheException     if the path does not exist.
 * @throws PermissionDeniedCacheException if the user is not allowed to remove the label.
 * @throws CacheException                 a generic failure in removing the labe.
 */
public void removeLabel(Subject subject, FsPath path, String label) throws CacheException {
    try {
        ExtendedInode target = pathToInode(subject, path.toString());
        if (!Subjects.isRoot(subject)) {
            FileAttributes attributes = getFileAttributesForPermissionHandler(target);
            if (target.isDirectory()) {
                throw new NotFileCacheException("Directory object cannot have a label.");
            } else {
                if (_permissionHandler.canWriteFile(subject, attributes) != ACCESS_ALLOWED) {
                    throw new PermissionDeniedCacheException("Access denied");
                }
            }
        }
        _fs.removeLabel(target, label);
    } catch (FileNotFoundChimeraFsException e) {
        throw new FileNotFoundCacheException("No such file " + path);
    } catch (ChimeraFsException e) {
        throw new CacheException("Failed to remove the label: " + Exceptions.messageOrClassName(e), e);
    }
}
Also used : FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) 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) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 5 with ChimeraFsException

use of org.dcache.chimera.ChimeraFsException 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)

Aggregations

ChimeraFsException (org.dcache.chimera.ChimeraFsException)20 CacheException (diskCacheV111.util.CacheException)18 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)17 FileNotFoundChimeraFsException (org.dcache.chimera.FileNotFoundChimeraFsException)15 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)11 DirNotEmptyChimeraFsException (org.dcache.chimera.DirNotEmptyChimeraFsException)11 FileExistsChimeraFsException (org.dcache.chimera.FileExistsChimeraFsException)11 AttributeExistsCacheException (diskCacheV111.util.AttributeExistsCacheException)10 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)10 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)10 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)10 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)10 LockedCacheException (diskCacheV111.util.LockedCacheException)10 NoAttributeCacheException (diskCacheV111.util.NoAttributeCacheException)10 NotDirCacheException (diskCacheV111.util.NotDirCacheException)10 NotFileCacheException (diskCacheV111.util.NotFileCacheException)10 FileAttributes (org.dcache.vehicles.FileAttributes)7 FsPath (diskCacheV111.util.FsPath)3 StorageInfo (diskCacheV111.vehicles.StorageInfo)3 IOException (java.io.IOException)3