Skip to content

Commit

Permalink
Exponential resilience during app upload
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanBorislavovDimitrov committed Sep 27, 2024
1 parent 06a0b9d commit 6e53670
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sap.cloudfoundry.client.facade;

import java.nio.file.Path;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -660,9 +661,9 @@ Optional<String> unbindServiceInstance(String applicationName, String serviceIns

void updateServiceSyslogDrainUrl(String serviceName, String syslogDrainUrl);

CloudPackage asyncUploadApplication(String applicationName, Path file);
CloudPackage asyncUploadApplication(String applicationName, Path file, Duration uploadTimeout);

CloudPackage asyncUploadApplication(String applicationName, Path file, UploadStatusCallback callback);
CloudPackage asyncUploadApplication(String applicationName, Path file, UploadStatusCallback callback, Duration uploadTimeout);

Upload getUploadStatus(UUID packageGuid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import java.net.URL;
import java.nio.file.Path;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.function.Supplier;

import com.sap.cloudfoundry.client.facade.dto.ApplicationToCreateDto;
import org.cloudfoundry.AbstractCloudFoundryException;
import org.cloudfoundry.client.v3.Metadata;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -38,6 +38,7 @@
import com.sap.cloudfoundry.client.facade.domain.Staging;
import com.sap.cloudfoundry.client.facade.domain.Upload;
import com.sap.cloudfoundry.client.facade.domain.UserRole;
import com.sap.cloudfoundry.client.facade.dto.ApplicationToCreateDto;
import com.sap.cloudfoundry.client.facade.rest.CloudControllerRestClient;
import com.sap.cloudfoundry.client.facade.rest.CloudControllerRestClientFactory;
import com.sap.cloudfoundry.client.facade.rest.ImmutableCloudControllerRestClientFactory;
Expand Down Expand Up @@ -560,13 +561,13 @@ public void updateServiceSyslogDrainUrl(String serviceName, String syslogDrainUr
}

@Override
public CloudPackage asyncUploadApplication(String applicationName, Path file) {
return handleExceptions(() -> delegate.asyncUploadApplication(applicationName, file, null));
public CloudPackage asyncUploadApplication(String applicationName, Path file, Duration uploadTimeout) {
return handleExceptions(() -> delegate.asyncUploadApplication(applicationName, file, null, uploadTimeout));
}

@Override
public CloudPackage asyncUploadApplication(String applicationName, Path file, UploadStatusCallback callback) {
return handleExceptions(() -> delegate.asyncUploadApplication(applicationName, file, callback));
public CloudPackage asyncUploadApplication(String applicationName, Path file, UploadStatusCallback callback, Duration uploadTimeout) {
return handleExceptions(() -> delegate.asyncUploadApplication(applicationName, file, callback, uploadTimeout));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sap.cloudfoundry.client.facade.rest;

import java.nio.file.Path;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -205,7 +206,7 @@ public interface CloudControllerRestClient {

void updateServiceTags(String serviceName, List<String> tags);

CloudPackage asyncUploadApplication(String applicationName, Path file, UploadStatusCallback callback);
CloudPackage asyncUploadApplication(String applicationName, Path file, UploadStatusCallback callback, Duration uploadTimeout);

Upload getUploadStatus(UUID packageGuid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1406,8 +1406,8 @@ public CloudTask cancelTask(UUID taskGuid) {
}

@Override
public CloudPackage asyncUploadApplication(String applicationName, Path file, UploadStatusCallback callback) {
CloudPackage cloudPackage = startUpload(applicationName, file);
public CloudPackage asyncUploadApplication(String applicationName, Path file, UploadStatusCallback callback, Duration uploadTimeout) {
CloudPackage cloudPackage = startUpload(applicationName, file, uploadTimeout);
processAsyncUploadInBackground(cloudPackage, callback);
return cloudPackage;
}
Expand Down Expand Up @@ -1754,7 +1754,7 @@ private Mono<? extends Task> cancelTaskResource(UUID taskGuid) {
.cancel(request);
}

private CloudPackage startUpload(String applicationName, Path file) {
private CloudPackage startUpload(String applicationName, Path file, Duration uploadTimeout) {
Assert.notNull(applicationName, "AppName must not be null");
Assert.notNull(file, "File must not be null");

Expand All @@ -1766,6 +1766,7 @@ private CloudPackage startUpload(String applicationName, Path file) {
.bits(file)
.packageId(packageGuid.toString())
.build())
.timeout(uploadTimeout)
.block();

return getPackage(packageGuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.nio.file.Path;
import java.text.MessageFormat;
import java.time.Duration;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
Expand All @@ -17,9 +18,11 @@

public class ApplicationUtil {

public static final Duration UPLOAD_TIMEOUT = Duration.ofMinutes(15);

public static CloudPackage uploadApplication(CloudControllerClient client, String applicationName, Path pathToFile)
throws InterruptedException {
CloudPackage cloudPackage = client.asyncUploadApplication(applicationName, pathToFile);
CloudPackage cloudPackage = client.asyncUploadApplication(applicationName, pathToFile, UPLOAD_TIMEOUT);
while (cloudPackage.getStatus() != Status.READY && !hasUploadFailed(cloudPackage.getStatus())) {
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
cloudPackage = client.getPackage(cloudPackage.getGuid());
Expand Down

0 comments on commit 6e53670

Please sign in to comment.