|
137 | 137 | import org.springframework.http.HttpStatus;
|
138 | 138 | import org.springframework.util.StringUtils;
|
139 | 139 |
|
140 |
| -//TODO: refactor this class |
141 | 140 | @SuppressWarnings({"PMD.GodClass", "PMD.CyclomaticComplexity", "PMD.ExcessiveClassLength"})
|
142 | 141 | public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware {
|
143 | 142 |
|
| 143 | + private static final Duration DEFAULT_PLATFORM_OPERATION_DURATION = Duration.ofMinutes(10); |
| 144 | + |
144 | 145 | private static final Logger LOG = LoggerFactory.getLogger(CloudFoundryAppDeployer.class);
|
145 | 146 |
|
146 | 147 | private static final String REQUEST_LOG_TEMPLATE = "request={}";
|
@@ -454,7 +455,7 @@ private Mono<GetDeploymentResponse> waitForDeploymentDeployed(String deploymentI
|
454 | 455 | .deploymentId(deploymentId)
|
455 | 456 | .build())
|
456 | 457 | .filter(this::deploymentFinished)
|
457 |
| - .repeatWhenEmpty(getExponentialBackOff()) |
| 458 | + .repeatWhenEmpty(getExponentialBackOff(getDeploymentTimeout())) |
458 | 459 | .doOnRequest(l -> LOG.debug("Waiting for deployment to complete. deploymentId={}", deploymentId))
|
459 | 460 | .doOnSuccess(response -> {
|
460 | 461 | LOG.info("Success waiting for deployment to complete. deploymentId={}", deploymentId);
|
@@ -503,7 +504,7 @@ private Mono<GetBuildResponse> waitForBuildStaged(String buildId) {
|
503 | 504 | .buildId(buildId)
|
504 | 505 | .build())
|
505 | 506 | .filter(p -> p.getState().equals(BuildState.STAGED))
|
506 |
| - .repeatWhenEmpty(getExponentialBackOff()) |
| 507 | + .repeatWhenEmpty(getExponentialBackOff(getStagingTimeout())) |
507 | 508 | .doOnRequest(l -> LOG.debug("Waiting for build to stage. buildId={}", buildId))
|
508 | 509 | .doOnSuccess(response -> {
|
509 | 510 | LOG.info("Success waiting for build to stage. buildId={}", buildId);
|
@@ -535,7 +536,7 @@ private Mono<GetPackageResponse> waitForPackageReady(String packageId) {
|
535 | 536 | .packages()
|
536 | 537 | .get(GetPackageRequest.builder().packageId(packageId).build())
|
537 | 538 | .filter(p -> p.getState().equals(PackageState.READY))
|
538 |
| - .repeatWhenEmpty(getExponentialBackOff()) |
| 539 | + .repeatWhenEmpty(getExponentialBackOff(DEFAULT_PLATFORM_OPERATION_DURATION)) |
539 | 540 | .doOnRequest(l -> LOG.debug("Waiting for package ready. packageId={}", packageId))
|
540 | 541 | .doOnSuccess(response -> {
|
541 | 542 | LOG.info("Success waiting for package ready. packageId={}", packageId);
|
@@ -679,8 +680,22 @@ private Mono<CreatePackageResponse> createPackageForApplication(String applicati
|
679 | 680 | applicationId, e.getMessage()), e));
|
680 | 681 | }
|
681 | 682 |
|
682 |
| - private Function<Flux<Long>, Publisher<?>> getExponentialBackOff() { |
683 |
| - return DelayUtils.exponentialBackOff(Duration.ofSeconds(2), Duration.ofMinutes(5), Duration.ofMinutes(10)); |
| 683 | + private Duration getStagingTimeout() { |
| 684 | + if (targetProperties.getStagingTimeout() == null) { |
| 685 | + return DEFAULT_PLATFORM_OPERATION_DURATION; |
| 686 | + } |
| 687 | + return Duration.ofMinutes(targetProperties.getStagingTimeout()); |
| 688 | + } |
| 689 | + |
| 690 | + private Duration getDeploymentTimeout() { |
| 691 | + if (targetProperties.getDeploymentTimeout() == null) { |
| 692 | + return DEFAULT_PLATFORM_OPERATION_DURATION; |
| 693 | + } |
| 694 | + return Duration.ofMinutes(targetProperties.getDeploymentTimeout()); |
| 695 | + } |
| 696 | + |
| 697 | + private Function<Flux<Long>, Publisher<?>> getExponentialBackOff(Duration timeout) { |
| 698 | + return DelayUtils.exponentialBackOff(Duration.ofSeconds(2), Duration.ofMinutes(5), timeout); |
684 | 699 | }
|
685 | 700 |
|
686 | 701 | private Mono<Void> pushApplication(DeployApplicationRequest request, Map<String, String> deploymentProperties,
|
|
0 commit comments