Search in sources :

Example 1 with PoolSetStickyMessage

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());
}
Also used : CellAddressCore(dmg.cells.nucleus.CellAddressCore) Pin(org.dcache.pinmanager.model.Pin) SelectedPool(org.dcache.poolmanager.SelectedPool) Pool(diskCacheV111.poolManager.Pool) PoolMonitor(org.dcache.poolmanager.PoolMonitor) PoolSetStickyMessage(diskCacheV111.vehicles.PoolSetStickyMessage) Date(java.util.Date) Test(org.junit.Test)

Example 2 with PoolSetStickyMessage

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);
}
Also used : CellPath(dmg.cells.nucleus.CellPath) FileNotOnlineCacheException(diskCacheV111.util.FileNotOnlineCacheException) CacheException(diskCacheV111.util.CacheException) PoolSetStickyMessage(diskCacheV111.vehicles.PoolSetStickyMessage) Date(java.util.Date)

Example 3 with PoolSetStickyMessage

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();
}
Also used : PnfsGetCacheLocationsMessage(diskCacheV111.vehicles.PnfsGetCacheLocationsMessage) PnfsId(diskCacheV111.util.PnfsId) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) AuthorizedString(dmg.util.AuthorizedString) PoolSetStickyMessage(diskCacheV111.vehicles.PoolSetStickyMessage) CellEndpoint(dmg.cells.nucleus.CellEndpoint) CommandThrowableException(dmg.util.CommandThrowableException) AclException(dmg.util.AclException) CommandException(dmg.util.CommandException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) FileNotFoundException(java.io.FileNotFoundException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CommandExitException(dmg.util.CommandExitException) SerializationException(dmg.cells.nucleus.SerializationException) CacheException(diskCacheV111.util.CacheException) CommandSyntaxException(dmg.util.CommandSyntaxException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with PoolSetStickyMessage

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);
}
Also used : CellPath(dmg.cells.nucleus.CellPath) CacheException(diskCacheV111.util.CacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) PoolSelectionUnit(diskCacheV111.poolManager.PoolSelectionUnit) PoolSetStickyMessage(diskCacheV111.vehicles.PoolSetStickyMessage)

Example 5 with PoolSetStickyMessage

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);
}
Also used : CellPath(dmg.cells.nucleus.CellPath) PoolSelectionUnit(diskCacheV111.poolManager.PoolSelectionUnit) PoolSetStickyMessage(diskCacheV111.vehicles.PoolSetStickyMessage)

Aggregations

PoolSetStickyMessage (diskCacheV111.vehicles.PoolSetStickyMessage)6 CacheException (diskCacheV111.util.CacheException)3 CellPath (dmg.cells.nucleus.CellPath)3 Date (java.util.Date)3 PoolSelectionUnit (diskCacheV111.poolManager.PoolSelectionUnit)2 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)2 CellAddressCore (dmg.cells.nucleus.CellAddressCore)2 Pin (org.dcache.pinmanager.model.Pin)2 SelectedPool (org.dcache.poolmanager.SelectedPool)2 Test (org.junit.Test)2 Pool (diskCacheV111.poolManager.Pool)1 PoolMonitorV5 (diskCacheV111.poolManager.PoolMonitorV5)1 PoolCostInfo (diskCacheV111.pools.PoolCostInfo)1 CheckStagePermission (diskCacheV111.util.CheckStagePermission)1 FileNotOnlineCacheException (diskCacheV111.util.FileNotOnlineCacheException)1 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)1 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)1 PnfsId (diskCacheV111.util.PnfsId)1 DCapProtocolInfo (diskCacheV111.vehicles.DCapProtocolInfo)1 PnfsGetCacheLocationsMessage (diskCacheV111.vehicles.PnfsGetCacheLocationsMessage)1