feature(web): 优化 cloud 服务相关信息获取
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.lanyuanxiaoyao.service.web;
|
package com.lanyuanxiaoyao.service.web;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
@@ -8,7 +9,9 @@ import org.springframework.boot.SpringApplication;
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
|
import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
|
||||||
import org.springframework.cache.annotation.EnableCaching;
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.netflix.eureka.EurekaServiceInstance;
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.lanyuanxiaoyao.service.web.controller;
|
package com.lanyuanxiaoyao.service.web.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
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 com.netflix.appinfo.InstanceInfo;
|
||||||
import org.eclipse.collections.api.block.function.Function;
|
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;
|
||||||
@@ -9,6 +11,7 @@ import org.eclipse.collections.api.list.ImmutableList;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||||
|
import org.springframework.cloud.netflix.eureka.EurekaServiceInstance;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@@ -33,7 +36,8 @@ public class CloudController extends BaseController {
|
|||||||
private ImmutableList<CloudServiceVO> serviceVOS(Function<CloudServiceVO.Service, String> groupByField) {
|
private ImmutableList<CloudServiceVO> serviceVOS(Function<CloudServiceVO.Service, String> groupByField) {
|
||||||
return Lists.immutable.ofAll(client.getServices())
|
return Lists.immutable.ofAll(client.getServices())
|
||||||
.flatCollect(client::getInstances)
|
.flatCollect(client::getInstances)
|
||||||
.collect(instance -> new CloudServiceVO.Service(
|
.collect(instance -> {
|
||||||
|
CloudServiceVO.Service service = new CloudServiceVO.Service(
|
||||||
instance.getInstanceId(),
|
instance.getInstanceId(),
|
||||||
instance.getServiceId(),
|
instance.getServiceId(),
|
||||||
instance.getHost(),
|
instance.getHost(),
|
||||||
@@ -41,7 +45,23 @@ 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())
|
||||||
))
|
);
|
||||||
|
if (instance instanceof EurekaServiceInstance) {
|
||||||
|
EurekaServiceInstance eurekaServiceInstance = (EurekaServiceInstance) instance;
|
||||||
|
InstanceInfo info = eurekaServiceInstance.getInstanceInfo();
|
||||||
|
service.setActionType(info.getActionType().name());
|
||||||
|
service.setStatus(info.getStatus().name());
|
||||||
|
service.setUpdateTime(info.getLastUpdatedTimestamp());
|
||||||
|
if (ObjectUtil.isNotNull(info.getLeaseInfo())) {
|
||||||
|
service.setDuration(info.getLeaseInfo().getDurationInSecs());
|
||||||
|
service.setRegistrationTime(info.getLeaseInfo().getRegistrationTimestamp());
|
||||||
|
service.setLastRenewalTime(info.getLeaseInfo().getRenewalTimestamp());
|
||||||
|
service.setEvictionTime(info.getLeaseInfo().getEvictionTimestamp());
|
||||||
|
service.setServiceUpTime(info.getLeaseInfo().getServiceUpTimestamp());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return service;
|
||||||
|
})
|
||||||
.groupBy(groupByField)
|
.groupBy(groupByField)
|
||||||
.toMap()
|
.toMap()
|
||||||
.collectValues((serviceId, services) -> new CloudServiceVO(serviceId, services.toList().toImmutable()))
|
.collectValues((serviceId, services) -> new CloudServiceVO(serviceId, services.toList().toImmutable()))
|
||||||
|
|||||||
@@ -44,6 +44,15 @@ public class CloudServiceVO {
|
|||||||
private final String url;
|
private final String url;
|
||||||
private final ImmutableMap<String, String> metadata;
|
private final ImmutableMap<String, String> metadata;
|
||||||
|
|
||||||
|
private String actionType;
|
||||||
|
private String status;
|
||||||
|
private Long updateTime;
|
||||||
|
private Integer duration;
|
||||||
|
private Long registrationTime;
|
||||||
|
private Long lastRenewalTime;
|
||||||
|
private Long evictionTime;
|
||||||
|
private Long serviceUpTime;
|
||||||
|
|
||||||
public Service(String instanceId, String serviceId, String host, Integer port, Boolean secure, String url, ImmutableMap<String, String> metadata) {
|
public Service(String instanceId, String serviceId, String host, Integer port, Boolean secure, String url, ImmutableMap<String, String> metadata) {
|
||||||
this.instanceId = instanceId;
|
this.instanceId = instanceId;
|
||||||
this.serviceId = serviceId;
|
this.serviceId = serviceId;
|
||||||
@@ -82,6 +91,70 @@ public class CloudServiceVO {
|
|||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getActionType() {
|
||||||
|
return actionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActionType(String actionType) {
|
||||||
|
this.actionType = actionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getUpdateTime() {
|
||||||
|
return updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdateTime(Long updateTime) {
|
||||||
|
this.updateTime = updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDuration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDuration(Integer duration) {
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getRegistrationTime() {
|
||||||
|
return registrationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRegistrationTime(Long registrationTime) {
|
||||||
|
this.registrationTime = registrationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getLastRenewalTime() {
|
||||||
|
return lastRenewalTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastRenewalTime(Long lastRenewalTime) {
|
||||||
|
this.lastRenewalTime = lastRenewalTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getEvictionTime() {
|
||||||
|
return evictionTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEvictionTime(Long evictionTime) {
|
||||||
|
this.evictionTime = evictionTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getServiceUpTime() {
|
||||||
|
return serviceUpTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServiceUpTime(Long serviceUpTime) {
|
||||||
|
this.serviceUpTime = serviceUpTime;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Service{" +
|
return "Service{" +
|
||||||
@@ -92,6 +165,9 @@ public class CloudServiceVO {
|
|||||||
", secure=" + secure +
|
", secure=" + secure +
|
||||||
", url='" + url + '\'' +
|
", url='" + url + '\'' +
|
||||||
", metadata=" + metadata +
|
", metadata=" + metadata +
|
||||||
|
", actionType='" + actionType + '\'' +
|
||||||
|
", status='" + status + '\'' +
|
||||||
|
", updateTime='" + updateTime + '\'' +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
function time(field) {
|
||||||
|
return {
|
||||||
|
type: 'tpl',
|
||||||
|
tpl: `\${${field}|date:YYYY-MM-DD HH\\:mm\\:ss:x}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function cloudCrud(title, path) {
|
function cloudCrud(title, path) {
|
||||||
return {
|
return {
|
||||||
type: 'crud',
|
type: 'crud',
|
||||||
@@ -13,11 +20,41 @@ function cloudCrud(title, path) {
|
|||||||
columns: [
|
columns: [
|
||||||
{name: 'name', label: '名称'},
|
{name: 'name', label: '名称'},
|
||||||
{
|
{
|
||||||
name: 'serviceId',
|
name: 'status',
|
||||||
label: '服务',
|
label: '状态',
|
||||||
width: 200,
|
align: 'center',
|
||||||
|
width: 60,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'serviceUpTime',
|
||||||
|
label: '启动时间',
|
||||||
|
...time('serviceUpTime'),
|
||||||
|
align: 'center',
|
||||||
|
width: 140,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'registrationTime',
|
||||||
|
label: '注册时间',
|
||||||
|
...time('registrationTime'),
|
||||||
|
align: 'center',
|
||||||
|
width: 140,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'lastRenewalTime',
|
||||||
|
label: '上次更新时间',
|
||||||
|
...time('lastRenewalTime'),
|
||||||
|
align: 'center',
|
||||||
|
width: 140,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'evictionTime',
|
||||||
|
label: '驱逐时间',
|
||||||
|
...time('evictionTime'),
|
||||||
|
align: 'center',
|
||||||
|
width: 140,
|
||||||
},
|
},
|
||||||
{name: 'url', label: '地址', width: 200},
|
{name: 'url', label: '地址', width: 200},
|
||||||
|
{name: 'serviceId', label: '服务', width: 180, fixed: 'right'},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user