Search in sources :

Example 1 with PnfsSetFileAttributes

use of org.dcache.vehicles.PnfsSetFileAttributes in project dcache by dCache.

the class PnfsManagerTest method testSetFilePermissions.

@Test
public void testSetFilePermissions() throws Exception {
    FsInode base = _fs.path2inode("/pnfs");
    FsInode inode = _fs.createFile(base, "afile");
    Stat stat = _fs.stat(inode);
    int mode = 0222;
    PnfsSetFileAttributes pnfsSetFileAttributes = new PnfsSetFileAttributes(new PnfsId(inode.statCache().getId()), FileAttributes.ofMode(mode));
    _pnfsManager.setFileAttributes(pnfsSetFileAttributes);
    Stat new_stat = _fs.stat(inode);
    assertEquals("setFileAttributes change file type", stat.getMode() & ~UnixPermission.S_PERMS | mode, new_stat.getMode());
}
Also used : Stat(org.dcache.chimera.posix.Stat) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) FsInode(org.dcache.chimera.FsInode) PnfsId(diskCacheV111.util.PnfsId) Test(org.junit.Test)

Example 2 with PnfsSetFileAttributes

use of org.dcache.vehicles.PnfsSetFileAttributes in project dcache by dCache.

the class PnfsManagerTest method testGetStorageInfoForFlushedFiles.

@Test
public void testGetStorageInfoForFlushedFiles() throws Exception {
    PnfsCreateEntryMessage pnfsCreateEntryMessage = new PnfsCreateEntryMessage("/pnfs/testRoot/tapeFile", FileAttributes.ofFileType(REGULAR));
    _pnfsManager.createEntry(pnfsCreateEntryMessage);
    assertThat("Creating entry failed", pnfsCreateEntryMessage.getReturnCode(), is(0));
    StorageInfo si = pnfsCreateEntryMessage.getFileAttributes().getStorageInfo();
    si.addLocation(new URI(OSM_URI_STEM + "?store=tape"));
    si.isSetAddLocation(true);
    PnfsSetFileAttributes setFileAttributesMessage = new PnfsSetFileAttributes(pnfsCreateEntryMessage.getPnfsId(), FileAttributes.of().accessLatency(NEARLINE).retentionPolicy(CUSTODIAL).storageInfo(si).build());
    _pnfsManager.setFileAttributes(setFileAttributesMessage);
    assertThat("Setting storage info failed", setFileAttributesMessage.getReturnCode(), is(0));
    PnfsGetFileAttributes message = new PnfsGetFileAttributes(pnfsCreateEntryMessage.getPnfsId(), SOME_ATTRIBUTES);
    _pnfsManager.getFileAttributes(message);
    assertEquals("failed to get storageInfo for flushed files", 0, message.getReturnCode());
}
Also used : PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) StorageInfo(diskCacheV111.vehicles.StorageInfo) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) PnfsCreateEntryMessage(diskCacheV111.vehicles.PnfsCreateEntryMessage) URI(java.net.URI) Test(org.junit.Test)

Example 3 with PnfsSetFileAttributes

use of org.dcache.vehicles.PnfsSetFileAttributes in project dcache by dCache.

the class RepositorySubsystemTest method createEntry4.

/* Helper method for creating a fourth entry in the repository.
     */
private void createEntry4(final boolean failSetAttributes, final boolean cancel, final ReplicaState transferState, final ReplicaState finalState) throws Throwable {
    new CellStubHelper(cell) {

        boolean setAttr;

        boolean addCache;

        @Message(required = false, step = 1, cell = "pnfs")
        public Object whenFileIsGarbageCollected(PnfsClearCacheLocationMessage msg) {
            msg.setSucceeded();
            return msg;
        }

        @Message(required = false, step = 3, cell = "pnfs")
        public Object whenDescriptorIsCommitted(PnfsSetFileAttributes msg) {
            assertEquals(size4, msg.getFileAttributes().getSize());
            if (failSetAttributes) {
                msg.setFailed(1, null);
            } else {
                msg.setSucceeded();
            }
            setAttr = true;
            return msg;
        }

        @Message(required = false, step = 5, cell = "pnfs")
        public Object whenDescriptorFails(PnfsAddCacheLocationMessage msg) {
            assertTrue(failSetAttributes || cancel);
            msg.setSucceeded();
            addCache = true;
            return msg;
        }

        @Message(required = false, step = 5, cell = "pnfs")
        public Object whenDescriptorFails(PnfsSetFileAttributes msg) {
            assertTrue(failSetAttributes || cancel);
            msg.setSucceeded();
            return msg;
        }

        @Override
        protected void run() throws FileInCacheException, CacheException, InterruptedException, IOException {
            List<StickyRecord> stickyRecords = Collections.emptyList();
            ReplicaDescriptor handle = repository.createEntry(attributes4, transferState, finalState, stickyRecords, EnumSet.noneOf(OpenFlags.class), OptionalLong.empty());
            try {
                assertStep("No clear after this point", 2);
                createFile(handle, size4);
                if (!cancel) {
                    handle.commit();
                }
            } finally {
                assertStep("Only failure registration after this point", 4);
                handle.close();
            }
            assertEquals("SetFileAttributes must be sent unless we don't try to commit", !cancel, setAttr);
            assertEquals("AddCacheLocation must be sent if not committed", cancel || failSetAttributes, addCache);
        }
    };
}
Also used : StickyRecord(org.dcache.pool.repository.StickyRecord) ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) OpenFlags(org.dcache.pool.repository.Repository.OpenFlags) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) PnfsClearCacheLocationMessage(diskCacheV111.vehicles.PnfsClearCacheLocationMessage) CellStubHelper(org.dcache.tests.cells.CellStubHelper) PnfsAddCacheLocationMessage(diskCacheV111.vehicles.PnfsAddCacheLocationMessage)

Example 4 with PnfsSetFileAttributes

use of org.dcache.vehicles.PnfsSetFileAttributes in project dcache by dCache.

the class RepositorySubsystemTest method testCreateEntryFromStore.

@Test
public void testCreateEntryFromStore() throws Throwable {
    repository.init();
    repository.load();
    stateChangeEvents.clear();
    new CellStubHelper(cell) {

        @Message(required = true, step = 1, cell = "pnfs")
        public Object message(PnfsSetFileAttributes msg) {
            if (msg.getFileAttributes().isDefined(FileAttribute.SIZE)) {
                return new CacheException("");
            }
            msg.setSucceeded();
            return msg;
        }

        @Override
        protected void run() throws CacheException, InterruptedException {
            List<StickyRecord> stickyRecords = Collections.emptyList();
            ReplicaDescriptor handle = repository.createEntry(attributes5, FROM_STORE, CACHED, stickyRecords, EnumSet.noneOf(OpenFlags.class), OptionalLong.empty());
            try {
                createFile(handle, attributes5.getSize());
                handle.commit();
            } catch (IOException e) {
                throw new DiskErrorCacheException(e.getMessage());
            } finally {
                handle.close();
            }
        }
    };
}
Also used : StickyRecord(org.dcache.pool.repository.StickyRecord) ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) OpenFlags(org.dcache.pool.repository.Repository.OpenFlags) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) LockedCacheException(diskCacheV111.util.LockedCacheException) FileInCacheException(diskCacheV111.util.FileInCacheException) CacheException(diskCacheV111.util.CacheException) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) CellStubHelper(org.dcache.tests.cells.CellStubHelper) IOException(java.io.IOException) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) Test(org.junit.Test)

Example 5 with PnfsSetFileAttributes

use of org.dcache.vehicles.PnfsSetFileAttributes in project dcache by dCache.

the class RepositorySubsystemTest method createEntry.

private void createEntry(final FileAttributes attributes, final ReplicaState state, final List<StickyRecord> sticky) throws Throwable {
    new CellStubHelper(cell) {

        @Message(cell = "pnfs")
        public Object message(PnfsSetFileAttributes msg) {
            msg.setSucceeded();
            return msg;
        }

        @Override
        protected void run() throws CacheException, IOException, InterruptedException {
            ReplicaDescriptor handle = repository.createEntry(attributes, ReplicaState.FROM_CLIENT, state, sticky, EnumSet.noneOf(OpenFlags.class), OptionalLong.empty());
            try {
                createFile(handle, attributes.getSize());
                handle.commit();
            } finally {
                handle.close();
            }
        }
    };
}
Also used : ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) OpenFlags(org.dcache.pool.repository.Repository.OpenFlags) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) CellStubHelper(org.dcache.tests.cells.CellStubHelper)

Aggregations

PnfsSetFileAttributes (org.dcache.vehicles.PnfsSetFileAttributes)12 Test (org.junit.Test)7 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)6 PnfsId (diskCacheV111.util.PnfsId)4 FileAttributes (org.dcache.vehicles.FileAttributes)4 PnfsCreateEntryMessage (diskCacheV111.vehicles.PnfsCreateEntryMessage)3 StorageInfo (diskCacheV111.vehicles.StorageInfo)3 URI (java.net.URI)3 ReplicaDescriptor (org.dcache.pool.repository.ReplicaDescriptor)3 OpenFlags (org.dcache.pool.repository.Repository.OpenFlags)3 CellStubHelper (org.dcache.tests.cells.CellStubHelper)3 CacheException (diskCacheV111.util.CacheException)2 PnfsAddCacheLocationMessage (diskCacheV111.vehicles.PnfsAddCacheLocationMessage)2 PnfsClearCacheLocationMessage (diskCacheV111.vehicles.PnfsClearCacheLocationMessage)2 CellMessage (dmg.cells.nucleus.CellMessage)2 StickyRecord (org.dcache.pool.repository.StickyRecord)2 AccessLatency (diskCacheV111.util.AccessLatency)1 DiskErrorCacheException (diskCacheV111.util.DiskErrorCacheException)1 FileInCacheException (diskCacheV111.util.FileInCacheException)1 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)1