Search in sources :

Example 1 with LABELS

use of org.dcache.namespace.FileAttribute.LABELS in project dcache by dCache.

the class ChimeraNameSpaceProvider method setFileAttributes.

@Override
public FileAttributes setFileAttributes(Subject subject, PnfsId pnfsId, FileAttributes attr, Set<FileAttribute> acquire) throws CacheException {
    LOGGER.debug("File attributes update: {}", attr.getDefinedAttributes());
    try {
        ExtendedInode inode = new ExtendedInode(_fs, pnfsId, Subjects.isExemptFromNamespaceChecks(subject) ? NO_STAT : STAT);
        if (!Subjects.isExemptFromNamespaceChecks(subject)) {
            FileAttributes attributes = getFileAttributesForPermissionHandler(inode);
            if (_permissionHandler.canSetAttributes(subject, attributes, attr) != ACCESS_ALLOWED) {
                throw new PermissionDeniedCacheException("Access denied: " + pnfsId);
            }
        }
        /* Update the t_inodes row first (the Stat object) to acquire a FOR UPDATE / FOR NO KEY UPDATE
             * first. If the inserts into secondary table referring t_inodes would be done first, the
             * referential integrity check would obtain a FOR SHARE / FOR KEY SHARE on the t_inodes row which
             * latter would have to be upgraded (potentially leading to deadlocks if that's not possible).
             */
        Stat stat = new Stat();
        for (FileAttribute attribute : attr.getDefinedAttributes()) {
            switch(attribute) {
                case LOCATIONS:
                    // REVISIT: may be we need an explicit indication from pool
                    if (attr.isDefined(SIZE)) {
                        stat.setState(FileState.STORED);
                    }
                    break;
                case SIZE:
                    // REVISIT: pool shouldn't update the files size on flush, but this is required due to space manager accounting
                    if (!attr.isDefined(STORAGEINFO) || !attr.getStorageInfo().isSetAddLocation()) {
                        stat.setSize(attr.getSize());
                    }
                    break;
                case MODE:
                    stat.setMode(attr.getMode());
                    break;
                case CREATION_TIME:
                    stat.setCrTime(attr.getCreationTime());
                    break;
                case CHANGE_TIME:
                    stat.setCTime(attr.getChangeTime());
                    break;
                case MODIFICATION_TIME:
                    stat.setMTime(attr.getModificationTime());
                    break;
                case ACCESS_TIME:
                    stat.setATime(attr.getAccessTime());
                    break;
                case OWNER:
                    stat.setUid(attr.getOwner());
                    break;
                case OWNER_GROUP:
                    stat.setGid(attr.getGroup());
                    break;
                case CHECKSUM:
                    break;
                case ACCESS_LATENCY:
                    stat.setAccessLatency(attr.getAccessLatency());
                    break;
                case RETENTION_POLICY:
                    stat.setRetentionPolicy(attr.getRetentionPolicy());
                    break;
                case FLAGS:
                    break;
                case ACL:
                    break;
                case STORAGEINFO:
                    _extractor.setStorageInfo(inode, attr.getStorageInfo());
                    break;
                case XATTR:
                    break;
                case LABELS:
                    break;
                default:
                    throw new UnsupportedOperationException("Attribute " + attribute + " not supported yet.");
            }
        }
        if (stat.isDefinedAny()) {
            inode.setStat(stat);
        }
        if (attr.isDefined(XATTR)) {
            Map<String, String> xattrs = attr.getXattrs();
            for (Map.Entry<String, String> e : xattrs.entrySet()) {
                _fs.setXattr(inode, e.getKey(), e.getValue().getBytes(StandardCharsets.UTF_8), SetXattrMode.EITHER);
            }
        }
        if (attr.isDefined(LABELS)) {
            for (String label : attr.getLabels()) {
                _fs.addLabel(inode, label);
            }
        }
        if (attr.isDefined(FileAttribute.LOCATIONS)) {
            for (String location : attr.getLocations()) {
                _fs.addInodeLocation(inode, StorageGenericLocation.DISK, location);
            }
        }
        if (attr.isDefined(FileAttribute.CHECKSUM)) {
            for (Checksum newChecksum : attr.getChecksums()) {
                ChecksumType type = newChecksum.getType();
                Optional<Checksum> existingChecksum = _fs.getInodeChecksums(inode).stream().filter(c -> c.getType() == type).findFirst();
                if (existingChecksum.isPresent()) {
                    Checksum existing = existingChecksum.get();
                    if (!existing.equals(newChecksum)) {
                        throw new FileCorruptedCacheException(existing, newChecksum);
                    }
                } else {
                    _fs.setInodeChecksum(inode, type.getType(), newChecksum.getValue());
                }
            }
        }
        if (attr.isDefined(FileAttribute.FLAGS)) {
            FsInode level2 = new ExtendedInode(_fs, pnfsId, NO_STAT).getLevel(2);
            ChimeraCacheInfo cacheInfo = new ChimeraCacheInfo(level2);
            for (Map.Entry<String, String> flag : attr.getFlags().entrySet()) {
                cacheInfo.getFlags().put(flag.getKey(), flag.getValue());
            }
            cacheInfo.writeCacheInfo(level2);
        }
        if (attr.isDefined(FileAttribute.ACL)) {
            ACL acl = attr.getAcl();
            _fs.setACL(inode, acl.getList());
        }
        return getFileAttributes(inode, acquire);
    } catch (FileNotFoundChimeraFsException e) {
        throw new FileNotFoundCacheException("No such file or directory: " + pnfsId);
    } catch (IOException e) {
        LOGGER.error("Exception in setFileAttributes: {}", e);
        throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
    }
}
Also used : FsInode(org.dcache.chimera.FsInode) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) Subjects(org.dcache.auth.Subjects) StorageLocatable(org.dcache.chimera.StorageLocatable) CACHECLASS(org.dcache.namespace.FileAttribute.CACHECLASS) PermissionHandler(org.dcache.namespace.PermissionHandler) NLINK(org.dcache.namespace.FileAttribute.NLINK) FileState(org.dcache.chimera.FileState) UnixPermission(org.dcache.chimera.UnixPermission) Command(dmg.util.command.Command) ACCESS_ALLOWED(org.dcache.acl.enums.AccessType.ACCESS_ALLOWED) Map(java.util.Map) StorageGenericLocation(org.dcache.chimera.StorageGenericLocation) SIZE(org.dcache.namespace.FileAttribute.SIZE) EnumSet(java.util.EnumSet) PrintWriter(java.io.PrintWriter) NotDirChimeraException(org.dcache.chimera.NotDirChimeraException) PNFSID(org.dcache.namespace.FileAttribute.PNFSID) Range(com.google.common.collect.Range) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) CellInfo(dmg.cells.nucleus.CellInfo) LockedCacheException(diskCacheV111.util.LockedCacheException) Set(java.util.Set) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) Stream(java.util.stream.Stream) ChimeraDirectoryEntry(org.dcache.chimera.ChimeraDirectoryEntry) ACCESS_LATENCY(org.dcache.namespace.FileAttribute.ACCESS_LATENCY) Iterables(com.google.common.collect.Iterables) FsPath(diskCacheV111.util.FsPath) DirectoryStreamB(org.dcache.chimera.DirectoryStreamB) Callable(java.util.concurrent.Callable) NameSpaceProvider(diskCacheV111.namespace.NameSpaceProvider) ArrayList(java.util.ArrayList) OWNER(org.dcache.namespace.FileAttribute.OWNER) Lists(com.google.common.collect.Lists) NotDirCacheException(diskCacheV111.util.NotDirCacheException) TYPE(org.dcache.namespace.FileAttribute.TYPE) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) STAT(org.dcache.chimera.FileSystemProvider.StatCacheOption.STAT) Nullable(javax.annotation.Nullable) FileType(org.dcache.namespace.FileType) STORAGECLASS(org.dcache.namespace.FileAttribute.STORAGECLASS) PnfsId(diskCacheV111.util.PnfsId) MonitoringProxy(org.dcache.commons.stats.MonitoringProxy) LOCATIONS(org.dcache.namespace.FileAttribute.LOCATIONS) Glob(org.dcache.util.Glob) IOException(java.io.IOException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) ACE(org.dcache.acl.ACE) File(java.io.File) CREATION_TIME(org.dcache.namespace.FileAttribute.CREATION_TIME) LABELS(org.dcache.namespace.FileAttribute.LABELS) FileAttribute(org.dcache.namespace.FileAttribute) SIMPLE_TYPE(org.dcache.namespace.FileAttribute.SIMPLE_TYPE) SetXattrMode(org.dcache.chimera.FileSystemProvider.SetXattrMode) AccessLatency(diskCacheV111.util.AccessLatency) ChecksumType(org.dcache.util.ChecksumType) LoggerFactory(org.slf4j.LoggerFactory) XATTR(org.dcache.namespace.FileAttribute.XATTR) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ACL(org.dcache.acl.ACL) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Stat(org.dcache.chimera.posix.Stat) RequestCounters(org.dcache.commons.stats.RequestCounters) Method(java.lang.reflect.Method) FileAttributes(org.dcache.vehicles.FileAttributes) NoXdataChimeraException(org.dcache.chimera.NoXdataChimeraException) Collection(java.util.Collection) FileSystemProvider(org.dcache.chimera.FileSystemProvider) UUID(java.util.UUID) CellCommandListener(dmg.cells.nucleus.CellCommandListener) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) CreateOption(org.dcache.namespace.CreateOption) List(java.util.List) Optional(java.util.Optional) ChimeraFsException(org.dcache.chimera.ChimeraFsException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) MODE(org.dcache.namespace.FileAttribute.MODE) Pattern(java.util.regex.Pattern) CHECKSUM(org.dcache.namespace.FileAttribute.CHECKSUM) RetentionPolicy(diskCacheV111.util.RetentionPolicy) CellInfoProvider(dmg.cells.nucleus.CellInfoProvider) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) HashMap(java.util.HashMap) HSM(org.dcache.namespace.FileAttribute.HSM) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) RETENTION_POLICY(org.dcache.namespace.FileAttribute.RETENTION_POLICY) CacheException(diskCacheV111.util.CacheException) StorageInfo(diskCacheV111.vehicles.StorageInfo) ImmutableList(com.google.common.collect.ImmutableList) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) ListHandler(org.dcache.namespace.ListHandler) Nonnull(javax.annotation.Nonnull) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) Exceptions(org.dcache.util.Exceptions) STORAGEINFO(org.dcache.namespace.FileAttribute.STORAGEINFO) Logger(org.slf4j.Logger) UTF_8(java.nio.charset.StandardCharsets.UTF_8) RequestExecutionTimeGauges(org.dcache.commons.stats.RequestExecutionTimeGauges) Maps(com.google.common.collect.Maps) Ints(com.google.common.primitives.Ints) Subject(javax.security.auth.Subject) NO_STAT(org.dcache.chimera.FileSystemProvider.StatCacheOption.NO_STAT) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) Consumer(java.util.function.Consumer) Checksum(org.dcache.util.Checksum) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) OWNER_GROUP(org.dcache.namespace.FileAttribute.OWNER_GROUP) FLAGS(org.dcache.namespace.FileAttribute.FLAGS) Required(org.springframework.beans.factory.annotation.Required) Collections(java.util.Collections) 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) ACL(org.dcache.acl.ACL) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ChecksumType(org.dcache.util.ChecksumType) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) Stat(org.dcache.chimera.posix.Stat) Checksum(org.dcache.util.Checksum) FsInode(org.dcache.chimera.FsInode) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) Map(java.util.Map) HashMap(java.util.HashMap) FileAttribute(org.dcache.namespace.FileAttribute)

Aggregations

Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Strings.nullToEmpty (com.google.common.base.Strings.nullToEmpty)1 ImmutableList (com.google.common.collect.ImmutableList)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Range (com.google.common.collect.Range)1 Sets (com.google.common.collect.Sets)1 Ints (com.google.common.primitives.Ints)1 NameSpaceProvider (diskCacheV111.namespace.NameSpaceProvider)1 AccessLatency (diskCacheV111.util.AccessLatency)1 AttributeExistsCacheException (diskCacheV111.util.AttributeExistsCacheException)1 CacheException (diskCacheV111.util.CacheException)1 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)1 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)1 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)1 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)1 FsPath (diskCacheV111.util.FsPath)1 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)1