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();
}
}
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);
}
}
}
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);
}
}
}
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.");
}
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();
}
Aggregations