1818import org .cloudfoundry .multiapps .controller .core .util .ApplicationConfiguration ;
1919
2020public class CustomServiceKeysClient extends CustomControllerClient {
21-
2221 private static final String SERVICE_KEYS_RESOURCE_BASE_URI = "/v3/service_credential_bindings" ;
2322 private static final String SERVICE_KEYS_BY_METADATA_SELECTOR_URI = SERVICE_KEYS_RESOURCE_BASE_URI + "?type=key&label_selector={value}" ;
2423 private static final String INCLUDE_SERVICE_INSTANCE_RESOURCES_PARAM = "&include=service_instance" ;
25-
24+ private static final String SERVICE_INSTANCE_GUIDS_PARAM_PREFIX = "&service_instance_guids=" ;
2625 private final CloudEntityResourceMapper resourceMapper = new CloudEntityResourceMapper ();
2726
2827 public CustomServiceKeysClient (ApplicationConfiguration configuration , WebClientFactory webClientFactory , CloudCredentials credentials ,
@@ -35,17 +34,13 @@ public List<DeployedMtaServiceKey> getServiceKeysByMetadataAndExistingGuids(
3534 String mtaId ,
3635 String mtaNamespace ,
3736 List <String > existingServiceGuids ) {
38-
3937 String labelSelector = buildMtaMetadataLabelSelector (spaceGuid , mtaId , mtaNamespace );
40-
4138 List <String > allServiceGuids = existingServiceGuids .stream ()
4239 .filter (Objects ::nonNull )
4340 .toList ();
44-
4541 if (allServiceGuids .isEmpty ()) {
4642 return List .of ();
4743 }
48-
4944 return new CustomControllerClientErrorHandler ()
5045 .handleErrorsOrReturnResult (
5146 () -> getServiceKeysByMetadataInternal (labelSelector , allServiceGuids )
@@ -57,15 +52,11 @@ public List<DeployedMtaServiceKey> getServiceKeysByMetadataAndManagedServices(
5752 String mtaId ,
5853 String mtaNamespace ,
5954 List <DeployedMtaService > services ) {
60-
6155 String labelSelector = buildMtaMetadataLabelSelector (spaceGuid , mtaId , mtaNamespace );
62-
6356 List <String > managedGuids = extractManagedServiceGuids (services );
64-
6557 if (managedGuids .isEmpty ()) {
6658 return List .of ();
6759 }
68-
6960 return new CustomControllerClientErrorHandler ()
7061 .handleErrorsOrReturnResult (
7162 () -> getServiceKeysByMetadataInternal (labelSelector , managedGuids )
@@ -75,7 +66,6 @@ public List<DeployedMtaServiceKey> getServiceKeysByMetadataAndManagedServices(
7566 private String buildMtaMetadataLabelSelector (String spaceGuid ,
7667 String mtaId ,
7768 String mtaNamespace ) {
78-
7969 return MtaMetadataCriteriaBuilder .builder ()
8070 .label (MtaMetadataLabels .SPACE_GUID )
8171 .hasValue (spaceGuid )
@@ -98,13 +88,12 @@ private List<String> extractManagedServiceGuids(List<DeployedMtaService> service
9888 }
9989
10090 private List <DeployedMtaServiceKey > getServiceKeysByMetadataInternal (String labelSelector , List <String > guids ) {
101-
102- String uriSuffix = INCLUDE_SERVICE_INSTANCE_RESOURCES_PARAM
103- + "&service_instance_guids=" + String .join ("," , guids );
104-
105- return getListOfResources (new ServiceKeysResponseMapper (),
106- SERVICE_KEYS_BY_METADATA_SELECTOR_URI + uriSuffix ,
107- labelSelector );
91+ String expandedUriPrefix = SERVICE_KEYS_BY_METADATA_SELECTOR_URI .replace ("{value}" , labelSelector )
92+ + INCLUDE_SERVICE_INSTANCE_RESOURCES_PARAM ;
93+ return getListOfResourcesInBatches (new ServiceKeysResponseMapper (),
94+ expandedUriPrefix ,
95+ SERVICE_INSTANCE_GUIDS_PARAM_PREFIX ,
96+ guids );
10897 }
10998
11099 private List <DeployedMtaService > getManagedServices (List <DeployedMtaService > services ) {
@@ -132,12 +121,10 @@ public List<DeployedMtaServiceKey> getMappedResources() {
132121
133122 public Map <String , CloudServiceInstance > getIncludedServiceInstancesMapping () {
134123 List <Object > serviceInstances = getIncludedResources ().getOrDefault ("service_instances" , Collections .emptyList ());
135-
136124 return serviceInstances .stream ()
137125 .distinct ()
138126 .map (service -> (Map <String , Object >) service )
139127 .collect (Collectors .toMap (service -> (String ) service .get ("guid" ), resourceMapper ::mapService ));
140-
141128 }
142129 }
143- }
130+ }
0 commit comments