use of diskCacheV111.vehicles.PoolSetStickyMessage in project dcache by dCache.
the class TestPoolManagerStub method testExtendLifetime.
@Test
public void testExtendLifetime() 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));
Pool pool = new Pool(POOL1.getName());
pool.setActive(true);
pool.setAddress(POOL1.getAddress());
PoolMonitor poolMonitor = mock(PoolMonitor.class, RETURNS_DEEP_STUBS);
when(poolMonitor.getPoolSelectionUnit().getPool(POOL1.getName())).thenReturn(pool);
MovePinRequestProcessor processor = new MovePinRequestProcessor();
processor.setDao(dao);
processor.setPoolStub(new TestStub(new CellAddressCore("PinManager")) {
public PoolSetStickyMessage messageArrived(PoolSetStickyMessage msg) {
return msg;
}
});
processor.setAuthorizationPolicy(new DefaultAuthorizationPolicy());
processor.setMaxLifetime(-1);
processor.setPoolMonitor(poolMonitor);
Date expiration = new Date(now() + 60);
PinManagerExtendPinMessage message = new PinManagerExtendPinMessage(getAttributes(PNFS_ID1), pin.getPinId(), 60);
message = processor.messageArrived(message);
assertEquals(0, message.getReturnCode());
assertFalse(message.getExpirationTime().before(expiration));
Pin newPin = dao.get(dao.where().id(pin.getPinId()));
assertEquals(PNFS_ID1, newPin.getPnfsId());
assertEquals(pin.getCreationTime(), newPin.getCreationTime());
assertEquals(message.getExpirationTime(), newPin.getExpirationTime());
assertEquals(pin.getUid(), newPin.getUid());
assertEquals(pin.getGid(), newPin.getGid());
assertEquals(pin.getRequestId(), newPin.getRequestId());
assertEquals(pin.getPool(), newPin.getPool());
assertEquals(pin.getState(), newPin.getState());
assertValidSticky(newPin.getSticky());
}
use of diskCacheV111.vehicles.PoolSetStickyMessage in project dcache by dCache.
the class PinRequestProcessor method setStickyFlag.
private void setStickyFlag(final PinTask task, final String poolName, CellAddressCore poolAddress) {
/* The pin lifetime should be from the moment the file is
* actually pinned. Due to staging and pool to pool transfers
* this may be much later than when the pin was requested.
*/
Date pinExpiration = task.freezeExpirationTime();
/* To allow for some drift in clocks we add a safety margin to
* the lifetime of the sticky bit.
*/
long poolExpiration = (pinExpiration == null) ? -1 : pinExpiration.getTime() + CLOCK_DRIFT_MARGIN;
PoolSetStickyMessage msg = new PoolSetStickyMessage(poolName, task.getPnfsId(), true, task.getSticky(), poolExpiration);
CellStub.addCallback(_poolStub.send(new CellPath(poolAddress), msg), new AbstractMessageCallback<PoolSetStickyMessage>() {
@Override
public void success(PoolSetStickyMessage msg) {
try {
setToPinned(task);
task.success();
} catch (CacheException e) {
fail(task, e.getRc(), e.getMessage());
} catch (RuntimeException e) {
fail(task, CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.toString());
}
}
@Override
public void failure(int rc, Object error) {
switch(rc) {
case CacheException.POOL_DISABLED:
/* Pool manager had outdated
* information about the pool. Give
* it a chance to be updated and
* then retry.
*/
retry(task, RETRY_DELAY, "pool " + poolName + " declared itself disabled");
break;
case CacheException.FILE_NOT_IN_REPOSITORY:
/* Pnfs manager had stale location
* information. The pool clears
* this information as a result of
* this error, so we retry in a
* moment.
*/
retry(task, SMALL_DELAY, "file not on pool " + poolName);
break;
default:
fail(task, rc, error.toString());
break;
}
}
@Override
public void noroute(CellPath path) {
/* The pool must have gone down. Give
* pool manager a moment to notice this
* and then retry.
*/
retry(task, RETRY_DELAY, "no route to pool at " + poolAddress);
}
@Override
public void timeout(String error) {
/* No response from pool. Typically this is
* because the pool is overloaded.
*/
fail(task, CacheException.TIMEOUT, error);
}
}, _executor);
}
use of diskCacheV111.vehicles.PoolSetStickyMessage in project dcache by dCache.
the class LegacyAdminShell method setSticky.
private String setSticky(String destination, String target, boolean mode, StringBuffer sb) throws Exception {
if (Strings.isNullOrEmpty(target)) {
target = "*";
}
boolean verbose = sb != null;
PnfsFlagReply reply = setPnfsFlag(destination, "s", target, mode);
PnfsId pnfsId = reply.getPnfsId();
PnfsGetCacheLocationsMessage pnfsMessage = new PnfsGetCacheLocationsMessage(pnfsId);
pnfsMessage = (PnfsGetCacheLocationsMessage) sendObject("PnfsManager", pnfsMessage);
if (pnfsMessage.getReturnCode() != 0) {
throw new FileNotFoundException(destination);
}
List<String> list = pnfsMessage.getCacheLocations();
if (verbose) {
sb.append("Location(s) : ");
for (String location : list) {
sb.append(location).append(",");
}
sb.append("\n");
}
if (target.equals("*")) {
if (verbose) {
sb.append("Selection : <all>\n");
}
} else if (list.contains(target)) {
if (verbose) {
sb.append("Selection : ").append(target).append("\n");
}
list = new ArrayList<>();
list.add(target);
} else {
if (verbose) {
sb.append("Selection : <nothing>\n");
}
return sb == null ? "" : sb.toString();
}
PoolSetStickyMessage sticky;
for (String poolName : list) {
if (verbose) {
sb.append(poolName).append(" : ");
}
try {
sticky = new PoolSetStickyMessage(poolName, pnfsId, mode);
sticky = (PoolSetStickyMessage) sendObject(poolName, sticky);
if (verbose) {
int rc = sticky.getReturnCode();
if (rc != 0) {
sb.append("[").append(rc).append("] ").append(sticky.getErrorObject().toString());
} else {
sb.append("ok");
}
}
} catch (Exception ee) {
if (verbose) {
sb.append(ee.getMessage());
}
}
if (verbose) {
sb.append("\n");
}
}
return sb == null ? "" : sb.toString();
}
use of diskCacheV111.vehicles.PoolSetStickyMessage in project dcache by dCache.
the class MovePinRequestProcessor method setSticky.
private void setSticky(String poolName, PnfsId pnfsId, boolean sticky, String owner, long validTill) throws CacheException, InterruptedException, NoRouteToCellException {
PoolSelectionUnit.SelectionPool pool = _poolMonitor.getPoolSelectionUnit().getPool(poolName);
if (pool == null || !pool.isActive()) {
throw new CacheException("Unable to move sticky flag because pool " + poolName + " is unavailable");
}
PoolSetStickyMessage msg = new PoolSetStickyMessage(poolName, pnfsId, sticky, owner, validTill);
_poolStub.sendAndWait(new CellPath(pool.getAddress()), msg);
}
use of diskCacheV111.vehicles.PoolSetStickyMessage in project dcache by dCache.
the class UnpinProcessor method clearStickyFlag.
private void clearStickyFlag(final Semaphore idle, final Pin pin, Executor executor) throws InterruptedException {
PoolSelectionUnit.SelectionPool pool = _poolMonitor.getPoolSelectionUnit().getPool(pin.getPool());
if (pool == null || !pool.isActive()) {
LOGGER.warn("Unable to clear sticky flag for pin {} on pnfsid {} because pool {} is unavailable", pin.getPinId(), pin.getPnfsId(), pin.getPool());
failedToUnpin(pin);
return;
}
idle.acquire();
PoolSetStickyMessage msg = new PoolSetStickyMessage(pin.getPool(), pin.getPnfsId(), false, pin.getSticky(), 0);
CellStub.addCallback(_poolStub.send(new CellPath(pool.getAddress()), msg), new AbstractMessageCallback<PoolSetStickyMessage>() {
@Override
public void success(PoolSetStickyMessage msg) {
idle.release();
_dao.delete(pin);
}
@Override
public void failure(int rc, Object error) {
idle.release();
switch(rc) {
case CacheException.FILE_NOT_IN_REPOSITORY:
_dao.delete(pin);
break;
default:
LOGGER.warn("Failed to clear sticky flag: {} [{}]", error, rc);
failedToUnpin(pin);
break;
}
}
}, executor);
}
Aggregations