/** * Copy method to populate the builder with values from the given instance. * @return this builder instance */ public Builder copy(UploadPartRequest o) { namespaceName(o.getNamespaceName()); bucketName(o.getBucketName()); objectName(o.getObjectName()); uploadId(o.getUploadId()); uploadPartNum(o.getUploadPartNum()); contentLength(o.getContentLength()); uploadPartBody(o.getUploadPartBody()); opcClientRequestId(o.getOpcClientRequestId()); ifMatch(o.getIfMatch()); ifNoneMatch(o.getIfNoneMatch()); expect(o.getExpect()); contentMD5(o.getContentMD5()); invocationCallback(o.getInvocationCallback()); return this; }
@Override public UploadPartResponse apply(UploadPartRequest request) { InputStream stream = request.getUploadPartBody(); BmcException ex = null; for (int i = 1; i <= MAX_RETRIES; i++) { try { return service.uploadPart(request); } catch (BmcException e) { ex = e; if (canRetry(stream, e, i)) { request = UploadPartRequest.builder() .copy(request) .uploadPartBody( ((DuplicatableInputStream) stream).duplicate()) .build(); } else { break; } } } throw ex; } };
@Override public Void call() throws Exception { try { // Use a random sleep before each part begins upload. Too many concurrent requests // starting around the same time leads to 409 conflicts. Thread.sleep( random.nextInt( MAX_RANDOM_SLEEP_BEFORE_UPLOAD_START_MS)); UploadPartResponse response = simpleRetry.createUploadPartFunction().apply(request); manifest.registerSuccess(request.getUploadPartNum(), response); } catch (Exception e) { LOG.debug("Failed to upload part", e); manifest.registerFailure(request.getUploadPartNum()); } return null; } });
@Override public UploadPartResponse uploadPart(UploadPartRequest request) { LOG.trace("Called uploadPart"); request = UploadPartConverter.interceptRequest(request); com.oracle.bmc.http.internal.WrappedInvocationBuilder ib = UploadPartConverter.fromRequest(client, request); com.google.common.base.Function<javax.ws.rs.core.Response, UploadPartResponse> transformer = UploadPartConverter.fromResponse(); ib.property( com.oracle.bmc.http.internal.AuthnClientFilter.SIGNING_STRATEGY_PROPERTY_NAME, com.oracle.bmc.http.signing.SigningStrategy.EXCLUDE_BODY); int attempts = 0; while (true) { try { javax.ws.rs.core.Response response = client.put(ib, request.getUploadPartBody(), request); return transformer.apply(response); } catch (com.oracle.bmc.model.BmcException e) { if (++attempts < MAX_IMMEDIATE_RETRIES_IF_USING_INSTANCE_PRINCIPALS && canRetryRequestIfRefreshableAuthTokenUsed(e)) { continue; } else { throw e; } } } }
private int doUploadPart( InputStream stream, long contentLength, String md5, int partNumber, boolean allowPartOverwrite) { validateState(); String ifNoneMatch = ObjectStorageUtils.getIfNoneMatchHeader(allowPartOverwrite); UploadPartRequest request = UploadPartRequest.builder() .namespaceName(namespaceName) .bucketName(bucketName) .objectName(objectName) .contentMD5(md5) .contentLength(contentLength) .uploadId(manifest.getUploadId()) .ifNoneMatch(ifNoneMatch) .uploadPartNum(partNumber) .uploadPartBody(stream) .opcClientRequestId(createClientRequestId("-" + partNumber)) .build(); transferManager.startTransfer(request); return partNumber; }
public synchronized void startTransfer(final UploadPartRequest request) { if (executor.isShutdown()) { throw new CancellationException("Executor used for transfers has been shutdown"); } manifest.registerTransfer(request.getUploadPartNum()); Future<Void> futureResponse = executor.submit( new Callable<Void>() { @Override public Void call() throws Exception { try { // Use a random sleep before each part begins upload. Too many concurrent requests // starting around the same time leads to 409 conflicts. Thread.sleep( random.nextInt( MAX_RANDOM_SLEEP_BEFORE_UPLOAD_START_MS)); UploadPartResponse response = simpleRetry.createUploadPartFunction().apply(request); manifest.registerSuccess(request.getUploadPartNum(), response); } catch (Exception e) { LOG.debug("Failed to upload part", e); manifest.registerFailure(request.getUploadPartNum()); } return null; } }); responses.add(futureResponse); }
client.put( ib, interceptedRequest.getUploadPartBody(), interceptedRequest, onSuccess,
public static com.oracle.bmc.http.internal.WrappedInvocationBuilder fromRequest( com.oracle.bmc.http.internal.RestClient client, UploadPartRequest request) { Validate.notNull(request, "request instance is required"); Validate.notBlank(request.getNamespaceName(), "namespaceName must not be blank"); Validate.notBlank(request.getBucketName(), "bucketName must not be blank"); Validate.notBlank(request.getObjectName(), "objectName must not be blank"); Validate.notNull(request.getUploadId(), "uploadId is required"); Validate.notNull(request.getUploadPartNum(), "uploadPartNum is required"); Validate.notNull(request.getUploadPartBody(), "uploadPartBody is required"); .path( com.oracle.bmc.util.internal.HttpUtils.encodePathSegment( request.getNamespaceName())) .path("b") .path( com.oracle.bmc.util.internal.HttpUtils.encodePathSegment( request.getBucketName())) .path("u") .path( com.oracle.bmc.util.internal.HttpUtils.encodePathSegment( request.getObjectName())); "uploadId", com.oracle.bmc.util.internal.HttpUtils.attemptEncodeQueryParam( request.getUploadId())); "uploadPartNum", com.oracle.bmc.util.internal.HttpUtils.attemptEncodeQueryParam( request.getUploadPartNum()));