Search in sources :

Example 1 with PnfsRenameMessage

use of diskCacheV111.vehicles.PnfsRenameMessage in project dcache by dCache.

the class PnfsManagerTest method testMoveEntry.

@Test
public void testMoveEntry() throws Exception {
    PnfsCreateEntryMessage message = new PnfsCreateEntryMessage("/pnfs/testRoot/testMoveEntry", FileAttributes.ofFileType(DIR));
    _pnfsManager.createEntry(message);
    assertTrue("failed to create a directory", message.getReturnCode() == 0);
    FsInode srcInode = _fs.mkdir("/pnfs/testRoot/testMoveEntry/sourceDirectory");
    byte[] srcTagData = "foo".getBytes();
    _fs.setTag(srcInode, "sGroup", srcTagData, 0, srcTagData.length);
    FsInode dstInode = _fs.mkdir("/pnfs/testRoot/testMoveEntry/destinationDirectory");
    byte[] dstTagData = "bar".getBytes();
    _fs.setTag(dstInode, "sGroup", dstTagData, 0, dstTagData.length);
    message = new PnfsCreateEntryMessage("/pnfs/testRoot/testMoveEntry/sourceDirectory/sourceFile", FileAttributes.ofFileType(REGULAR));
    _pnfsManager.createEntry(message);
    assertTrue("failed to create an entry", message.getReturnCode() == 0);
    PnfsRenameMessage pnfsRenameMessage = new PnfsRenameMessage("/pnfs/testRoot/testMoveEntry/sourceDirectory/sourceFile", "/pnfs/testRoot/testMoveEntry/destinationDirectory/destinationFile", false);
    _pnfsManager.rename(pnfsRenameMessage);
    assertTrue("failed to move file to directory", pnfsRenameMessage.getReturnCode() == 0);
    ChimeraNameSpaceProvider provider = (ChimeraNameSpaceProvider) _pnfsManager.getNameSpaceProvider();
    provider.setAllowMoveToDirectoryWithDifferentStorageClass(false);
    pnfsRenameMessage = new PnfsRenameMessage("/pnfs/testRoot/testMoveEntry/destinationDirectory/destinationFile", "/pnfs/testRoot/testMoveEntry/sourceDirectory/sourceFile", false);
    _pnfsManager.rename(pnfsRenameMessage);
    assertTrue("succeeded to move file to directory with different tag, a failure", pnfsRenameMessage.getReturnCode() != 0);
    pnfsRenameMessage = new PnfsRenameMessage("/pnfs/testRoot/testMoveEntry/destinationDirectory", "/pnfs/testRoot/testMoveEntry/sourceDirectory/destinationDirectory", false);
    _pnfsManager.rename(pnfsRenameMessage);
    assertTrue("succeeded to move directory to directory with different tag, a failure", pnfsRenameMessage.getReturnCode() != 0);
}
Also used : FsInode(org.dcache.chimera.FsInode) PnfsCreateEntryMessage(diskCacheV111.vehicles.PnfsCreateEntryMessage) PnfsRenameMessage(diskCacheV111.vehicles.PnfsRenameMessage) ChimeraNameSpaceProvider(org.dcache.chimera.namespace.ChimeraNameSpaceProvider) Test(org.junit.Test)

Example 2 with PnfsRenameMessage

use of diskCacheV111.vehicles.PnfsRenameMessage in project dcache by dCache.

the class PnfsManagerV3 method rename.

public void rename(PnfsRenameMessage msg) {
    try {
        checkMask(msg);
        PnfsId pnfsId = msg.getPnfsId();
        String sourcePath = msg.getPnfsPath();
        String destinationPath = msg.newName();
        // This case is for compatibility with versions before 2.14
        if (sourcePath == null) {
            if (pnfsId == null) {
                throw new InvalidMessageCacheException("Either path or pnfs id is required.");
            }
            sourcePath = _nameSpaceProvider.pnfsidToPath(msg.getSubject(), pnfsId);
        }
        LOGGER.info("Rename {} to new name: {}", sourcePath, destinationPath);
        checkRestriction(msg, MANAGE, FsPath.create(sourcePath).parent());
        checkRestriction(msg, MANAGE, FsPath.create(destinationPath).parent());
        boolean overwrite = msg.getOverwrite() && !msg.getRestriction().isRestricted(DELETE, FsPath.create(destinationPath));
        _nameSpaceProvider.rename(msg.getSubject(), pnfsId, sourcePath, destinationPath, overwrite);
    } catch (CacheException e) {
        msg.setFailed(e.getRc(), e.getMessage());
    } catch (RuntimeException e) {
        LOGGER.error(e.toString(), e);
        msg.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Pnfs rename failed");
    }
}
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) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) PnfsId(diskCacheV111.util.PnfsId)

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 PnfsCreateEntryMessage (diskCacheV111.vehicles.PnfsCreateEntryMessage)1 PnfsRenameMessage (diskCacheV111.vehicles.PnfsRenameMessage)1 FsInode (org.dcache.chimera.FsInode)1 ChimeraNameSpaceProvider (org.dcache.chimera.namespace.ChimeraNameSpaceProvider)1 Test (org.junit.Test)1