admin服务列表在线/离线筛选(在线靠前)

1.x
tanghc 5 years ago
parent 273f3c97d7
commit 50b5e8f854
  1. 14
      sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/bean/ServiceInfo.java
  2. 7
      sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/impl/RegistryServiceNacos.java

@ -1,24 +1,16 @@
package com.gitee.sop.registryapi.bean; package com.gitee.sop.registryapi.bean;
import lombok.Getter; import lombok.Data;
import lombok.Setter;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
* @author tanghc * @author tanghc
*/ */
@Getter @Data
@Setter
public class ServiceInfo { public class ServiceInfo {
/** 服务名称 */ /** 服务名称 */
private String serviceId; private String serviceId;
/** 实例列表 */ /** 实例列表 */
private List<ServiceInstance> instances = Collections.emptyList(); private List<ServiceInstance> instances;
@Override
public String toString() {
return "服务名称: " + serviceId + ", 实例数:" + instances.size();
}
} }

@ -18,6 +18,8 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -51,7 +53,9 @@ public class RegistryServiceNacos implements RegistryService {
ServiceInfo serviceInfo = new ServiceInfo(); ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setServiceId(serviceName); serviceInfo.setServiceId(serviceName);
List<Instance> instanceList = namingService.getAllInstances(serviceName); List<Instance> instanceList = namingService.getAllInstances(serviceName);
if (!CollectionUtils.isEmpty(instanceList)) { if (CollectionUtils.isEmpty(instanceList)) {
serviceInfo.setInstances(Collections.emptyList());
} else {
serviceInfo.setInstances(new ArrayList<>(instanceList.size())); serviceInfo.setInstances(new ArrayList<>(instanceList.size()));
for (Instance instance : instanceList) { for (Instance instance : instanceList) {
ServiceInstance serviceInstance = new ServiceInstance(); ServiceInstance serviceInstance = new ServiceInstance();
@ -68,6 +72,7 @@ public class RegistryServiceNacos implements RegistryService {
} }
serviceInfoList.add(serviceInfo); serviceInfoList.add(serviceInfo);
} }
serviceInfoList.sort(Comparator.comparingInt(o -> o.getInstances().size()));
return serviceInfoList; return serviceInfoList;
} }

Loading…
Cancel
Save