feature(web): 增加查看服务部署架构
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.lanyuanxiaoyao.service.web.controller;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.lanyuanxiaoyao.service.configuration.entity.AmisResponse;
|
||||
import com.lanyuanxiaoyao.service.web.entity.CloudServiceVO;
|
||||
import com.netflix.appinfo.InstanceInfo;
|
||||
@@ -8,6 +10,8 @@ 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;
|
||||
import org.eclipse.collections.api.list.MutableList;
|
||||
import org.eclipse.collections.api.map.MutableMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
@@ -16,6 +20,8 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 云页面
|
||||
*
|
||||
@@ -33,7 +39,7 @@ public class CloudController extends BaseController {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
private ImmutableList<CloudServiceVO> serviceVOS(Function<CloudServiceVO.Service, String> groupByField) {
|
||||
private ImmutableList<CloudServiceVO.Service> services() {
|
||||
return Lists.immutable.ofAll(client.getServices())
|
||||
.flatCollect(client::getInstances)
|
||||
.collect(instance -> {
|
||||
@@ -61,7 +67,11 @@ public class CloudController extends BaseController {
|
||||
}
|
||||
}
|
||||
return service;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
private ImmutableList<CloudServiceVO> serviceVOS(Function<CloudServiceVO.Service, String> groupByField) {
|
||||
return services()
|
||||
.groupBy(groupByField)
|
||||
.toMap()
|
||||
.collectValues((serviceId, services) -> new CloudServiceVO(serviceId, services.toSortedListBy(CloudServiceVO.Service::getServiceUpTime).toImmutable()))
|
||||
@@ -81,4 +91,51 @@ public class CloudController extends BaseController {
|
||||
ImmutableList<CloudServiceVO> serviceVOS = serviceVOS(CloudServiceVO.Service::getHost);
|
||||
return responseCrudData(serviceVOS, serviceVOS.size());
|
||||
}
|
||||
|
||||
@GetMapping("deploy_plan")
|
||||
public AmisResponse deployPlan() {
|
||||
ImmutableList<CloudServiceVO.Service> services = services();
|
||||
ImmutableList<String> deployExists = services.collect(service -> StrUtil.format("{}-{}", service.getServiceId(), service.getHost()));
|
||||
ImmutableList<String> serviceIds = services.collect(CloudServiceVO.Service::getServiceId).distinct().toSortedList().toImmutable();
|
||||
ImmutableList<String> hosts = services.collect(CloudServiceVO.Service::getHost).distinct().toSortedList().toImmutable();
|
||||
MutableList<MutableMap<String, Object>> data = Lists.mutable.empty();
|
||||
serviceIds.forEach(serviceId -> {
|
||||
MutableMap<String, Object> item = Maps.mutable.empty();
|
||||
item.put("service", serviceId);
|
||||
hosts.forEach(host -> item.put(host.replaceAll("\\.", "_"), deployExists.contains(StrUtil.format("{}-{}", serviceId, host)) ? "" : null));
|
||||
data.add(item);
|
||||
});
|
||||
ImmutableList<Map<String, Object>> columns =
|
||||
Lists.immutable.of(MapUtil.<String, Object>builder()
|
||||
.put("name", "service")
|
||||
.put("label", "服务")
|
||||
.put("width", 250)
|
||||
.build())
|
||||
.newWithAll(hosts.collect(host -> {
|
||||
String key = host.replaceAll("\\.", "_");
|
||||
return MapUtil.<String, Object>builder()
|
||||
.put("name", key)
|
||||
.put("label", host)
|
||||
.put("align", "center")
|
||||
.put("classNameExpr", "<%= data['" + key + "'] === '' ? 'bg-success' : '' %>")
|
||||
.put("type", "tpl")
|
||||
.put("tpl", "${" + key + "}")
|
||||
.build();
|
||||
}));
|
||||
return responseData(
|
||||
MapUtil.<String, Object>builder()
|
||||
.put("type", "service")
|
||||
.put("data", MapUtil.builder()
|
||||
.put("rows", data)
|
||||
.build())
|
||||
.put("silentPolling", true)
|
||||
.put("body", MapUtil.builder()
|
||||
.put("type", "table")
|
||||
.put("title", "部署分布")
|
||||
.put("source", "$rows")
|
||||
.put("columns", columns)
|
||||
.build())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,11 @@ function cloudTab() {
|
||||
],
|
||||
},
|
||||
{type: 'divider'},
|
||||
/*{
|
||||
type: 'service',
|
||||
silentPolling: true,
|
||||
schemaApi: 'get:${base}/cloud/deploy_plan',
|
||||
},*/
|
||||
cloudCrud('服务列表', '/cloud/list'),
|
||||
cloudCrud('服务列表 (IP)', '/cloud/list_ip'),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user