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>
</td>
<td align="center">
<a href="https://github.com/BigXin0109">
<img src="https://avatars.githubusercontent.com/u/24769514?v=4" width="50;" alt="BigXin0109"/>
<a href="https://github.com/shanjianq">
<img src="https://avatars.githubusercontent.com/u/49084314?v=4" width="50;" alt="shanjianq"/>
<br />
<sub><b>BigXin0109</b></sub>
<sub><b>Shanjianq</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/shanjianq">
<img src="https://avatars.githubusercontent.com/u/49084314?v=4" width="50;" alt="shanjianq"/>
<a href="https://github.com/BigXin0109">
<img src="https://avatars.githubusercontent.com/u/24769514?v=4" width="50;" alt="BigXin0109"/>
<br />
<sub><b>Shanjianq</b></sub>
<sub><b>BigXin0109</b></sub>
</a>
</td>
<td align="center">
@ -157,6 +157,13 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池
<sub><b>Lijx</b></sub>
</a>
</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">
<a href="https://github.com/liulinfei121">
<img src="https://avatars.githubusercontent.com/u/57127515?v=4" width="50;" alt="liulinfei121"/>
@ -184,15 +191,15 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池
<br />
<sub><b>杨镇涛</b></sub>
</a>
</td>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/Tliutao">
<img src="https://avatars.githubusercontent.com/u/17719583?v=4" width="50;" alt="Tliutao"/>
<br />
<sub><b>Liutao</b></sub>
</a>
</td></tr>
<tr>
</td>
<td align="center">
<a href="https://github.com/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>
</a>
</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">
<a href="https://github.com/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>
</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" ><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" >machen@apache.org</td>
</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" >hao3073liu@163.com</td>
</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>

@ -223,6 +223,56 @@ public class StringUtil {
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
*

@ -18,83 +18,108 @@
package cn.hippo4j.common.toolkit;
import org.junit.Test;
import java.util.Objects;
import org.junit.Assert;
public class StringUtilTest {
@Test
public void assertIsEmpty() {
String string = "";
Assert.isTrue(StringUtil.isEmpty(string));
Assert.assertTrue(StringUtil.isEmpty(string));
}
@Test
public void assertIsNotEmpty() {
String string = "string";
Assert.isTrue(StringUtil.isNotEmpty(string));
Assert.assertTrue(StringUtil.isNotEmpty(string));
}
@Test
public void emptyToNull() {
String string = "";
Assert.isNull(StringUtil.emptyToNull(string));
Assert.assertNull(StringUtil.emptyToNull(string));
}
@Test
public void nullToEmpty() {
String string = "null";
Assert.notEmpty(StringUtil.nullToEmpty(string));
Assert.assertEquals("null", StringUtil.nullToEmpty(string));
}
@Test
public void isNullOrEmpty() {
String string = "null";
Assert.isTrue(!StringUtil.isNullOrEmpty(string));
Assert.assertFalse(StringUtil.isNullOrEmpty(string));
}
@Test
public void isBlank() {
String string = "";
Assert.isTrue(StringUtil.isBlank(string));
Assert.assertTrue(StringUtil.isBlank(string));
}
@Test
public void isNotBlank() {
String string = "null";
Assert.isTrue(StringUtil.isNotBlank(string));
Assert.assertTrue(StringUtil.isNotBlank(string));
}
@Test
public void isAllNotEmpty() {
String strings = "str";
Assert.isTrue(StringUtil.isAllNotEmpty(strings));
Assert.assertTrue(StringUtil.isAllNotEmpty(strings));
}
@Test
public void hasEmpty() {
String strings = "";
Assert.isTrue(StringUtil.hasEmpty(strings));
Assert.assertTrue(StringUtil.hasEmpty(strings));
}
@Test
public void toUnderlineCase() {
String string = "str";
String s = StringUtil.toUnderlineCase(string);
Assert.isTrue(Objects.equals(s, "str"));
Assert.assertEquals("str", s);
}
@Test
public void toSymbolCase() {
String string = "str";
String s = StringUtil.toSymbolCase(string, StringUtil.UNDERLINE);
Assert.isTrue(Objects.equals(s, "str"));
Assert.assertEquals("str", s);
}
@Test
public void toCamelCase() {
String string = "str_str";
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 com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@ -38,7 +37,6 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
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;
/**
@ -49,7 +47,7 @@ import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL;
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<>();
@ -98,18 +96,23 @@ public class ThreadPoolAdapterService {
List<String> addressList = actual.stream().map(ThreadPoolAdapterState::getClientAddress).collect(Collectors.toList());
List<ThreadPoolAdapterRespDTO> result = new ArrayList<>(addressList.size());
addressList.forEach(each -> {
String urlString = new StringBuilder()
.append("http://")
.append(each)
.append("/adapter/thread-pool/info")
.toString();
StringBuilder builder = StringUtil.createBuilder("http://", each, "/adapter/thread-pool/info");
Map<String, Object> param = new HashMap<>();
param.put("mark", requestParameter.getMark());
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 {
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)) {
Result<ThreadPoolAdapterRespDTO> restResult = JSONUtil.parseObject(resultStr, new TypeReference<Result<ThreadPoolAdapterRespDTO>>() {
});
@ -131,22 +134,16 @@ public class ThreadPoolAdapterService {
return actual.keySet();
}
}
return new HashSet();
return new HashSet<>();
}
public static void remove(String identify) {
synchronized (ThreadPoolAdapterService.class) {
THREAD_POOL_ADAPTER_MAP.values().forEach(each -> each.forEach((key, val) -> {
val.forEach((threadPoolKey, states) -> {
Iterator<ThreadPoolAdapterState> iterator = states.iterator();
while (iterator.hasNext()) {
ThreadPoolAdapterState adapterState = iterator.next();
if (Objects.equals(adapterState.getIdentify(), identify)) {
iterator.remove();
}
}
});
}));
THREAD_POOL_ADAPTER_MAP.values().forEach(each -> each.forEach((key, val) ->
val.forEach((threadPoolKey, states) ->
states.removeIf(adapterState -> Objects.equals(adapterState.getIdentify(), identify))
)
));
}
}

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

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

@ -26,7 +26,6 @@ import cn.hippo4j.message.platform.base.RobotMessageExecuteDTO;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
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-enable=true
### Whether to enable authentication.
hippo4j.core.auth.enabled=false
### Use netty to report thread pool monitoring data. The default is http.
# hippo4j.core.monitor.report-type=netty

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

Loading…
Cancel
Save