|
28 | 28 | import java.util.function.Supplier; |
29 | 29 | import javax.net.ssl.SSLException; |
30 | 30 | import org.cloudfoundry.client.CloudFoundryClient; |
31 | | -import org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsRequest; |
32 | 31 | import org.cloudfoundry.client.v2.applications.RemoveApplicationServiceBindingRequest; |
33 | 32 | import org.cloudfoundry.client.v2.buildpacks.DeleteBuildpackRequest; |
34 | 33 | import org.cloudfoundry.client.v2.buildpacks.ListBuildpacksRequest; |
|
79 | 78 | import org.cloudfoundry.client.v3.applications.Application; |
80 | 79 | import org.cloudfoundry.client.v3.applications.DeleteApplicationRequest; |
81 | 80 | import org.cloudfoundry.client.v3.applications.ListApplicationsRequest; |
| 81 | +import org.cloudfoundry.client.v3.servicebindings.DeleteServiceBindingRequest; |
| 82 | +import org.cloudfoundry.client.v3.servicebindings.ListServiceBindingsRequest; |
82 | 83 | import org.cloudfoundry.client.v3.serviceinstances.ListSharedSpacesRelationshipRequest; |
83 | 84 | import org.cloudfoundry.client.v3.serviceinstances.ListSharedSpacesRelationshipResponse; |
84 | 85 | import org.cloudfoundry.client.v3.serviceinstances.UnshareServiceInstanceRequest; |
@@ -129,6 +130,8 @@ final class CloudFoundryCleaner implements InitializingBean, DisposableBean { |
129 | 130 |
|
130 | 131 | private static final Logger LOGGER = LoggerFactory.getLogger("cloudfoundry-client.test"); |
131 | 132 |
|
| 133 | + private static final boolean RUN_V2_CLEANUP = RequiresV2Api.V2ApiCondition.isEnabled(); |
| 134 | + |
132 | 135 | private static final Map<String, Boolean> STANDARD_FEATURE_FLAGS = |
133 | 136 | FluentMap.<String, Boolean>builder() |
134 | 137 | .entry("app_bits_upload", true) |
@@ -186,6 +189,28 @@ public void destroy() { |
186 | 189 | } |
187 | 190 |
|
188 | 191 | void clean() { |
| 192 | + if (!RUN_V2_CLEANUP) { |
| 193 | + LOGGER.info("Skipping V2 API cleanup operations (SKIP_V2_TESTS=true)"); |
| 194 | + // Only run V3 and UAA cleanup operations |
| 195 | + Flux.empty() |
| 196 | + .thenMany( |
| 197 | + Mono.when( // No prerequisites - V3/UAA only |
| 198 | + cleanClients(this.uaaClient, this.nameFactory), |
| 199 | + cleanGroups(this.uaaClient, this.nameFactory), |
| 200 | + cleanIdentityProviders(this.uaaClient, this.nameFactory), |
| 201 | + cleanIdentityZones(this.uaaClient, this.nameFactory))) |
| 202 | + .thenMany( |
| 203 | + Mono.when( |
| 204 | + cleanApplicationsV3(this.cloudFoundryClient, this.nameFactory), |
| 205 | + cleanUsers(this.uaaClient, this.nameFactory))) |
| 206 | + .retryWhen(Retry.max(5).filter(SSLException.class::isInstance)) |
| 207 | + .doOnSubscribe(s -> LOGGER.debug(">> CLEANUP (V3 only) <<")) |
| 208 | + .doOnComplete(() -> LOGGER.debug("<< CLEANUP (V3 only) >>")) |
| 209 | + .then() |
| 210 | + .block(Duration.ofMinutes(30)); |
| 211 | + return; |
| 212 | + } |
| 213 | + |
189 | 214 | Flux.empty() |
190 | 215 | .thenMany( |
191 | 216 | Mono.when( // Before Routes |
@@ -216,10 +241,7 @@ void clean() { |
216 | 241 | cleanUsers(this.cloudFoundryClient, this.nameFactory))) |
217 | 242 | .thenMany( |
218 | 243 | Mono.when( |
219 | | - cleanApplicationsV3( |
220 | | - this.cloudFoundryClient, |
221 | | - this.nameFactory), // After Routes, cannot run with |
222 | | - // other cleanApps |
| 244 | + cleanApplicationsV3(this.cloudFoundryClient, this.nameFactory), |
223 | 245 | cleanUsers(this.uaaClient, this.nameFactory) // After CF Users |
224 | 246 | )) |
225 | 247 | .thenMany( |
@@ -1160,21 +1182,24 @@ private static boolean isCleanable(NameFactory nameFactory, UserResource resourc |
1160 | 1182 |
|
1161 | 1183 | private static Flux<Void> removeApplicationServiceBindings( |
1162 | 1184 | CloudFoundryClient cloudFoundryClient, Application application) { |
1163 | | - return PaginationUtils.requestClientV2Resources( |
| 1185 | + return PaginationUtils.requestClientV3Resources( |
1164 | 1186 | page -> |
1165 | 1187 | cloudFoundryClient |
1166 | | - .applicationsV2() |
1167 | | - .listServiceBindings( |
1168 | | - ListApplicationServiceBindingsRequest.builder() |
| 1188 | + .serviceBindingsV3() |
| 1189 | + .list( |
| 1190 | + ListServiceBindingsRequest.builder() |
1169 | 1191 | .page(page) |
1170 | 1192 | .applicationId(application.getId()) |
1171 | 1193 | .build())) |
1172 | 1194 | .flatMap( |
1173 | 1195 | serviceBinding -> |
1174 | | - requestRemoveServiceBinding( |
1175 | | - cloudFoundryClient, |
1176 | | - application.getId(), |
1177 | | - ResourceUtils.getId(serviceBinding)) |
| 1196 | + cloudFoundryClient |
| 1197 | + .serviceBindingsV3() |
| 1198 | + .delete( |
| 1199 | + DeleteServiceBindingRequest.builder() |
| 1200 | + .serviceBindingId(serviceBinding.getId()) |
| 1201 | + .build()) |
| 1202 | + .then() |
1178 | 1203 | .doOnError( |
1179 | 1204 | t -> |
1180 | 1205 | LOGGER.error( |
|
0 commit comments