Adding platform timeout configuration

This commit is contained in:
Alberto C. Ríos
2024-09-23 16:56:02 +02:00
parent 2d927d460a
commit b7da77941e
4 changed files with 53 additions and 7 deletions

View File

@@ -30,6 +30,7 @@ import org.springframework.cloud.appbroker.deployer.BackingServicesProvisionServ
import org.springframework.cloud.appbroker.deployer.BrokeredService;
import org.springframework.cloud.appbroker.deployer.BrokeredServices;
import org.springframework.cloud.appbroker.deployer.DeployerClient;
import org.springframework.cloud.appbroker.deployer.cloudfoundry.CloudFoundryTargetProperties;
import org.springframework.cloud.appbroker.extensions.parameters.BackingApplicationsParametersTransformationService;
import org.springframework.cloud.appbroker.extensions.parameters.BackingServicesParametersTransformationService;
import org.springframework.cloud.appbroker.extensions.parameters.EnvironmentMappingParametersTransformerFactory;
@@ -217,7 +218,9 @@ class AppBrokerAutoConfigurationTest {
"spring.cloud.appbroker.deployer.cloudfoundry.api-host=https://api.example.local",
"spring.cloud.appbroker.deployer.cloudfoundry.username=user",
"spring.cloud.appbroker.deployer.cloudfoundry.password=secret"
"spring.cloud.appbroker.deployer.cloudfoundry.password=secret",
"spring.cloud.appbroker.deployer.cloudfoundry.staging-timeout=3",
"spring.cloud.appbroker.deployer.cloudfoundry.deployment-timeout=4"
);
}
@@ -255,6 +258,12 @@ class AppBrokerAutoConfigurationTest {
}
private void assertPropertiesLoaded(AssertableApplicationContext context) {
CloudFoundryTargetProperties cloudFoundryTargetProperties = context.getBean(CloudFoundryTargetProperties.class);
assertThat(cloudFoundryTargetProperties.getUsername()).isEqualTo("user");
assertThat(cloudFoundryTargetProperties.getPassword()).isEqualTo("secret");
assertThat(cloudFoundryTargetProperties.getDeploymentTimeout()).isEqualTo(4L);
assertThat(cloudFoundryTargetProperties.getStagingTimeout()).isEqualTo(3L);
BrokeredServices brokeredServices = context.getBean(BrokeredServices.class);
assertThat(brokeredServices).hasSize(2);

View File

@@ -137,10 +137,11 @@ import org.springframework.core.io.ResourceLoader;
import org.springframework.http.HttpStatus;
import org.springframework.util.StringUtils;
//TODO: refactor this class
@SuppressWarnings({"PMD.GodClass", "PMD.CyclomaticComplexity", "PMD.ExcessiveClassLength"})
public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware {
private static final Duration DEFAULT_PLATFORM_OPERATION_DURATION = Duration.ofMinutes(10);
private static final Logger LOG = LoggerFactory.getLogger(CloudFoundryAppDeployer.class);
private static final String REQUEST_LOG_TEMPLATE = "request={}";
@@ -454,7 +455,7 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.deploymentId(deploymentId)
.build())
.filter(this::deploymentFinished)
.repeatWhenEmpty(getExponentialBackOff())
.repeatWhenEmpty(getExponentialBackOff(getDeploymentTimeout()))
.doOnRequest(l -> LOG.debug("Waiting for deployment to complete. deploymentId={}", deploymentId))
.doOnSuccess(response -> {
LOG.info("Success waiting for deployment to complete. deploymentId={}", deploymentId);
@@ -503,7 +504,7 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.buildId(buildId)
.build())
.filter(p -> p.getState().equals(BuildState.STAGED))
.repeatWhenEmpty(getExponentialBackOff())
.repeatWhenEmpty(getExponentialBackOff(getStagingTimeout()))
.doOnRequest(l -> LOG.debug("Waiting for build to stage. buildId={}", buildId))
.doOnSuccess(response -> {
LOG.info("Success waiting for build to stage. buildId={}", buildId);
@@ -535,7 +536,7 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
.packages()
.get(GetPackageRequest.builder().packageId(packageId).build())
.filter(p -> p.getState().equals(PackageState.READY))
.repeatWhenEmpty(getExponentialBackOff())
.repeatWhenEmpty(getExponentialBackOff(DEFAULT_PLATFORM_OPERATION_DURATION))
.doOnRequest(l -> LOG.debug("Waiting for package ready. packageId={}", packageId))
.doOnSuccess(response -> {
LOG.info("Success waiting for package ready. packageId={}", packageId);
@@ -679,8 +680,22 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
applicationId, e.getMessage()), e));
}
private Function<Flux<Long>, Publisher<?>> getExponentialBackOff() {
return DelayUtils.exponentialBackOff(Duration.ofSeconds(2), Duration.ofMinutes(5), Duration.ofMinutes(10));
private Duration getStagingTimeout() {
if (targetProperties.getStagingTimeout() == null) {
return DEFAULT_PLATFORM_OPERATION_DURATION;
}
return Duration.ofMinutes(targetProperties.getStagingTimeout());
}
private Duration getDeploymentTimeout() {
if (targetProperties.getDeploymentTimeout() == null) {
return DEFAULT_PLATFORM_OPERATION_DURATION;
}
return Duration.ofMinutes(targetProperties.getDeploymentTimeout());
}
private Function<Flux<Long>, Publisher<?>> getExponentialBackOff(Duration timeout) {
return DelayUtils.exponentialBackOff(Duration.ofSeconds(2), Duration.ofMinutes(5), timeout);
}
private Mono<Void> pushApplication(DeployApplicationRequest request, Map<String, String> deploymentProperties,

View File

@@ -44,6 +44,10 @@ public class CloudFoundryTargetProperties {
private String identityZoneSubdomain;
private Long deploymentTimeout;
private Long stagingTimeout;
public String getApiHost() {
return apiHost;
}
@@ -136,6 +140,22 @@ public class CloudFoundryTargetProperties {
return null;
}
public Long getDeploymentTimeout() {
return deploymentTimeout;
}
public void setDeploymentTimeout(Long deploymentTimeout) {
this.deploymentTimeout = deploymentTimeout;
}
public Long getStagingTimeout() {
return stagingTimeout;
}
public void setStagingTimeout(Long stagingTimeout) {
this.stagingTimeout = stagingTimeout;
}
private static String parseApiHost(String api) {
final URI uri = URI.create(api);
return uri.getHost() == null ? api : uri.getHost();

View File

@@ -21,6 +21,8 @@ spring:
*client-secret: EXAMPLE_SECRET*
*default-org: test*
*default-space: development*
*staging-timeout: 15*
*deployment-timeout: 10*
----
====