Merge remote-tracking branch 'upstream/develop' into config_change_verify

# Conflicts:
#	hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolAdapterController.java
#	hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolController.java
pull/780/head
yewei 3 years ago
commit f5755984ee

@ -101,17 +101,17 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池
</a> </a>
</td> </td>
<td align="center"> <td align="center">
<a href="https://github.com/BigXin0109"> <a href="https://github.com/shanjianq">
<img src="https://avatars.githubusercontent.com/u/24769514?v=4" width="50;" alt="BigXin0109"/> <img src="https://avatars.githubusercontent.com/u/49084314?v=4" width="50;" alt="shanjianq"/>
<br /> <br />
<sub><b>BigXin0109</b></sub> <sub><b>Shanjianq</b></sub>
</a> </a>
</td> </td>
<td align="center"> <td align="center">
<a href="https://github.com/shanjianq"> <a href="https://github.com/BigXin0109">
<img src="https://avatars.githubusercontent.com/u/49084314?v=4" width="50;" alt="shanjianq"/> <img src="https://avatars.githubusercontent.com/u/24769514?v=4" width="50;" alt="BigXin0109"/>
<br /> <br />
<sub><b>Shanjianq</b></sub> <sub><b>BigXin0109</b></sub>
</a> </a>
</td> </td>
<td align="center"> <td align="center">
@ -157,6 +157,13 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池
<sub><b>Lijx</b></sub> <sub><b>Lijx</b></sub>
</a> </a>
</td> </td>
<td align="center">
<a href="https://github.com/baymax55">
<img src="https://avatars.githubusercontent.com/u/35788491?v=4" width="50;" alt="baymax55"/>
<br />
<sub><b>Baymax55</b></sub>
</a>
</td>
<td align="center"> <td align="center">
<a href="https://github.com/liulinfei121"> <a href="https://github.com/liulinfei121">
<img src="https://avatars.githubusercontent.com/u/57127515?v=4" width="50;" alt="liulinfei121"/> <img src="https://avatars.githubusercontent.com/u/57127515?v=4" width="50;" alt="liulinfei121"/>
@ -184,15 +191,15 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池
<br /> <br />
<sub><b>杨镇涛</b></sub> <sub><b>杨镇涛</b></sub>
</a> </a>
</td> </td></tr>
<tr>
<td align="center"> <td align="center">
<a href="https://github.com/Tliutao"> <a href="https://github.com/Tliutao">
<img src="https://avatars.githubusercontent.com/u/17719583?v=4" width="50;" alt="Tliutao"/> <img src="https://avatars.githubusercontent.com/u/17719583?v=4" width="50;" alt="Tliutao"/>
<br /> <br />
<sub><b>Liutao</b></sub> <sub><b>Liutao</b></sub>
</a> </a>
</td></tr> </td>
<tr>
<td align="center"> <td align="center">
<a href="https://github.com/monsterxxp"> <a href="https://github.com/monsterxxp">
<img src="https://avatars.githubusercontent.com/u/37952446?v=4" width="50;" alt="monsterxxp"/> <img src="https://avatars.githubusercontent.com/u/37952446?v=4" width="50;" alt="monsterxxp"/>
@ -242,13 +249,6 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池
<sub><b>Serenity</b></sub> <sub><b>Serenity</b></sub>
</a> </a>
</td> </td>
<td align="center">
<a href="https://github.com/baymax55">
<img src="https://avatars.githubusercontent.com/u/35788491?v=4" width="50;" alt="baymax55"/>
<br />
<sub><b>Baymax55</b></sub>
</a>
</td>
<td align="center"> <td align="center">
<a href="https://github.com/gewuwo"> <a href="https://github.com/gewuwo">
<img src="https://avatars.githubusercontent.com/u/97213587?v=4" width="50;" alt="gewuwo"/> <img src="https://avatars.githubusercontent.com/u/97213587?v=4" width="50;" alt="gewuwo"/>

@ -13,9 +13,9 @@ sidebar_position: 2
<td align="center" width="26%">联系方式</td> <td align="center" width="26%">联系方式</td>
</tr> </tr>
<tr> <tr>
<td align="center" ><a href="https://github.com/agentart"><img src="https://avatars.githubusercontent.com/u/77398366?v=4?s=64" width="64px;"/></a></td> <td align="center" ><a href="https://github.com/itmachen"><img src="https://avatars.githubusercontent.com/u/77398366?v=4?s=64" width="64px;"/></a></td>
<td align="center" >马称</td> <td align="center" >马称</td>
<td align="center" ><a href="https://github.com/agentart">agentart</a></td> <td align="center" ><a href="https://github.com/itmachen">itmachen</a></td>
<td align="center" ><a href="http://www.xiaomage.info/">小马哥的技术专栏</a></td> <td align="center" ><a href="http://www.xiaomage.info/">小马哥的技术专栏</a></td>
<td align="center" >machen@apache.org</td> <td align="center" >machen@apache.org</td>
</tr> </tr>
@ -54,4 +54,11 @@ sidebar_position: 2
<td align="center" ><a href="https://www.yuque.com/chenghu-08dla/pizig1">pizihao</a></td> <td align="center" ><a href="https://www.yuque.com/chenghu-08dla/pizig1">pizihao</a></td>
<td align="center" >hao3073liu@163.com</td> <td align="center" >hao3073liu@163.com</td>
</tr> </tr>
<tr>
<td align="center"><a href="https://github.com/pizihao"><img src="https://avatars.githubusercontent.com/u/49084314?v=4?s=64" width="64px;"/></a></td>
<td align="center">叶炜</td>
<td align="center" ><a href="https://github.com/shanjianq">shanjianq</a></td>
<td align="center" >-</td>
<td align="center" >17855368071@163.com</td>
</tr>
</table> </table>

@ -223,6 +223,56 @@ public class StringUtil {
return sb.toString(); return sb.toString();
} }
/**
* combination CharSequence, get a String
*
* @param charSequences CharSequence, if null or empty, get {@link StringUtil#EMPTY}
* @return String
*/
public static String newBuilder(CharSequence... charSequences) {
if (charSequences == null || charSequences.length == 0) {
return StringUtil.EMPTY;
}
return createBuilder(charSequences).toString();
}
/**
* combination CharSequence, get a StringBuilder
*
* @param charSequences CharSequence
* @return StringBuilder
*/
public static StringBuilder createBuilder(CharSequence... charSequences) {
StringBuilder builder = new StringBuilder();
if (charSequences == null || charSequences.length == 0) {
return builder;
}
for (CharSequence sequence : charSequences) {
builder.append(sequence);
}
return builder;
}
/**
* combination CharSequence, to StringBuilder
*
* @param builder StringBuilder, if null create a new
* @param charSequences CharSequence
* @return StringBuilder
*/
public static StringBuilder appends(StringBuilder builder, CharSequence... charSequences) {
if (builder == null) {
return createBuilder(charSequences);
}
if (charSequences == null || charSequences.length == 0) {
return builder;
}
for (CharSequence sequence : charSequences) {
builder.append(sequence);
}
return builder;
}
/** /**
* Replace a portion of the string, replacing all found * Replace a portion of the string, replacing all found
* *

@ -18,83 +18,108 @@
package cn.hippo4j.common.toolkit; package cn.hippo4j.common.toolkit;
import org.junit.Test; import org.junit.Test;
import org.junit.Assert;
import java.util.Objects;
public class StringUtilTest { public class StringUtilTest {
@Test @Test
public void assertIsEmpty() { public void assertIsEmpty() {
String string = ""; String string = "";
Assert.isTrue(StringUtil.isEmpty(string)); Assert.assertTrue(StringUtil.isEmpty(string));
} }
@Test @Test
public void assertIsNotEmpty() { public void assertIsNotEmpty() {
String string = "string"; String string = "string";
Assert.isTrue(StringUtil.isNotEmpty(string)); Assert.assertTrue(StringUtil.isNotEmpty(string));
} }
@Test @Test
public void emptyToNull() { public void emptyToNull() {
String string = ""; String string = "";
Assert.isNull(StringUtil.emptyToNull(string)); Assert.assertNull(StringUtil.emptyToNull(string));
} }
@Test @Test
public void nullToEmpty() { public void nullToEmpty() {
String string = "null"; String string = "null";
Assert.notEmpty(StringUtil.nullToEmpty(string)); Assert.assertEquals("null", StringUtil.nullToEmpty(string));
} }
@Test @Test
public void isNullOrEmpty() { public void isNullOrEmpty() {
String string = "null"; String string = "null";
Assert.isTrue(!StringUtil.isNullOrEmpty(string)); Assert.assertFalse(StringUtil.isNullOrEmpty(string));
} }
@Test @Test
public void isBlank() { public void isBlank() {
String string = ""; String string = "";
Assert.isTrue(StringUtil.isBlank(string)); Assert.assertTrue(StringUtil.isBlank(string));
} }
@Test @Test
public void isNotBlank() { public void isNotBlank() {
String string = "null"; String string = "null";
Assert.isTrue(StringUtil.isNotBlank(string)); Assert.assertTrue(StringUtil.isNotBlank(string));
} }
@Test @Test
public void isAllNotEmpty() { public void isAllNotEmpty() {
String strings = "str"; String strings = "str";
Assert.isTrue(StringUtil.isAllNotEmpty(strings)); Assert.assertTrue(StringUtil.isAllNotEmpty(strings));
} }
@Test @Test
public void hasEmpty() { public void hasEmpty() {
String strings = ""; String strings = "";
Assert.isTrue(StringUtil.hasEmpty(strings)); Assert.assertTrue(StringUtil.hasEmpty(strings));
} }
@Test @Test
public void toUnderlineCase() { public void toUnderlineCase() {
String string = "str"; String string = "str";
String s = StringUtil.toUnderlineCase(string); String s = StringUtil.toUnderlineCase(string);
Assert.isTrue(Objects.equals(s, "str")); Assert.assertEquals("str", s);
} }
@Test @Test
public void toSymbolCase() { public void toSymbolCase() {
String string = "str"; String string = "str";
String s = StringUtil.toSymbolCase(string, StringUtil.UNDERLINE); String s = StringUtil.toSymbolCase(string, StringUtil.UNDERLINE);
Assert.isTrue(Objects.equals(s, "str")); Assert.assertEquals("str", s);
} }
@Test @Test
public void toCamelCase() { public void toCamelCase() {
String string = "str_str"; String string = "str_str";
String s = StringUtil.toCamelCase(string, StringUtil.UNDERLINE); String s = StringUtil.toCamelCase(string, StringUtil.UNDERLINE);
Assert.isTrue(Objects.equals(s, "strStr")); Assert.assertEquals("strStr", s);
}
@Test
public void newBuilder() {
String s1 = StringUtil.newBuilder(null);
Assert.assertEquals("", s1);
String s2 = StringUtil.newBuilder("H", "ippo", "4j");
Assert.assertEquals("Hippo4j", s2);
}
@Test
public void createBuilder() {
StringBuilder s1 = StringUtil.createBuilder(null);
Assert.assertEquals("", s1.toString());
StringBuilder s2 = StringUtil.createBuilder("H", "ippo", "4j");
Assert.assertEquals("Hippo4j", s2.toString());
}
@Test
public void appends() {
StringBuilder sb1 = StringUtil.appends(null, "H", "ippo", "4j");
Assert.assertEquals("Hippo4j", sb1.toString());
StringBuilder sb2 = StringUtil.appends(StringUtil.createBuilder("To "), null);
Assert.assertEquals("To ", sb2.toString());
StringBuilder sb3 = StringUtil.appends(StringUtil.createBuilder("To "), "H", "ippo", "4j");
Assert.assertEquals("To Hippo4j", sb3.toString());
} }
} }

@ -30,7 +30,6 @@ import cn.hippo4j.config.model.biz.adapter.ThreadPoolAdapterReqDTO;
import cn.hippo4j.config.model.biz.adapter.ThreadPoolAdapterRespDTO; import cn.hippo4j.config.model.biz.adapter.ThreadPoolAdapterRespDTO;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@ -38,7 +37,6 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cn.hippo4j.common.constant.Constants.HTTP_EXECUTE_TIMEOUT;
import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL; import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL;
/** /**
@ -49,7 +47,7 @@ import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL;
public class ThreadPoolAdapterService { public class ThreadPoolAdapterService {
/** /**
* Map<mark, Map<tenantItem, Map<threadPoolKey, List<ThreadPoolAdapterState>>>> * Map&lt;mark, Map&lt;tenantItem, Map&lt;threadPoolKey, List&lt;ThreadPoolAdapterState&gt;&gt;&gt;&gt;
*/ */
private static final Map<String, Map<String, Map<String, List<ThreadPoolAdapterState>>>> THREAD_POOL_ADAPTER_MAP = new ConcurrentHashMap<>(); private static final Map<String, Map<String, Map<String, List<ThreadPoolAdapterState>>>> THREAD_POOL_ADAPTER_MAP = new ConcurrentHashMap<>();
@ -98,18 +96,23 @@ public class ThreadPoolAdapterService {
List<String> addressList = actual.stream().map(ThreadPoolAdapterState::getClientAddress).collect(Collectors.toList()); List<String> addressList = actual.stream().map(ThreadPoolAdapterState::getClientAddress).collect(Collectors.toList());
List<ThreadPoolAdapterRespDTO> result = new ArrayList<>(addressList.size()); List<ThreadPoolAdapterRespDTO> result = new ArrayList<>(addressList.size());
addressList.forEach(each -> { addressList.forEach(each -> {
String urlString = new StringBuilder() StringBuilder builder = StringUtil.createBuilder("http://", each, "/adapter/thread-pool/info");
.append("http://")
.append(each)
.append("/adapter/thread-pool/info")
.toString();
Map<String, Object> param = new HashMap<>(); Map<String, Object> param = new HashMap<>();
param.put("mark", requestParameter.getMark()); param.put("mark", requestParameter.getMark());
param.put("threadPoolKey", requestParameter.getThreadPoolKey()); param.put("threadPoolKey", requestParameter.getThreadPoolKey());
List<String> paramKey = new ArrayList<>(param.keySet());
for (int i = 0; i < paramKey.size(); i++) {
if (i == 0) {
builder.append("?");
} else {
builder.append("&");
}
String s = paramKey.get(i);
builder.append(StringUtil.newBuilder(s, "={", s, "}"));
}
try { try {
RestTemplate template = new RestTemplate(); RestTemplate template = new RestTemplate();
String resultStr = template.getForObject(urlString, String.class, param); String resultStr = template.getForObject(builder.toString(), String.class, param);
if (StringUtil.isNotBlank(resultStr)) { if (StringUtil.isNotBlank(resultStr)) {
Result<ThreadPoolAdapterRespDTO> restResult = JSONUtil.parseObject(resultStr, new TypeReference<Result<ThreadPoolAdapterRespDTO>>() { Result<ThreadPoolAdapterRespDTO> restResult = JSONUtil.parseObject(resultStr, new TypeReference<Result<ThreadPoolAdapterRespDTO>>() {
}); });
@ -131,22 +134,16 @@ public class ThreadPoolAdapterService {
return actual.keySet(); return actual.keySet();
} }
} }
return new HashSet(); return new HashSet<>();
} }
public static void remove(String identify) { public static void remove(String identify) {
synchronized (ThreadPoolAdapterService.class) { synchronized (ThreadPoolAdapterService.class) {
THREAD_POOL_ADAPTER_MAP.values().forEach(each -> each.forEach((key, val) -> { THREAD_POOL_ADAPTER_MAP.values().forEach(each -> each.forEach((key, val) ->
val.forEach((threadPoolKey, states) -> { val.forEach((threadPoolKey, states) ->
Iterator<ThreadPoolAdapterState> iterator = states.iterator(); states.removeIf(adapterState -> Objects.equals(adapterState.getIdentify(), identify))
while (iterator.hasNext()) { )
ThreadPoolAdapterState adapterState = iterator.next(); ));
if (Objects.equals(adapterState.getIdentify(), identify)) {
iterator.remove();
}
}
});
}));
} }
} }

@ -21,6 +21,7 @@ import cn.hippo4j.common.constant.ConfigModifyTypeConstants;
import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.common.toolkit.BeanUtil;
import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.toolkit.UserContext; import cn.hippo4j.common.toolkit.UserContext;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.common.web.base.Result; import cn.hippo4j.common.web.base.Result;
import cn.hippo4j.common.web.base.Results; import cn.hippo4j.common.web.base.Results;
import cn.hippo4j.config.model.biz.adapter.ThreadPoolAdapterReqDTO; import cn.hippo4j.config.model.biz.adapter.ThreadPoolAdapterReqDTO;
@ -29,15 +30,20 @@ import cn.hippo4j.config.model.biz.threadpool.ConfigModifySaveReqDTO;
import cn.hippo4j.config.service.ThreadPoolAdapterService; import cn.hippo4j.config.service.ThreadPoolAdapterService;
import cn.hippo4j.config.verify.ConfigModificationVerifyServiceChoose; import cn.hippo4j.config.verify.ConfigModificationVerifyServiceChoose;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import static cn.hippo4j.common.constant.Constants.HTTP_EXECUTE_TIMEOUT;
import static cn.hippo4j.common.constant.Constants.REGISTER_ADAPTER_BASE_PATH; import static cn.hippo4j.common.constant.Constants.REGISTER_ADAPTER_BASE_PATH;
/** /**
@ -51,8 +57,6 @@ public class ThreadPoolAdapterController {
private final ConfigModificationVerifyServiceChoose configModificationVerifyServiceChoose; private final ConfigModificationVerifyServiceChoose configModificationVerifyServiceChoose;
private final RestTemplate restTemplate = new RestTemplate();
@GetMapping(REGISTER_ADAPTER_BASE_PATH + "/query") @GetMapping(REGISTER_ADAPTER_BASE_PATH + "/query")
public Result<List<ThreadPoolAdapterRespDTO>> queryAdapterThreadPool(ThreadPoolAdapterReqDTO requestParameter) { public Result<List<ThreadPoolAdapterRespDTO>> queryAdapterThreadPool(ThreadPoolAdapterReqDTO requestParameter) {
List<ThreadPoolAdapterRespDTO> result = threadPoolAdapterService.query(requestParameter); List<ThreadPoolAdapterRespDTO> result = threadPoolAdapterService.query(requestParameter);
@ -69,12 +73,13 @@ public class ThreadPoolAdapterController {
public Result<Void> updateAdapterThreadPool(@RequestBody ThreadPoolAdapterReqDTO requestParameter) { public Result<Void> updateAdapterThreadPool(@RequestBody ThreadPoolAdapterReqDTO requestParameter) {
if (UserContext.getUserRole().equals("ROLE_ADMIN")) { if (UserContext.getUserRole().equals("ROLE_ADMIN")) {
for (String each : requestParameter.getClientAddressList()) { for (String each : requestParameter.getClientAddressList()) {
String urlString = new StringBuilder() String urlString = StringUtil.newBuilder("http://", each, "/adapter/thread-pool/update");
.append("http://") RestTemplate restTemplate = new RestTemplate();
.append(each) // again appoint MediaType
.append("/adapter/thread-pool/update") HttpHeaders requestHeaders = new HttpHeaders();
.toString(); requestHeaders.setContentType(MediaType.APPLICATION_JSON);
restTemplate.postForObject(urlString, JSONUtil.toJSONString(requestParameter), Object.class); HttpEntity<String> requestEntity = new HttpEntity<>(JSONUtil.toJSONString(requestParameter), requestHeaders);
restTemplate.postForObject(urlString, requestEntity, Object.class);
} }
} else { } else {
ConfigModifySaveReqDTO modifySaveReqDTO = BeanUtil.convert(requestParameter, ConfigModifySaveReqDTO.class); ConfigModifySaveReqDTO modifySaveReqDTO = BeanUtil.convert(requestParameter, ConfigModifySaveReqDTO.class);

@ -36,6 +36,9 @@ import cn.hippo4j.discovery.core.BaseInstanceRegistry;
import cn.hippo4j.discovery.core.Lease; import cn.hippo4j.discovery.core.Lease;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@ -62,8 +65,6 @@ public class ThreadPoolController {
private final ConfigModificationVerifyServiceChoose configModificationVerifyServiceChoose; private final ConfigModificationVerifyServiceChoose configModificationVerifyServiceChoose;
private final RestTemplate restTemplate = new RestTemplate();
@PostMapping("/query/page") @PostMapping("/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));
@ -109,12 +110,8 @@ public class ThreadPoolController {
@GetMapping("/run/state/{tpId}") @GetMapping("/run/state/{tpId}")
public Result runState(@PathVariable("tpId") String tpId, public Result runState(@PathVariable("tpId") String tpId,
@RequestParam(value = "clientAddress") String clientAddress) { @RequestParam(value = "clientAddress") String clientAddress) {
String urlString = new StringBuilder() String urlString = StringUtil.newBuilder("http://", clientAddress, "/run/state/", tpId);
.append("http://") RestTemplate restTemplate = new RestTemplate();
.append(clientAddress)
.append("/run/state/")
.append(tpId)
.toString();
String data = restTemplate.getForObject(urlString, String.class, new HashMap<>()); String data = restTemplate.getForObject(urlString, String.class, new HashMap<>());
Result result = JSONUtil.parseObject(data, Result.class); Result result = JSONUtil.parseObject(data, Result.class);
return result; return result;
@ -123,12 +120,8 @@ public class ThreadPoolController {
@GetMapping("/run/thread/state/{tpId}") @GetMapping("/run/thread/state/{tpId}")
public Result runThreadState(@PathVariable("tpId") String tpId, public Result runThreadState(@PathVariable("tpId") String tpId,
@RequestParam(value = "clientAddress") String clientAddress) { @RequestParam(value = "clientAddress") String clientAddress) {
String urlString = new StringBuilder() String urlString = StringUtil.newBuilder("http://", clientAddress, "/run/thread/state/", tpId);
.append("http://") RestTemplate restTemplate = new RestTemplate();
.append(clientAddress)
.append("/run/thread/state/")
.append(tpId)
.toString();
String data = restTemplate.getForObject(urlString, String.class, new HashMap<>()); String data = restTemplate.getForObject(urlString, String.class, new HashMap<>());
Result result = JSONUtil.parseObject(data, Result.class); Result result = JSONUtil.parseObject(data, Result.class);
return result; return result;
@ -166,11 +159,8 @@ public class ThreadPoolController {
@GetMapping("/web/base/info") @GetMapping("/web/base/info")
public Result getPoolBaseState(@RequestParam(value = "clientAddress") String clientAddress) { public Result getPoolBaseState(@RequestParam(value = "clientAddress") String clientAddress) {
String urlString = new StringBuilder() String urlString = StringUtil.newBuilder("http://", clientAddress, "/web/base/info");
.append("http://") RestTemplate restTemplate = new RestTemplate();
.append(clientAddress)
.append("/web/base/info")
.toString();
String data = restTemplate.getForObject(urlString, String.class, new HashMap<>()); String data = restTemplate.getForObject(urlString, String.class, new HashMap<>());
Result result = JSONUtil.parseObject(data, Result.class); Result result = JSONUtil.parseObject(data, Result.class);
return result; return result;
@ -178,11 +168,8 @@ public class ThreadPoolController {
@GetMapping("/web/run/state") @GetMapping("/web/run/state")
public Result getPoolRunState(@RequestParam(value = "clientAddress") String clientAddress) { public Result getPoolRunState(@RequestParam(value = "clientAddress") String clientAddress) {
String urlString = new StringBuilder() String urlString = StringUtil.newBuilder("http://", clientAddress, "/web/run/state");
.append("http://") RestTemplate restTemplate = new RestTemplate();
.append(clientAddress)
.append("/web/run/state")
.toString();
String data = restTemplate.getForObject(urlString, String.class, new HashMap<>()); String data = restTemplate.getForObject(urlString, String.class, new HashMap<>());
Result result = JSONUtil.parseObject(data, Result.class); Result result = JSONUtil.parseObject(data, Result.class);
return result; return result;
@ -192,12 +179,13 @@ public class ThreadPoolController {
public Result<Void> updateWebThreadPool(@RequestBody WebThreadPoolReqDTO requestParam) { public Result<Void> updateWebThreadPool(@RequestBody WebThreadPoolReqDTO requestParam) {
if (UserContext.getUserRole().equals("ROLE_ADMIN")) { if (UserContext.getUserRole().equals("ROLE_ADMIN")) {
for (String each : requestParam.getClientAddressList()) { for (String each : requestParam.getClientAddressList()) {
String urlString = new StringBuilder() String urlString = StringUtil.newBuilder("http://", each, "/web/update/pool");
.append("http://") RestTemplate restTemplate = new RestTemplate();
.append(each) // again appoint MediaType
.append("/web/update/pool") HttpHeaders requestHeaders = new HttpHeaders();
.toString(); requestHeaders.setContentType(MediaType.APPLICATION_JSON);
restTemplate.postForObject(urlString, JSONUtil.toJSONString(requestParam), Object.class); HttpEntity<String> requestEntity = new HttpEntity<>(JSONUtil.toJSONString(requestParam), requestHeaders);
restTemplate.postForObject(urlString, requestEntity, Object.class);
} }
} else { } else {
ConfigModifySaveReqDTO modifySaveReqDTO = BeanUtil.convert(requestParam, ConfigModifySaveReqDTO.class); ConfigModifySaveReqDTO modifySaveReqDTO = BeanUtil.convert(requestParam, ConfigModifySaveReqDTO.class);
@ -238,5 +226,4 @@ public class ThreadPoolController {
}); });
return Results.success(returnThreadPool); return Results.success(returnThreadPool);
} }
} }

@ -26,7 +26,6 @@ import cn.hippo4j.message.platform.base.RobotMessageExecuteDTO;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import static cn.hippo4j.message.platform.constant.WeChatAlarmConstants.*; import static cn.hippo4j.message.platform.constant.WeChatAlarmConstants.*;

@ -20,6 +20,9 @@ tenant=hippo4j
hippo4j.core.clean-history-data-period=30 hippo4j.core.clean-history-data-period=30
hippo4j.core.clean-history-data-enable=true hippo4j.core.clean-history-data-enable=true
### Whether to enable authentication.
hippo4j.core.auth.enabled=false
### Use netty to report thread pool monitoring data. The default is http. ### Use netty to report thread pool monitoring data. The default is http.
# hippo4j.core.monitor.report-type=netty # hippo4j.core.monitor.report-type=netty

@ -20,6 +20,8 @@ tenant=hippo4j
### Regularly clean up the historical running data of thread pool. unit: minute. ### Regularly clean up the historical running data of thread pool. unit: minute.
hippo4j.core.clean-history-data-period=30 hippo4j.core.clean-history-data-period=30
hippo4j.core.clean-history-data-enable=true hippo4j.core.clean-history-data-enable=true
### Whether to enable authentication.
hippo4j.core.auth.enabled=false hippo4j.core.auth.enabled=false
### Initialize the database dialect class. ### Initialize the database dialect class.

Loading…
Cancel
Save