Search in sources :

Example 1 with Checksum

use of org.dcache.util.Checksum in project dcache by dCache.

the class AbstractBlockingNearlineStorage method stage.

@Override
public void stage(Iterable<StageRequest> requests) {
    for (StageRequest request : requests) {
        Task<StageRequest, Set<Checksum>> task = new Task<StageRequest, Set<Checksum>>(request) {

            @Override
            public Set<Checksum> call() throws Exception {
                FileAttributes attributes = request.getFileAttributes();
                NDC.push(attributes.getPnfsId().toString());
                try {
                    request.allocate().get();
                    return stage(request);
                } finally {
                    NDC.pop();
                }
            }

            @Override
            protected void execute() {
                getStageExecutor().execute(this);
            }
        };
        task.execute();
    }
}
Also used : Set(java.util.Set) StageRequest(org.dcache.pool.nearline.spi.StageRequest) Checksum(org.dcache.util.Checksum) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 2 with Checksum

use of org.dcache.util.Checksum 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 Checksum

use of org.dcache.util.Checksum in project dcache by dCache.

the class Companion method transfer.

private void transfer(String uri) {
    ReplicaDescriptor handle;
    synchronized (this) {
        try {
            handle = createReplicaEntry();
        } catch (FileInCacheException e) {
            _fsm.fileExists();
            return;
        } catch (CacheException e) {
            _fsm.createEntryFailed(e.getRc(), e.getMessage());
            return;
        }
        setThread(Thread.currentThread());
    }
    Throwable error = null;
    try {
        try {
            Set<Checksum> actualChecksums = copy(uri, handle);
            _checksumModule.enforcePostTransferPolicy(handle, actualChecksums);
        } finally {
            setThread(null);
            Thread.interrupted();
        }
        if (_atime != null) {
            handle.setLastAccessTime(_atime);
        }
        handle.commit();
    } catch (Throwable e) {
        error = e;
    } finally {
        handle.close();
        synchronized (this) {
            _fsm.transferEnded(error);
        }
    }
}
Also used : ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) FileInCacheException(diskCacheV111.util.FileInCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) FileInCacheException(diskCacheV111.util.FileInCacheException) CacheException(diskCacheV111.util.CacheException) Checksum(org.dcache.util.Checksum)

Example 4 with Checksum

use of org.dcache.util.Checksum in project dcache by dCache.

the class AbstractXrootdRequestHandler method selectChecksum.

protected QueryResponse selectChecksum(ChecksumInfo info, Set<Checksum> checksums, QueryRequest msg) throws XrootdException {
    if (!checksums.isEmpty()) {
        /**
         * xrdcp expects lower case names for checksum algorithms
         * https://github.com/xrootd/xrootd/issues/459
         * TODO: remove toLowerCase() call when above issue is addressed
         */
        Optional<String> type = info.getType();
        if (type.isPresent()) {
            Optional<Checksum> result = checksums.stream().filter((c) -> type.get().equalsIgnoreCase(c.getType().getName())).findFirst();
            if (result.isPresent()) {
                Checksum checksum = result.get();
                return new QueryResponse(msg, checksum.getType().getName().toLowerCase() + " " + checksum.getValue());
            }
            throw new XrootdException(kXR_Unsupported, "Checksum exists, " + "but not of the requested type.");
        }
        Checksum checksum = Checksums.preferredOrder().min(checksums);
        return new QueryResponse(msg, checksum.getType().getName().toLowerCase() + " " + checksum.getValue());
    }
    throw new XrootdException(kXR_Unsupported, "No checksum available " + "for this file.");
}
Also used : ChecksumInfo(org.dcache.xrootd.util.ChecksumInfo) Logger(org.slf4j.Logger) QueryRequest(org.dcache.xrootd.protocol.messages.QueryRequest) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) QueryResponse(org.dcache.xrootd.protocol.messages.QueryResponse) Checksum(org.dcache.util.Checksum) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) XrootdException(org.dcache.xrootd.core.XrootdException) LocateRequest(org.dcache.xrootd.protocol.messages.LocateRequest) SetRequest(org.dcache.xrootd.protocol.messages.SetRequest) XrootdResponse(org.dcache.xrootd.protocol.messages.XrootdResponse) XrootdProtocol.kXR_Unsupported(org.dcache.xrootd.protocol.XrootdProtocol.kXR_Unsupported) XrootdProtocolRequestHandler(org.dcache.xrootd.core.XrootdProtocolRequestHandler) Optional(java.util.Optional) Checksums(org.dcache.util.Checksums) SetResponse(org.dcache.xrootd.protocol.messages.SetResponse) LocateResponse(org.dcache.xrootd.protocol.messages.LocateResponse) Checksum(org.dcache.util.Checksum) QueryResponse(org.dcache.xrootd.protocol.messages.QueryResponse) XrootdException(org.dcache.xrootd.core.XrootdException)

Example 5 with Checksum

use of org.dcache.util.Checksum in project dcache by dCache.

the class FsInode_PCRC method value.

protected String value() throws ChimeraFsException {
    Set<Checksum> results = _fs.getInodeChecksums(this);
    StringBuilder sb = new StringBuilder();
    Iterator<Checksum> it = results.iterator();
    if (it.hasNext()) {
        Checksum result = it.next();
        sb.append(result.getType()).append(':').append(result.getValue());
    }
    while (it.hasNext()) {
        Checksum result = it.next();
        sb.append(", ").append(result.getType()).append(':').append(result.getValue());
    }
    sb.append(NEWLINE);
    return sb.toString();
}
Also used : Checksum(org.dcache.util.Checksum)

Aggregations

Checksum (org.dcache.util.Checksum)29 ChecksumType (org.dcache.util.ChecksumType)10 CacheException (diskCacheV111.util.CacheException)9 IOException (java.io.IOException)8 FileAttributes (org.dcache.vehicles.FileAttributes)6 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)5 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)4 Test (org.junit.Test)4 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)3 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)3 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)3 NotFileCacheException (diskCacheV111.util.NotFileCacheException)3 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)3 PnfsId (diskCacheV111.util.PnfsId)3 MessageDigest (java.security.MessageDigest)3 Set (java.util.Set)3 RepositoryChannel (org.dcache.pool.repository.RepositoryChannel)3 Iterables (com.google.common.collect.Iterables)2 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2