Skip to content

Commit b7da779

Browse files
committed
Adding platform timeout configuration
1 parent 2d927d4 commit b7da779

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed

spring-cloud-app-broker-autoconfigure/src/test/java/org/springframework/cloud/appbroker/autoconfigure/AppBrokerAutoConfigurationTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.cloud.appbroker.deployer.BrokeredService;
3131
import org.springframework.cloud.appbroker.deployer.BrokeredServices;
3232
import org.springframework.cloud.appbroker.deployer.DeployerClient;
33+
import org.springframework.cloud.appbroker.deployer.cloudfoundry.CloudFoundryTargetProperties;
3334
import org.springframework.cloud.appbroker.extensions.parameters.BackingApplicationsParametersTransformationService;
3435
import org.springframework.cloud.appbroker.extensions.parameters.BackingServicesParametersTransformationService;
3536
import org.springframework.cloud.appbroker.extensions.parameters.EnvironmentMappingParametersTransformerFactory;
@@ -217,7 +218,9 @@ private ApplicationContextRunner configuredContext() {
217218

218219
"spring.cloud.appbroker.deployer.cloudfoundry.api-host=https://api.example.local",
219220
"spring.cloud.appbroker.deployer.cloudfoundry.username=user",
220-
"spring.cloud.appbroker.deployer.cloudfoundry.password=secret"
221+
"spring.cloud.appbroker.deployer.cloudfoundry.password=secret",
222+
"spring.cloud.appbroker.deployer.cloudfoundry.staging-timeout=3",
223+
"spring.cloud.appbroker.deployer.cloudfoundry.deployment-timeout=4"
221224
);
222225
}
223226

@@ -255,6 +258,12 @@ private void assertBeansCreated(AssertableApplicationContext context) {
255258
}
256259

257260
private void assertPropertiesLoaded(AssertableApplicationContext context) {
261+
CloudFoundryTargetProperties cloudFoundryTargetProperties = context.getBean(CloudFoundryTargetProperties.class);
262+
assertThat(cloudFoundryTargetProperties.getUsername()).isEqualTo("user");
263+
assertThat(cloudFoundryTargetProperties.getPassword()).isEqualTo("secret");
264+
assertThat(cloudFoundryTargetProperties.getDeploymentTimeout()).isEqualTo(4L);
265+
assertThat(cloudFoundryTargetProperties.getStagingTimeout()).isEqualTo(3L);
266+
258267
BrokeredServices brokeredServices = context.getBean(BrokeredServices.class);
259268
assertThat(brokeredServices).hasSize(2);
260269

spring-cloud-app-broker-deployer-cloudfoundry/src/main/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployer.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,11 @@
137137
import org.springframework.http.HttpStatus;
138138
import org.springframework.util.StringUtils;
139139

140-
//TODO: refactor this class
141140
@SuppressWarnings({"PMD.GodClass", "PMD.CyclomaticComplexity", "PMD.ExcessiveClassLength"})
142141
public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware {
143142

143+
private static final Duration DEFAULT_PLATFORM_OPERATION_DURATION = Duration.ofMinutes(10);
144+
144145
private static final Logger LOG = LoggerFactory.getLogger(CloudFoundryAppDeployer.class);
145146

146147
private static final String REQUEST_LOG_TEMPLATE = "request={}";
@@ -454,7 +455,7 @@ private Mono<GetDeploymentResponse> waitForDeploymentDeployed(String deploymentI
454455
.deploymentId(deploymentId)
455456
.build())
456457
.filter(this::deploymentFinished)
457-
.repeatWhenEmpty(getExponentialBackOff())
458+
.repeatWhenEmpty(getExponentialBackOff(getDeploymentTimeout()))
458459
.doOnRequest(l -> LOG.debug("Waiting for deployment to complete. deploymentId={}", deploymentId))
459460
.doOnSuccess(response -> {
460461
LOG.info("Success waiting for deployment to complete. deploymentId={}", deploymentId);
@@ -503,7 +504,7 @@ private Mono<GetBuildResponse> waitForBuildStaged(String buildId) {
503504
.buildId(buildId)
504505
.build())
505506
.filter(p -> p.getState().equals(BuildState.STAGED))
506-
.repeatWhenEmpty(getExponentialBackOff())
507+
.repeatWhenEmpty(getExponentialBackOff(getStagingTimeout()))
507508
.doOnRequest(l -> LOG.debug("Waiting for build to stage. buildId={}", buildId))
508509
.doOnSuccess(response -> {
509510
LOG.info("Success waiting for build to stage. buildId={}", buildId);
@@ -535,7 +536,7 @@ private Mono<GetPackageResponse> waitForPackageReady(String packageId) {
535536
.packages()
536537
.get(GetPackageRequest.builder().packageId(packageId).build())
537538
.filter(p -> p.getState().equals(PackageState.READY))
538-
.repeatWhenEmpty(getExponentialBackOff())
539+
.repeatWhenEmpty(getExponentialBackOff(DEFAULT_PLATFORM_OPERATION_DURATION))
539540
.doOnRequest(l -> LOG.debug("Waiting for package ready. packageId={}", packageId))
540541
.doOnSuccess(response -> {
541542
LOG.info("Success waiting for package ready. packageId={}", packageId);
@@ -679,8 +680,22 @@ private Mono<CreatePackageResponse> createPackageForApplication(String applicati
679680
applicationId, e.getMessage()), e));
680681
}
681682

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);
684699
}
685700

686701
private Mono<Void> pushApplication(DeployApplicationRequest request, Map<String, String> deploymentProperties,

spring-cloud-app-broker-deployer-cloudfoundry/src/main/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryTargetProperties.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public class CloudFoundryTargetProperties {
4444

4545
private String identityZoneSubdomain;
4646

47+
private Long deploymentTimeout;
48+
49+
private Long stagingTimeout;
50+
4751
public String getApiHost() {
4852
return apiHost;
4953
}
@@ -136,6 +140,22 @@ public ProxyConfiguration getProxyConfiguration() {
136140
return null;
137141
}
138142

143+
public Long getDeploymentTimeout() {
144+
return deploymentTimeout;
145+
}
146+
147+
public void setDeploymentTimeout(Long deploymentTimeout) {
148+
this.deploymentTimeout = deploymentTimeout;
149+
}
150+
151+
public Long getStagingTimeout() {
152+
return stagingTimeout;
153+
}
154+
155+
public void setStagingTimeout(Long stagingTimeout) {
156+
this.stagingTimeout = stagingTimeout;
157+
}
158+
139159
private static String parseApiHost(String api) {
140160
final URI uri = URI.create(api);
141161
return uri.getHost() == null ? api : uri.getHost();

spring-cloud-app-broker-docs/src/docs/asciidoc/deployment-platforms.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ spring:
2121
*client-secret: EXAMPLE_SECRET*
2222
*default-org: test*
2323
*default-space: development*
24+
*staging-timeout: 15*
25+
*deployment-timeout: 10*
2426
----
2527
====
2628

0 commit comments

Comments
 (0)