commit
b94b48eb60
@ -0,0 +1,23 @@ |
|||||||
|
use sop; |
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `config_service_route`; |
||||||
|
|
||||||
|
CREATE TABLE `config_service_route` ( |
||||||
|
`id` varchar(128) NOT NULL DEFAULT '' COMMENT '路由id', |
||||||
|
`service_id` varchar(128) NOT NULL DEFAULT '', |
||||||
|
`name` varchar(128) NOT NULL DEFAULT '' COMMENT '接口名', |
||||||
|
`version` varchar(64) NOT NULL DEFAULT '' COMMENT '版本号', |
||||||
|
`predicates` varchar(256) DEFAULT NULL COMMENT '路由断言(SpringCloudGateway专用)', |
||||||
|
`filters` varchar(256) DEFAULT NULL COMMENT '路由过滤器(SpringCloudGateway专用)', |
||||||
|
`uri` varchar(128) NOT NULL DEFAULT '' COMMENT '路由规则转发的目标uri', |
||||||
|
`path` varchar(128) NOT NULL DEFAULT '' COMMENT 'uri后面跟的path', |
||||||
|
`order` int(11) NOT NULL DEFAULT '0' COMMENT '路由执行的顺序', |
||||||
|
`ignore_validate` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否忽略验证,业务参数验证除外', |
||||||
|
`status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态,0:待审核,1:启用,2:禁用', |
||||||
|
`merge_result` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否合并结果', |
||||||
|
`permission` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否需要授权才能访问', |
||||||
|
`gmt_create` datetime DEFAULT CURRENT_TIMESTAMP, |
||||||
|
`gmt_modified` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
||||||
|
PRIMARY KEY (`id`), |
||||||
|
KEY `idx_serviceid` (`service_id`) USING BTREE |
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='路由配置'; |
@ -0,0 +1,69 @@ |
|||||||
|
package com.gitee.sop.adminserver.service; |
||||||
|
|
||||||
|
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 lombok.extern.slf4j.Slf4j; |
||||||
|
import org.apache.commons.lang.StringUtils; |
||||||
|
import org.springframework.beans.BeanUtils; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collections; |
||||||
|
import java.util.List; |
||||||
|
import java.util.concurrent.atomic.AtomicInteger; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author tanghc |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@Service |
||||||
|
public class ServerService { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private RegistryService registryService; |
||||||
|
|
||||||
|
public List<ServiceInstanceVO> listService(ServiceSearchParam param) { |
||||||
|
List<ServiceInfo> serviceInfos; |
||||||
|
try { |
||||||
|
serviceInfos = registryService.listAllService(1, Integer.MAX_VALUE); |
||||||
|
} catch (Exception e) { |
||||||
|
log.error("获取服务实例失败", e); |
||||||
|
return Collections.emptyList(); |
||||||
|
} |
||||||
|
List<ServiceInstanceVO> serviceInfoVoList = new ArrayList<>(); |
||||||
|
AtomicInteger idGen = new AtomicInteger(1); |
||||||
|
serviceInfos.stream() |
||||||
|
.filter(serviceInfo -> { |
||||||
|
if (StringUtils.isBlank(param.getServiceId())) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
return StringUtils.containsIgnoreCase(serviceInfo.getServiceId(), param.getServiceId()); |
||||||
|
}) |
||||||
|
.forEach(serviceInfo -> { |
||||||
|
int pid = idGen.getAndIncrement(); |
||||||
|
String serviceId = serviceInfo.getServiceId(); |
||||||
|
ServiceInstanceVO parent = new ServiceInstanceVO(); |
||||||
|
parent.setId(pid); |
||||||
|
parent.setServiceId(serviceId); |
||||||
|
parent.setParentId(0); |
||||||
|
serviceInfoVoList.add(parent); |
||||||
|
List<ServiceInstance> instanceList = serviceInfo.getInstances(); |
||||||
|
for (ServiceInstance instance : instanceList) { |
||||||
|
ServiceInstanceVO instanceVO = new ServiceInstanceVO(); |
||||||
|
BeanUtils.copyProperties(instance, instanceVO); |
||||||
|
int id = idGen.getAndIncrement(); |
||||||
|
instanceVO.setId(id); |
||||||
|
instanceVO.setParentId(pid); |
||||||
|
if (instanceVO.getMetadata() == null) { |
||||||
|
instanceVO.setMetadata(Collections.emptyMap()); |
||||||
|
} |
||||||
|
serviceInfoVoList.add(instanceVO); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
return serviceInfoVoList; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue