Search in sources :

Example 1 with CellMessage

use of dmg.cells.nucleus.CellMessage in project dcache by dCache.

the class FileOperationHandler method handleStaging.

/**
 * <p>Called when there are no available replicas, but the file
 * can be retrieved from an HSM.</p>
 *
 * <p>Issues a fire and forget request.  Task is considered complete at
 * that point.</p>
 *
 * <p>When staging actually completes on the PoolManager end, the new
 * cache location message should be processed by Resilience as a new FileOperation.</p>
 *
 * <p>Should staging not complete before the pool is once again scanned,
 * PoolManager should collapse the repeated staging request.</p>
 */
public void handleStaging(PnfsId pnfsId, ResilientFileTask task) {
    try {
        FileOperation operation = fileOpMap.getOperation(pnfsId);
        FileAttributes attributes = namespace.getRequiredAttributesForStaging(pnfsId);
        String poolGroup = poolInfoMap.getGroup(operation.getPoolGroup());
        LOGGER.trace("handleStaging {}, pool group {}.", pnfsId, poolGroup);
        migrationTaskService.schedule(() -> {
            try {
                PoolMgrSelectReadPoolMsg msg = new PoolMgrSelectReadPoolMsg(attributes, getProtocolInfo(), null);
                msg.setSubject(Subjects.ROOT);
                msg.setPoolGroup(poolGroup);
                CellMessage cellMessage = new CellMessage(new CellPath(poolManagerAddress), msg);
                ACTIVITY_LOGGER.info("Staging {}", pnfsId);
                endpoint.sendMessage(cellMessage);
                LOGGER.trace("handleStaging, sent select read pool message " + "for {} to poolManager.", pnfsId);
                completionHandler.taskCompleted(pnfsId);
            } catch (URISyntaxException e) {
                completionHandler.taskFailed(pnfsId, CacheExceptionUtils.getCacheException(CacheException.INVALID_ARGS, "could not construct HTTP protocol: %s.", pnfsId, Type.WAIT_FOR_STAGE, e.getMessage(), null));
            }
        }, 0, TimeUnit.MILLISECONDS);
    } catch (CacheException ce) {
        completionHandler.taskFailed(pnfsId, ce);
    }
}
Also used : PoolMgrSelectReadPoolMsg(diskCacheV111.vehicles.PoolMgrSelectReadPoolMsg) CellMessage(dmg.cells.nucleus.CellMessage) CellPath(dmg.cells.nucleus.CellPath) CacheException(diskCacheV111.util.CacheException) FileOperation(org.dcache.resilience.data.FileOperation) URISyntaxException(java.net.URISyntaxException) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 2 with CellMessage

use of dmg.cells.nucleus.CellMessage in project dcache by dCache.

the class FileOperationHandler method handleStagingReply.

/**
 * <p>If the reply from the Pool Manager indicates that the file has
 * been staged to a pool outside the pool group, resend the message with refreshed attributes to
 * trigger a p2p by the Pool Manager to a readable resilient pool in the correct group.
 * Otherwise, discard the message.</p>
 */
public void handleStagingReply(PoolMgrSelectReadPoolMsg reply) {
    PnfsId pnfsId = reply.getPnfsId();
    try {
        if (reply.getReturnCode() == CacheException.OUT_OF_DATE) {
            FileAttributes attributes = namespace.getRequiredAttributesForStaging(pnfsId);
            /*
                 *  Check to see if one of the new locations is not resilient.
                 */
            Collection<String> locations = attributes.getLocations();
            List<String> valid = poolInfoMap.getReadableLocations(locations).stream().filter(poolInfoMap::isResilientPool).collect(Collectors.toList());
            LOGGER.trace("{}, handleStagingReply, readable resilience " + "locations are now {}.", valid);
            if (valid.size() == 0) {
                LOGGER.trace("{}, handleStagingReply, " + "PoolManager staged to" + " a non-resilient pool, " + "requesting p2p.", pnfsId);
                /*
                     *  Figure out on which pool group this should be.
                     *
                     *  It's possible that the file was "resilient" when the
                     *  stage request was sent and a subsequently configuration
                     *  change has resulted in the file no longer being
                     *  "resilient".  If this happens, the file may have no
                     *  corresponding resilient pool group.
                     *
                     *  Another possibility is the lack of resilient pool group
                     *  is due to a bug somewhere.
                     */
                Integer gIndex = null;
                for (String loc : locations) {
                    Integer pIndex = poolInfoMap.getPoolIndex(loc);
                    gIndex = poolInfoMap.getResilientPoolGroup(pIndex);
                    if (gIndex != null) {
                        break;
                    }
                }
                if (gIndex == null) {
                    LOGGER.warn("{}, handleStagingReply, file no longer" + " hosted on resilient pool group", pnfsId);
                    return;
                }
                final String poolGroup = poolInfoMap.getGroup(gIndex);
                LOGGER.trace("{}, handleStagingReply, resilient pool group " + "for p2p request: {}.", pnfsId, poolGroup);
                migrationTaskService.schedule(() -> {
                    PoolMgrSelectReadPoolMsg msg = new PoolMgrSelectReadPoolMsg(attributes, reply.getProtocolInfo(), reply.getContext(), reply.getAllowedStates());
                    msg.setSubject(reply.getSubject());
                    msg.setPoolGroup(poolGroup);
                    CellMessage cellMessage = new CellMessage(new CellPath(poolManagerAddress), msg);
                    ACTIVITY_LOGGER.info("Selecting read pool for file {}" + " staged to a non-resilient pool", pnfsId);
                    endpoint.sendMessage(cellMessage);
                    LOGGER.trace("handleStagingReply, resent select read pool " + "message for {} to poolManager.", pnfsId);
                }, 0, TimeUnit.MILLISECONDS);
                return;
            }
        }
        LOGGER.trace("{} handleStagingReply {}, nothing to do.", pnfsId, reply);
    } catch (CacheException ce) {
        LOGGER.error("handleStagingReply failed: {}.", ce.toString());
    }
}
Also used : PoolMgrSelectReadPoolMsg(diskCacheV111.vehicles.PoolMgrSelectReadPoolMsg) CellMessage(dmg.cells.nucleus.CellMessage) CellPath(dmg.cells.nucleus.CellPath) CacheException(diskCacheV111.util.CacheException) PnfsId(diskCacheV111.util.PnfsId) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 3 with CellMessage

use of dmg.cells.nucleus.CellMessage in project dcache by dCache.

the class CellStub method send.

public <T> ListenableFuture<T> send(CellPath destination, Serializable message, Class<T> type, long timeout, CellEndpoint.SendFlag... flags) {
    CellMessage envelope = new CellMessage(requireNonNull(destination), requireNonNull(message));
    Semaphore concurrency = _concurrency;
    CallbackFuture<T> future = new CallbackFuture<>(type, concurrency);
    concurrency.acquireUninterruptibly();
    _rateLimiter.acquire();
    _endpoint.sendMessage(envelope, future, MoreExecutors.directExecutor(), timeout, mergeFlags(_flags, flags));
    return future;
}
Also used : CellMessage(dmg.cells.nucleus.CellMessage) Semaphore(java.util.concurrent.Semaphore)

Example 4 with CellMessage

use of dmg.cells.nucleus.CellMessage in project dcache by dCache.

the class CellStub method notify.

/**
 * Sends {@literal message} to {@literal destination} specifying a timeout.  This is used
 * primarily to support legacy cell code that has explicit asynchronous message handling; newer
 * code should use the ListenableFuture from the equivalent send method.
 */
public void notify(CellPath destination, Serializable message, long timeout) {
    _rateLimiter.acquire();
    CellMessage envelope = new CellMessage(destination, message);
    if (timeout < Long.MAX_VALUE) {
        envelope.setTtl(timeout);
    }
    _endpoint.sendMessage(envelope);
}
Also used : CellMessage(dmg.cells.nucleus.CellMessage)

Example 5 with CellMessage

use of dmg.cells.nucleus.CellMessage in project dcache by dCache.

the class EndpointMessageReceiver method mockMessageResponses.

private void mockMessageResponses() {
    Answer a = i -> {
        CellMessage envelope = i.getArgument(0, CellMessage.class);
        messageResponses.forEach(s -> s.accept(envelope));
        return null;
    };
    Mockito.doAnswer(a).when(endpoint).sendMessage(any());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CellMessageReceiver(dmg.cells.nucleus.CellMessageReceiver) CellAddressCore(dmg.cells.nucleus.CellAddressCore) CellMessage(dmg.cells.nucleus.CellMessage) IOException(java.io.IOException) SettableFuture(com.google.common.util.concurrent.SettableFuture) CellEndpoint(dmg.cells.nucleus.CellEndpoint) Message(diskCacheV111.vehicles.Message) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) CellStub(org.dcache.cells.CellStub) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) CellPath(dmg.cells.nucleus.CellPath) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) CellMessage(dmg.cells.nucleus.CellMessage) Answer(org.mockito.stubbing.Answer)

Aggregations

CellMessage (dmg.cells.nucleus.CellMessage)69 CellPath (dmg.cells.nucleus.CellPath)18 CellAddressCore (dmg.cells.nucleus.CellAddressCore)17 Test (org.junit.Test)16 Message (diskCacheV111.vehicles.Message)12 CellEndpoint (dmg.cells.nucleus.CellEndpoint)12 Serializable (java.io.Serializable)10 ArrayList (java.util.ArrayList)9 CacheException (diskCacheV111.util.CacheException)8 PnfsId (diskCacheV111.util.PnfsId)8 PoolMgrSelectReadPoolMsg (diskCacheV111.vehicles.PoolMgrSelectReadPoolMsg)8 FileAttributes (org.dcache.vehicles.FileAttributes)7 PoolCostInfo (diskCacheV111.pools.PoolCostInfo)6 PoolV2Mode (diskCacheV111.pools.PoolV2Mode)6 PoolManagerPoolUpMessage (diskCacheV111.vehicles.PoolManagerPoolUpMessage)6 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 DCapProtocolInfo (diskCacheV111.vehicles.DCapProtocolInfo)4 PnfsMessage (diskCacheV111.vehicles.PnfsMessage)4