refactor: 资源池后台修改

This commit is contained in:
Captain.B 2021-08-27 11:10:06 +08:00 committed by 刘瑞斌
parent 85a19bfce7
commit 1c4084132f
1 changed files with 18 additions and 2 deletions

View File

@ -12,7 +12,9 @@ import io.metersphere.performance.engine.EngineContext;
import io.metersphere.performance.parse.xml.reader.DocumentParser;
import io.metersphere.service.TestResourcePoolService;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@ -591,7 +593,7 @@ public class JmeterDocumentParser implements DocumentParser {
private void processBackendListener(Element backendListener) {
String resourcePoolId = context.getResourcePoolId();
TestResourcePool resourcePool = CommonBeanFactory.getBean(TestResourcePoolService.class).getResourcePool(resourcePoolId);
if (!BooleanUtils.toBoolean(resourcePool.getBackendListener())) {
if (checkLicense() && !BooleanUtils.toBoolean(resourcePool.getBackendListener())) {
return;
}
KafkaProperties kafkaProperties = CommonBeanFactory.getBean(KafkaProperties.class);
@ -656,7 +658,7 @@ public class JmeterDocumentParser implements DocumentParser {
private void processCheckoutBackendListener(Element element) {
String resourcePoolId = context.getResourcePoolId();
TestResourcePool resourcePool = CommonBeanFactory.getBean(TestResourcePoolService.class).getResourcePool(resourcePoolId);
if (!BooleanUtils.toBoolean(resourcePool.getBackendListener())) {
if (checkLicense() && !BooleanUtils.toBoolean(resourcePool.getBackendListener())) {
return;
}
@ -677,6 +679,20 @@ public class JmeterDocumentParser implements DocumentParser {
listenerParent.appendChild(document.createElement(HASH_TREE_ELEMENT));
}
private boolean checkLicense() {
try {
ClassUtils.getClass("io.metersphere.xpack.license.service.LicenseService");
Object licenseService = CommonBeanFactory.getBean("licenseService");
Object result = MethodUtils.invokeMethod(licenseService, "valid");
Object status = MethodUtils.invokeMethod(result, "getStatus");
if (StringUtils.equalsIgnoreCase("VALID", status.toString())) {
return true;
}
} catch (Exception ignored) {
}
return false;
}
private void processThreadGroup(Element threadGroup) {
// 检查 threadgroup 后面的hashtree是否为空
Node hashTree = threadGroup.getNextSibling();