Search in sources :

Example 1 with PnfsGetParentMessage

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

the class PnfsManagerV3 method getParent.

private void getParent(PnfsGetParentMessage msg) {
    try {
        PnfsId pnfsId = populatePnfsId(msg);
        checkMask(msg);
        _nameSpaceProvider.find(msg.getSubject(), pnfsId).forEach(l -> msg.addLocation(l.getParent(), l.getName()));
    } catch (CacheException e) {
        LOGGER.warn(e.toString());
        msg.setFailed(e.getRc(), e.getMessage());
    } catch (RuntimeException e) {
        LOGGER.error(e.toString(), e);
        msg.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
    }
}
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)

Example 2 with PnfsGetParentMessage

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

the class RemoteNameSpaceProviderTests method shouldSucceedForFindExistingEntry.

@Test
public void shouldSucceedForFindExistingEntry() throws Exception {
    givenSuccessfulResponse((Modifier<PnfsGetParentMessage>) (r) -> r.addLocation(ANOTHER_PNFSID, "file"));
    Collection<Link> locations = _namespace.find(ROOT, A_PNFSID);
    PnfsGetParentMessage sent = getSingleSendAndWaitMessage(PnfsGetParentMessage.class);
    assertThat(sent.getReplyRequired(), is(true));
    assertThat(sent.getSubject(), is(ROOT));
    assertThat(sent.getPnfsId(), is(A_PNFSID));
    assertThat(locations.size(), is(1));
    Link location = locations.iterator().next();
    assertThat(location.getParent(), is(ANOTHER_PNFSID));
    assertThat(location.getName(), is("file"));
}
Also used : FILE_NOT_FOUND(diskCacheV111.util.CacheException.FILE_NOT_FOUND) ListDirectoryHandler(org.dcache.util.list.ListDirectoryHandler) Link(diskCacheV111.namespace.NameSpaceProvider.Link) CellMessage(dmg.cells.nucleus.CellMessage) ChecksumType(org.dcache.util.ChecksumType) FILE_EXISTS(diskCacheV111.util.CacheException.FILE_EXISTS) PnfsHandler(diskCacheV111.util.PnfsHandler) BDDMockito.verify(org.mockito.BDDMockito.verify) FlagOperation(diskCacheV111.vehicles.PnfsFlagMessage.FlagOperation) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) SIZE(org.dcache.namespace.FileAttribute.SIZE) EnumSet(java.util.EnumSet) FileAttributes(org.dcache.vehicles.FileAttributes) FileAttributesBuilder.fileAttributes(org.dcache.util.FileAttributesBuilder.fileAttributes) PnfsGetParentMessage(diskCacheV111.vehicles.PnfsGetParentMessage) BDDMockito.never(org.mockito.BDDMockito.never) Collection(java.util.Collection) Range(com.google.common.collect.Range) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) PnfsGetCacheLocationsMessage(diskCacheV111.vehicles.PnfsGetCacheLocationsMessage) Preconditions.checkState(com.google.common.base.Preconditions.checkState) PnfsFlagMessage(diskCacheV111.vehicles.PnfsFlagMessage) SerializationHandler(dmg.cells.nucleus.SerializationHandler) List(java.util.List) DirectoryEntry(org.dcache.util.list.DirectoryEntry) CellMessageAnswerable(dmg.cells.nucleus.CellMessageAnswerable) Matchers.is(org.hamcrest.Matchers.is) PnfsCreateEntryMessage(diskCacheV111.vehicles.PnfsCreateEntryMessage) CellPath(dmg.cells.nucleus.CellPath) PnfsClearCacheLocationMessage(diskCacheV111.vehicles.PnfsClearCacheLocationMessage) PnfsDeleteEntryMessage(diskCacheV111.vehicles.PnfsDeleteEntryMessage) PnfsMessage(diskCacheV111.vehicles.PnfsMessage) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) NOT_FILE(diskCacheV111.util.CacheException.NOT_FILE) HashMap(java.util.HashMap) CellEndpoint(dmg.cells.nucleus.CellEndpoint) SerializationException(dmg.cells.nucleus.SerializationException) Answer(org.mockito.stubbing.Answer) BDDMockito.any(org.mockito.BDDMockito.any) BDDMockito.anyLong(org.mockito.BDDMockito.anyLong) Lists(com.google.common.collect.Lists) CacheException(diskCacheV111.util.CacheException) CellStub(org.dcache.cells.CellStub) ArgumentCaptor(org.mockito.ArgumentCaptor) TYPE(org.dcache.namespace.FileAttribute.TYPE) PnfsListDirectoryMessage(org.dcache.vehicles.PnfsListDirectoryMessage) ListHandler(org.dcache.namespace.ListHandler) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileType(org.dcache.namespace.FileType) Before(org.junit.Before) PnfsId(diskCacheV111.util.PnfsId) ROOT(org.dcache.auth.Subjects.ROOT) BDDMockito.doAnswer(org.mockito.BDDMockito.doAnswer) Executor(java.util.concurrent.Executor) REGULAR(org.dcache.namespace.FileType.REGULAR) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) Test(org.junit.Test) NotFileCacheException(diskCacheV111.util.NotFileCacheException) BDDMockito.willAnswer(org.mockito.BDDMockito.willAnswer) PnfsRemoveChecksumMessage(org.dcache.vehicles.PnfsRemoveChecksumMessage) Matchers.hasItem(org.hamcrest.Matchers.hasItem) PnfsAddCacheLocationMessage(diskCacheV111.vehicles.PnfsAddCacheLocationMessage) FileAttribute(org.dcache.namespace.FileAttribute) BDDMockito.mock(org.mockito.BDDMockito.mock) Collections(java.util.Collections) PnfsMapPathMessage(diskCacheV111.vehicles.PnfsMapPathMessage) PnfsGetParentMessage(diskCacheV111.vehicles.PnfsGetParentMessage) Link(diskCacheV111.namespace.NameSpaceProvider.Link) Test(org.junit.Test)

Example 3 with PnfsGetParentMessage

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

the class PnfsHandler method find.

public Collection<Link> find(PnfsId pnfsId) throws CacheException {
    PnfsGetParentMessage response = request(new PnfsGetParentMessage(pnfsId));
    List<PnfsId> parents = response.getParents();
    List<String> names = response.getNames();
    int count = Math.min(parents.size(), names.size());
    List<Link> locations = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
        locations.add(new Link(parents.get(i), names.get(i)));
    }
    return locations;
}
Also used : PnfsGetParentMessage(diskCacheV111.vehicles.PnfsGetParentMessage) ArrayList(java.util.ArrayList) CellEndpoint(dmg.cells.nucleus.CellEndpoint) Link(diskCacheV111.namespace.NameSpaceProvider.Link)

Example 4 with PnfsGetParentMessage

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

the class PnfsManagerTest method testAddCacheLocationNonExist.

/*
        @Test
        public void testGetParentOf() throws ChimeraFsException {
            PnfsCreateDirectoryMessage pnfsCreateDirectoryMessage = new PnfsCreateDirectoryMessage("/pnfs/testRoot/testDir", 3750, 1000, 0750);
            _pnfsManager.createDirectory(pnfsCreateDirectoryMessage);

            FsInode rootInode = _fs.path2inode("/pnfs");
            FsInode parentDirInode = _fs.path2inode("/pnfs/testRoot");
            FsInode testDirInode = _fs.path2inode("/pnfs/testRoot/testDir");

            PnfsId rootDirPnfs = new PnfsId(rootInode.toString());
            PnfsId parentDirPnfs = new PnfsId(parentDirInode.toString());
            PnfsId testDirPnfs = new PnfsId(testDirInode.toString());

            PnfsGetParentMessage pnfsGetParentMessage1 = new PnfsGetParentMessage(testDirPnfs);
            _pnfsManager.getParent(pnfsGetParentMessage1);
            PnfsId pnfsOfParent1 = pnfsGetParentMessage1.getParent();

            assertEquals("ok: pnfsOfParent1=parentDirPnfs", parentDirPnfs.toString(), pnfsOfParent1.toString());

            PnfsGetParentMessage pnfsGetParentMessage2 = new PnfsGetParentMessage(parentDirPnfs);
            _pnfsManager.getParent(pnfsGetParentMessage2);
            PnfsId pnfsOfParent2 = pnfsGetParentMessage2.getParent();

            assertEquals("ok: pnfsOfParent2=rootDirPnfs", rootDirPnfs.toString(), pnfsOfParent2.toString());

            PnfsGetParentMessage pnfsGetParentMessage3 = new PnfsGetParentMessage(rootDirPnfs);
            _pnfsManager.getParent(pnfsGetParentMessage3);
            PnfsId pnfsOfParent3 = pnfsGetParentMessage3.getParent();

            assertEquals("ok: pnfsOfParent3=000000000000000000000000000000000000","000000000000000000000000000000000000",pnfsOfParent3.toString());

        }

        @Test
        public void testGetParentOfNotExistingResource() throws ChimeraFsException {

            PnfsId tmp=new PnfsId("111113333300000000000000000000222222");
            PnfsGetParentMessage pnfsGetParentMessage = new PnfsGetParentMessage(tmp);

            _pnfsManager.getParent(pnfsGetParentMessage);

            assertTrue("get parent of non existing resource should return FILE_NOT_FOUND", pnfsGetParentMessage.getReturnCode() == CacheException.FILE_NOT_FOUND );

        }
    */
@Test
@Ignore
public void testAddCacheLocationNonExist() {
    PnfsAddCacheLocationMessage pnfsAddCacheLocationMessage = new PnfsAddCacheLocationMessage(new PnfsId(FsInode.generateNewID()), "aPool");
    _pnfsManager.addCacheLocation(pnfsAddCacheLocationMessage);
    assertTrue("add cache location of non existing file should return FILE_NOT_FOUND", pnfsAddCacheLocationMessage.getReturnCode() == CacheException.FILE_NOT_FOUND);
}
Also used : PnfsId(diskCacheV111.util.PnfsId) PnfsAddCacheLocationMessage(diskCacheV111.vehicles.PnfsAddCacheLocationMessage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

PnfsId (diskCacheV111.util.PnfsId)3 Link (diskCacheV111.namespace.NameSpaceProvider.Link)2 CacheException (diskCacheV111.util.CacheException)2 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)2 PnfsAddCacheLocationMessage (diskCacheV111.vehicles.PnfsAddCacheLocationMessage)2 PnfsGetParentMessage (diskCacheV111.vehicles.PnfsGetParentMessage)2 CellEndpoint (dmg.cells.nucleus.CellEndpoint)2 Test (org.junit.Test)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Lists (com.google.common.collect.Lists)1 Range (com.google.common.collect.Range)1 FILE_EXISTS (diskCacheV111.util.CacheException.FILE_EXISTS)1 FILE_NOT_FOUND (diskCacheV111.util.CacheException.FILE_NOT_FOUND)1 NOT_FILE (diskCacheV111.util.CacheException.NOT_FILE)1 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)1 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)1 MissingResourceCacheException (diskCacheV111.util.MissingResourceCacheException)1 NotDirCacheException (diskCacheV111.util.NotDirCacheException)1 NotFileCacheException (diskCacheV111.util.NotFileCacheException)1 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)1