feature: 服务端提供获取 ThreadPool 集群环境具体实例功能.

pull/161/head
chen.ma 3 years ago
parent d11f1c86f1
commit 3db93a2fcc

@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@Getter @Getter
@Setter @Setter
@Accessors(chain = true)
public class InstanceInfo { public class InstanceInfo {
private static final String UNKNOWN = "unknown"; private static final String UNKNOWN = "unknown";
@ -23,10 +24,16 @@ public class InstanceInfo {
private String hostName; private String hostName;
private String port;
private String instanceId; private String instanceId;
private String ipApplicationName; private String ipApplicationName;
private String clientBasePath;
private String callBackUrl;
private volatile String vipAddress; private volatile String vipAddress;
private volatile String secureVipAddress; private volatile String secureVipAddress;

@ -20,6 +20,11 @@
<groupId>com.github.dynamic-threadpool</groupId> <groupId>com.github.dynamic-threadpool</groupId>
<artifactId>config</artifactId> <artifactId>config</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.github.dynamic-threadpool</groupId>
<artifactId>discovery</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -2,17 +2,19 @@ package com.github.dynamic.threadpool.console.controller;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.dynamic.threadpool.common.constant.Constants; import com.github.dynamic.threadpool.common.constant.Constants;
import com.github.dynamic.threadpool.common.model.InstanceInfo;
import com.github.dynamic.threadpool.common.web.base.Result; import com.github.dynamic.threadpool.common.web.base.Result;
import com.github.dynamic.threadpool.common.web.base.Results; import com.github.dynamic.threadpool.common.web.base.Results;
import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolQueryReqDTO; import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolQueryReqDTO;
import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolRespDTO; import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolRespDTO;
import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolSaveOrUpdateReqDTO; import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolSaveOrUpdateReqDTO;
import com.github.dynamic.threadpool.config.service.biz.ThreadPoolService; import com.github.dynamic.threadpool.config.service.biz.ThreadPoolService;
import com.github.dynamic.threadpool.discovery.core.BaseInstanceRegistry;
import com.github.dynamic.threadpool.discovery.core.Lease;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import java.util.List;
import org.springframework.web.bind.annotation.RestController;
/** /**
* Thread pool controller. * Thread pool controller.
@ -27,6 +29,8 @@ public class ThreadPoolController {
private final ThreadPoolService threadPoolService; private final ThreadPoolService threadPoolService;
private final BaseInstanceRegistry baseInstanceRegistry;
@PostMapping("/pool/query/page") @PostMapping("/pool/query/page")
public Result<IPage<ThreadPoolRespDTO>> queryNameSpacePage(@RequestBody ThreadPoolQueryReqDTO reqDTO) { public Result<IPage<ThreadPoolRespDTO>> queryNameSpacePage(@RequestBody ThreadPoolQueryReqDTO reqDTO) {
return Results.success(threadPoolService.queryThreadPoolPage(reqDTO)); return Results.success(threadPoolService.queryThreadPoolPage(reqDTO));
@ -43,4 +47,10 @@ public class ThreadPoolController {
return Results.success(); return Results.success();
} }
@GetMapping("/pool/list/instance/{itemId}")
public Result<List<Lease<InstanceInfo>>> listInstance(@PathVariable("itemId") String itemId) {
List<Lease<InstanceInfo>> leases = baseInstanceRegistry.listInstance(itemId);
return Results.success(leases);
}
} }

@ -28,10 +28,15 @@ public class DiscoveryConfig {
@SneakyThrows @SneakyThrows
public InstanceInfo instanceConfig() { public InstanceInfo instanceConfig() {
InstanceInfo instanceInfo = new InstanceInfo(); InstanceInfo instanceInfo = new InstanceInfo();
instanceInfo.setInstanceId(getDefaultInstanceId(environment)); instanceInfo.setInstanceId(getDefaultInstanceId(environment))
instanceInfo.setIpApplicationName(getIpApplicationName(environment)); .setIpApplicationName(getIpApplicationName(environment))
instanceInfo.setAppName(environment.getProperty("spring.application.name")); .setHostName(InetAddress.getLocalHost().getHostAddress())
instanceInfo.setHostName(InetAddress.getLocalHost().getHostAddress()); .setAppName(environment.getProperty("spring.application.name"))
.setClientBasePath(environment.getProperty("server.servlet.context-path"));
String callBackUrl = new StringBuilder().append(instanceInfo.getHostName()).append(":")
.append(environment.getProperty("server.port")).append(instanceInfo.getClientBasePath())
.toString();
instanceInfo.setCallBackUrl(callBackUrl);
return instanceInfo; return instanceInfo;
} }

Loading…
Cancel
Save