/
ServiceInfoCreator.java
36 lines (26 loc) · 1.21 KB
/
ServiceInfoCreator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package io.pivotal.pccpizza.config;
import org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator;
import org.springframework.cloud.cloudfoundry.Tags;
import java.util.List;
import java.util.Map;
public class ServiceInfoCreator extends CloudFoundryServiceInfoCreator<org.springframework.cloud.service.ServiceInfo> {
public ServiceInfoCreator() {
super(new Tags("gemfire"));
}
@Override
public org.springframework.cloud.service.ServiceInfo createServiceInfo(Map<String, Object> serviceData) {
String id = (String) serviceData.get("name");
Map<String, Object> credentials = getCredentials(serviceData);
List<String> locators = (List<String>) credentials.get("locators");
List<Map<String, String>> users = (List<Map<String, String>>) credentials.get("users");
return new ServiceInfo(id, locators, users);
}
@Override
public boolean accept(Map<String, Object> serviceData) {
return containsLocators(serviceData) || super.accept(serviceData);
}
private boolean containsLocators(Map<String, Object> serviceData) {
Object locators = getCredentials(serviceData).get("locators");
return locators != null;
}
}