Search in sources :

Example 1 with TYPE

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

the class RemoteNameSpaceProviderTests method shouldSucceedWhenGetFileAttributesForExistingEntry.

@Test
public void shouldSucceedWhenGetFileAttributesForExistingEntry() throws Exception {
    givenSuccessfulResponse((Modifier<PnfsGetFileAttributes>) (r) -> r.setFileAttributes(fileAttributes().withSize(1234L).withType(REGULAR).build()));
    FileAttributes attributes = _namespace.getFileAttributes(ROOT, A_PNFSID, EnumSet.of(TYPE, SIZE));
    PnfsGetFileAttributes sent = getSingleSendAndWaitMessage(PnfsGetFileAttributes.class);
    assertThat(sent.getReplyRequired(), is(true));
    assertThat(sent.getSubject(), is(ROOT));
    assertThat(sent.getPnfsId(), is(A_PNFSID));
    assertThat(sent.getRequestedAttributes(), hasSize(2));
    assertThat(sent.getRequestedAttributes(), hasItem(TYPE));
    assertThat(sent.getRequestedAttributes(), hasItem(SIZE));
    assertThat(attributes.getSize(), is(1234L));
    assertThat(attributes.getFileType(), is(REGULAR));
}
Also used : FILE_NOT_FOUND(diskCacheV111.util.CacheException.FILE_NOT_FOUND) ListDirectoryHandler(org.dcache.util.list.ListDirectoryHandler) Link(diskCacheV111.namespace.NameSpaceProvider.Link) CellMessage(dmg.cells.nucleus.CellMessage) ChecksumType(org.dcache.util.ChecksumType) FILE_EXISTS(diskCacheV111.util.CacheException.FILE_EXISTS) PnfsHandler(diskCacheV111.util.PnfsHandler) BDDMockito.verify(org.mockito.BDDMockito.verify) FlagOperation(diskCacheV111.vehicles.PnfsFlagMessage.FlagOperation) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) SIZE(org.dcache.namespace.FileAttribute.SIZE) EnumSet(java.util.EnumSet) FileAttributes(org.dcache.vehicles.FileAttributes) FileAttributesBuilder.fileAttributes(org.dcache.util.FileAttributesBuilder.fileAttributes) PnfsGetParentMessage(diskCacheV111.vehicles.PnfsGetParentMessage) BDDMockito.never(org.mockito.BDDMockito.never) Collection(java.util.Collection) Range(com.google.common.collect.Range) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) PnfsGetCacheLocationsMessage(diskCacheV111.vehicles.PnfsGetCacheLocationsMessage) Preconditions.checkState(com.google.common.base.Preconditions.checkState) PnfsFlagMessage(diskCacheV111.vehicles.PnfsFlagMessage) SerializationHandler(dmg.cells.nucleus.SerializationHandler) List(java.util.List) DirectoryEntry(org.dcache.util.list.DirectoryEntry) CellMessageAnswerable(dmg.cells.nucleus.CellMessageAnswerable) Matchers.is(org.hamcrest.Matchers.is) PnfsCreateEntryMessage(diskCacheV111.vehicles.PnfsCreateEntryMessage) CellPath(dmg.cells.nucleus.CellPath) PnfsClearCacheLocationMessage(diskCacheV111.vehicles.PnfsClearCacheLocationMessage) PnfsDeleteEntryMessage(diskCacheV111.vehicles.PnfsDeleteEntryMessage) PnfsMessage(diskCacheV111.vehicles.PnfsMessage) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) NOT_FILE(diskCacheV111.util.CacheException.NOT_FILE) HashMap(java.util.HashMap) CellEndpoint(dmg.cells.nucleus.CellEndpoint) SerializationException(dmg.cells.nucleus.SerializationException) Answer(org.mockito.stubbing.Answer) BDDMockito.any(org.mockito.BDDMockito.any) BDDMockito.anyLong(org.mockito.BDDMockito.anyLong) Lists(com.google.common.collect.Lists) CacheException(diskCacheV111.util.CacheException) CellStub(org.dcache.cells.CellStub) ArgumentCaptor(org.mockito.ArgumentCaptor) TYPE(org.dcache.namespace.FileAttribute.TYPE) PnfsListDirectoryMessage(org.dcache.vehicles.PnfsListDirectoryMessage) ListHandler(org.dcache.namespace.ListHandler) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileType(org.dcache.namespace.FileType) Before(org.junit.Before) PnfsId(diskCacheV111.util.PnfsId) ROOT(org.dcache.auth.Subjects.ROOT) BDDMockito.doAnswer(org.mockito.BDDMockito.doAnswer) Executor(java.util.concurrent.Executor) REGULAR(org.dcache.namespace.FileType.REGULAR) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) Test(org.junit.Test) NotFileCacheException(diskCacheV111.util.NotFileCacheException) BDDMockito.willAnswer(org.mockito.BDDMockito.willAnswer) PnfsRemoveChecksumMessage(org.dcache.vehicles.PnfsRemoveChecksumMessage) Matchers.hasItem(org.hamcrest.Matchers.hasItem) PnfsAddCacheLocationMessage(diskCacheV111.vehicles.PnfsAddCacheLocationMessage) FileAttribute(org.dcache.namespace.FileAttribute) BDDMockito.mock(org.mockito.BDDMockito.mock) Collections(java.util.Collections) PnfsMapPathMessage(diskCacheV111.vehicles.PnfsMapPathMessage) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileAttributes(org.dcache.vehicles.FileAttributes) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) Test(org.junit.Test)

Example 2 with TYPE

use of org.dcache.namespace.FileAttribute.TYPE 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.checkState (com.google.common.base.Preconditions.checkState)2 Lists (com.google.common.collect.Lists)2 Range (com.google.common.collect.Range)2 CacheException (diskCacheV111.util.CacheException)2 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)2 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)2 NotFileCacheException (diskCacheV111.util.NotFileCacheException)2 PnfsId (diskCacheV111.util.PnfsId)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 EnumSet (java.util.EnumSet)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 FileAttribute (org.dcache.namespace.FileAttribute)2 SIZE (org.dcache.namespace.FileAttribute.SIZE)2 TYPE (org.dcache.namespace.FileAttribute.TYPE)2 FileType (org.dcache.namespace.FileType)2 ListHandler (org.dcache.namespace.ListHandler)2 ChecksumType (org.dcache.util.ChecksumType)2