Search in sources :

Example 1 with BackgroundExceptionCallable

use of ch.cyberduck.core.threading.BackgroundExceptionCallable in project cyberduck by iterate-ch.

the class BoxLargeUploadService method submit.

private Future<File> submit(final ThreadPool pool, final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus overall, final String uploadSessionId, final int partNumber, final long offset, final long length, final ConnectionCallback callback) {
    if (log.isInfoEnabled()) {
        log.info(String.format("Submit %s to queue with offset %d and length %d", file, offset, length));
    }
    final BytecountStreamListener counter = new BytecountStreamListener(listener);
    return pool.execute(new SegmentRetryCallable<>(session.getHost(), new BackgroundExceptionCallable<File>() {

        @Override
        public File call() throws BackgroundException {
            overall.validate();
            final TransferStatus status = new TransferStatus().segment(true).withOffset(offset).withLength(length);
            status.setPart(partNumber);
            status.setHeader(overall.getHeader());
            status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status));
            final Map<String, String> parameters = new HashMap<>();
            parameters.put(UPLOAD_SESSION_ID, uploadSessionId);
            parameters.put(OVERALL_LENGTH, String.valueOf(overall.getLength()));
            status.withParameters(parameters);
            final File response = BoxLargeUploadService.this.upload(file, local, throttle, listener, status, overall, status, callback);
            if (log.isInfoEnabled()) {
                log.info(String.format("Received response %s for part %d", response, partNumber));
            }
            return response;
        }
    }, overall, counter));
}
Also used : BackgroundExceptionCallable(ch.cyberduck.core.threading.BackgroundExceptionCallable) HashMap(java.util.HashMap) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) File(ch.cyberduck.core.box.io.swagger.client.model.File) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener)

Example 2 with BackgroundExceptionCallable

use of ch.cyberduck.core.threading.BackgroundExceptionCallable in project cyberduck by iterate-ch.

the class BrickUploadFeature method submit.

private Future<TransferStatus> submit(final ThreadPool pool, final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus overall, final String url, final Integer partNumber, final long offset, final long length, final ConnectionCallback callback) {
    if (log.isInfoEnabled()) {
        log.info(String.format("Submit part %d of %s to queue with offset %d and length %d", partNumber, file, offset, length));
    }
    final BytecountStreamListener counter = new BytecountStreamListener(listener);
    return pool.execute(new SegmentRetryCallable<>(session.getHost(), new BackgroundExceptionCallable<TransferStatus>() {

        @Override
        public TransferStatus call() throws BackgroundException {
            overall.validate();
            final TransferStatus status = new TransferStatus().segment(true).withLength(length).withOffset(offset);
            status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status));
            status.setUrl(url);
            status.setPart(partNumber);
            status.setHeader(overall.getHeader());
            BrickUploadFeature.super.upload(file, local, throttle, listener, status, overall, status, callback);
            if (log.isInfoEnabled()) {
                log.info(String.format("Received response for part number %d", partNumber));
            }
            return status;
        }
    }, overall, counter));
}
Also used : BackgroundExceptionCallable(ch.cyberduck.core.threading.BackgroundExceptionCallable) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener)

Example 3 with BackgroundExceptionCallable

use of ch.cyberduck.core.threading.BackgroundExceptionCallable in project cyberduck by iterate-ch.

the class EueLargeUploadService method submit.

private Future<EueWriteFeature.Chunk> submit(final ThreadPool pool, final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus overall, final String url, final String resourceId, final int partNumber, final long offset, final long length, final ConnectionCallback callback) {
    if (log.isInfoEnabled()) {
        log.info(String.format("Submit %s to queue with offset %d and length %d", file, offset, length));
    }
    final BytecountStreamListener counter = new BytecountStreamListener(listener);
    return pool.execute(new SegmentRetryCallable<>(session.getHost(), new BackgroundExceptionCallable<EueWriteFeature.Chunk>() {

        @Override
        public EueWriteFeature.Chunk call() throws BackgroundException {
            overall.validate();
            final Map<String, String> parameters = new HashMap<>();
            parameters.put(RESOURCE_ID, resourceId);
            final TransferStatus status = new TransferStatus().segment(true).withOffset(offset).withLength(length).withParameters(parameters);
            status.setPart(partNumber);
            status.setHeader(overall.getHeader());
            status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status));
            status.setUrl(url);
            final EueWriteFeature.Chunk chunk = EueLargeUploadService.this.upload(file, local, throttle, listener, status, overall, status, callback);
            if (log.isInfoEnabled()) {
                log.info(String.format("Received response %s for part %d", chunk, partNumber));
            }
            return chunk;
        }
    }, overall, counter));
}
Also used : BackgroundExceptionCallable(ch.cyberduck.core.threading.BackgroundExceptionCallable) HashMap(java.util.HashMap) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener)

Example 4 with BackgroundExceptionCallable

use of ch.cyberduck.core.threading.BackgroundExceptionCallable in project cyberduck by iterate-ch.

the class S3MultipartUploadService method submit.

private Future<MultipartPart> submit(final ThreadPool pool, final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus overall, final MultipartUpload multipart, final int partNumber, final long offset, final long length, final ConnectionCallback callback) {
    if (log.isInfoEnabled()) {
        log.info(String.format("Submit part %d of %s to queue with offset %d and length %d", partNumber, file, offset, length));
    }
    final BytecountStreamListener counter = new BytecountStreamListener(listener);
    return pool.execute(new SegmentRetryCallable<>(session.getHost(), new BackgroundExceptionCallable<MultipartPart>() {

        @Override
        public MultipartPart call() throws BackgroundException {
            overall.validate();
            final TransferStatus status = new TransferStatus().withLength(length).withOffset(offset);
            final Map<String, String> requestParameters = new HashMap<>();
            requestParameters.put("uploadId", multipart.getUploadId());
            requestParameters.put("partNumber", String.valueOf(partNumber));
            status.setParameters(requestParameters);
            status.setPart(partNumber);
            status.setHeader(overall.getHeader());
            switch(session.getSignatureVersion()) {
                case AWS4HMACSHA256:
                    status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status));
                    break;
            }
            status.setSegment(true);
            final StorageObject part = S3MultipartUploadService.super.upload(file, local, throttle, counter, status, overall, status, callback);
            if (log.isInfoEnabled()) {
                log.info(String.format("Received response %s for part number %d", part, partNumber));
            }
            // Populate part with response data that is accessible via the object's metadata
            return new MultipartPart(partNumber, null == part.getLastModifiedDate() ? new Date(System.currentTimeMillis()) : part.getLastModifiedDate(), null == part.getETag() ? StringUtils.EMPTY : part.getETag(), part.getContentLength());
        }
    }, overall, counter));
}
Also used : BackgroundExceptionCallable(ch.cyberduck.core.threading.BackgroundExceptionCallable) MultipartPart(org.jets3t.service.model.MultipartPart) StorageObject(org.jets3t.service.model.StorageObject) HashMap(java.util.HashMap) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) Date(java.util.Date) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener)

Example 5 with BackgroundExceptionCallable

use of ch.cyberduck.core.threading.BackgroundExceptionCallable in project cyberduck by iterate-ch.

the class S3Session method login.

@Override
public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
    if (Scheme.isURL(host.getProtocol().getContext())) {
        try {
            final Credentials temporary = new AWSSessionCredentialsRetriever(trust, key, this, host.getProtocol().getContext()).get();
            client.setProviderCredentials(new AWSSessionCredentials(temporary.getUsername(), temporary.getPassword(), temporary.getToken()));
        } catch (ConnectionTimeoutException | ConnectionRefusedException | ResolveFailedException | NotfoundException | InteroperabilityException e) {
            log.warn(String.format("Failure to retrieve session credentials from . %s", e.getMessage()));
            throw new LoginFailureException(e.getDetail(false), e);
        }
    } else {
        final Credentials credentials;
        // Only for AWS
        if (isAwsHostname(host.getHostname())) {
            // Try auto-configure
            credentials = new STSCredentialsConfigurator(new ThreadLocalHostnameDelegatingTrustManager(trust, host.getHostname()), key, prompt).configure(host);
        } else {
            credentials = host.getCredentials();
        }
        if (StringUtils.isNotBlank(credentials.getToken())) {
            client.setProviderCredentials(credentials.isAnonymousLogin() ? null : new AWSSessionCredentials(credentials.getUsername(), credentials.getPassword(), credentials.getToken()));
        } else {
            client.setProviderCredentials(credentials.isAnonymousLogin() ? null : new AWSCredentials(credentials.getUsername(), credentials.getPassword()));
        }
    }
    if (host.getCredentials().isPassed()) {
        log.warn(String.format("Skip verifying credentials with previous successful authentication event for %s", this));
        return;
    }
    try {
        final Location.Name location = new S3PathStyleFallbackAdapter<>(this, new BackgroundExceptionCallable<Location.Name>() {

            @Override
            public Location.Name call() throws BackgroundException {
                return new S3LocationFeature(S3Session.this, client.getRegionEndpointCache()).getLocation(new DelegatingHomeFeature(new DefaultPathHomeFeature(host)).find());
            }
        }).call();
        if (log.isDebugEnabled()) {
            log.debug(String.format("Retrieved region %s", location));
        }
        if (!Location.unknown.equals(location)) {
            client.getConfiguration().setProperty("storage-service.default-region", location.getIdentifier());
        }
    } catch (AccessDeniedException | InteroperabilityException e) {
        log.warn(String.format("Failure %s querying region", e));
        final Path home = new DefaultHomeFinderService(this).find();
        if (log.isDebugEnabled()) {
            log.debug(String.format("Retrieved %s", home));
        }
    }
}
Also used : Path(ch.cyberduck.core.Path) NotfoundException(ch.cyberduck.core.exception.NotfoundException) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) DelegatingHomeFeature(ch.cyberduck.core.shared.DelegatingHomeFeature) DefaultPathHomeFeature(ch.cyberduck.core.shared.DefaultPathHomeFeature) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) ConnectionRefusedException(ch.cyberduck.core.exception.ConnectionRefusedException) ResolveFailedException(ch.cyberduck.core.exception.ResolveFailedException) AWSCredentials(org.jets3t.service.security.AWSCredentials) BackgroundExceptionCallable(ch.cyberduck.core.threading.BackgroundExceptionCallable) ConnectionTimeoutException(ch.cyberduck.core.exception.ConnectionTimeoutException) LoginFailureException(ch.cyberduck.core.exception.LoginFailureException) AWSSessionCredentials(org.jets3t.service.security.AWSSessionCredentials) ThreadLocalHostnameDelegatingTrustManager(ch.cyberduck.core.ssl.ThreadLocalHostnameDelegatingTrustManager) AWSSessionCredentialsRetriever(ch.cyberduck.core.auth.AWSSessionCredentialsRetriever) AWSCredentials(org.jets3t.service.security.AWSCredentials) Credentials(ch.cyberduck.core.Credentials) AWSSessionCredentials(org.jets3t.service.security.AWSSessionCredentials) STSCredentialsConfigurator(ch.cyberduck.core.sts.STSCredentialsConfigurator)

Aggregations

BackgroundExceptionCallable (ch.cyberduck.core.threading.BackgroundExceptionCallable)11 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)8 BytecountStreamListener (ch.cyberduck.core.BytecountStreamListener)6 HashMap (java.util.HashMap)4 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)2 BackgroundException (ch.cyberduck.core.exception.BackgroundException)2 DefaultHttpResponseExceptionMappingService (ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService)2 ApiException (ch.cyberduck.core.sds.io.swagger.client.ApiException)2 DefaultHomeFinderService (ch.cyberduck.core.shared.DefaultHomeFinderService)2 IOException (java.io.IOException)2 HttpEntity (org.apache.http.HttpEntity)2 HttpResponse (org.apache.http.HttpResponse)2 HttpResponseException (org.apache.http.client.HttpResponseException)2 BufferedHttpEntity (org.apache.http.entity.BufferedHttpEntity)2 Credentials (ch.cyberduck.core.Credentials)1 Path (ch.cyberduck.core.Path)1 AWSSessionCredentialsRetriever (ch.cyberduck.core.auth.AWSSessionCredentialsRetriever)1 File (ch.cyberduck.core.box.io.swagger.client.model.File)1 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)1 ConnectionRefusedException (ch.cyberduck.core.exception.ConnectionRefusedException)1