mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
3.2.0
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package com.gitee.sop.adminserver.service;
|
||||
|
||||
import com.gitee.fastmybatis.core.query.Query;
|
||||
import com.gitee.sop.adminserver.api.service.param.ServiceSearchParam;
|
||||
import com.gitee.sop.adminserver.api.service.result.ServiceInstanceVO;
|
||||
import com.gitee.sop.adminserver.bean.ServiceInfo;
|
||||
import com.gitee.sop.adminserver.bean.ServiceInstance;
|
||||
import com.gitee.sop.adminserver.entity.ConfigGrayInstance;
|
||||
import com.gitee.sop.adminserver.mapper.ConfigGrayInstanceMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -12,8 +15,12 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
@@ -22,9 +29,13 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
@Service
|
||||
public class ServerService {
|
||||
|
||||
public static final int GRAY_OPEN = 1;
|
||||
@Autowired
|
||||
private RegistryService registryService;
|
||||
|
||||
@Autowired
|
||||
private ConfigGrayInstanceMapper grayInstanceMapper;
|
||||
|
||||
public List<ServiceInstanceVO> listService(ServiceSearchParam param) {
|
||||
List<ServiceInfo> serviceInfos;
|
||||
try {
|
||||
@@ -33,6 +44,10 @@ public class ServerService {
|
||||
log.error("获取服务实例失败", e);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<ConfigGrayInstance> configGrayInstances = grayInstanceMapper.list(new Query());
|
||||
// key: instanceId
|
||||
Map<String, ConfigGrayInstance> grayInstanceMap = configGrayInstances.stream()
|
||||
.collect(Collectors.toMap(ConfigGrayInstance::getInstanceId, Function.identity()));
|
||||
List<ServiceInstanceVO> serviceInfoVoList = new ArrayList<>();
|
||||
AtomicInteger idGen = new AtomicInteger(1);
|
||||
serviceInfos.stream()
|
||||
@@ -58,12 +73,22 @@ public class ServerService {
|
||||
instanceVO.setId(id);
|
||||
instanceVO.setParentId(pid);
|
||||
if (instanceVO.getMetadata() == null) {
|
||||
instanceVO.setMetadata(Collections.emptyMap());
|
||||
instanceVO.setMetadata(new HashMap<>(8));
|
||||
}
|
||||
bindGrayEnv(instanceVO, grayInstanceMap);
|
||||
serviceInfoVoList.add(instanceVO);
|
||||
}
|
||||
});
|
||||
|
||||
return serviceInfoVoList;
|
||||
}
|
||||
|
||||
private void bindGrayEnv(ServiceInstanceVO instanceVO, Map<String, ConfigGrayInstance> grayInstanceMap) {
|
||||
String instanceId = instanceVO.getInstanceId();
|
||||
ConfigGrayInstance configGrayInstance = grayInstanceMap.get(instanceId);
|
||||
if (configGrayInstance != null && configGrayInstance.getStatus() == GRAY_OPEN) {
|
||||
Map<String, String> metadata = instanceVO.getMetadata();
|
||||
metadata.put("env", "gray");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user