From 00d035d4ee1cd0cb5ff1f12a645a7d10d8d7a2d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20C=2E=20R=C3=ADos?= Date: Wed, 8 Feb 2023 12:31:00 +0100 Subject: [PATCH] Fixing space parallelization [Fixes #701] --- ...erServiceInstanceTargetAcceptanceTest.java | 102 ++++++++++++++++++ .../cloudfoundry/CloudFoundryAppDeployer.java | 1 + 2 files changed, 103 insertions(+) create mode 100644 spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithServicesSpacePerServiceInstanceTargetAcceptanceTest.java diff --git a/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithServicesSpacePerServiceInstanceTargetAcceptanceTest.java b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithServicesSpacePerServiceInstanceTargetAcceptanceTest.java new file mode 100644 index 0000000..6e2aadb --- /dev/null +++ b/spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/CreateInstanceWithServicesSpacePerServiceInstanceTargetAcceptanceTest.java @@ -0,0 +1,102 @@ +/* + * Copyright 2002-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.appbroker.acceptance; + +import java.util.List; +import java.util.Optional; + +import org.cloudfoundry.operations.applications.ApplicationSummary; +import org.cloudfoundry.operations.services.ServiceInstance; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class CreateInstanceWithServicesSpacePerServiceInstanceTargetAcceptanceTest extends CloudFoundryAcceptanceTest { + + private static final String APP_NAME = "app-create-two-space-per"; + private static final String SI_NAME = "si-create-two-space-per"; + private static final String BACKING_SI_NAME_1 = "backing-service-two-space-per-target-1"; + private static final String BACKING_SI_NAME_2 = "backing-service-two-space-per-target-2"; + private static final String SUFFIX = "two-space-per-si"; + private static final String APP_SERVICE_NAME = "app-service-" + SUFFIX; + private static final String BACKING_SERVICE_NAME = "backing-service-" + SUFFIX; + + @Override + protected String testSuffix() { + return SUFFIX; + } + + @Override + protected String appServiceName() { + return APP_SERVICE_NAME; + } + + @Override + protected String backingServiceName() { + return BACKING_SERVICE_NAME; + } + + @Test + @AppBrokerTestProperties({ + "spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME, + "spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME, + "spring.cloud.appbroker.services[0].target.name=SpacePerServiceInstance", + + "spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME, + "spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH, + "spring.cloud.appbroker.services[0].apps[0].services[0].service-instance-name=" + BACKING_SI_NAME_1, + "spring.cloud.appbroker.services[0].apps[0].services[1].service-instance-name=" + BACKING_SI_NAME_2, + + "spring.cloud.appbroker.services[0].services[0].name=" + BACKING_SERVICE_NAME, + "spring.cloud.appbroker.services[0].services[0].plan=" + PLAN_NAME, + "spring.cloud.appbroker.services[0].services[0].service-instance-name=" + BACKING_SI_NAME_1, + + "spring.cloud.appbroker.services[0].services[1].name=" + BACKING_SERVICE_NAME, + "spring.cloud.appbroker.services[0].services[1].plan=" + PLAN_NAME, + "spring.cloud.appbroker.services[0].services[1].service-instance-name=" + BACKING_SI_NAME_2 + }) + void deployAppsInTargetSpaceOnCreateService() { + // when a service instance is created with targets + createServiceInstance(SI_NAME); + + // then backing applications are deployed in a space named as the service instance id + String spaceName = getServiceInstanceGuid(SI_NAME); + + Optional backingApplication1 = getApplicationSummary(APP_NAME, spaceName); + assertThat(backingApplication1).hasValueSatisfying(app -> { + assertThat(app.getRunningInstances()).isEqualTo(1); + + // and has its route with the service instance id appended to it + assertThat(app.getUrls()).isNotEmpty(); + assertThat(app.getUrls().get(0)).startsWith(APP_NAME + "-" + spaceName); + }); + + // and the services are bound to it + ServiceInstance serviceInstance1 = getBackingServiceInstance(BACKING_SI_NAME_1, spaceName); + assertThat(serviceInstance1.getApplications()).contains(APP_NAME); + ServiceInstance serviceInstance2 = getBackingServiceInstance(BACKING_SI_NAME_2, spaceName); + assertThat(serviceInstance2.getApplications()).contains(APP_NAME); + + // when the service instance is deleted + deleteServiceInstance(SI_NAME); + + // then the space is deleted + List spaces = getSpaces(); + assertThat(spaces).doesNotContain(spaceName); + } + +} diff --git a/spring-cloud-app-broker-deployer-cloudfoundry/src/main/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployer.java b/spring-cloud-app-broker-deployer-cloudfoundry/src/main/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployer.java index 0952377..df8c676 100644 --- a/spring-cloud-app-broker-deployer-cloudfoundry/src/main/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployer.java +++ b/spring-cloud-app-broker-deployer-cloudfoundry/src/main/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployer.java @@ -767,6 +767,7 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware }) .doOnError(e -> LOG.error(String.format("Error creating space. spaceName=%s, " + ERROR_LOG_TEMPLATE, spaceName, e.getMessage()), e)) + .onErrorResume(e -> Mono.empty()) .map(response -> response.getMetadata().getId()) .flatMap(spaceId -> addSpaceDeveloperRoleForCurrentUser(orgName, spaceName, spaceId) .thenReturn(spaceId)))));