Skip to content

Commit

Permalink
增加控制台获取网关名列表接口
Browse files Browse the repository at this point in the history
  • Loading branch information
HaojunRen committed Sep 1, 2020
1 parent 71b0965 commit d1c4add
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ public List<String> services() {
return getServices();
}

@RequestMapping(path = "/gateways", method = RequestMethod.GET)
@ApiOperation(value = "获取服务注册中心的网关名列表", notes = "", response = List.class, httpMethod = "GET")
@ResponseBody
public List<String> gateways() {
return getGateways();
}

@RequestMapping(path = "/instances/{serviceId}", method = RequestMethod.GET)
@ApiOperation(value = "获取服务注册中心的服务实例列表", notes = "", response = List.class, httpMethod = "GET")
@ResponseBody
Expand Down Expand Up @@ -293,6 +300,26 @@ public List<ServiceInstance> getInstances(String serviceId) {
return discoveryClient.getInstances(serviceId);
}

public List<String> getGateways() {
List<String> gateways = new ArrayList<String>();
List<String> services = getServices();
for (String service : services) {
List<ServiceInstance> serviceInstances = getInstances(service);
for (ServiceInstance serviceInstance : serviceInstances) {
Map<String, String> metadata = serviceInstance.getMetadata();
String serviceId = serviceInstance.getServiceId().toLowerCase();
String serviceType = metadata.get(DiscoveryConstant.SPRING_APPLICATION_TYPE);
if (StringUtils.equals(serviceType, DiscoveryConstant.GATEWAY_TYPE)) {
if (!gateways.contains(serviceId)) {
gateways.add(serviceId);
}
}
}
}

return gateways;
}

public List<InstanceEntity> getInstanceList(String service) {
List<ServiceInstance> serviceInstances = getInstances(service);
List<InstanceEntity> instanceEntityList = new ArrayList<InstanceEntity>(serviceInstances.size());
Expand Down

0 comments on commit d1c4add

Please sign in to comment.