Search in sources :

Example 1 with FileAttributes

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();
    }
}
Also used : Set(java.util.Set) FlushRequest(org.dcache.pool.nearline.spi.FlushRequest) URI(java.net.URI) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 2 with FileAttributes

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();
    }
}
Also used : Set(java.util.Set) StageRequest(org.dcache.pool.nearline.spi.StageRequest) Checksum(org.dcache.util.Checksum) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 3 with FileAttributes

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));
}
Also used : HttpClientContext(org.apache.http.client.protocol.HttpClientContext) IOException(java.io.IOException) HttpHead(org.apache.http.client.methods.HttpHead) ThirdPartyTransferFailedCacheException(diskCacheV111.util.ThirdPartyTransferFailedCacheException) StatusLine(org.apache.http.StatusLine) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) OptionalLong(java.util.OptionalLong) List(java.util.List) ArrayList(java.util.ArrayList) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 4 with FileAttributes

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;
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) FlushRequest(org.dcache.pool.nearline.spi.FlushRequest) BoundedExecutor(org.dcache.util.BoundedExecutor) URISyntaxException(java.net.URISyntaxException) ChecksumType(org.dcache.util.ChecksumType) LoggerFactory(org.slf4j.LoggerFactory) StorageInfos(diskCacheV111.vehicles.StorageInfos) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) AbstractBlockingNearlineStorage(org.dcache.pool.nearline.AbstractBlockingNearlineStorage) RemoveRequest(org.dcache.pool.nearline.spi.RemoveRequest) CacheException(diskCacheV111.util.CacheException) StorageInfo(diskCacheV111.vehicles.StorageInfo) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) URI(java.net.URI) CDCScheduledExecutorServiceDecorator(org.dcache.util.CDCScheduledExecutorServiceDecorator) Splitter(com.google.common.base.Splitter) ExecutorService(java.util.concurrent.ExecutorService) FileAttributes(org.dcache.vehicles.FileAttributes) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Executor(java.util.concurrent.Executor) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Collectors(java.util.stream.Collectors) File(java.io.File) Executors(java.util.concurrent.Executors) US_ASCII(java.nio.charset.StandardCharsets.US_ASCII) HsmRunSystem(diskCacheV111.util.HsmRunSystem) TimeUnit(java.util.concurrent.TimeUnit) Checksum(org.dcache.util.Checksum) List(java.util.List) Stream(java.util.stream.Stream) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) StageRequest(org.dcache.pool.nearline.spi.StageRequest) CDCExecutorServiceDecorator(org.dcache.util.CDCExecutorServiceDecorator) StorageInfo(diskCacheV111.vehicles.StorageInfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with FileAttributes

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);
    }
}
Also used : HsmRunSystem(diskCacheV111.util.HsmRunSystem) CacheException(diskCacheV111.util.CacheException) FileAttributes(org.dcache.vehicles.FileAttributes)

Aggregations

FileAttributes (org.dcache.vehicles.FileAttributes)204 CacheException (diskCacheV111.util.CacheException)71 Test (org.junit.Test)71 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)49 PnfsId (diskCacheV111.util.PnfsId)47 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)45 FileAttribute (org.dcache.namespace.FileAttribute)45 NotDirCacheException (diskCacheV111.util.NotDirCacheException)34 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)31 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)31 FsPath (diskCacheV111.util.FsPath)25 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)24 NotFileCacheException (diskCacheV111.util.NotFileCacheException)24 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)22 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)21 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)20 ArrayList (java.util.ArrayList)20 PoolPreferenceLevel (diskCacheV111.poolManager.PoolPreferenceLevel)19 PnfsSetFileAttributes (org.dcache.vehicles.PnfsSetFileAttributes)19 LockedCacheException (diskCacheV111.util.LockedCacheException)16