Search in sources :

Example 11 with Pin

use of org.dcache.pinmanager.model.Pin in project dcache by dCache.

the class MovePinRequestProcessor method messageArrived.

public PinManagerExtendPinMessage messageArrived(PinManagerExtendPinMessage message) throws CacheException, InterruptedException {
    try {
        Pin pin = _dao.get(_dao.where().pnfsId(message.getFileAttributes().getPnfsId()).id(message.getPinId()));
        if (pin == null) {
            throw new InvalidMessageCacheException("Pin does not exist");
        } else if (!_pdp.canExtend(message.getSubject(), pin)) {
            throw new PermissionDeniedCacheException("Access denied");
        } else if (pin.getState() == PINNING) {
            throw new InvalidMessageCacheException("File is not pinned yet");
        } else if (pin.getState() == READY_TO_UNPIN || pin.getState() == UNPINNING || pin.getState() == FAILED_TO_UNPIN) {
            throw new InvalidMessageCacheException("Pin is no longer valid");
        }
        if (_maxLifetime > -1) {
            message.setLifetime(Math.min(_maxLifetimeUnit.toMillis(_maxLifetime), message.getLifetime()));
        }
        long lifetime = message.getLifetime();
        if (pin.hasRemainingLifetimeLessThan(lifetime)) {
            long now = System.currentTimeMillis();
            Date date = (lifetime == -1) ? null : new Date(now + lifetime);
            move(pin, pin.getPool(), date);
            message.setExpirationTime(date);
        } else {
            message.setExpirationTime(pin.getExpirationTime());
        }
        LOGGER.info("Extended pin for {} ({})", pin.getPnfsId(), pin.getPinId());
        return message;
    } catch (NoRouteToCellException e) {
        throw new CacheException("Failed to extend pin due to communication failure: " + e.getDestinationPath(), e);
    }
}
Also used : PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) Pin(org.dcache.pinmanager.model.Pin) CacheException(diskCacheV111.util.CacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) Date(java.util.Date)

Example 12 with Pin

use of org.dcache.pinmanager.model.Pin in project dcache by dCache.

the class PinRequestProcessor method createTask.

@Transactional(isolation = REPEATABLE_READ)
protected PinTask createTask(PinManagerPinMessage message, MessageReply<PinManagerPinMessage> reply) {
    PnfsId pnfsId = message.getFileAttributes().getPnfsId();
    if (message.getRequestId() != null) {
        Pin pin = _dao.get(_dao.where().pnfsId(pnfsId).requestId(message.getRequestId()));
        if (pin != null) {
            /* In this case the request is a resubmission. If the
                 * previous pin completed then use it. Otherwise abort the
                 * previous pin and create a new one.
                 */
            if (pin.getState() == PINNED) {
                message.setPin(pin);
                reply.reply(message);
                return null;
            }
            _dao.update(pin, _dao.set().state(READY_TO_UNPIN).requestId(null));
        }
    }
    Pin pin = _dao.create(_dao.set().subject(message.getSubject()).state(PINNING).pnfsId(pnfsId).requestId(message.getRequestId()).sticky("PinManager-" + UUID.randomUUID().toString()).expirationTime(getExpirationTimeForPoolSelection()));
    return new PinTask(message, reply, pin);
}
Also used : Pin(org.dcache.pinmanager.model.Pin) PnfsId(diskCacheV111.util.PnfsId) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with Pin

use of org.dcache.pinmanager.model.Pin in project dcache by dCache.

the class TestPoolManagerStub method create.

@Override
public Pin create(PinUpdate update) {
    Pin pin = ((TestUpdate) update).createPin(_counter++);
    _pins.put(pin.getPinId(), pin);
    return pin;
}
Also used : Pin(org.dcache.pinmanager.model.Pin)

Example 14 with Pin

use of org.dcache.pinmanager.model.Pin in project dcache by dCache.

the class TestPoolManagerStub method testUnpinningByPinId.

@Test
public void testUnpinningByPinId() throws Exception {
    TestDao dao = new TestDao();
    Pin pin = dao.create(dao.set().subject(Subjects.ROOT).requestId(REQUEST_ID1).expirationTime(new Date(now() + 30)).pnfsId(PNFS_ID1).pool(POOL1.getName()).sticky(STICKY1).state(PINNED));
    UnpinRequestProcessor processor = new UnpinRequestProcessor();
    processor.setDao(dao);
    processor.setAuthorizationPolicy(new DefaultAuthorizationPolicy());
    PinManagerUnpinMessage message = new PinManagerUnpinMessage(PNFS_ID1);
    message.setPinId(pin.getPinId());
    message = processor.messageArrived(message);
    assertEquals(0, message.getReturnCode());
    assertEquals(pin.getPinId(), (long) message.getPinId());
    assertEquals(pin.getRequestId(), message.getRequestId());
    Pin newPin = dao.get(dao.where().id(pin.getPinId()));
    assertEquals(PNFS_ID1, newPin.getPnfsId());
    assertEquals(pin.getPool(), newPin.getPool());
    assertEquals(READY_TO_UNPIN, newPin.getState());
    assertEquals(pin.getSticky(), newPin.getSticky());
}
Also used : Pin(org.dcache.pinmanager.model.Pin) Date(java.util.Date) Test(org.junit.Test)

Example 15 with Pin

use of org.dcache.pinmanager.model.Pin in project dcache by dCache.

the class TestPoolManagerStub method testPinning.

@Test
public void testPinning() throws Exception {
    TestDao dao = new TestDao();
    PinRequestProcessor processor = new PinRequestProcessor();
    processor.setScheduledExecutor(new TestExecutor());
    processor.setExecutor(MoreExecutors.directExecutor());
    processor.setDao(dao);
    processor.setPoolStub(new TestStub(new CellAddressCore("PinManager")) {

        public PoolSetStickyMessage messageArrived(PoolSetStickyMessage msg) {
            return msg;
        }
    });
    processor.setPoolManagerStub(new TestPoolManagerStub(new CellAddressCore("PinManager")) {

        public PoolMgrSelectReadPoolMsg messageArrived(PoolMgrSelectReadPoolMsg msg) {
            msg.setPool(POOL1);
            return msg;
        }
    });
    processor.setMaxLifetime(-1);
    processor.setStagePermission(new CheckStagePermission(null));
    processor.setPoolMonitor(new PoolMonitorV5() {

        @Override
        public PoolSelector getPoolSelector(FileAttributes fileAttributes, ProtocolInfo protocolInfo, String linkGroup, Set<String> excludes) {
            return new PoolMonitorV5.PnfsFileLocation(fileAttributes, protocolInfo, linkGroup, excludes) {

                @Override
                public SelectedPool selectPinPool() {
                    return new SelectedPool(new PoolInfo(POOL1.getAddress(), new PoolCostInfo(POOL1.getName(), IoQueueManager.DEFAULT_QUEUE), ImmutableMap.of()));
                }
            };
        }
    });
    Date expiration = new Date(now() + 30);
    PinManagerPinMessage message = new PinManagerPinMessage(getAttributes(PNFS_ID1), PROTOCOL_INFO, REQUEST_ID1, 30);
    Date start = new Date();
    message = processor.messageArrived(message).get();
    Date stop = new Date();
    assertEquals(0, message.getReturnCode());
    assertFalse(message.getExpirationTime().before(expiration));
    Pin pin = dao.get(dao.where().id(message.getPinId()));
    assertEquals(PNFS_ID1, pin.getPnfsId());
    assertBetween(start, stop, pin.getCreationTime());
    assertEquals(message.getExpirationTime(), pin.getExpirationTime());
    assertEquals(0, pin.getUid());
    assertEquals(0, pin.getGid());
    assertEquals(REQUEST_ID1, pin.getRequestId());
    assertEquals(POOL1.getName(), pin.getPool());
    assertEquals(PINNED, pin.getState());
    assertValidSticky(pin.getSticky());
}
Also used : PoolMgrSelectReadPoolMsg(diskCacheV111.vehicles.PoolMgrSelectReadPoolMsg) CellAddressCore(dmg.cells.nucleus.CellAddressCore) SelectedPool(org.dcache.poolmanager.SelectedPool) PoolSetStickyMessage(diskCacheV111.vehicles.PoolSetStickyMessage) Date(java.util.Date) Pin(org.dcache.pinmanager.model.Pin) CheckStagePermission(diskCacheV111.util.CheckStagePermission) ProtocolInfo(diskCacheV111.vehicles.ProtocolInfo) DCapProtocolInfo(diskCacheV111.vehicles.DCapProtocolInfo) PoolInfo(org.dcache.poolmanager.PoolInfo) PoolMonitorV5(diskCacheV111.poolManager.PoolMonitorV5) FileAttributes(org.dcache.vehicles.FileAttributes) PoolCostInfo(diskCacheV111.pools.PoolCostInfo) PoolSelector(org.dcache.poolmanager.PoolSelector) Test(org.junit.Test)

Aggregations

Pin (org.dcache.pinmanager.model.Pin)17 Date (java.util.Date)7 CacheException (diskCacheV111.util.CacheException)4 PnfsId (diskCacheV111.util.PnfsId)4 Test (org.junit.Test)4 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)3 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)3 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)3 CellEndpoint (dmg.cells.nucleus.CellEndpoint)3 PoolSetStickyMessage (diskCacheV111.vehicles.PoolSetStickyMessage)2 CellAddressCore (dmg.cells.nucleus.CellAddressCore)2 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)2 Timestamp (java.sql.Timestamp)2 SelectedPool (org.dcache.poolmanager.SelectedPool)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Pool (diskCacheV111.poolManager.Pool)1 PoolMonitorV5 (diskCacheV111.poolManager.PoolMonitorV5)1 PoolCostInfo (diskCacheV111.pools.PoolCostInfo)1 CheckStagePermission (diskCacheV111.util.CheckStagePermission)1