Search in sources :

Example 1 with Message

use of diskCacheV111.vehicles.Message in project dcache by dCache.

the class QoSMessageHandler method messageArrived.

/**
 * Returns whether replica exists, the status of its system sticky flag and whether its state
 * allows for reading and removal.
 */
public Reply messageArrived(ReplicaStatusMessage message) {
    MessageReply<Message> reply = new MessageReply<>();
    executor.execute(() -> {
        PnfsId pnfsId = message.getPnfsId();
        try {
            CacheEntry entry = repository.getEntry(pnfsId);
            message.setExists(true);
            switch(entry.getState()) {
                case FROM_CLIENT:
                case FROM_POOL:
                case FROM_STORE:
                    message.setWaiting(true);
                    break;
                case CACHED:
                    message.setReadable(true);
                    message.setRemovable(true);
                    break;
                case BROKEN:
                    message.setBroken(true);
                    message.setRemovable(true);
                    break;
                case PRECIOUS:
                    message.setReadable(true);
                    message.setPrecious(true);
                    break;
                default:
                    break;
            }
            Collection<StickyRecord> records = entry.getStickyRecords();
            for (StickyRecord record : records) {
                if (record.owner().equals(SYSTEM_OWNER) && record.isNonExpiring()) {
                    message.setSystemSticky(true);
                    break;
                }
            }
            reply.reply(message);
        } catch (FileNotInCacheException e) {
            reply.reply(message);
        } catch (Exception e) {
            reply.fail(message, e);
        }
    });
    return reply;
}
Also used : StickyRecord(org.dcache.pool.repository.StickyRecord) ChangePreciousBitMessage(org.dcache.vehicles.qos.ChangePreciousBitMessage) Message(diskCacheV111.vehicles.Message) ChangeStickyBitMessage(org.dcache.vehicles.qos.ChangeStickyBitMessage) ReplicaStatusMessage(org.dcache.vehicles.qos.ReplicaStatusMessage) MessageReply(org.dcache.cells.MessageReply) PnfsId(diskCacheV111.util.PnfsId) CacheEntry(org.dcache.pool.repository.CacheEntry) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException)

Example 2 with Message

use of diskCacheV111.vehicles.Message in project dcache by dCache.

the class RemoteHttpDataTransferProtocol method receiveFile.

private void receiveFile(final RemoteHttpDataTransferProtocolInfo info) throws ThirdPartyTransferFailedCacheException {
    Set<Checksum> checksums;
    long deadline = System.currentTimeMillis() + GET_RETRY_DURATION;
    HttpClientContext context = storeContext(new HttpClientContext());
    try {
        try (CloseableHttpResponse response = doGet(info, context, deadline)) {
            String rfc3230 = headerValue(response, "Digest");
            checksums = Checksums.decodeRfc3230(rfc3230);
            checksums.forEach(_integrityChecker);
            HttpEntity entity = response.getEntity();
            if (entity == null) {
                throw new ThirdPartyTransferFailedCacheException("GET response contains no content");
            }
            long length = entity.getContentLength();
            if (length > 0) {
                _channel.truncate(length);
            }
            if (response.getStatusLine() != null && response.getStatusLine().getStatusCode() < 300 && length > -1) {
                _expectedTransferSize = length;
            }
            entity.writeTo(Channels.newOutputStream(_channel));
        } catch (SocketTimeoutException e) {
            String message = "socket timeout on GET (received " + describeSize(_channel.getBytesTransferred()) + " of data; " + describeSize(e.bytesTransferred) + " pending)";
            if (e.getMessage() != null) {
                message += ": " + e.getMessage();
            }
            throw new ThirdPartyTransferFailedCacheException(message, e);
        } catch (IOException e) {
            throw new ThirdPartyTransferFailedCacheException(messageOrClassName(e), e);
        } catch (InterruptedException e) {
            throw new ThirdPartyTransferFailedCacheException("pool is shutting down", e);
        }
    } catch (ThirdPartyTransferFailedCacheException e) {
        List<URI> redirections = context.getRedirectLocations();
        if (redirections != null && !redirections.isEmpty()) {
            StringBuilder message = new StringBuilder(e.getMessage());
            message.append("; redirects ").append(redirections);
            throw new ThirdPartyTransferFailedCacheException(message.toString(), e.getCause());
        } else {
            throw e;
        }
    }
    // HEAD requests.
    if (checksums.isEmpty() && info.isVerificationRequired()) {
        HttpHead head = buildHeadRequest(info, deadline);
        head.addHeader("Want-Digest", WANT_DIGEST_VALUE);
        try {
            try (CloseableHttpResponse response = _client.execute(head)) {
                String rfc3230 = headerValue(response, "Digest");
                checkThirdPartyTransferSuccessful(rfc3230 != null, "no checksums in HEAD response");
                checksums = Checksums.decodeRfc3230(rfc3230);
                checkThirdPartyTransferSuccessful(!checksums.isEmpty(), "no useful checksums in HEAD response: %s", rfc3230);
                // Ensure integrety.  If we're lucky, this won't trigger
                // rescanning the uploaded file.
                checksums.forEach(_integrityChecker);
            }
        } catch (IOException e) {
            throw new ThirdPartyTransferFailedCacheException("HEAD request failed: " + messageOrClassName(e), e);
        }
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) IOException(java.io.IOException) HttpHead(org.apache.http.client.methods.HttpHead) ThirdPartyTransferFailedCacheException(diskCacheV111.util.ThirdPartyTransferFailedCacheException) SocketTimeoutException(java.net.SocketTimeoutException) Checksum(org.dcache.util.Checksum) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with Message

use of diskCacheV111.vehicles.Message in project dcache by dCache.

the class P2PClient method messageArrived.

public synchronized void messageArrived(DoorTransferFinishedMessage message) {
    HttpProtocolInfo pinfo = (HttpProtocolInfo) message.getProtocolInfo();
    int sessionId = pinfo.getSessionId();
    Companion companion = _companions.get(sessionId);
    if (companion != null) {
        companion.messageArrived(message);
    }
}
Also used : HttpProtocolInfo(diskCacheV111.vehicles.HttpProtocolInfo)

Example 4 with Message

use of diskCacheV111.vehicles.Message in project dcache by dCache.

the class StagingAdjuster method poll.

/**
 * Polled by main map thread.  If the future is done, this will trigger the completion handler.
 */
public void poll() {
    synchronized (this) {
        if (future == null) {
            completionHandler.taskFailed(pnfsId, Optional.empty(), new CacheException(CacheException.SERVICE_UNAVAILABLE, "no future returned by message send."));
            return;
        }
    }
    PinManagerPinMessage migrationReply = null;
    Object error = null;
    try {
        LOGGER.debug("poll, checking pin request future.isDone() for {}.", pnfsId);
        if (!future.isDone()) {
            return;
        }
        migrationReply = getUninterruptibly(future);
        if (migrationReply.getReturnCode() != 0) {
            error = migrationReply.getErrorObject();
        }
    } catch (CancellationException e) {
    /*
             *  Cancelled state set by caller.
             */
    } catch (ExecutionException e) {
        error = e.getCause();
    }
    LOGGER.debug("poll, calling completion handler for {}.", pnfsId);
    String target = migrationReply.getPool();
    if (error == null) {
        completionHandler.taskCompleted(pnfsId, Optional.ofNullable(target));
    } else if (error instanceof Throwable) {
        completionHandler.taskFailed(pnfsId, Optional.ofNullable(target), new CacheException("Pin failure", (Throwable) error));
    } else {
        completionHandler.taskFailed(pnfsId, Optional.ofNullable(target), new CacheException(String.valueOf(error)));
    }
}
Also used : CacheException(diskCacheV111.util.CacheException) CancellationException(java.util.concurrent.CancellationException) PinManagerPinMessage(org.dcache.pinmanager.PinManagerPinMessage) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with Message

use of diskCacheV111.vehicles.Message in project dcache by dCache.

the class QoSAdjustmentReceiver method messageArrived.

public void messageArrived(QoSAdjustmentCancelledMessage message) {
    PnfsId pnfsId = message.getPnfsId();
    ACTIVITY_LOGGER.info("Received cancellation for adjustment of {}.", pnfsId);
    if (messageGuard.getStatus("QoSAdjustmentCancelledMessage", message) == Status.DISABLED) {
        return;
    }
    taskHandler.handleAdjustmentCancelled(pnfsId);
}
Also used : PnfsId(diskCacheV111.util.PnfsId)

Aggregations

CacheException (diskCacheV111.util.CacheException)72 PnfsId (diskCacheV111.util.PnfsId)44 Message (diskCacheV111.vehicles.Message)41 Test (org.junit.Test)38 CellMessage (dmg.cells.nucleus.CellMessage)36 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)32 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)31 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)31 CellPath (dmg.cells.nucleus.CellPath)25 FileAttributes (org.dcache.vehicles.FileAttributes)24 ApiOperation (io.swagger.annotations.ApiOperation)20 ApiResponses (io.swagger.annotations.ApiResponses)20 Produces (javax.ws.rs.Produces)20 BadRequestException (javax.ws.rs.BadRequestException)19 Path (javax.ws.rs.Path)19 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)19 ForbiddenException (javax.ws.rs.ForbiddenException)17 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)17 FsPath (diskCacheV111.util.FsPath)16 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)16