提交 b8fcee6a 编写于 作者: C Captain.B

k8s 启动 jmeter

上级 a72ba551
......@@ -6,6 +6,7 @@ import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.metersphere.base.domain.TestResource;
import io.metersphere.base.domain.TestResourcePool;
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil;
......@@ -17,6 +18,7 @@ import io.metersphere.engine.kubernetes.provider.ClientCredential;
import io.metersphere.engine.kubernetes.provider.KubernetesProvider;
import io.metersphere.service.TestResourcePoolService;
import io.metersphere.service.TestResourceService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import java.util.HashMap;
......@@ -29,7 +31,6 @@ public class KubernetesTestEngine implements Engine {
@Override
public boolean init(EngineContext context) {
// todo 初始化操作
this.context = context;
this.testResourcePoolService = CommonBeanFactory.getBean(TestResourcePoolService.class);
this.testResourceService = CommonBeanFactory.getBean(TestResourceService.class);
......@@ -47,10 +48,22 @@ public class KubernetesTestEngine implements Engine {
if (resourcePool == null) {
MSException.throwException("Resource Pool is empty");
}
if (!ResourcePoolTypeEnum.K8S.name().equals(resourcePool.getType())) {
MSException.throwException("Invalid Resource Pool type.");
}
List<TestResource> resourceList = testResourceService.getResourcesByPoolId(resourcePool.getId());
// todo 运行测试
ClientCredential credential = new ClientCredential();
credential.setMasterUrl("https://172.16.10.93:6443");
if (CollectionUtils.isEmpty(resourceList)) {
MSException.throwException("Test Resource is empty");
}
// resourceList size 1
resourceList.forEach(r -> {
String configuration = r.getConfiguration();
ClientCredential clientCredential = JSON.parseObject(configuration, ClientCredential.class);
runTest(clientCredential);
});
}
private void runTest(ClientCredential credential) {
KubernetesProvider kubernetesProvider = new KubernetesProvider(JSON.toJSONString(credential));
// create namespace
kubernetesProvider.confirmNamespace(context.getNamespace());
......@@ -73,6 +86,7 @@ public class KubernetesTestEngine implements Engine {
}
}
// create jmeter
// todo image
try {
Jmeter jmeter = new Jmeter();
jmeter.setMetadata(new ObjectMeta() {{
......
......@@ -233,11 +233,10 @@ public class JmeterDocumentParser implements DocumentParser {
collectionProp.appendChild(createKafkaProp(document, "kafka.batch.size", kafkaProperties.getBatchSize()));
collectionProp.appendChild(createKafkaProp(document, "kafka.client.id", kafkaProperties.getClientId()));
collectionProp.appendChild(createKafkaProp(document, "kafka.connections.max.idle.ms", kafkaProperties.getConnectionsMaxIdleMs()));
// 添加关联关系 test.id test.name test.startTime test.size
// 添加关联关系 test.id test.name test.startTime
collectionProp.appendChild(createKafkaProp(document, "test.id", context.getTestId()));
collectionProp.appendChild(createKafkaProp(document, "test.name", context.getTestName()));
collectionProp.appendChild(createKafkaProp(document, "test.startTime", "" + System.currentTimeMillis()));
collectionProp.appendChild(createKafkaProp(document, "test.size", "1"));
elementProp.appendChild(collectionProp);
// set elementProp
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册