Search in sources :

Example 1 with PnfsClearCacheLocationMessage

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

the class RemoteNameSpaceProviderTests method shouldSucceedWhenClearCacheLocationRemoveLast.

@Test
public void shouldSucceedWhenClearCacheLocationRemoveLast() throws Exception {
    givenSuccessfulResponse();
    _namespace.clearCacheLocation(ROOT, A_PNFSID, "pool-1", true);
    PnfsClearCacheLocationMessage sent = getSingleSendAndWaitMessage(PnfsClearCacheLocationMessage.class);
    assertThat(sent.getReplyRequired(), is(true));
    assertThat(sent.getSubject(), is(ROOT));
    assertThat(sent.getPnfsId(), is(A_PNFSID));
    assertThat(sent.getPoolName(), is("pool-1"));
    assertThat(sent.removeIfLast(), is(true));
}
Also used : PnfsClearCacheLocationMessage(diskCacheV111.vehicles.PnfsClearCacheLocationMessage) Test(org.junit.Test)

Example 2 with PnfsClearCacheLocationMessage

use of diskCacheV111.vehicles.PnfsClearCacheLocationMessage 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 3 with PnfsClearCacheLocationMessage

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

the class RepositorySubsystemTest method testRemoveOpenAgain.

@Test(expected = LockedCacheException.class)
public void testRemoveOpenAgain() throws Throwable {
    repository.init();
    repository.load();
    stateChangeEvents.clear();
    new CellStubHelper(cell) {

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

        @Override
        protected void run() throws CacheException, InterruptedException, IllegalTransitionException {
            ReplicaDescriptor h1 = repository.openEntry(id1, EnumSet.noneOf(OpenFlags.class));
            repository.setState(id1, REMOVED, "test");
            expectStateChangeEvent(id1, PRECIOUS, REMOVED);
            assertStep("Cache location should have been cleared", 1);
            ReplicaDescriptor h2 = repository.openEntry(id1, EnumSet.noneOf(OpenFlags.class));
        }
    };
}
Also used : ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) OpenFlags(org.dcache.pool.repository.Repository.OpenFlags) PnfsClearCacheLocationMessage(diskCacheV111.vehicles.PnfsClearCacheLocationMessage) CellStubHelper(org.dcache.tests.cells.CellStubHelper) Test(org.junit.Test)

Example 4 with PnfsClearCacheLocationMessage

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

the class PnfsManagerV3 method postProcessLocationModificationMessage.

private void postProcessLocationModificationMessage(CellMessage envelope, PnfsMessage message) {
    if (message.getReplyRequired()) {
        envelope.revertDirection();
        sendMessage(envelope);
    }
    if (message instanceof PnfsAddCacheLocationMessage) {
        PnfsMessage msg = new PnfsAddCacheLocationMessage(message.getPnfsId(), ((PnfsAddCacheLocationMessage) message).getPoolName());
        sendMessage(new CellMessage(_cacheModificationRelay, msg));
    } else if (message instanceof PnfsClearCacheLocationMessage) {
        PnfsMessage msg = new PnfsClearCacheLocationMessage(message.getPnfsId(), ((PnfsClearCacheLocationMessage) message).getPoolName());
        sendMessage(new CellMessage(_cacheModificationRelay, msg));
    } else if (message instanceof PnfsSetFileAttributes) {
        Collection<String> locations = ((PnfsSetFileAttributes) message).getLocations();
        if (locations == null) {
            return;
        }
        PnfsId pnfsId = message.getPnfsId();
        locations.stream().forEach((pool) -> {
            PnfsMessage msg = new PnfsAddCacheLocationMessage(pnfsId, pool);
            sendMessage(new CellMessage(_cacheModificationRelay, msg));
        });
    }
}
Also used : CellMessage(dmg.cells.nucleus.CellMessage) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) PnfsId(diskCacheV111.util.PnfsId) PnfsClearCacheLocationMessage(diskCacheV111.vehicles.PnfsClearCacheLocationMessage) PnfsMessage(diskCacheV111.vehicles.PnfsMessage) PnfsAddCacheLocationMessage(diskCacheV111.vehicles.PnfsAddCacheLocationMessage)

Example 5 with PnfsClearCacheLocationMessage

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

the class PnfsManagerV3 method clearCacheLocation.

public void clearCacheLocation(PnfsClearCacheLocationMessage pnfsMessage) {
    PnfsId pnfsId = pnfsMessage.getPnfsId();
    LOGGER.info("clearCacheLocation : {} for {}", pnfsMessage.getPoolName(), pnfsId);
    try {
        checkMask(pnfsMessage);
        checkRestriction(pnfsMessage, UPDATE_METADATA);
        _nameSpaceProvider.clearCacheLocation(pnfsMessage.getSubject(), pnfsId, pnfsMessage.getPoolName(), pnfsMessage.removeIfLast());
    } catch (FileNotFoundCacheException fnf) {
        pnfsMessage.setFailed(CacheException.FILE_NOT_FOUND, fnf.getMessage());
    } catch (CacheException e) {
        LOGGER.warn("Exception in clearCacheLocation for {}: {}", pnfsId, e.toString());
        pnfsMessage.setFailed(e.getRc(), e.getMessage());
    } catch (RuntimeException e) {
        LOGGER.error("Exception in clearCacheLocation for " + pnfsId, e);
        pnfsMessage.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) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException)

Aggregations

PnfsClearCacheLocationMessage (diskCacheV111.vehicles.PnfsClearCacheLocationMessage)9 Test (org.junit.Test)6 PnfsId (diskCacheV111.util.PnfsId)3 PnfsAddCacheLocationMessage (diskCacheV111.vehicles.PnfsAddCacheLocationMessage)3 ReplicaDescriptor (org.dcache.pool.repository.ReplicaDescriptor)3 OpenFlags (org.dcache.pool.repository.Repository.OpenFlags)3 CellStubHelper (org.dcache.tests.cells.CellStubHelper)3 PnfsSetFileAttributes (org.dcache.vehicles.PnfsSetFileAttributes)2 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 PnfsHandler (diskCacheV111.util.PnfsHandler)1 PnfsCreateEntryMessage (diskCacheV111.vehicles.PnfsCreateEntryMessage)1 PnfsGetCacheLocationsMessage (diskCacheV111.vehicles.PnfsGetCacheLocationsMessage)1 PnfsMessage (diskCacheV111.vehicles.PnfsMessage)1 CellMessage (dmg.cells.nucleus.CellMessage)1 FileAttribute (org.dcache.namespace.FileAttribute)1