feature(web): 优化服务集群展示,新增按 ip 展示微服务节点情况

This commit is contained in:
2023-05-05 12:31:27 +08:00
parent 027fa10d50
commit 44f6cb67b1
2 changed files with 54 additions and 32 deletions

View File

@@ -2,6 +2,7 @@ package com.lanyuanxiaoyao.service.web.controller;
import com.lanyuanxiaoyao.service.configuration.entity.AmisResponse; import com.lanyuanxiaoyao.service.configuration.entity.AmisResponse;
import com.lanyuanxiaoyao.service.web.entity.CloudServiceVO; 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.Lists;
import org.eclipse.collections.api.factory.Maps; import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.ImmutableList;
@@ -29,22 +30,35 @@ public class CloudController extends BaseController {
this.client = client; 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") @GetMapping("list")
public AmisResponse list() { public AmisResponse list() {
ImmutableList<CloudServiceVO> serviceVOS = Lists.immutable.ofAll(client.getServices()) ImmutableList<CloudServiceVO> serviceVOS = serviceVOS(CloudServiceVO.Service::getServiceId);
.collect(name -> { return responseCrudData(serviceVOS, serviceVOS.size());
ImmutableList<CloudServiceVO.Service> instances = Lists.immutable.ofAll(client.getInstances(name)) }
.collect(instance -> new CloudServiceVO.Service(
instance.getInstanceId(), @GetMapping("list_ip")
instance.getServiceId(), public AmisResponse listIp() {
instance.getHost(), ImmutableList<CloudServiceVO> serviceVOS = serviceVOS(CloudServiceVO.Service::getHost);
instance.getPort(),
instance.isSecure(),
instance.getUri().toString(),
Maps.immutable.ofAll(instance.getMetadata())
));
return new CloudServiceVO(name, instances);
});
return responseCrudData(serviceVOS, serviceVOS.size()); return responseCrudData(serviceVOS, serviceVOS.size());
} }
} }

View File

@@ -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() { function cloudTab() {
return { return {
title: 'Cloud 集群', title: 'Cloud 集群',
@@ -16,24 +40,8 @@ function cloudTab() {
], ],
}, },
{type: 'divider'}, {type: 'divider'},
{ cloudCrud('服务列表', '/cloud/list'),
type: 'crud', cloudCrud('服务列表 (IP)', '/cloud/list_ip'),
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},
]
}
], ],
} }
} }