From 3db93a2fcc1ea7d9f93990002e5051c62fb023c6 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Mon, 25 Oct 2021 00:39:02 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E6=9C=8D=E5=8A=A1=E7=AB=AF=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E8=8E=B7=E5=8F=96=20ThreadPool=20=E9=9B=86=E7=BE=A4?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=85=B7=E4=BD=93=E5=AE=9E=E4=BE=8B=E5=8A=9F?= =?UTF-8?q?=E8=83=BD.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../threadpool/common/model/InstanceInfo.java | 7 +++++++ console/pom.xml | 5 +++++ .../controller/ThreadPoolController.java | 18 ++++++++++++++---- .../starter/config/DiscoveryConfig.java | 13 +++++++++---- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/com/github/dynamic/threadpool/common/model/InstanceInfo.java b/common/src/main/java/com/github/dynamic/threadpool/common/model/InstanceInfo.java index 714e51bd..88cb054d 100644 --- a/common/src/main/java/com/github/dynamic/threadpool/common/model/InstanceInfo.java +++ b/common/src/main/java/com/github/dynamic/threadpool/common/model/InstanceInfo.java @@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j @Getter @Setter +@Accessors(chain = true) public class InstanceInfo { private static final String UNKNOWN = "unknown"; @@ -23,10 +24,16 @@ public class InstanceInfo { private String hostName; + private String port; + private String instanceId; private String ipApplicationName; + private String clientBasePath; + + private String callBackUrl; + private volatile String vipAddress; private volatile String secureVipAddress; diff --git a/console/pom.xml b/console/pom.xml index f66de5ce..c7b98a8f 100644 --- a/console/pom.xml +++ b/console/pom.xml @@ -20,6 +20,11 @@ com.github.dynamic-threadpool config + + + com.github.dynamic-threadpool + discovery + diff --git a/console/src/main/java/com/github/dynamic/threadpool/console/controller/ThreadPoolController.java b/console/src/main/java/com/github/dynamic/threadpool/console/controller/ThreadPoolController.java index 004d6209..d25dabd9 100644 --- a/console/src/main/java/com/github/dynamic/threadpool/console/controller/ThreadPoolController.java +++ b/console/src/main/java/com/github/dynamic/threadpool/console/controller/ThreadPoolController.java @@ -2,17 +2,19 @@ package com.github.dynamic.threadpool.console.controller; import com.baomidou.mybatisplus.core.metadata.IPage; 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.Results; 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.ThreadPoolSaveOrUpdateReqDTO; 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 org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; /** * Thread pool controller. @@ -27,6 +29,8 @@ public class ThreadPoolController { private final ThreadPoolService threadPoolService; + private final BaseInstanceRegistry baseInstanceRegistry; + @PostMapping("/pool/query/page") public Result> queryNameSpacePage(@RequestBody ThreadPoolQueryReqDTO reqDTO) { return Results.success(threadPoolService.queryThreadPoolPage(reqDTO)); @@ -43,4 +47,10 @@ public class ThreadPoolController { return Results.success(); } + @GetMapping("/pool/list/instance/{itemId}") + public Result>> listInstance(@PathVariable("itemId") String itemId) { + List> leases = baseInstanceRegistry.listInstance(itemId); + return Results.success(leases); + } + } diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/com/github/dynamic/threadpool/starter/config/DiscoveryConfig.java b/dynamic-threadpool-spring-boot-starter/src/main/java/com/github/dynamic/threadpool/starter/config/DiscoveryConfig.java index 99c479bf..4e2f6950 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/com/github/dynamic/threadpool/starter/config/DiscoveryConfig.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/com/github/dynamic/threadpool/starter/config/DiscoveryConfig.java @@ -28,10 +28,15 @@ public class DiscoveryConfig { @SneakyThrows public InstanceInfo instanceConfig() { InstanceInfo instanceInfo = new InstanceInfo(); - instanceInfo.setInstanceId(getDefaultInstanceId(environment)); - instanceInfo.setIpApplicationName(getIpApplicationName(environment)); - instanceInfo.setAppName(environment.getProperty("spring.application.name")); - instanceInfo.setHostName(InetAddress.getLocalHost().getHostAddress()); + instanceInfo.setInstanceId(getDefaultInstanceId(environment)) + .setIpApplicationName(getIpApplicationName(environment)) + .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; }