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);
}
}
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);
}
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;
}
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());
}
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());
}
Aggregations