From b8fcee6a0c679e123f9457a8c6dac7cdd367546d Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Tue, 24 Mar 2020 17:05:59 +0800 Subject: [PATCH] =?UTF-8?q?k8s=20=E5=90=AF=E5=8A=A8=20jmeter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kubernetes/KubernetesTestEngine.java | 22 +++++++++++++++---- .../xml/reader/jmx/JmeterDocumentParser.java | 3 +-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/io/metersphere/engine/kubernetes/KubernetesTestEngine.java b/backend/src/main/java/io/metersphere/engine/kubernetes/KubernetesTestEngine.java index 06f97114ca..2f4f2e0d24 100644 --- a/backend/src/main/java/io/metersphere/engine/kubernetes/KubernetesTestEngine.java +++ b/backend/src/main/java/io/metersphere/engine/kubernetes/KubernetesTestEngine.java @@ -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 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() {{ diff --git a/backend/src/main/java/io/metersphere/parse/xml/reader/jmx/JmeterDocumentParser.java b/backend/src/main/java/io/metersphere/parse/xml/reader/jmx/JmeterDocumentParser.java index 003b225590..484f6464bf 100644 --- a/backend/src/main/java/io/metersphere/parse/xml/reader/jmx/JmeterDocumentParser.java +++ b/backend/src/main/java/io/metersphere/parse/xml/reader/jmx/JmeterDocumentParser.java @@ -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