Search in sources :

Example 46 with ConnectionCanceledException

use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.

the class WritePermissionWorker method run.

@Override
public Boolean run(final Session<?> session) throws BackgroundException {
    final UnixPermission feature = session.getFeature(UnixPermission.class);
    if (log.isDebugEnabled()) {
        log.debug(String.format("Run with feature %s", feature));
    }
    for (Path file : files) {
        if (this.isCanceled()) {
            throw new ConnectionCanceledException();
        }
        final Permission merged = permissions.get(file);
        this.write(session, feature, file, merged);
    }
    return true;
}
Also used : Path(ch.cyberduck.core.Path) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) UnixPermission(ch.cyberduck.core.features.UnixPermission) Permission(ch.cyberduck.core.Permission) UnixPermission(ch.cyberduck.core.features.UnixPermission)

Example 47 with ConnectionCanceledException

use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.

the class WriteRedundancyWorker method write.

protected void write(final Session<?> session, final Redundancy feature, final Path file) throws BackgroundException {
    if (this.isCanceled()) {
        throw new ConnectionCanceledException();
    }
    if (!level.equals(file.attributes().getStorageClass())) {
        listener.message(MessageFormat.format(LocaleFactory.localizedString("Writing metadata of {0}", "Status"), file.getName()));
        feature.setClass(file, level);
        file.attributes().setStorageClass(level);
    }
    if (file.isDirectory()) {
        if (callback.recurse(file, level)) {
            for (Path child : session.getFeature(ListService.class).list(file, new WorkerListProgressListener(this, listener))) {
                this.write(session, feature, child);
            }
        }
    }
}
Also used : Path(ch.cyberduck.core.Path) ListService(ch.cyberduck.core.ListService) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException)

Example 48 with ConnectionCanceledException

use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.

the class WriteTransferAccelerationWorker method run.

@Override
public Boolean run(final Session<?> session) throws BackgroundException {
    final TransferAcceleration feature = session.getFeature(TransferAcceleration.class);
    if (log.isDebugEnabled()) {
        log.debug(String.format("Run with feature %s", feature));
    }
    final PathContainerService container = session.getFeature(PathContainerService.class);
    for (Path file : this.getContainers(container, files)) {
        if (this.isCanceled()) {
            throw new ConnectionCanceledException();
        }
        this.write(feature, file);
    }
    return true;
}
Also used : Path(ch.cyberduck.core.Path) PathContainerService(ch.cyberduck.core.PathContainerService) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) TransferAcceleration(ch.cyberduck.core.features.TransferAcceleration)

Example 49 with ConnectionCanceledException

use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.

the class StreamCopierTest method testTransferInterrupt.

@Test
public void testTransferInterrupt() throws Exception {
    final TransferStatus status = new TransferStatus();
    final CyclicBarrier lock = new CyclicBarrier(2);
    final CyclicBarrier exit = new CyclicBarrier(2);
    status.setLength(432768L);
    final BytecountStreamListener count = new BytecountStreamListener() {

        @Override
        public void sent(final long bytes) {
            super.sent(bytes);
            try {
                lock.await();
                exit.await();
            } catch (InterruptedException | BrokenBarrierException e) {
                fail(e.getMessage());
            }
        }
    };
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                new StreamCopier(status, status).withListener(count).transfer(new NullInputStream(status.getLength()), NullOutputStream.NULL_OUTPUT_STREAM);
            } catch (BackgroundException e) {
                assertTrue(e instanceof ConnectionCanceledException);
            }
        }
    }).start();
    lock.await();
    status.setCanceled();
    exit.await();
    assertFalse(status.isComplete());
    try {
        status.validate();
        fail();
    } catch (ConnectionCanceledException e) {
    }
    assertEquals(32768L, count.getRecv());
    assertEquals(32768L, count.getSent());
    assertEquals(0L, status.getOffset());
}
Also used : BrokenBarrierException(java.util.concurrent.BrokenBarrierException) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) BackgroundException(ch.cyberduck.core.exception.BackgroundException) CyclicBarrier(java.util.concurrent.CyclicBarrier) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) NullInputStream(org.apache.commons.io.input.NullInputStream) Test(org.junit.Test)

Example 50 with ConnectionCanceledException

use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.

the class EueLargeUploadService method upload.

@Override
public EueWriteFeature.Chunk upload(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
    final ThreadPool pool = ThreadPoolFactory.get("multipart", concurrency);
    try {
        final List<Future<EueWriteFeature.Chunk>> parts = new ArrayList<>();
        long offset = 0;
        long remaining = status.getLength();
        final String resourceId;
        final String uploadUri;
        if (status.isExists()) {
            resourceId = fileid.getFileId(file, new DisabledListProgressListener());
            uploadUri = EueUploadHelper.updateResource(session, resourceId, UploadType.CHUNKED).getUploadURI();
        } else {
            final ResourceCreationResponseEntry uploadResourceCreationResponseEntry = EueUploadHelper.createResource(session, fileid.getFileId(file.getParent(), new DisabledListProgressListener()), file.getName(), status, UploadType.CHUNKED);
            resourceId = EueResourceIdProvider.getResourceIdFromResourceUri(uploadResourceCreationResponseEntry.getHeaders().getLocation());
            uploadUri = uploadResourceCreationResponseEntry.getEntity().getUploadURI();
        }
        for (int partNumber = 1; remaining > 0; partNumber++) {
            final long length = Math.min(chunksize, remaining);
            parts.add(this.submit(pool, file, local, throttle, listener, status, uploadUri, resourceId, partNumber, offset, length, callback));
            remaining -= length;
            offset += length;
        }
        // Checksums for uploaded segments
        final List<EueWriteFeature.Chunk> chunks = new ArrayList<>();
        for (Future<EueWriteFeature.Chunk> uploadResponseFuture : parts) {
            try {
                chunks.add(uploadResponseFuture.get());
            } catch (InterruptedException e) {
                log.error("Part upload failed with interrupt failure");
                status.setCanceled();
                throw new ConnectionCanceledException(e);
            } catch (ExecutionException e) {
                log.warn(String.format("Part upload failed with execution failure %s", e.getMessage()));
                if (e.getCause() instanceof BackgroundException) {
                    throw (BackgroundException) e.getCause();
                }
                throw new BackgroundException(e.getCause());
            }
        }
        final MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
        final AtomicLong totalSize = new AtomicLong();
        chunks.stream().sorted(Comparator.comparing(EueWriteFeature.Chunk::getPartnumber)).forEach(chunk -> {
            try {
                messageDigest.update(Hex.decodeHex(chunk.getChecksum().hash));
            } catch (DecoderException e) {
                log.error(String.format("Failure %s decoding hash %s", e, chunk.getChecksum()));
            }
            messageDigest.update(ChunkListSHA256ChecksumCompute.intToBytes(chunk.getLength().intValue()));
            totalSize.set(totalSize.get() + chunk.getLength());
        });
        final String cdash64 = Base64.encodeBase64URLSafeString(messageDigest.digest());
        final EueUploadHelper.UploadResponse completedUploadResponse = new EueMultipartUploadCompleter(session).getCompletedUploadResponse(uploadUri, totalSize.get(), cdash64);
        final EueWriteFeature.Chunk object = new EueWriteFeature.Chunk(totalSize.get(), cdash64);
        // Mark parent status as complete
        status.withResponse(new EueAttributesAdapter().toAttributes(object)).setComplete();
        return object;
    } catch (NoSuchAlgorithmException e) {
        throw new ChecksumException(LocaleFactory.localizedString("Checksum failure", "Error"), e);
    } finally {
        // Cancel future tasks
        pool.shutdown(false);
    }
}
Also used : DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) ChecksumException(ch.cyberduck.core.exception.ChecksumException) ThreadPool(ch.cyberduck.core.threading.ThreadPool) ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ResourceCreationResponseEntry(ch.cyberduck.core.eue.io.swagger.client.model.ResourceCreationResponseEntry) ExecutionException(java.util.concurrent.ExecutionException) MessageDigest(java.security.MessageDigest) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) DecoderException(org.apache.commons.codec.DecoderException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Future(java.util.concurrent.Future) BackgroundException(ch.cyberduck.core.exception.BackgroundException)

Aggregations

ConnectionCanceledException (ch.cyberduck.core.exception.ConnectionCanceledException)66 Path (ch.cyberduck.core.Path)28 BackgroundException (ch.cyberduck.core.exception.BackgroundException)17 ArrayList (java.util.ArrayList)16 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)12 IOException (java.io.IOException)11 ExecutionException (java.util.concurrent.ExecutionException)11 Future (java.util.concurrent.Future)11 ThreadPool (ch.cyberduck.core.threading.ThreadPool)10 Test (org.junit.Test)9 ListService (ch.cyberduck.core.ListService)8 PathContainerService (ch.cyberduck.core.PathContainerService)8 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)7 HashMap (java.util.HashMap)7 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)6 IntegrationTest (ch.cyberduck.test.IntegrationTest)6 AttributedList (ch.cyberduck.core.AttributedList)5 Host (ch.cyberduck.core.Host)5 LinkedHashMap (java.util.LinkedHashMap)5 ChecksumException (ch.cyberduck.core.exception.ChecksumException)4