Search in sources :

Example 1 with Checksums

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

Aggregations

ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Checksum (org.dcache.util.Checksum)1 Checksums (org.dcache.util.Checksums)1 XrootdException (org.dcache.xrootd.core.XrootdException)1 XrootdProtocolRequestHandler (org.dcache.xrootd.core.XrootdProtocolRequestHandler)1 XrootdProtocol.kXR_Unsupported (org.dcache.xrootd.protocol.XrootdProtocol.kXR_Unsupported)1 LocateRequest (org.dcache.xrootd.protocol.messages.LocateRequest)1 LocateResponse (org.dcache.xrootd.protocol.messages.LocateResponse)1 QueryRequest (org.dcache.xrootd.protocol.messages.QueryRequest)1 QueryResponse (org.dcache.xrootd.protocol.messages.QueryResponse)1 SetRequest (org.dcache.xrootd.protocol.messages.SetRequest)1 SetResponse (org.dcache.xrootd.protocol.messages.SetResponse)1 XrootdResponse (org.dcache.xrootd.protocol.messages.XrootdResponse)1 ChecksumInfo (org.dcache.xrootd.util.ChecksumInfo)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1