Search in sources :

Example 1 with RetentionPolicy

use of diskCacheV111.util.RetentionPolicy in project dcache by dCache.

the class ALRPStorageUnitQoSProvider method fetchRequirements.

@Override
public FileQoSRequirements fetchRequirements(FileQoSUpdate update) throws QoSException {
    FileQoSRequirements descriptor = initialize(update);
    if (descriptor == null) {
        /*
             *  Should only happen when a CLEAR CACHE LOCATION finds no locations.
             */
        return null;
    }
    FileAttributes attributes = descriptor.getAttributes();
    AccessLatency accessLatency = attributes.getAccessLatency();
    RetentionPolicy retentionPolicy = attributes.getRetentionPolicy();
    String unitKey = attributes.getStorageClass() + "@" + attributes.getHsm();
    SelectionUnit unit = poolSelectionUnit().getStorageUnit(unitKey);
    if (!(unit instanceof StorageUnit)) {
        throw new QoSException(unitKey + " does not correspond to a storage unit; " + "cannot retrieve requirements for " + descriptor.getPnfsId());
    }
    StorageUnit storageUnit = (StorageUnit) unit;
    Integer required = storageUnit.getRequiredCopies();
    List<String> onlyOneCopyPer = storageUnit.getOnlyOneCopyPer();
    if (retentionPolicy == CUSTODIAL) {
        /*
             *  REVISIT -- currently we support only one tape location.
             */
        descriptor.setRequiredTape(1);
    } else {
        descriptor.setRequiredTape(0);
    }
    if (accessLatency == ONLINE) {
        /*
             *  REVISIT -- current override of file AL based on storage unit
             *  REVISIT -- eventually we will want to override the storage unit default for a given file
             */
        descriptor.setRequiredDisk(required == null ? 1 : required);
        if (onlyOneCopyPer != null) {
            descriptor.setPartitionKeys(new HashSet<>(onlyOneCopyPer));
        }
    } else {
        descriptor.setRequiredDisk(0);
    }
    LOGGER.debug("fetchRequirements for {}, returning {}.", update, descriptor);
    return descriptor;
}
Also used : AccessLatency(diskCacheV111.util.AccessLatency) SelectionUnit(diskCacheV111.poolManager.PoolSelectionUnit.SelectionUnit) PoolSelectionUnit(diskCacheV111.poolManager.PoolSelectionUnit) StorageUnit(diskCacheV111.poolManager.StorageUnit) QoSException(org.dcache.qos.QoSException) FileQoSRequirements(org.dcache.qos.data.FileQoSRequirements) FileAttributes(org.dcache.vehicles.FileAttributes) RetentionPolicy(diskCacheV111.util.RetentionPolicy)

Example 2 with RetentionPolicy

use of diskCacheV111.util.RetentionPolicy in project dcache by dCache.

the class ChimeraNameSpaceProvider method createUploadPath.

@Override
public FsPath createUploadPath(Subject subject, FsPath path, FsPath rootPath, Long size, AccessLatency al, RetentionPolicy rp, String spaceToken, Set<CreateOption> options) throws CacheException {
    checkState(_uploadDirectory != null, "Upload directory is not configured.");
    try {
        /* Parent directory must exist.
             */
        ExtendedInode parentOfPath = options.contains(CreateOption.CREATE_PARENTS) ? installDirectory(subject, path.parent(), INHERIT_MODE) : lookupDirectory(subject, path.parent());
        FileAttributes attributesOfParent = !Subjects.isExemptFromNamespaceChecks(subject) ? getFileAttributesForPermissionHandler(parentOfPath) : null;
        /* File must not exist unless overwrite is enabled.
             */
        try {
            ExtendedInode inodeOfPath = parentOfPath.inodeOf(path.name(), STAT);
            if (!options.contains(CreateOption.OVERWRITE_EXISTING) || (inodeOfPath.statCache().getMode() & UnixPermission.S_TYPE) != UnixPermission.S_IFREG) {
                throw new FileExistsCacheException("File exists: " + path);
            }
            /* User must be authorized to delete existing file.
                 */
            if (!Subjects.isExemptFromNamespaceChecks(subject)) {
                FileAttributes attributesOfPath = getFileAttributesForPermissionHandler(inodeOfPath);
                if (_permissionHandler.canDeleteFile(subject, attributesOfParent, attributesOfPath) != ACCESS_ALLOWED) {
                    throw new PermissionDeniedCacheException("Access denied: " + path);
                }
            }
        } catch (FileNotFoundChimeraFsException ignored) {
        }
        /* User must be authorized to create file.
             */
        if (!Subjects.isExemptFromNamespaceChecks(subject)) {
            if (_permissionHandler.canCreateFile(subject, attributesOfParent) != ACCESS_ALLOWED) {
                throw new PermissionDeniedCacheException("Access denied: " + path);
            }
        }
        /* Attributes are inherited from real parent directory.
             */
        int mode = parentOfPath.statCache().getMode() & UnixPermission.S_PERMS;
        int gid;
        if ((mode & UnixPermission.S_ISGID) != 0) {
            gid = parentOfPath.statCache().getGid();
        } else if (Subjects.isNobody(subject) || _inheritFileOwnership) {
            gid = parentOfPath.statCache().getGid();
        } else {
            gid = Ints.checkedCast(Subjects.getPrimaryGid(subject));
        }
        int uid;
        if (Subjects.isNobody(subject) || _inheritFileOwnership) {
            uid = parentOfPath.statCache().getUid();
        } else {
            uid = Ints.checkedCast(Subjects.getUid(subject));
        }
        /* ACLs are copied from real parent to the temporary upload directory
             * such that the upload is allowed (in case write permissions rely
             * on ACLs) and such that the file will inherit the correct ACLs.
             */
        List<ACE> acl = _fs.getACL(parentOfPath);
        /* The temporary upload directory has the same tags as the real parent,
             * except target file specific properties are stored as tags local to
             * the upload directory.
             */
        Map<String, byte[]> tags = Maps.newHashMap(parentOfPath.getTags());
        if (spaceToken != null) {
            tags.put(TAG_WRITE_TOKEN, spaceToken.getBytes(UTF_8));
            /* If client provides space token to upload to, the access latency and
                 * retention policy tags of the upload directory must be disregarded.
                 */
            tags.remove(TAG_ACCESS_LATENCY);
            tags.remove(TAG_RETENTION_POLICY);
        }
        if (al != null) {
            tags.put(TAG_ACCESS_LATENCY, al.toString().getBytes(UTF_8));
        }
        if (rp != null) {
            tags.put(TAG_RETENTION_POLICY, rp.toString().getBytes(UTF_8));
        }
        if (size != null) {
            tags.put(TAG_EXPECTED_SIZE, size.toString().getBytes(UTF_8));
        }
        tags.put(TAG_PATH, path.toString().getBytes(UTF_8));
        /* Upload directory may optionally be relative to the user's root path. Whether
             * that's the case depends on if the configured upload directory is an absolute
             * or relative path.
             */
        FsPath uploadDirectory = rootPath.resolve(_uploadDirectory);
        if (_uploadSubDirectory != null) {
            uploadDirectory = uploadDirectory.chroot(String.format(_uploadSubDirectory, threadId.get()));
        }
        /* Upload directory must exist and have the right permissions.
             */
        ExtendedInode inodeOfUploadDir = installSystemDirectory(uploadDirectory, 0711, Collections.emptyList(), Collections.emptyMap());
        if (inodeOfUploadDir.statCache().getUid() != 0) {
            LOGGER.error("Owner must be root: {}", uploadDirectory);
            throw new CacheException("Owner must be root: " + uploadDirectory);
        }
        if ((inodeOfUploadDir.statCache().getMode() & UnixPermission.S_PERMS) != 0711) {
            LOGGER.error("File mode must be 0711: {}", uploadDirectory);
            throw new CacheException("File mode must be 0711: " + uploadDirectory);
        }
        /* Use cryptographically strong pseudo random UUID to create temporary upload directory.
             */
        UUID uuid = UUID.randomUUID();
        _fs.mkdir(inodeOfUploadDir, uuid.toString(), uid, gid, mode, acl, tags);
        return uploadDirectory.child(uuid.toString()).child(path.name());
    } catch (ChimeraFsException e) {
        LOGGER.error("Problem with database: {}", e.getMessage());
        throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
    }
}
Also used : ACE(org.dcache.acl.ACE) 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) 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) UUID(java.util.UUID) FileAttributes(org.dcache.vehicles.FileAttributes) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) FsPath(diskCacheV111.util.FsPath)

Example 3 with RetentionPolicy

use of diskCacheV111.util.RetentionPolicy in project dcache by dCache.

the class PerformanceTest method processOperation.

private void processOperation(Operation aOp, String path) {
    try {
        switch(aOp) {
            case CREATE_ENTRY:
                provider.createFile(Subjects.ROOT, path, FileAttributes.of().uid(UID).gid(GID).mode(0664).build(), EnumSet.noneOf(FileAttribute.class));
                break;
            case PATH_TO_PNFS_ID:
                getPnfsid(path);
                break;
            case FILE_META_DATA:
                provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.of(OWNER, OWNER_GROUP, MODE, TYPE, SIZE, CREATION_TIME, ACCESS_TIME, MODIFICATION_TIME, CHANGE_TIME));
                break;
            case DELETE_ENTRY:
                provider.deleteEntry(Subjects.ROOT, EnumSet.allOf(FileType.class), path, EnumSet.noneOf(FileAttribute.class));
                break;
            case PNFS_ID_TO_PATH:
                provider.pnfsidToPath(Subjects.ROOT, getPnfsid(path));
                break;
            case FIND:
                provider.find(Subjects.ROOT, getPnfsid(path));
                break;
            case ADD_CHECKSUM:
                provider.setFileAttributes(Subjects.ROOT, getPnfsid(path), FileAttributes.ofChecksum(CHECKSUM), EnumSet.noneOf(FileAttribute.class));
                break;
            case GET_CHECKSUMS:
                provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.of(FileAttribute.CHECKSUM)).getChecksums();
                break;
            case SET_FILE_ATTR:
                provider.setFileAttributes(Subjects.ROOT, getPnfsid(path), FileAttributes.of().accessLatency(ONLINE).retentionPolicy(REPLICA).build(), EnumSet.noneOf(FileAttribute.class));
                break;
            case GET_FILE_ATTR:
                provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.allOf(FileAttribute.class));
                break;
            case ADD_CACHE_LOC:
                provider.addCacheLocation(Subjects.ROOT, getPnfsid(path), CACHE_LOCATION);
                break;
            case GET_CACHE_LOC:
                provider.getCacheLocation(Subjects.ROOT, getPnfsid(path));
                break;
            case STORAGE_INFO:
                provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.of(FileAttribute.STORAGEINFO)).getStorageInfo();
                break;
            case SET_STORAGE_INFO:
                StorageInfo info = provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.of(FileAttribute.STORAGEINFO)).getStorageInfo();
                info.setHsm("hsm");
                info.setKey("store", "test");
                info.setKey("group", "disk");
                info.addLocation(URI.create("osm://hsm/?store=test&group=disk&bdif=1234"));
                provider.setFileAttributes(Subjects.ROOT, getPnfsid(path), FileAttributes.ofStorageInfo(info), EnumSet.noneOf(FileAttribute.class));
                break;
            case MKDIR:
                provider.createDirectory(Subjects.ROOT, path, FileAttributes.of().uid(UID).gid(GID).mode(0755).build());
                break;
            case RMDIR:
                provider.deleteEntry(Subjects.ROOT, EnumSet.of(FileType.DIR), path, EnumSet.noneOf(FileAttribute.class));
                break;
            default:
                break;
        }
    } catch (CacheException e) {
        System.err.println("Exception " + aOp.getUserInput() + " :" + e.getMessage());
    }
}
Also used : FileType(org.dcache.namespace.FileType) CacheException(diskCacheV111.util.CacheException) StorageInfo(diskCacheV111.vehicles.StorageInfo) FileAttribute(org.dcache.namespace.FileAttribute)

Example 4 with RetentionPolicy

use of diskCacheV111.util.RetentionPolicy in project dcache by dCache.

the class ChimeraHsmStorageInfoExtractor method getRetentionPolicy.

@Override
public RetentionPolicy getRetentionPolicy(ExtendedInode inode) throws CacheException {
    try {
        if (!inode.exists()) {
            throw new FileNotFoundCacheException(inode.toString() + " does not exists");
        }
        ExtendedInode dirInode;
        if (inode.isDirectory()) {
            dirInode = inode;
        } else {
            if (inode.statCache().isDefined(Stat.StatAttributes.RETENTION_POLICY)) {
                return inode.statCache().getRetentionPolicy();
            }
            dirInode = inode.getParent();
            if (dirInode == null) {
                throw new FileNotFoundCacheException("File " + inode + " has been deleted.");
            }
        }
        Optional<String> retentionPolicy = getFirstLine(dirInode.getTag("RetentionPolicy"));
        if (retentionPolicy.isPresent()) {
            try {
                return RetentionPolicy.getRetentionPolicy(retentionPolicy.get());
            } catch (IllegalArgumentException e) {
                LOGGER.error("Badly formatted RetentionPolicy tag in {}: {}", dirInode, e.getMessage());
            }
        }
        Optional<String> spaceToken = getFirstLine(dirInode.getTag("WriteToken"));
        if (spaceToken.isPresent()) {
            return null;
        }
        return getDefaultRetentionPolicy();
    } catch (FileNotFoundChimeraFsException e) {
        throw new FileNotFoundCacheException(e.getMessage(), e);
    } catch (ChimeraFsException e) {
        throw new CacheException("Failed to obtain RetentionPolicy: " + e.getMessage(), e);
    }
}
Also used : FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) ChimeraFsException(org.dcache.chimera.ChimeraFsException) CacheException(diskCacheV111.util.CacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException)

Example 5 with RetentionPolicy

use of diskCacheV111.util.RetentionPolicy in project dcache by dCache.

the class PnfsManagerTest method testDefaultALandRP.

@Test
public void testDefaultALandRP() throws ChimeraFsException {
    /*
         * this test relays on the fact that default values in PnfsManager
         * is CUSTODIAL/NEARLINE
         */
    // use back door to create the tag
    FsInode dirInode = _fs.path2inode("/pnfs/testRoot");
    _fs.createTag(dirInode, "AccessLatency");
    _fs.createTag(dirInode, "RetentionPolicy");
    String al = "ONLINE";
    String rp = "OUTPUT";
    _fs.setTag(dirInode, "AccessLatency", al.getBytes(), 0, al.getBytes().length);
    _fs.setTag(dirInode, "RetentionPolicy", rp.getBytes(), 0, rp.getBytes().length);
    PnfsCreateEntryMessage pnfsCreateEntryMessage = new PnfsCreateEntryMessage("/pnfs/testRoot/testDefaultALandRP", FileAttributes.ofFileType(REGULAR));
    _pnfsManager.createEntry(pnfsCreateEntryMessage);
    FileAttributes fileAttributes = pnfsCreateEntryMessage.getFileAttributes();
    assertEquals("AccessLatensy is not taken from the parent directory", AccessLatency.ONLINE, fileAttributes.getAccessLatency());
    assertEquals("RetentionPolicy is not taken from the parent directory", RetentionPolicy.OUTPUT, fileAttributes.getRetentionPolicy());
}
Also used : FsInode(org.dcache.chimera.FsInode) PnfsCreateEntryMessage(diskCacheV111.vehicles.PnfsCreateEntryMessage) FileAttributes(org.dcache.vehicles.FileAttributes) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) Test(org.junit.Test)

Aggregations

RetentionPolicy (diskCacheV111.util.RetentionPolicy)14 AccessLatency (diskCacheV111.util.AccessLatency)10 FileAttributes (org.dcache.vehicles.FileAttributes)9 CacheException (diskCacheV111.util.CacheException)7 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)5 StorageInfo (diskCacheV111.vehicles.StorageInfo)5 URI (java.net.URI)5 Test (org.junit.Test)5 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)4 PnfsSetFileAttributes (org.dcache.vehicles.PnfsSetFileAttributes)4 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)3 PnfsId (diskCacheV111.util.PnfsId)3 PnfsCreateEntryMessage (diskCacheV111.vehicles.PnfsCreateEntryMessage)3 Stat (org.dcache.chimera.posix.Stat)3 Space (diskCacheV111.services.space.Space)2 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)2 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)2 FileLocality (diskCacheV111.util.FileLocality)2 FsPath (diskCacheV111.util.FsPath)2 NotDirCacheException (diskCacheV111.util.NotDirCacheException)2