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.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,11 +30,9 @@ public class CloudController extends BaseController {
|
|||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("list")
|
private ImmutableList<CloudServiceVO> serviceVOS(Function<CloudServiceVO.Service, String> groupByField) {
|
||||||
public AmisResponse list() {
|
return Lists.immutable.ofAll(client.getServices())
|
||||||
ImmutableList<CloudServiceVO> serviceVOS = Lists.immutable.ofAll(client.getServices())
|
.flatCollect(client::getInstances)
|
||||||
.collect(name -> {
|
|
||||||
ImmutableList<CloudServiceVO.Service> instances = Lists.immutable.ofAll(client.getInstances(name))
|
|
||||||
.collect(instance -> new CloudServiceVO.Service(
|
.collect(instance -> new CloudServiceVO.Service(
|
||||||
instance.getInstanceId(),
|
instance.getInstanceId(),
|
||||||
instance.getServiceId(),
|
instance.getServiceId(),
|
||||||
@@ -42,9 +41,24 @@ public class CloudController extends BaseController {
|
|||||||
instance.isSecure(),
|
instance.isSecure(),
|
||||||
instance.getUri().toString(),
|
instance.getUri().toString(),
|
||||||
Maps.immutable.ofAll(instance.getMetadata())
|
Maps.immutable.ofAll(instance.getMetadata())
|
||||||
));
|
))
|
||||||
return new CloudServiceVO(name, instances);
|
.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 = 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());
|
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() {
|
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},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user