Search in sources :

Example 1 with PnfsCreateSymLinkMessage

use of org.dcache.vehicles.PnfsCreateSymLinkMessage 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)

Aggregations

CacheException (diskCacheV111.util.CacheException)1 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)1 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)1 MissingResourceCacheException (diskCacheV111.util.MissingResourceCacheException)1 NotDirCacheException (diskCacheV111.util.NotDirCacheException)1 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)1 PnfsId (diskCacheV111.util.PnfsId)1 StorageInfo (diskCacheV111.vehicles.StorageInfo)1 File (java.io.File)1 Subject (javax.security.auth.Subject)1 FileAttribute (org.dcache.namespace.FileAttribute)1 FileType (org.dcache.namespace.FileType)1 FileAttributes (org.dcache.vehicles.FileAttributes)1 PnfsCreateSymLinkMessage (org.dcache.vehicles.PnfsCreateSymLinkMessage)1 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)1 PnfsSetFileAttributes (org.dcache.vehicles.PnfsSetFileAttributes)1