|
|
|
@ -2,15 +2,11 @@ package cn.hippo4j.console.controller;
|
|
|
|
|
|
|
|
|
|
import cn.hippo4j.common.constant.Constants;
|
|
|
|
|
import cn.hippo4j.common.model.InstanceInfo;
|
|
|
|
|
import cn.hippo4j.common.model.PoolBaseInfo;
|
|
|
|
|
import cn.hippo4j.common.model.PoolParameterInfo;
|
|
|
|
|
import cn.hippo4j.common.model.PoolRunStateInfo;
|
|
|
|
|
import cn.hippo4j.common.model.ThreadDetailStateInfo;
|
|
|
|
|
import cn.hippo4j.common.toolkit.JSONUtil;
|
|
|
|
|
import cn.hippo4j.common.toolkit.StringUtil;
|
|
|
|
|
import cn.hippo4j.common.web.base.Result;
|
|
|
|
|
import cn.hippo4j.common.web.base.Results;
|
|
|
|
|
import cn.hippo4j.common.web.executor.WebThreadPoolService;
|
|
|
|
|
import cn.hippo4j.config.model.CacheItem;
|
|
|
|
|
import cn.hippo4j.config.model.biz.threadpool.ThreadPoolDelReqDTO;
|
|
|
|
|
import cn.hippo4j.config.model.biz.threadpool.ThreadPoolQueryReqDTO;
|
|
|
|
@ -26,7 +22,6 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.text.StrBuilder;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
@ -35,9 +30,9 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.Executor;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static cn.hippo4j.common.constant.Constants.HTTP_EXECUTE_TIMEOUT;
|
|
|
|
|
import static cn.hippo4j.common.toolkit.ContentUtil.getGroupKey;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -67,7 +62,7 @@ public class ThreadPoolController {
|
|
|
|
|
|
|
|
|
|
@PostMapping("/save_or_update")
|
|
|
|
|
public Result saveOrUpdateThreadPoolConfig(@RequestParam(value = "identify", required = false) String identify,
|
|
|
|
|
@Validated @RequestBody ThreadPoolSaveOrUpdateReqDTO reqDTO) {
|
|
|
|
|
@Validated @RequestBody ThreadPoolSaveOrUpdateReqDTO reqDTO) {
|
|
|
|
|
threadPoolService.saveOrUpdateThreadPoolConfig(identify, reqDTO);
|
|
|
|
|
return Results.success();
|
|
|
|
|
}
|
|
|
|
@ -86,50 +81,50 @@ public class ThreadPoolController {
|
|
|
|
|
|
|
|
|
|
@GetMapping("/run/state/{tpId}")
|
|
|
|
|
public Result runState(@PathVariable("tpId") String tpId,
|
|
|
|
|
@RequestParam(value = "clientAddress", required = true) String clientAddress) {
|
|
|
|
|
@RequestParam(value = "clientAddress") String clientAddress) {
|
|
|
|
|
String urlString = StrBuilder.create("http://", clientAddress, "/run/state/", tpId).toString();
|
|
|
|
|
String data = HttpUtil.get(urlString);
|
|
|
|
|
String data = HttpUtil.get(urlString, HTTP_EXECUTE_TIMEOUT);
|
|
|
|
|
Result result = JSONUtil.parseObject(data, Result.class);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/run/thread/state/{tpId}")
|
|
|
|
|
public Result runThreadState(@PathVariable("tpId") String tpId,
|
|
|
|
|
@RequestParam(value = "clientAddress", required = true) String clientAddress) {
|
|
|
|
|
@RequestParam(value = "clientAddress") String clientAddress) {
|
|
|
|
|
String urlString = StrBuilder.create("http://", clientAddress, "/run/thread/state/", tpId).toString();
|
|
|
|
|
String data = HttpUtil.get(urlString);
|
|
|
|
|
String data = HttpUtil.get(urlString, HTTP_EXECUTE_TIMEOUT);
|
|
|
|
|
Result result = JSONUtil.parseObject(data, Result.class);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/web/base/info")
|
|
|
|
|
public Result getPoolBaseState(@RequestParam(value = "clientAddress", required = true) String clientAddress) {
|
|
|
|
|
public Result getPoolBaseState(@RequestParam(value = "clientAddress") String clientAddress) {
|
|
|
|
|
String urlString = StrBuilder.create("http://", clientAddress, "/web/base/info").toString();
|
|
|
|
|
String data = HttpUtil.get(urlString);
|
|
|
|
|
String data = HttpUtil.get(urlString, HTTP_EXECUTE_TIMEOUT);
|
|
|
|
|
Result result = JSONUtil.parseObject(data, Result.class);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/web/run/state")
|
|
|
|
|
public Result getPoolRunState(@RequestParam(value = "clientAddress", required = true) String clientAddress) {
|
|
|
|
|
public Result getPoolRunState(@RequestParam(value = "clientAddress") String clientAddress) {
|
|
|
|
|
String urlString = StrBuilder.create("http://", clientAddress, "/web/run/state").toString();
|
|
|
|
|
String data = HttpUtil.get(urlString);
|
|
|
|
|
String data = HttpUtil.get(urlString, HTTP_EXECUTE_TIMEOUT);
|
|
|
|
|
Result result = JSONUtil.parseObject(data, Result.class);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/web/update/pool")
|
|
|
|
|
public Result<Void> updateWebThreadPool(@RequestParam(value = "clientAddress", required = true) String clientAddress,
|
|
|
|
|
@RequestBody PoolParameterInfo poolParameterInfo) {
|
|
|
|
|
public Result<Void> updateWebThreadPool(@RequestParam(value = "clientAddress") String clientAddress,
|
|
|
|
|
@RequestBody PoolParameterInfo poolParameterInfo) {
|
|
|
|
|
String urlString = StrBuilder.create("http://", clientAddress, "/web/update/pool").toString();
|
|
|
|
|
String data = HttpUtil.post(urlString, JSONUtil.toJSONString(poolParameterInfo));
|
|
|
|
|
String data = HttpUtil.post(urlString, JSONUtil.toJSONString(poolParameterInfo), HTTP_EXECUTE_TIMEOUT);
|
|
|
|
|
Result result = JSONUtil.parseObject(data, Result.class);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/list/instance/{itemId}/{tpId}")
|
|
|
|
|
public Result<List<ThreadPoolInstanceInfo>> listInstance(@PathVariable("itemId") String itemId,
|
|
|
|
|
@PathVariable("tpId") String tpId) {
|
|
|
|
|
@PathVariable("tpId") String tpId) {
|
|
|
|
|
List<Lease<InstanceInfo>> leases = baseInstanceRegistry.listInstance(itemId);
|
|
|
|
|
Lease<InstanceInfo> first = CollUtil.getFirst(leases);
|
|
|
|
|
if (first == null) {
|
|
|
|
@ -141,8 +136,8 @@ public class ThreadPoolController {
|
|
|
|
|
String groupKey = getGroupKey(tpId, itemTenantKey);
|
|
|
|
|
Map<String, CacheItem> content = ConfigCacheService.getContent(groupKey);
|
|
|
|
|
Map<String, String> activeMap =
|
|
|
|
|
leases.stream().map(each -> each.getHolder()).filter(each -> StringUtil.isNotBlank(each.getActive()))
|
|
|
|
|
.collect(Collectors.toMap(InstanceInfo::getIdentify, InstanceInfo::getActive));
|
|
|
|
|
leases.stream().map(each -> each.getHolder()).filter(each -> StringUtil.isNotBlank(each.getActive()))
|
|
|
|
|
.collect(Collectors.toMap(InstanceInfo::getIdentify, InstanceInfo::getActive));
|
|
|
|
|
|
|
|
|
|
Map<String, String> clientBasePathMap = leases.stream().map(each -> each.getHolder())
|
|
|
|
|
.filter(each -> StringUtil.isNotBlank(each.getClientBasePath()))
|
|
|
|
@ -151,7 +146,7 @@ public class ThreadPoolController {
|
|
|
|
|
List<ThreadPoolInstanceInfo> returnThreadPool = Lists.newArrayList();
|
|
|
|
|
content.forEach((key, val) -> {
|
|
|
|
|
ThreadPoolInstanceInfo threadPoolInstanceInfo =
|
|
|
|
|
BeanUtil.convert(val.configAllInfo, ThreadPoolInstanceInfo.class);
|
|
|
|
|
BeanUtil.convert(val.configAllInfo, ThreadPoolInstanceInfo.class);
|
|
|
|
|
threadPoolInstanceInfo.setClientAddress(StrUtil.subBefore(key, Constants.IDENTIFY_SLICER_SYMBOL, false));
|
|
|
|
|
threadPoolInstanceInfo.setActive(activeMap.get(key));
|
|
|
|
|
threadPoolInstanceInfo.setIdentify(key);
|
|
|
|
|