refactor: 使用k8s资源池

This commit is contained in:
Captain.B 2020-12-15 13:56:23 +08:00
parent 7377fd530b
commit e32ff12d22
5 changed files with 42 additions and 9 deletions

View File

@ -272,9 +272,9 @@
<!-- swagger3 解析 -->
<!--<dependency>-->
<!--<groupId>io.swagger.parser.v3</groupId>-->
<!--<artifactId>swagger-parser</artifactId>-->
<!--<version>2.0.24</version>-->
<!--<groupId>io.swagger.parser.v3</groupId>-->
<!--<artifactId>swagger-parser</artifactId>-->
<!--<version>2.0.24</version>-->
<!--</dependency>-->
<!-- 执行 js 代码依赖 -->
@ -373,6 +373,12 @@
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<!-- 反射工具包 -->
<dependency>
<groupId>net.oneandone.reflections8</groupId>
<artifactId>reflections8</artifactId>
<version>0.11.7</version>
</dependency>
</dependencies>
<build>

View File

@ -58,7 +58,8 @@ public abstract class AbstractEngine implements Engine {
if (resourcePool == null) {
MSException.throwException("Resource Pool is empty");
}
if (!ResourcePoolTypeEnum.NODE.name().equals(resourcePool.getType())) {
if (!ResourcePoolTypeEnum.K8S.name().equals(resourcePool.getType())
&& !ResourcePoolTypeEnum.NODE.name().equals(resourcePool.getType())) {
MSException.throwException("Invalid Resource Pool type.");
}
this.resourceList = testResourceService.getResourcesByPoolId(resourcePool.getId());

View File

@ -2,6 +2,7 @@ package io.metersphere.performance.engine;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.Application;
import io.metersphere.base.domain.FileContent;
import io.metersphere.base.domain.FileMetadata;
import io.metersphere.base.domain.LoadTestWithBLOBs;
@ -16,17 +17,17 @@ import io.metersphere.performance.engine.docker.DockerTestEngine;
import io.metersphere.performance.parse.EngineSourceParser;
import io.metersphere.performance.parse.EngineSourceParserFactory;
import io.metersphere.service.FileService;
import io.metersphere.service.KubernetesTestEngine;
import io.metersphere.service.TestResourcePoolService;
import org.apache.commons.beanutils.ConstructorUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.reflections8.Reflections;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Service
@ -34,6 +35,17 @@ public class EngineFactory {
private static FileService fileService;
private static TestResourcePoolService testResourcePoolService;
private static KafkaProperties kafkaProperties;
private static Class<? extends KubernetesTestEngine> kubernetesTestEngineClass;
static {
Reflections reflections = new Reflections(Application.class.getPackage().getName());
Set<Class<? extends KubernetesTestEngine>> implClass = reflections.getSubTypesOf(KubernetesTestEngine.class);
for (Class<? extends KubernetesTestEngine> aClass : implClass) {
kubernetesTestEngineClass = aClass;
// 第一个
break;
}
}
public static Engine createEngine(LoadTestWithBLOBs loadTest) {
String resourcePoolId = loadTest.getTestResourcePoolId();
@ -51,6 +63,14 @@ public class EngineFactory {
if (type == ResourcePoolTypeEnum.NODE) {
return new DockerTestEngine(loadTest);
}
if (type == ResourcePoolTypeEnum.K8S) {
try {
return ConstructorUtils.invokeConstructor(kubernetesTestEngineClass, loadTest);
} catch (Exception e) {
LogUtil.error(e);
return null;
}
}
return null;
}

View File

@ -0,0 +1,6 @@
package io.metersphere.service;
import io.metersphere.performance.engine.Engine;
public interface KubernetesTestEngine extends Engine {
}

@ -1 +1 @@
Subproject commit acb5adf44cf5f4a3b512abbff1e437957a9fcfb5
Subproject commit 61397c16728a63493507679f7e0940d9099f337f