Search in sources :

Example 6 with FileType

use of org.dcache.namespace.FileType in project dcache by dCache.

the class PnfsManagerV3 method createEntry.

public void createEntry(PnfsCreateEntryMessage pnfsMessage) {
    checkArgument(pnfsMessage.getFileAttributes().isDefined(TYPE));
    FileAttributes assign = pnfsMessage.getFileAttributes();
    FileType type = assign.removeFileType();
    Subject subject = pnfsMessage.getSubject();
    String path = pnfsMessage.getPnfsPath();
    try {
        File file = new File(path);
        checkMask(subject, file.getParent(), pnfsMessage.getAccessMask());
        Set<FileAttribute> requested = pnfsMessage.getAcquire();
        FileAttributes attrs = null;
        switch(type) {
            case DIR:
                LOGGER.info("create directory {}", path);
                checkMkdirAllowed(pnfsMessage);
                PnfsId pnfsId = _nameSpaceProvider.createDirectory(subject, path, assign);
                pnfsMessage.setPnfsId(pnfsId);
                // the createEntry seem to be ok.
                try {
                    LOGGER.info("Trying to get storageInfo for {}", pnfsId);
                    /* If we were allowed to create the entry above, then
                         * we also ought to be allowed to read it here. Hence
                         * we use ROOT as the subject.
                         */
                    attrs = _nameSpaceProvider.getFileAttributes(ROOT, pnfsId, requested);
                } catch (CacheException e) {
                    LOGGER.warn("Can't determine storageInfo: {}", e.toString());
                }
                break;
            case REGULAR:
                LOGGER.info("create file {}", path);
                checkRestriction(pnfsMessage, UPLOAD);
                requested.add(FileAttribute.STORAGEINFO);
                requested.add(FileAttribute.PNFSID);
                attrs = _nameSpaceProvider.createFile(subject, path, assign, requested);
                StorageInfo info = attrs.getStorageInfo();
                if (info.getKey("path") == null) {
                    info.setKey("path", path);
                }
                info.setKey("uid", Integer.toString(assign.getOwnerIfPresent().orElse(-1)));
                info.setKey("gid", Integer.toString(assign.getGroupIfPresent().orElse(-1)));
                // REVISIT: consider removing xattr injection once pools can accept FileAttribute.XATTR
                if (assign.isDefined(XATTR)) {
                    assign.getXattrs().forEach((k, v) -> info.setKey(STORAGE_INFO_XATTR_PREFIX + k, v));
                }
                pnfsMessage.setPnfsId(attrs.getPnfsId());
                break;
            case LINK:
                checkArgument(pnfsMessage instanceof PnfsCreateSymLinkMessage);
                String destination = ((PnfsCreateSymLinkMessage) pnfsMessage).getDestination();
                LOGGER.info("create symlink {} to {}", path, destination);
                checkRestrictionOnParent(pnfsMessage, MANAGE);
                pnfsId = _nameSpaceProvider.createSymLink(subject, path, destination, assign);
                pnfsMessage.setPnfsId(pnfsId);
                break;
            default:
                throw new IllegalArgumentException("Unsupported type: " + type);
        }
        pnfsMessage.setFileAttributes(attrs);
        pnfsMessage.setSucceeded();
    } catch (CacheException e) {
        pnfsMessage.setFailed(e.getRc(), e.getMessage());
    } catch (RuntimeException e) {
        LOGGER.error("Bug found when creating entry:", e);
        pnfsMessage.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e);
    }
}
Also used : MissingResourceCacheException(diskCacheV111.util.MissingResourceCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) PnfsId(diskCacheV111.util.PnfsId) PnfsCreateSymLinkMessage(org.dcache.vehicles.PnfsCreateSymLinkMessage) Subject(javax.security.auth.Subject) FileType(org.dcache.namespace.FileType) StorageInfo(diskCacheV111.vehicles.StorageInfo) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileAttributes(org.dcache.vehicles.FileAttributes) File(java.io.File) FileAttribute(org.dcache.namespace.FileAttribute)

Example 7 with FileType

use of org.dcache.namespace.FileType in project dcache by dCache.

the class Transfer method readNameSpaceEntryAsync.

private ListenableFuture<Void> readNameSpaceEntryAsync(boolean allowWrite, long timeout) {
    Set<FileAttribute> attr = EnumSet.of(PNFSID, TYPE, STORAGEINFO, SIZE);
    attr.addAll(_additionalAttributes);
    attr.addAll(PoolMgrSelectReadPoolMsg.getRequiredAttributes());
    Set<AccessMask> mask;
    if (allowWrite) {
        mask = EnumSet.of(AccessMask.READ_DATA, AccessMask.WRITE_DATA);
    } else {
        mask = EnumSet.of(AccessMask.READ_DATA);
    }
    PnfsId pnfsId = getPnfsId();
    PnfsGetFileAttributes request;
    if (pnfsId != null) {
        request = new PnfsGetFileAttributes(pnfsId, attr);
        if (_path != null) {
            // Needed for restriction check.
            request.setPnfsPath(_path.toString());
        }
    } else {
        request = new PnfsGetFileAttributes(_path.toString(), attr);
    }
    request.setAccessMask(mask);
    request.setUpdateAtime(true);
    ListenableFuture<PnfsGetFileAttributes> reply = _pnfs.requestAsync(request, timeout);
    setStatusUntil("PnfsManager: Fetching storage info", reply);
    return CellStub.transformAsync(reply, msg -> {
        FileAttributes attributes = msg.getFileAttributes();
        /* We can only transfer regular files.
                   */
        FileType type = attributes.getFileType();
        if (type == FileType.DIR || type == FileType.SPECIAL) {
            throw new NotFileCacheException("Not a regular file");
        }
        /* I/O mode must match completeness of the file.
                   */
        if (!attributes.getStorageInfo().isCreatedOnly()) {
            setWrite(false);
        } else if (allowWrite) {
            setWrite(true);
        } else {
            throw new FileIsNewCacheException();
        }
        setFileAttributes(attributes);
        return immediateFuture(null);
    });
}
Also used : NotFileCacheException(diskCacheV111.util.NotFileCacheException) FileType(org.dcache.namespace.FileType) PnfsId(diskCacheV111.util.PnfsId) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) AccessMask(org.dcache.acl.enums.AccessMask) FileAttributes(org.dcache.vehicles.FileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileAttribute(org.dcache.namespace.FileAttribute)

Example 8 with FileType

use of org.dcache.namespace.FileType in project dcache by dCache.

the class MonitoringNameSpaceProviderTest method shouldNotifyOnPnfsIdDelete.

@Test
public void shouldNotifyOnPnfsIdDelete() throws Exception {
    PnfsId parent = new PnfsId("000000000000000000000000000000000001");
    PnfsId target = new PnfsId("000000000000000000000000000000000002");
    given(inner.find(any(), eq(target))).willReturn(singleLink(parent, "foo"));
    given(inner.deleteEntry(any(), any(), eq(target), any())).willReturn(FileAttributes.of().fileType(FileType.REGULAR).accessTime(42L).build());
    FileAttributes result = monitor.deleteEntry(TEST_USER, EnumSet.allOf(FileType.class), target, EnumSet.of(FileAttribute.ACCESS_TIME));
    verify(inner).deleteEntry(eq(TEST_USER), eq(EnumSet.allOf(FileType.class)), eq(target), (Set<FileAttribute>) argThat(hasItem(FileAttribute.ACCESS_TIME)));
    assertThat(result.getAccessTime(), is(equalTo(42L)));
    verify(receiver).notifyChildEvent(EventType.IN_DELETE, parent, "foo", FileType.REGULAR);
    verify(receiver).notifySelfEvent(EventType.IN_DELETE_SELF, target, FileType.REGULAR);
    verify(receiver, never()).notifyMovedEvent(any(), any(), any(), any(), any());
}
Also used : FileType(org.dcache.namespace.FileType) PnfsId(diskCacheV111.util.PnfsId) FileAttributes(org.dcache.vehicles.FileAttributes) FileAttribute(org.dcache.namespace.FileAttribute) Test(org.junit.Test)

Example 9 with FileType

use of org.dcache.namespace.FileType in project dcache by dCache.

the class PnfsManagerV3 method deleteEntry.

public void deleteEntry(PnfsDeleteEntryMessage pnfsMessage) {
    String path = pnfsMessage.getPnfsPath();
    PnfsId pnfsId = pnfsMessage.getPnfsId();
    Subject subject = pnfsMessage.getSubject();
    Set<FileType> allowed = pnfsMessage.getAllowedFileTypes();
    Set<FileAttribute> requested = pnfsMessage.getRequestedAttributes();
    try {
        if (path == null && pnfsId == null) {
            throw new InvalidMessageCacheException("pnfsid or path have to be defined for PnfsDeleteEntryMessage");
        }
        checkMask(pnfsMessage);
        checkRestriction(pnfsMessage, DELETE);
        FileAttributes attributes;
        if (path != null) {
            LOGGER.info("delete PNFS entry for {}", path);
            if (pnfsId != null) {
                attributes = _nameSpaceProvider.deleteEntry(subject, allowed, pnfsId, path, requested);
            } else {
                requested.add(PNFSID);
                attributes = _nameSpaceProvider.deleteEntry(subject, allowed, path, requested);
                pnfsMessage.setPnfsId(attributes.getPnfsId());
            }
        } else {
            LOGGER.info("delete PNFS entry for {}", pnfsId);
            attributes = _nameSpaceProvider.deleteEntry(subject, allowed, pnfsId, requested);
        }
        pnfsMessage.setFileAttributes(attributes);
        pnfsMessage.setSucceeded();
    } catch (FileNotFoundCacheException e) {
        pnfsMessage.setFailed(CacheException.FILE_NOT_FOUND, e.getMessage());
    } catch (CacheException e) {
        LOGGER.warn("Failed to delete entry: {}", e.getMessage());
        pnfsMessage.setFailed(e.getRc(), e.getMessage());
    } catch (RuntimeException e) {
        LOGGER.error("Failed to delete entry", e);
        pnfsMessage.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e);
    }
}
Also used : FileType(org.dcache.namespace.FileType) MissingResourceCacheException(diskCacheV111.util.MissingResourceCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) PnfsId(diskCacheV111.util.PnfsId) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileAttributes(org.dcache.vehicles.FileAttributes) Subject(javax.security.auth.Subject) FileAttribute(org.dcache.namespace.FileAttribute)

Example 10 with FileType

use of org.dcache.namespace.FileType in project dcache by dCache.

the class MonitoringNameSpaceProvider method rename.

@Override
public void rename(Subject subject, PnfsId target, String sourcePath, String destinationPath, boolean overwrite) throws CacheException {
    Optional<Link> sourceParent = findParent(sourcePath);
    PnfsId resolvedTarget = null;
    try {
        resolvedTarget = target == null ? super.pathToPnfsid(Subjects.ROOT, sourcePath, true) : target;
    } catch (FileNotFoundCacheException e) {
    } catch (CacheException e) {
        LOGGER.error("Failed to resolve path {}: {}", sourcePath, e.toString());
    }
    super.rename(subject, target, sourcePath, destinationPath, overwrite);
    if (resolvedTarget == null) {
        LOGGER.error("Earlier failure in monitoring lookup didn't fail move.");
        return;
    }
    // The cookie is a unique identifier for this move operation.
    byte[] cookieBytes = Hashing.murmur3_128().newHasher().putString(resolvedTarget.toString(), StandardCharsets.UTF_8).putString(sourcePath, StandardCharsets.UTF_8).putString(destinationPath, StandardCharsets.UTF_8).putLong(// FIXME replace with generation ID
    System.currentTimeMillis()).hash().asBytes();
    String cookie = BaseEncoding.base64().omitPadding().encode(cookieBytes);
    Optional<Link> destinationParent = findParent(destinationPath);
    FileType type = super.getFileAttributes(Subjects.ROOT, resolvedTarget, FILETYPE).getFileType();
    eventReceiver.notifySelfEvent(EventType.IN_MOVE_SELF, resolvedTarget, type);
    sourceParent.ifPresent(l -> eventReceiver.notifyMovedEvent(EventType.IN_MOVED_FROM, l.getParent(), l.getName(), cookie, type));
    destinationParent.ifPresent(l -> eventReceiver.notifyMovedEvent(EventType.IN_MOVED_TO, l.getParent(), l.getName(), cookie, type));
}
Also used : CacheException(diskCacheV111.util.CacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileType(org.dcache.namespace.FileType) PnfsId(diskCacheV111.util.PnfsId) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException)

Aggregations

FileType (org.dcache.namespace.FileType)16 PnfsId (diskCacheV111.util.PnfsId)10 FileAttributes (org.dcache.vehicles.FileAttributes)7 FileAttribute (org.dcache.namespace.FileAttribute)6 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)4 CacheException (diskCacheV111.util.CacheException)3 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)3 NotDirCacheException (diskCacheV111.util.NotDirCacheException)3 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)3 Test (org.junit.Test)3 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)2 MissingResourceCacheException (diskCacheV111.util.MissingResourceCacheException)2 NotFileCacheException (diskCacheV111.util.NotFileCacheException)2 PnfsHandler (diskCacheV111.util.PnfsHandler)2 IOException (java.io.IOException)2 Subject (javax.security.auth.Subject)2 FsInode (org.dcache.chimera.FsInode)2 Inode (org.dcache.nfs.vfs.Inode)2 PnfsSetFileAttributes (org.dcache.vehicles.PnfsSetFileAttributes)2 Hasher (com.google.common.hash.Hasher)1