11package de .tum .cit .aet .api_gateway ;
22
3+ import org .springframework .beans .factory .annotation .Value ;
34import org .springframework .cloud .client .ServiceInstance ;
45import org .springframework .cloud .client .discovery .DiscoveryClient ;
56import org .springframework .web .bind .annotation .GetMapping ;
67import org .springframework .web .bind .annotation .RestController ;
78
89import java .util .Arrays ;
910import java .util .List ;
11+ import java .util .Map ;
1012import java .util .Set ;
1113import java .util .stream .Collectors ;
14+ import java .util .stream .Stream ;
1215
1316import static de .tum .cit .aet .api_gateway .Constants .ARTEMIS_SERVICE_ID ;
1417
1518@ RestController
1619public class AggregatedProfileResource {
1720
21+ @ Value ("${custom-routing.profileMetadataKey}" )
22+ private String profileMetadataKey ;
23+
1824 private final DiscoveryClient discoveryClient ;
1925
2026 private final ProfilePathStore profilePathStore ;
@@ -33,8 +39,19 @@ public Set<String> activatedProfiles() {
3339 List <ServiceInstance > serviceInstances = discoveryClient .getInstances (ARTEMIS_SERVICE_ID );
3440
3541 return serviceInstances .stream ()
36- .flatMap (serviceInstance -> Arrays .stream (serviceInstance .getMetadata ().getOrDefault (profilePathStore .getDefaultProfile (), "" ).split ("," )))
37- .filter (profile -> !profile .isEmpty ())
42+ .flatMap (serviceInstance -> {
43+ Map <String , String > metadata = serviceInstance .getMetadata ();
44+ if (metadata .isEmpty ()) {
45+ return Stream .empty ();
46+ }
47+
48+ String profiles = metadata .get (profileMetadataKey );
49+ if (profiles == null ) {
50+ return Stream .empty ();
51+ }
52+
53+ return Arrays .stream (profiles .split ("," ));
54+ })
3855 .collect (Collectors .toSet ());
3956 }
4057
0 commit comments