use of org.dcache.vehicles.FileAttributes in project dcache by dCache.
the class AbstractBlockingNearlineStorage method flush.
@Override
public void flush(Iterable<FlushRequest> requests) {
for (FlushRequest request : requests) {
Task<FlushRequest, Set<URI>> task = new Task<FlushRequest, Set<URI>>(request) {
@Override
public Set<URI> call() throws Exception {
FileAttributes fileAttributes = request.getFileAttributes();
NDC.push(fileAttributes.getPnfsId().toString());
try {
return flush(request);
} finally {
NDC.pop();
}
}
@Override
protected void execute() {
getFlushExecutor().execute(this);
}
};
task.execute();
}
}
use of org.dcache.vehicles.FileAttributes 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.vehicles.FileAttributes in project dcache by dCache.
the class RemoteHttpDataTransferProtocol method verifyRemoteFile.
private void verifyRemoteFile(RemoteHttpDataTransferProtocolInfo info) throws ThirdPartyTransferFailedCacheException {
FileAttributes attributes = _channel.getFileAttributes();
boolean isFirstAttempt = true;
long t_max = maxRetryDuration(attributes.getSize());
long deadline = System.currentTimeMillis() + t_max;
try {
while (System.currentTimeMillis() < deadline) {
long sleepFor = Math.min(deadline - System.currentTimeMillis(), DELAY_BETWEEN_REQUESTS);
if (!isFirstAttempt && sleepFor > 0) {
Thread.sleep(sleepFor);
}
isFirstAttempt = false;
HttpClientContext context = storeContext(new HttpClientContext());
HttpHead head = buildHeadRequest(info, deadline);
buildWantDigest().ifPresent(v -> head.addHeader("Want-Digest", v));
try {
try (CloseableHttpResponse response = _client.execute(head, context)) {
StatusLine status = response.getStatusLine();
if (status.getStatusCode() >= 300) {
checkThirdPartyTransferSuccessful(!info.isVerificationRequired(), "rejected HEAD: %d %s", status.getStatusCode(), status.getReasonPhrase());
return;
}
if (shouldRetry(response)) {
continue;
}
OptionalLong contentLengthHeader = contentLength(response);
if (contentLengthHeader.isPresent()) {
long contentLength = contentLengthHeader.getAsLong();
long fileSize = attributes.getSize();
checkThirdPartyTransferSuccessful(contentLength == fileSize, "HEAD Content-Length (%d) does not match file size (%d)", contentLength, fileSize);
} else {
LOGGER.debug("HEAD response did not contain Content-Length");
}
String rfc3230 = headerValue(response, "Digest");
checkChecksums(info, rfc3230, attributes.getChecksumsIfPresent());
return;
} catch (IOException e) {
throw new ThirdPartyTransferFailedCacheException("failed to " + "connect to server: " + e.toString(), e);
}
} catch (ThirdPartyTransferFailedCacheException e) {
List<URI> redirections = context.getRedirectLocations();
if (redirections != null && !redirections.isEmpty()) {
throw new ThirdPartyTransferFailedCacheException(e.getMessage() + "; redirections " + redirections, e.getCause());
} else {
throw e;
}
}
}
} catch (InterruptedException e) {
throw new ThirdPartyTransferFailedCacheException("pool is shutting down", e);
}
throw new ThirdPartyTransferFailedCacheException("remote server failed " + "to provide length after " + describeDuration(GET_RETRY_DURATION, MILLISECONDS));
}
use of org.dcache.vehicles.FileAttributes in project dcache by dCache.
the class ScriptNearlineStorage method getFetchCommand.
@VisibleForTesting
String[] getFetchCommand(URI dataFile, FileAttributes fileAttributes) {
StorageInfo storageInfo = StorageInfos.extractFrom(fileAttributes);
String[] argsArray = Stream.of(Stream.of(command, "get", fileAttributes.getPnfsId().toString(), getFileString(dataFile), "-si=" + storageInfo), getLocations(fileAttributes).stream().map(uri -> "-uri=" + uri), options.stream()).flatMap(s -> s).toArray(String[]::new);
LOGGER.debug("COMMAND: {}", Arrays.deepToString(argsArray));
return argsArray;
}
use of org.dcache.vehicles.FileAttributes in project dcache by dCache.
the class ScriptNearlineStorage method stage.
@Override
protected Set<Checksum> stage(StageRequest request) throws IOException, CacheException {
try {
FileAttributes attributes = request.getFileAttributes();
String[] fetchCommand = getFetchCommand(request.getReplicaUri(), attributes);
new HsmRunSystem(name, MAX_LINES, request.getDeadline() - System.currentTimeMillis(), fetchCommand).execute();
return readChecksumFromHsm(request.getFile());
} catch (IllegalThreadStateException e) {
throw new CacheException(3, e.getMessage(), e);
}
}
Aggregations