feature(web): 优化服务集群展示,新增按 ip 展示微服务节点情况
This commit is contained in:
@@ -2,6 +2,7 @@ package com.lanyuanxiaoyao.service.web.controller;
|
||||
|
||||
import com.lanyuanxiaoyao.service.configuration.entity.AmisResponse;
|
||||
import com.lanyuanxiaoyao.service.web.entity.CloudServiceVO;
|
||||
import org.eclipse.collections.api.block.function.Function;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
@@ -29,22 +30,35 @@ public class CloudController extends BaseController {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
private ImmutableList<CloudServiceVO> serviceVOS(Function<CloudServiceVO.Service, String> groupByField) {
|
||||
return Lists.immutable.ofAll(client.getServices())
|
||||
.flatCollect(client::getInstances)
|
||||
.collect(instance -> new CloudServiceVO.Service(
|
||||
instance.getInstanceId(),
|
||||
instance.getServiceId(),
|
||||
instance.getHost(),
|
||||
instance.getPort(),
|
||||
instance.isSecure(),
|
||||
instance.getUri().toString(),
|
||||
Maps.immutable.ofAll(instance.getMetadata())
|
||||
))
|
||||
.groupBy(groupByField)
|
||||
.toMap()
|
||||
.collectValues((serviceId, services) -> new CloudServiceVO(serviceId, services.toList().toImmutable()))
|
||||
.valuesView()
|
||||
.toSortedListBy(CloudServiceVO::getName)
|
||||
.toImmutable();
|
||||
}
|
||||
|
||||
@GetMapping("list")
|
||||
public AmisResponse list() {
|
||||
ImmutableList<CloudServiceVO> serviceVOS = Lists.immutable.ofAll(client.getServices())
|
||||
.collect(name -> {
|
||||
ImmutableList<CloudServiceVO.Service> instances = Lists.immutable.ofAll(client.getInstances(name))
|
||||
.collect(instance -> new CloudServiceVO.Service(
|
||||
instance.getInstanceId(),
|
||||
instance.getServiceId(),
|
||||
instance.getHost(),
|
||||
instance.getPort(),
|
||||
instance.isSecure(),
|
||||
instance.getUri().toString(),
|
||||
Maps.immutable.ofAll(instance.getMetadata())
|
||||
));
|
||||
return new CloudServiceVO(name, instances);
|
||||
});
|
||||
ImmutableList<CloudServiceVO> serviceVOS = serviceVOS(CloudServiceVO.Service::getServiceId);
|
||||
return responseCrudData(serviceVOS, serviceVOS.size());
|
||||
}
|
||||
|
||||
@GetMapping("list_ip")
|
||||
public AmisResponse listIp() {
|
||||
ImmutableList<CloudServiceVO> serviceVOS = serviceVOS(CloudServiceVO.Service::getHost);
|
||||
return responseCrudData(serviceVOS, serviceVOS.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,27 @@
|
||||
function cloudCrud(title, path) {
|
||||
return {
|
||||
type: 'crud',
|
||||
title: title,
|
||||
api: `\${base}${path}`,
|
||||
interval: 2000,
|
||||
syncLocation: false,
|
||||
silentPolling: true,
|
||||
headerToolbar: ['reload'],
|
||||
loadDataOnce: true,
|
||||
affixHeader: false,
|
||||
perPage: 100,
|
||||
columns: [
|
||||
{name: 'name', label: '名称'},
|
||||
{
|
||||
name: 'serviceId',
|
||||
label: '服务',
|
||||
width: 200,
|
||||
},
|
||||
{name: 'url', label: '地址', width: 200},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
function cloudTab() {
|
||||
return {
|
||||
title: 'Cloud 集群',
|
||||
@@ -16,24 +40,8 @@ function cloudTab() {
|
||||
],
|
||||
},
|
||||
{type: 'divider'},
|
||||
{
|
||||
type: 'crud',
|
||||
title: '服务列表',
|
||||
api: '${base}/cloud/list',
|
||||
interval: 2000,
|
||||
syncLocation: false,
|
||||
silentPolling: true,
|
||||
headerToolbar: ['reload'],
|
||||
columns: [
|
||||
{name: 'name', label: '名称'},
|
||||
{
|
||||
name: 'serviceId',
|
||||
label: '服务',
|
||||
width: 100,
|
||||
},
|
||||
{name: 'url', label: '地址', width: 200},
|
||||
]
|
||||
}
|
||||
cloudCrud('服务列表', '/cloud/list'),
|
||||
cloudCrud('服务列表 (IP)', '/cloud/list_ip'),
|
||||
],
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user