Search in sources :

Example 1 with FileAttribute

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

the class XrootdDoor method getMultipleFileStatuses.

public int[] getMultipleFileStatuses(FsPath[] allPaths, Subject subject, Restriction restriction) throws CacheException {
    PnfsHandler pnfsHandler = new PnfsHandler(_pnfs, subject, restriction);
    int[] flags = new int[allPaths.length];
    // TODO: Use SpreadAndWait
    for (int i = 0; i < allPaths.length; i++) {
        try {
            Set<FileAttribute> requestedAttributes = EnumSet.of(TYPE);
            requestedAttributes.addAll(_pdp.getRequiredAttributes());
            FileAttributes attributes = pnfsHandler.getFileAttributes(allPaths[i].toString(), requestedAttributes);
            flags[i] = getFileStatusFlags(subject, restriction, allPaths[i], attributes);
        } catch (CacheException e) {
            if (e.getRc() != CacheException.FILE_NOT_FOUND) {
                throw e;
            }
            flags[i] = kXR_other;
        }
    }
    return flags;
}
Also used : FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) PnfsHandler(diskCacheV111.util.PnfsHandler) FileAttributes(org.dcache.vehicles.FileAttributes) FileAttribute(org.dcache.namespace.FileAttribute)

Example 2 with FileAttribute

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

the class MonitoringNameSpaceProviderTest method shouldNotifyOnCommitUpload.

@Test
public void shouldNotifyOnCommitUpload() throws Exception {
    PnfsId parent = new PnfsId("000000000000000000000000000000000001");
    PnfsId target = new PnfsId("000000000000000000000000000000000002");
    FsPath uploadPath = FsPath.create("/uploads/1/update-1/file-1");
    FsPath targetPath = FsPath.create("/data/file-1");
    given(inner.find(any(), eq(target))).willReturn(singleLink(parent, "file-1"));
    given(inner.commitUpload(any(), eq(uploadPath), eq(targetPath), any(), any())).willReturn(FileAttributes.of().accessTime(42L).pnfsId(target).build());
    FileAttributes result = monitor.commitUpload(TEST_USER, uploadPath, targetPath, EnumSet.noneOf(CreateOption.class), EnumSet.of(FileAttribute.ACCESS_TIME));
    verify(inner).commitUpload(eq(TEST_USER), eq(uploadPath), eq(targetPath), eq(EnumSet.noneOf(CreateOption.class)), (Set<FileAttribute>) argThat(hasItem(FileAttribute.ACCESS_TIME)));
    assertThat(result.getAccessTime(), is(equalTo(42L)));
    verify(receiver).notifyMovedEvent(eq(EventType.IN_MOVED_TO), eq(parent), eq("file-1"), argThat(not(emptyOrNullString())), eq(FileType.REGULAR));
}
Also used : PnfsId(diskCacheV111.util.PnfsId) CreateOption(org.dcache.namespace.CreateOption) FileAttributes(org.dcache.vehicles.FileAttributes) FsPath(diskCacheV111.util.FsPath) FileAttribute(org.dcache.namespace.FileAttribute) Test(org.junit.Test)

Example 3 with FileAttribute

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

the class MonitoringNameSpaceProviderTest method shouldNotifyOnCreateFile.

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

Example 4 with FileAttribute

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

the class DCacheAwareJdbcFs method getFileLocality.

/**
 * Callout to get pool monitor and check for live (network) status of a file instead of simply
 * its status as recorded in the Chimera database.
 */
private String getFileLocality(PnfsId pnfsId) throws ChimeraFsException {
    FileLocality locality = FileLocality.UNAVAILABLE;
    try {
        Set<FileAttribute> requestedAttributes = EnumSet.of(FileAttribute.TYPE, FileAttribute.SIZE, FileAttribute.STORAGEINFO, FileAttribute.LOCATIONS);
        Set<AccessMask> accessMask = EnumSet.of(AccessMask.READ_DATA);
        FileAttributes attributes = pnfsHandler.getFileAttributes(pnfsId, requestedAttributes, accessMask, false);
        /*
             * TODO improve code to pass in the actual InetAddress of the
             * client so that link net masks do not interfere; note that SRM uses
             * "localhost", so it is not a deviation from existing behavior.
             */
        locality = poolMonitor.getFileLocality(attributes, "localhost");
    } catch (CacheException t) {
        throw new ChimeraFsException("getFileLocality", t);
    }
    return locality.toString();
}
Also used : CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) AccessMask(org.dcache.acl.enums.AccessMask) FileLocality(diskCacheV111.util.FileLocality) FileAttributes(org.dcache.vehicles.FileAttributes) FileAttribute(org.dcache.namespace.FileAttribute)

Example 5 with FileAttribute

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

the class UserAdminShell method getFileAttributes.

/**
 * Queries the pnfs id and file locations of a file. Used by the {@literal \sl} command.
 */
private FileAttributes getFileAttributes(String file) throws CacheException, InterruptedException, NoRouteToCellException {
    /* Lookup file in name space */
    PnfsGetFileAttributes request;
    EnumSet<FileAttribute> attributeSet = EnumSet.of(FileAttribute.LOCATIONS, FileAttribute.PNFSID);
    if (PnfsId.isValid(file)) {
        request = new PnfsGetFileAttributes(new PnfsId(file), attributeSet);
    } else {
        request = new PnfsGetFileAttributes(file, attributeSet);
    }
    return _pnfsManager.sendAndWait(request).getFileAttributes();
}
Also used : PnfsId(diskCacheV111.util.PnfsId) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileAttribute(org.dcache.namespace.FileAttribute)

Aggregations

FileAttribute (org.dcache.namespace.FileAttribute)36 FileAttributes (org.dcache.vehicles.FileAttributes)32 CacheException (diskCacheV111.util.CacheException)19 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)19 PnfsId (diskCacheV111.util.PnfsId)18 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)16 FsPath (diskCacheV111.util.FsPath)10 NotDirCacheException (diskCacheV111.util.NotDirCacheException)9 FileType (org.dcache.namespace.FileType)9 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)9 PnfsHandler (diskCacheV111.util.PnfsHandler)8 Subject (javax.security.auth.Subject)8 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)7 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)6 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)6 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)6 ArrayList (java.util.ArrayList)6 PnfsSetFileAttributes (org.dcache.vehicles.PnfsSetFileAttributes)6 Test (org.junit.Test)6 StorageInfo (diskCacheV111.vehicles.StorageInfo)5