Skip to content

Commit c480741

Browse files
committed
fix metadata endpoint
1 parent 45008e8 commit c480741

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

api-gateway/src/main/java/de/tum/cit/aet/api_gateway/AggregatedProfileResource.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
package de.tum.cit.aet.api_gateway;
22

3+
import org.springframework.beans.factory.annotation.Value;
34
import org.springframework.cloud.client.ServiceInstance;
45
import org.springframework.cloud.client.discovery.DiscoveryClient;
56
import org.springframework.web.bind.annotation.GetMapping;
67
import org.springframework.web.bind.annotation.RestController;
78

89
import java.util.Arrays;
910
import java.util.List;
11+
import java.util.Map;
1012
import java.util.Set;
1113
import java.util.stream.Collectors;
14+
import java.util.stream.Stream;
1215

1316
import static de.tum.cit.aet.api_gateway.Constants.ARTEMIS_SERVICE_ID;
1417

1518
@RestController
1619
public 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

Comments
 (0)