refactor(性能测试): 资源池校验修改,停止容器错误处理

This commit is contained in:
Captain.B 2021-03-29 14:58:51 +08:00
parent 1d90a1b56c
commit 980190c6bf
2 changed files with 22 additions and 10 deletions

View File

@ -127,12 +127,18 @@ public class DockerTestEngine extends AbstractEngine {
Integer port = node.getPort(); Integer port = node.getPort();
String uri = String.format(BASE_URL + "/jmeter/container/stop/" + testId, ip, port); String uri = String.format(BASE_URL + "/jmeter/container/stop/" + testId, ip, port);
ResultHolder result = restTemplateWithTimeOut.getForObject(uri, ResultHolder.class); try {
if (result == null) { ResultHolder result = restTemplateWithTimeOut.getForObject(uri, ResultHolder.class);
MSException.throwException(Translator.get("container_delete_fail")); if (result == null) {
} MSException.throwException(Translator.get("container_delete_fail"));
if (!result.isSuccess()) { }
MSException.throwException(result.getMessage()); if (!result.isSuccess()) {
MSException.throwException(result.getMessage());
}
} catch (MSException e) {
throw e;
} catch (Exception e) {
MSException.throwException("Please check node-controller status.");
} }
}); });
} }

View File

@ -7,13 +7,13 @@ import io.metersphere.base.mapper.TestResourceMapper;
import io.metersphere.commons.constants.ResourceStatusEnum; import io.metersphere.commons.constants.ResourceStatusEnum;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.controller.ResultHolder;
import io.metersphere.dto.NodeDTO; import io.metersphere.dto.NodeDTO;
import io.metersphere.dto.TestResourcePoolDTO; import io.metersphere.dto.TestResourcePoolDTO;
import io.metersphere.i18n.Translator; import io.metersphere.i18n.Translator;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@ -71,12 +71,18 @@ public class NodeResourcePoolService {
private boolean validateNode(NodeDTO node) { private boolean validateNode(NodeDTO node) {
try { try {
ResponseEntity<String> entity = restTemplateWithTimeOut.getForEntity(String.format(nodeControllerUrl, node.getIp(), node.getPort()), String.class); ResponseEntity<ResultHolder> entity = restTemplateWithTimeOut.getForEntity(String.format(nodeControllerUrl, node.getIp(), node.getPort()), ResultHolder.class);
return HttpStatus.OK.equals(entity.getStatusCode()); ResultHolder body = entity.getBody();
if (body == null) {
return false;
}
if (body.getData() != null && StringUtils.equalsIgnoreCase("OK", body.getData().toString())) {
return true;
}
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage(), e); LogUtil.error(e.getMessage(), e);
return false;
} }
return false;
} }
private void updateTestResource(TestResource testResource) { private void updateTestResource(TestResource testResource) {