refactor(性能测试): 校验资源池逻辑修改
This commit is contained in:
parent
93ddd4b2c5
commit
fb755af931
|
@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -39,17 +40,25 @@ public class NodeResourcePoolService {
|
||||||
MSException.throwException(Translator.get("no_nodes_message"));
|
MSException.throwException(Translator.get("no_nodes_message"));
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteTestResource(testResourcePool.getId());
|
|
||||||
List<ImmutablePair> Ip_Port = testResourcePool.getResources().stream()
|
List<ImmutablePair<String, Integer>> ipPort = testResourcePool.getResources().stream()
|
||||||
.map(resource -> {
|
.map(resource -> {
|
||||||
NodeDTO nodeDTO = JSON.parseObject(resource.getConfiguration(), NodeDTO.class);
|
NodeDTO nodeDTO = JSON.parseObject(resource.getConfiguration(), NodeDTO.class);
|
||||||
return new ImmutablePair(nodeDTO.getIp(), nodeDTO.getPort());
|
return new ImmutablePair<>(nodeDTO.getIp(), nodeDTO.getPort());
|
||||||
})
|
})
|
||||||
.distinct()
|
.distinct()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (Ip_Port.size() < testResourcePool.getResources().size()) {
|
if (ipPort.size() < testResourcePool.getResources().size()) {
|
||||||
MSException.throwException(Translator.get("duplicate_node_ip_port"));
|
MSException.throwException(Translator.get("duplicate_node_ip_port"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<TestResource> resourcesFromDB = getResourcesFromDB(testResourcePool);
|
||||||
|
List<String> resourceIdsFromDB = resourcesFromDB.stream().map(TestResource::getId).collect(Collectors.toList());
|
||||||
|
List<String> resourceIdsFromPage = testResourcePool.getResources().stream().map(TestResource::getId).collect(Collectors.toList());
|
||||||
|
Collection<String> deletedResources = CollectionUtils.subtract(resourceIdsFromDB, resourceIdsFromPage);
|
||||||
|
// 删除不关联的资源节点
|
||||||
|
deleteTestResources(deletedResources);
|
||||||
|
|
||||||
testResourcePool.setStatus(VALID.name());
|
testResourcePool.setStatus(VALID.name());
|
||||||
boolean isValid = true;
|
boolean isValid = true;
|
||||||
for (TestResource resource : testResourcePool.getResources()) {
|
for (TestResource resource : testResourcePool.getResources()) {
|
||||||
|
@ -68,6 +77,18 @@ public class NodeResourcePoolService {
|
||||||
return isValid;
|
return isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deleteTestResources(Collection<String> ids) {
|
||||||
|
for (String deletedResourceId : ids) {
|
||||||
|
testResourceMapper.deleteByPrimaryKey(deletedResourceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TestResource> getResourcesFromDB(TestResourcePoolDTO testResourcePool) {
|
||||||
|
TestResourceExample example = new TestResourceExample();
|
||||||
|
example.createCriteria().andTestResourcePoolIdEqualTo(testResourcePool.getId());
|
||||||
|
return testResourceMapper.selectByExample(example);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean validateNode(NodeDTO node) {
|
private boolean validateNode(NodeDTO node) {
|
||||||
try {
|
try {
|
||||||
|
@ -90,14 +111,9 @@ public class NodeResourcePoolService {
|
||||||
testResource.setCreateTime(System.currentTimeMillis());
|
testResource.setCreateTime(System.currentTimeMillis());
|
||||||
if (StringUtils.isBlank(testResource.getId())) {
|
if (StringUtils.isBlank(testResource.getId())) {
|
||||||
testResource.setId(UUID.randomUUID().toString());
|
testResource.setId(UUID.randomUUID().toString());
|
||||||
|
testResourceMapper.insertSelective(testResource);
|
||||||
|
} else {
|
||||||
|
testResourceMapper.updateByPrimaryKeySelective(testResource);
|
||||||
}
|
}
|
||||||
// 如果是更新操作,插入与原来的ID相同的数据
|
|
||||||
testResourceMapper.insertSelective(testResource);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteTestResource(String testResourcePoolId) {
|
|
||||||
TestResourceExample testResourceExample = new TestResourceExample();
|
|
||||||
testResourceExample.createCriteria().andTestResourcePoolIdEqualTo(testResourcePoolId);
|
|
||||||
testResourceMapper.deleteByExample(testResourceExample);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue