From 66b60dbbc68993ad41bc36ec7bd78c0c41e482e4 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Mon, 8 Jun 2020 11:19:45 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/pom.xml | 7 - .../constants/ResourcePoolTypeEnum.java | 4 - .../performance/engine/AbstractEngine.java | 2 +- .../performance/engine/EngineFactory.java | 8 +- .../kubernetes/KubernetesTestEngine.java | 148 ---------- .../crds/MeterSphereCustomResource.java | 36 --- .../MeterSphereCustomResourceDoneable.java | 10 - .../crds/MeterSphereCustomResourceList.java | 6 - .../engine/kubernetes/crds/jmeter/Jmeter.java | 33 --- .../crds/jmeter/JmeterDoneable.java | 10 - .../kubernetes/crds/jmeter/JmeterSpec.java | 40 --- .../kubernetes/crds/jmeter/JmeterStatus.java | 36 --- .../provider/AbstractClientProvider.java | 267 ------------------ .../kubernetes/provider/ClientCredential.java | 32 --- .../kubernetes/provider/DockerRegistry.java | 50 ---- .../provider/DockerRegistryUtil.java | 24 -- .../provider/KubernetesProvider.java | 7 - .../service/PerformanceTestService.java | 2 +- .../service/TestResourcePoolService.java | 35 +-- .../track/service/TestCaseNodeService.java | 3 +- .../resources/i18n/messages_en_US.properties | 1 - .../resources/i18n/messages_zh_CN.properties | 1 - .../resources/i18n/messages_zh_TW.properties | 1 - .../settings/system/TestResourcePool.vue | 43 --- 24 files changed, 9 insertions(+), 797 deletions(-) delete mode 100644 backend/src/main/java/io/metersphere/performance/engine/kubernetes/KubernetesTestEngine.java delete mode 100644 backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/MeterSphereCustomResource.java delete mode 100644 backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/MeterSphereCustomResourceDoneable.java delete mode 100644 backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/MeterSphereCustomResourceList.java delete mode 100644 backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/Jmeter.java delete mode 100644 backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/JmeterDoneable.java delete mode 100644 backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/JmeterSpec.java delete mode 100644 backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/JmeterStatus.java delete mode 100644 backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/AbstractClientProvider.java delete mode 100644 backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/ClientCredential.java delete mode 100644 backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/DockerRegistry.java delete mode 100644 backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/DockerRegistryUtil.java delete mode 100644 backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/KubernetesProvider.java diff --git a/backend/pom.xml b/backend/pom.xml index a702be3bac..3088f0dedf 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -18,16 +18,9 @@ 1.5.1 1.8 5.2.1 - 4.9.0 - - - io.fabric8 - kubernetes-client - ${kubernetes-client.version} - org.springframework.boot spring-boot-starter-web diff --git a/backend/src/main/java/io/metersphere/commons/constants/ResourcePoolTypeEnum.java b/backend/src/main/java/io/metersphere/commons/constants/ResourcePoolTypeEnum.java index 1cc3f1a7c5..8707a5b61e 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/ResourcePoolTypeEnum.java +++ b/backend/src/main/java/io/metersphere/commons/constants/ResourcePoolTypeEnum.java @@ -1,10 +1,6 @@ package io.metersphere.commons.constants; public enum ResourcePoolTypeEnum { - /** - * k8s 资源池 - */ - K8S, /** * node controller 资源池 */ diff --git a/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java b/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java index be48194868..210829db7c 100644 --- a/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java +++ b/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java @@ -57,7 +57,7 @@ public abstract class AbstractEngine implements Engine { if (resourcePool == null) { MSException.throwException("Resource Pool is empty"); } - if (!ResourcePoolTypeEnum.K8S.name().equals(resourcePool.getType()) && !ResourcePoolTypeEnum.NODE.name().equals(resourcePool.getType())) { + if (!ResourcePoolTypeEnum.NODE.name().equals(resourcePool.getType())) { MSException.throwException("Invalid Resource Pool type."); } this.resourceList = testResourceService.getResourcesByPoolId(resourcePool.getId()); diff --git a/backend/src/main/java/io/metersphere/performance/engine/EngineFactory.java b/backend/src/main/java/io/metersphere/performance/engine/EngineFactory.java index c2a3ec7798..f92a264aa0 100644 --- a/backend/src/main/java/io/metersphere/performance/engine/EngineFactory.java +++ b/backend/src/main/java/io/metersphere/performance/engine/EngineFactory.java @@ -12,7 +12,6 @@ import io.metersphere.commons.exception.MSException; import io.metersphere.config.KafkaProperties; import io.metersphere.i18n.Translator; import io.metersphere.performance.engine.docker.DockerTestEngine; -import io.metersphere.performance.engine.kubernetes.KubernetesTestEngine; import io.metersphere.performance.parse.EngineSourceParser; import io.metersphere.performance.parse.EngineSourceParserFactory; import io.metersphere.service.FileService; @@ -47,11 +46,8 @@ public class EngineFactory { final ResourcePoolTypeEnum type = ResourcePoolTypeEnum.valueOf(resourcePool.getType()); - switch (type) { - case NODE: - return new DockerTestEngine(loadTest); - case K8S: - return new KubernetesTestEngine(loadTest); + if (type == ResourcePoolTypeEnum.NODE) { + return new DockerTestEngine(loadTest); } return null; } diff --git a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/KubernetesTestEngine.java b/backend/src/main/java/io/metersphere/performance/engine/kubernetes/KubernetesTestEngine.java deleted file mode 100644 index 63fee0f0ec..0000000000 --- a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/KubernetesTestEngine.java +++ /dev/null @@ -1,148 +0,0 @@ -package io.metersphere.performance.engine.kubernetes; - -import com.alibaba.fastjson.JSON; -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.fabric8.kubernetes.api.model.ObjectMeta; -import io.fabric8.kubernetes.client.KubernetesClient; -import io.metersphere.base.domain.LoadTestWithBLOBs; -import io.metersphere.commons.constants.FileType; -import io.metersphere.commons.exception.MSException; -import io.metersphere.commons.utils.LogUtil; -import io.metersphere.i18n.Translator; -import io.metersphere.performance.engine.AbstractEngine; -import io.metersphere.performance.engine.EngineContext; -import io.metersphere.performance.engine.EngineFactory; -import io.metersphere.performance.engine.kubernetes.crds.jmeter.Jmeter; -import io.metersphere.performance.engine.kubernetes.crds.jmeter.JmeterSpec; -import io.metersphere.performance.engine.kubernetes.provider.ClientCredential; -import io.metersphere.performance.engine.kubernetes.provider.KubernetesProvider; -import org.apache.commons.collections.MapUtils; - -import java.util.HashMap; -import java.util.Map; - -public class KubernetesTestEngine extends AbstractEngine { - - - public KubernetesTestEngine(LoadTestWithBLOBs loadTest) { - this.init(loadTest); - } - - @Override - public void init(LoadTestWithBLOBs loadTest) { - super.init(loadTest); - } - - - @Override - public void start() { - Integer sumThreadNum = getRunningThreadNum(); - // resourceList size 1 - resourceList.forEach(r -> { - String configuration = r.getConfiguration(); - ClientCredential clientCredential = JSON.parseObject(configuration, ClientCredential.class); - // 最大并发数 - Integer maxConcurrency = clientCredential.getMaxConcurrency(); - // 当前测试需要的并发数大于剩余的并发数报错 - if (threadNum > maxConcurrency - sumThreadNum) { - MSException.throwException(Translator.get("max_thread_insufficient")); - } - try { - EngineContext context = EngineFactory.createContext(loadTest, r.getId(), threadNum, this.getStartTime(), this.getReportId()); - runTest(context, clientCredential); - } catch (Exception e) { - MSException.throwException(e); - } - }); - } - - private void runTest(EngineContext context, ClientCredential credential) { - KubernetesProvider kubernetesProvider = new KubernetesProvider(JSON.toJSONString(credential)); - - // create namespace - kubernetesProvider.confirmNamespace(context.getNamespace()); - // create cm - try (KubernetesClient client = kubernetesProvider.getKubernetesClient()) { - String configMapName = "jmeter-" + context.getTestId() + "-files"; - ConfigMap configMap = client.configMaps().inNamespace(context.getNamespace()).withName(configMapName).get(); - if (configMap == null) { - ConfigMap item = new ConfigMap(); - item.setMetadata(new ObjectMeta() {{ - setName(configMapName); - }}); - item.setData(new HashMap() {{ - put(context.getTestId() + FileType.JMX.suffix(), context.getContent()); - if (MapUtils.isNotEmpty(context.getTestData())) { - putAll(context.getTestData()); - } - }}); - client.configMaps().inNamespace(context.getNamespace()).create(item); - } - } - // create jmeter - // todo image - try { - Jmeter jmeter = new Jmeter(); - jmeter.setMetadata(new ObjectMeta() {{ - setNamespace(context.getNamespace()); - setName(context.getTestId()); - }}); - jmeter.setSpec(new JmeterSpec() {{ - setReplicas(1); - setImage(JMETER_IMAGE); - setEnv(context.getEnv()); - }}); - LogUtil.info("Load test started. " + context.getTestId()); - kubernetesProvider.applyCustomResource(jmeter); - } catch (Exception e) { - MSException.throwException(e); - } - } - - @Override - public void stop() { - resourceList.forEach(r -> { - try { - String configuration = r.getConfiguration(); - ClientCredential clientCredential = JSON.parseObject(configuration, ClientCredential.class); - KubernetesProvider provider = new KubernetesProvider(JSON.toJSONString(clientCredential)); - provider.confirmNamespace(loadTest.getProjectId()); - Jmeter jmeter = new Jmeter(); - jmeter.setMetadata(new ObjectMeta() {{ - setName(loadTest.getId()); - setNamespace(loadTest.getProjectId()); - }}); - jmeter.setSpec(new JmeterSpec() {{ - setReplicas(1); - setImage(JMETER_IMAGE); - }}); - provider.deleteCustomResource(jmeter); - } catch (Exception e) { - MSException.throwException(e); - } - - }); - - } - - @Override - public Map log() { - Map logs = new HashMap<>(); - resourceList.forEach(r -> { - try { - String configuration = r.getConfiguration(); - ClientCredential clientCredential = JSON.parseObject(configuration, ClientCredential.class); - KubernetesProvider provider = new KubernetesProvider(JSON.toJSONString(clientCredential)); - provider.confirmNamespace(loadTest.getProjectId()); - try (KubernetesClient client = provider.getKubernetesClient()) { - String joblog = client.batch().jobs().inNamespace(loadTest.getProjectId()).withName("job-" + loadTest.getId()).getLog(); - logs.put(clientCredential.getMasterUrl(), joblog); - } - } catch (Exception e) { - MSException.throwException(e); - } - - }); - return logs; - } -} diff --git a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/MeterSphereCustomResource.java b/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/MeterSphereCustomResource.java deleted file mode 100644 index d0eed411c2..0000000000 --- a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/MeterSphereCustomResource.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.metersphere.performance.engine.kubernetes.crds; - -import io.fabric8.kubernetes.client.CustomResource; - -public class MeterSphereCustomResource extends CustomResource { - - private String crd; - - private Object spec; - - private Object status; - - public String getCrd() { - return crd; - } - - public void setCrd(String crd) { - this.crd = crd; - } - - public Object getSpec() { - return spec; - } - - public void setSpec(Object spec) { - this.spec = spec; - } - - public Object getStatus() { - return status; - } - - public void setStatus(Object status) { - this.status = status; - } -} diff --git a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/MeterSphereCustomResourceDoneable.java b/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/MeterSphereCustomResourceDoneable.java deleted file mode 100644 index a0aae5efa7..0000000000 --- a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/MeterSphereCustomResourceDoneable.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.metersphere.performance.engine.kubernetes.crds; - -import io.fabric8.kubernetes.api.builder.Function; -import io.fabric8.kubernetes.client.CustomResourceDoneable; - -public class MeterSphereCustomResourceDoneable extends CustomResourceDoneable { - public MeterSphereCustomResourceDoneable(T resource, Function function) { - super(resource, function); - } -} diff --git a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/MeterSphereCustomResourceList.java b/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/MeterSphereCustomResourceList.java deleted file mode 100644 index 73b0d494c5..0000000000 --- a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/MeterSphereCustomResourceList.java +++ /dev/null @@ -1,6 +0,0 @@ -package io.metersphere.performance.engine.kubernetes.crds; - -import io.fabric8.kubernetes.client.CustomResourceList; - -public class MeterSphereCustomResourceList extends CustomResourceList { -} diff --git a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/Jmeter.java b/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/Jmeter.java deleted file mode 100644 index 91ce1804ec..0000000000 --- a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/Jmeter.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.metersphere.performance.engine.kubernetes.crds.jmeter; - -import io.metersphere.performance.engine.kubernetes.crds.MeterSphereCustomResource; - -public class Jmeter extends MeterSphereCustomResource { - public static final String CRD = "jmeters.metersphere.io"; - public static final String KIND = "Jmeter"; - private JmeterSpec spec; - private JmeterStatus status; - - public Jmeter() { - this.setCrd(CRD); - this.setKind(KIND); - } - - @Override - public JmeterSpec getSpec() { - return spec; - } - - public void setSpec(JmeterSpec spec) { - this.spec = spec; - } - - @Override - public JmeterStatus getStatus() { - return status; - } - - public void setStatus(JmeterStatus status) { - this.status = status; - } -} diff --git a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/JmeterDoneable.java b/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/JmeterDoneable.java deleted file mode 100644 index ec8b80d742..0000000000 --- a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/JmeterDoneable.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.metersphere.performance.engine.kubernetes.crds.jmeter; - -import io.fabric8.kubernetes.api.builder.Function; -import io.fabric8.kubernetes.client.CustomResourceDoneable; - -public class JmeterDoneable extends CustomResourceDoneable { - public JmeterDoneable(Jmeter resource, Function function) { - super(resource, function); - } -} diff --git a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/JmeterSpec.java b/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/JmeterSpec.java deleted file mode 100644 index 6603e0257b..0000000000 --- a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/JmeterSpec.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.metersphere.performance.engine.kubernetes.crds.jmeter; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import io.fabric8.kubernetes.api.model.KubernetesResource; - -import java.util.HashMap; -import java.util.Map; - -@JsonDeserialize -@JsonInclude(JsonInclude.Include.NON_EMPTY) -public class JmeterSpec implements KubernetesResource { - private int replicas = 1; - private String image; - private Map env = new HashMap<>(); - - public int getReplicas() { - return replicas; - } - - public void setReplicas(int replicas) { - this.replicas = replicas; - } - - public String getImage() { - return image; - } - - public void setImage(String image) { - this.image = image; - } - - public Map getEnv() { - return env; - } - - public void setEnv(Map env) { - this.env = env; - } -} diff --git a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/JmeterStatus.java b/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/JmeterStatus.java deleted file mode 100644 index 8132f1781a..0000000000 --- a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/crds/jmeter/JmeterStatus.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.metersphere.performance.engine.kubernetes.crds.jmeter; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import io.fabric8.kubernetes.api.model.KubernetesResource; - -@JsonDeserialize -@JsonInclude(JsonInclude.Include.NON_NULL) -public class JmeterStatus implements KubernetesResource { - private String phase; - private String reason; - - public String getPhase() { - return phase; - } - - public void setPhase(String phase) { - this.phase = phase; - } - - public String getReason() { - return reason; - } - - public void setReason(String reason) { - this.reason = reason; - } - - @Override - public String toString() { - return "JmeterStatus{" + - "phase='" + phase + '\'' + - ", reason='" + reason + '\'' + - '}'; - } -} diff --git a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/AbstractClientProvider.java b/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/AbstractClientProvider.java deleted file mode 100644 index 4add6c111c..0000000000 --- a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/AbstractClientProvider.java +++ /dev/null @@ -1,267 +0,0 @@ -package io.metersphere.performance.engine.kubernetes.provider; - -import com.alibaba.fastjson.JSONObject; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.fabric8.kubernetes.api.model.*; -import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition; -import io.fabric8.kubernetes.client.ConfigBuilder; -import io.fabric8.kubernetes.client.DefaultKubernetesClient; -import io.fabric8.kubernetes.client.KubernetesClient; -import io.fabric8.kubernetes.client.dsl.*; -import io.metersphere.performance.engine.kubernetes.crds.MeterSphereCustomResource; -import io.metersphere.performance.engine.kubernetes.crds.MeterSphereCustomResourceDoneable; -import io.metersphere.performance.engine.kubernetes.crds.MeterSphereCustomResourceList; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; - -import java.util.*; -import java.util.regex.Pattern; - -public abstract class AbstractClientProvider { - private static ObjectMapper objectMapper = new ObjectMapper(); - - private String credential; - - public AbstractClientProvider(String credential) { - setCredential(credential); - } - - public String getCredential() { - return credential; - } - - public void setCredential(String credential) { - this.credential = credential; - } - - /** - * OpenShiftClient继承自KubernetesClient,OpenShiftClient对OpenShift和kubernetes的共有资源也是用KubernetesClient代理的, - * 所以可以在把client提取到抽象类 - */ - public KubernetesClient getKubernetesClient() { - ClientCredential providerCredential = JSONObject.parseObject(getCredential(), ClientCredential.class); - io.fabric8.kubernetes.client.ConfigBuilder configBuilder = new ConfigBuilder(); - configBuilder.withMasterUrl(providerCredential.getMasterUrl()); - configBuilder.withOauthToken(providerCredential.getToken()); - configBuilder.withTrustCerts(true); - //设置默认的 namespace 为 null, - configBuilder.withNamespace(null); - return new DefaultKubernetesClient(configBuilder.build()); - } - - - public void validateCredential() { - try (KubernetesClient client = getKubernetesClient()) { - client.namespaces().list(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - - /** - * 确保指定的namespace存在,不存在直接创建一个 - * - * @param namespace namespace标识 - * @return - */ - public synchronized String confirmNamespace(String namespace) { - KubernetesClient kubernetesClient = getKubernetesClient(); - Namespace currentNamespace = kubernetesClient.namespaces().withName(namespace).get(); - if (currentNamespace == null) { - Map annotations = new HashMap<>(); - Namespace newNamespace = new NamespaceBuilder() - .withNewMetadata() - .withName(namespace) - .withAnnotations(annotations) - .endMetadata() - .build(); - currentNamespace = kubernetesClient.namespaces().createOrReplace(newNamespace); - } - return currentNamespace.getMetadata().getName(); - } - - - /** - * 获取集群UUID,当前集群UUID等于default namespace的UID - * - * @return - */ - public String getClusterUUID() { - KubernetesClient kubernetesClient = getKubernetesClient(); - Namespace defaultNamespace = kubernetesClient.namespaces().withName("kube-system").get(); - if (defaultNamespace == null) { - throw new RuntimeException("无法获取集群的kube-system namespace"); - } else { - return defaultNamespace.getMetadata().getUid(); - } - } - - - /** - * 确保docker registry存在, - * 不存在 创建一个harbor-secret,并修改serviceaccount default - * - * @param registry - */ - public void dockerRegistry(DockerRegistry registry) { - - if (StringUtils.isEmpty(registry.getUsername()) || - StringUtils.isEmpty(registry.getPassword()) || - StringUtils.isEmpty(registry.getUrl()) - ) { - throw new RuntimeException("Please set the docker registry information"); - } - - String secretName = "docker-registry-ms-secret"; - KubernetesClient kubernetesClient = getKubernetesClient(); - - Secret secretRegistry = new SecretBuilder() - .withNewMetadata().withName(secretName).endMetadata() - .addToData(".dockerconfigjson", DockerRegistryUtil.getDockerConfig(registry)) - .withType("kubernetes.io/dockerconfigjson") - .build(); - kubernetesClient.secrets().inNamespace(registry.getNamespace()).createOrReplace(secretRegistry); - - //sa - ServiceAccount serviceAccount = kubernetesClient.serviceAccounts().inNamespace(registry.getNamespace()) - .withName("default").get(); - List imagePullSecrets = serviceAccount.getImagePullSecrets(); - for (LocalObjectReference pullSecret : imagePullSecrets) { - if (secretName.equals(pullSecret.getName())) { - return; - } - } - - LocalObjectReference localObjectReference = new LocalObjectReference(secretName); - imagePullSecrets.add(localObjectReference); - serviceAccount.setImagePullSecrets(imagePullSecrets); - - kubernetesClient.serviceAccounts().inNamespace(registry.getNamespace()) - .createOrReplace(serviceAccount); - - } - - - public T applyCustomResource(MeterSphereCustomResource customResource) throws Exception { - try (KubernetesClient kubernetesClient = getKubernetesClient()) { - CustomResourceDefinition crd = kubernetesClient.customResourceDefinitions().withName(customResource.getCrd()).get(); - if (crd == null) { - throw new Exception("CRD does not exists."); - } - MixedOperation> - operation = kubernetesClient.customResources(crd, MeterSphereCustomResource.class, MeterSphereCustomResourceList.class, MeterSphereCustomResourceDoneable.class); - MeterSphereCustomResource replace = operation.inNamespace(customResource.getMetadata().getNamespace()).createOrReplace(customResource); - return (T) objectMapper.readValue(objectMapper.writeValueAsString(replace), customResource.getClass()); - } - } - - - public boolean deleteCustomResource(MeterSphereCustomResource customResource) { - try (KubernetesClient kubernetesClient = getKubernetesClient()) { - CustomResourceDefinition crd = kubernetesClient.customResourceDefinitions().withName(customResource.getCrd()).get(); - MixedOperation> - operation = kubernetesClient.customResources(crd, MeterSphereCustomResource.class, MeterSphereCustomResourceList.class, MeterSphereCustomResourceDoneable.class); - Boolean result = operation.inNamespace(customResource.getMetadata().getNamespace()).withName(customResource.getMetadata().getName()).cascading(true).delete(); - return result == null ? false : result; - } - } - - - public T getCustomResource(MeterSphereCustomResource customResource) throws Exception { - try (KubernetesClient kubernetesClient = getKubernetesClient()) { - CustomResourceDefinition crd = kubernetesClient.customResourceDefinitions().withName(customResource.getCrd()).get(); - MixedOperation> - operation = kubernetesClient.customResources(crd, MeterSphereCustomResource.class, MeterSphereCustomResourceList.class, MeterSphereCustomResourceDoneable.class); - MeterSphereCustomResource meterSphereCustomResource = operation.inNamespace(customResource.getMetadata().getNamespace()).withName(customResource.getMetadata().getName()).get(); - if (meterSphereCustomResource == null) { - return null; - } - return (T) objectMapper.readValue(objectMapper.writeValueAsString(meterSphereCustomResource), customResource.getClass()); - } - } - - - public List listCustomResource(MeterSphereCustomResource customResource) throws Exception { - try (KubernetesClient kubernetesClient = getKubernetesClient()) { - CustomResourceDefinition crd = kubernetesClient.customResourceDefinitions().withName(customResource.getCrd()).get(); - MixedOperation> - operation = kubernetesClient.customResources(crd, MeterSphereCustomResource.class, MeterSphereCustomResourceList.class, MeterSphereCustomResourceDoneable.class); - MeterSphereCustomResourceList list; - if (StringUtils.isNotEmpty(customResource.getMetadata().getNamespace())) { - list = operation.inNamespace(customResource.getMetadata().getNamespace()).list(); - } else { - list = operation.inAnyNamespace().list(); - } - - List resultList = new ArrayList<>(); - for (Object cr : list.getItems()) { - resultList.add((T) objectMapper.readValue(objectMapper.writeValueAsString(cr), customResource.getClass())); - } - return resultList; - } - } - - - public boolean checkPVCNotExists(String namespace, String statefulsetName) { - KubernetesClient kubernetesClient = getKubernetesClient(); - NonNamespaceOperation> operation = kubernetesClient.persistentVolumeClaims() - .inNamespace(namespace); - - PersistentVolumeClaimList pvcList = operation.list(100, null); - Pattern compile = Pattern.compile(statefulsetName + "-\\d+"); - return checkPVCNotExists(pvcList, compile, operation); - } - - private boolean checkPVCNotExists(PersistentVolumeClaimList pvcList, Pattern compile, NonNamespaceOperation> operation) { - if (pvcList == null || CollectionUtils.isEmpty(pvcList.getItems())) { - return true; - } - Optional claimOptional = pvcList.getItems().stream().filter(pvc -> compile.matcher(pvc.getMetadata().getName()).matches()).findAny(); - if (claimOptional.isPresent()) { - return false; - } else if (StringUtils.isNotEmpty(pvcList.getMetadata().getContinue())) { - return checkPVCNotExists(operation.list(100, pvcList.getMetadata().getContinue()), compile, operation); - } else { - return true; - } - } - - public boolean deletePVC(HasMetadata hasMetadata) { - KubernetesClient kubernetesClient = getKubernetesClient(); - NonNamespaceOperation> operation = kubernetesClient.persistentVolumeClaims() - .inNamespace(hasMetadata.getMetadata().getNamespace()); - - if (MapUtils.isNotEmpty(hasMetadata.getMetadata().getLabels())) { - operation.withLabelSelector(new LabelSelector(null, hasMetadata.getMetadata().getLabels())); - } - if (StringUtils.isNotEmpty(hasMetadata.getMetadata().getName())) { - operation.withName(hasMetadata.getMetadata().getName()); - } - Boolean delete = operation.delete(); - return delete == null ? false : delete; - } - - - public boolean deleteNamespace(String namespace) { - KubernetesClient kubernetesClient = getKubernetesClient(); - Boolean delete = kubernetesClient.namespaces().withName(namespace).delete(); - - return delete == null ? false : delete; - } - - - public String getLog(String namespace, String pod, String container, int tailingLines) { - try (KubernetesClient client = getKubernetesClient()) { - PrettyLoggable loggable; - if (tailingLines > 0) { - loggable = client.pods().inNamespace(namespace).withName(pod).inContainer(container).tailingLines(tailingLines); - } else { - loggable = client.pods().inNamespace(namespace).withName(pod).inContainer(container); - } - - return loggable.getLog(); - } - } -} diff --git a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/ClientCredential.java b/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/ClientCredential.java deleted file mode 100644 index 0da95ac909..0000000000 --- a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/ClientCredential.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.metersphere.performance.engine.kubernetes.provider; - -public class ClientCredential { - - private String masterUrl; - private String token; - private Integer maxConcurrency; - - public String getMasterUrl() { - return masterUrl; - } - - public void setMasterUrl(String masterUrl) { - this.masterUrl = masterUrl; - } - - public String getToken() { - return token; - } - - public void setToken(String token) { - this.token = token; - } - - public Integer getMaxConcurrency() { - return maxConcurrency; - } - - public void setMaxConcurrency(Integer maxConcurrency) { - this.maxConcurrency = maxConcurrency; - } -} diff --git a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/DockerRegistry.java b/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/DockerRegistry.java deleted file mode 100644 index 301835fb4d..0000000000 --- a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/DockerRegistry.java +++ /dev/null @@ -1,50 +0,0 @@ -package io.metersphere.performance.engine.kubernetes.provider; - -public class DockerRegistry { - - private String url; - private String username; - private String password; - private String email; - private String namespace; - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getNamespace() { - return namespace; - } - - public void setNamespace(String namespace) { - this.namespace = namespace; - } -} diff --git a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/DockerRegistryUtil.java b/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/DockerRegistryUtil.java deleted file mode 100644 index f11512537a..0000000000 --- a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/DockerRegistryUtil.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.metersphere.performance.engine.kubernetes.provider; - -import com.alibaba.fastjson.JSONObject; - -import java.util.Base64; -import java.util.HashMap; -import java.util.Map; - -public class DockerRegistryUtil { - - - public static String getDockerConfig(DockerRegistry registry) { - Map config = new HashMap<>(); - config.put("username", registry.getUsername()); - config.put("password", registry.getPassword()); - config.put("auth", Base64.getEncoder().encodeToString((registry.getUsername() + ":" + registry.getPassword()).getBytes())); - - JSONObject jb = new JSONObject(); - jb.put(registry.getUrl(), config); - JSONObject result = new JSONObject(); - result.put("auths", jb); - return Base64.getEncoder().encodeToString(result.toJSONString().getBytes()); - } -} diff --git a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/KubernetesProvider.java b/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/KubernetesProvider.java deleted file mode 100644 index c7b645020d..0000000000 --- a/backend/src/main/java/io/metersphere/performance/engine/kubernetes/provider/KubernetesProvider.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.metersphere.performance.engine.kubernetes.provider; - -public class KubernetesProvider extends AbstractClientProvider { - public KubernetesProvider(String credential) { - super(credential); - } -} diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index 0960772c2a..b539a94f88 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -199,7 +199,7 @@ public class PerformanceTestService { } LogUtil.info("Load test started " + loadTest.getName()); - // engine type (NODE|K8S) + // engine type (NODE) final Engine engine = EngineFactory.createEngine(loadTest); if (engine == null) { MSException.throwException(String.format("Test cannot be run,test ID:%s", request.getId())); diff --git a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java index 2dc3f85df0..a4b710c84b 100644 --- a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java +++ b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java @@ -1,10 +1,12 @@ package io.metersphere.service; import com.alibaba.fastjson.JSON; -import io.metersphere.base.domain.*; +import io.metersphere.base.domain.TestResource; +import io.metersphere.base.domain.TestResourceExample; +import io.metersphere.base.domain.TestResourcePool; +import io.metersphere.base.domain.TestResourcePoolExample; import io.metersphere.base.mapper.TestResourceMapper; import io.metersphere.base.mapper.TestResourcePoolMapper; -import io.metersphere.commons.constants.ResourcePoolTypeEnum; import io.metersphere.commons.constants.ResourceStatusEnum; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.LogUtil; @@ -12,7 +14,6 @@ import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest; import io.metersphere.dto.NodeDTO; import io.metersphere.dto.TestResourcePoolDTO; import io.metersphere.i18n.Translator; -import io.metersphere.performance.engine.kubernetes.provider.KubernetesProvider; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -145,9 +146,6 @@ public class TestResourcePoolService { } private boolean validateTestResourcePool(TestResourcePoolDTO testResourcePool) { - if (StringUtils.equalsIgnoreCase(testResourcePool.getType(), ResourcePoolTypeEnum.K8S.name())) { - return validateK8s(testResourcePool); - } return validateNodes(testResourcePool); } @@ -194,31 +192,6 @@ public class TestResourcePoolService { } } - private boolean validateK8s(TestResourcePoolDTO testResourcePool) { - - if (CollectionUtils.isEmpty(testResourcePool.getResources()) || testResourcePool.getResources().size() != 1) { - throw new RuntimeException(Translator.get("only_one_k8s")); - } - - TestResource testResource = testResourcePool.getResources().get(0); - testResource.setTestResourcePoolId(testResourcePool.getId()); - boolean isValid; - try { - KubernetesProvider provider = new KubernetesProvider(testResource.getConfiguration()); - provider.validateCredential(); - testResource.setStatus(VALID.name()); - testResourcePool.setStatus(VALID.name()); - isValid = true; - } catch (Exception e) { - testResource.setStatus(ResourceStatusEnum.INVALID.name()); - testResourcePool.setStatus(ResourceStatusEnum.INVALID.name()); - isValid = false; - } - deleteTestResource(testResourcePool.getId()); - updateTestResource(testResource); - return isValid; - } - private void updateTestResource(TestResource testResource) { testResource.setUpdateTime(System.currentTimeMillis()); testResource.setCreateTime(System.currentTimeMillis()); diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java index 2579a45046..3f6981b90f 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java @@ -10,10 +10,10 @@ import io.metersphere.base.mapper.ext.ExtTestCaseMapper; import io.metersphere.commons.constants.TestCaseConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.BeanUtils; +import io.metersphere.exception.ExcelException; import io.metersphere.i18n.Translator; import io.metersphere.track.dto.TestCaseDTO; import io.metersphere.track.dto.TestCaseNodeDTO; -import io.metersphere.exception.ExcelException; import io.metersphere.track.request.testcase.DragNodeRequest; import io.metersphere.track.request.testcase.QueryTestCaseRequest; import org.apache.commons.lang3.StringUtils; @@ -22,7 +22,6 @@ import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.yaml.snakeyaml.nodes.NodeId; import javax.annotation.Resource; import java.util.*; diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index d75c4edc54..44edb7220a 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -37,7 +37,6 @@ test_not_running=Test is not running load_test_already_exists=Duplicate load test name no_nodes_message=No node message duplicate_node_ip=Duplicate IPs -only_one_k8s=Only one K8s can be added max_thread_insufficient=The number of concurrent users exceeds #workspace workspace_name_is_null=Workspace name cannot be null diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 6a1170d165..d8d305cc00 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -37,7 +37,6 @@ test_not_running=测试未运行 load_test_already_exists=测试名称不能重复 no_nodes_message=没有节点信息 duplicate_node_ip=节点 IP 重复 -only_one_k8s=只能添加一个 K8s max_thread_insufficient=并发用户数超额 #workspace workspace_name_is_null=工作空间名不能为空 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 2f00099283..f0453f2c57 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -37,7 +37,6 @@ test_not_running=測試未運行 load_test_already_exists=測試名稱不能重復 no_nodes_message=沒有節點信息 duplicate_node_ip=節點 IP 重復 -only_one_k8s=只能添加壹個 K8s max_thread_insufficient=並發用戶數超額 #workspace workspace_name_is_null=工作空間名不能為空 diff --git a/frontend/src/business/components/settings/system/TestResourcePool.vue b/frontend/src/business/components/settings/system/TestResourcePool.vue index 861132cd2b..f502006d92 100644 --- a/frontend/src/business/components/settings/system/TestResourcePool.vue +++ b/frontend/src/business/components/settings/system/TestResourcePool.vue @@ -11,7 +11,6 @@ @@ -61,31 +60,10 @@ - Kubernetes Node
-
- - - - - - - - - - - - - - - - - -
@@ -144,31 +122,10 @@ - Kubernetes Node
-
- - - - - - - - - - - - - - - - - -
From 88df2d69507ce283d2e2d501e399753c64589a96 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Fri, 5 Jun 2020 17:37:27 +0800 Subject: [PATCH 02/14] i18n --- .../business/components/track/case/components/TestCaseEdit.vue | 2 +- frontend/src/i18n/en-US.js | 1 + frontend/src/i18n/zh-CN.js | 1 + frontend/src/i18n/zh-TW.js | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/src/business/components/track/case/components/TestCaseEdit.vue b/frontend/src/business/components/track/case/components/TestCaseEdit.vue index af00e68f02..bda46a0224 100644 --- a/frontend/src/business/components/track/case/components/TestCaseEdit.vue +++ b/frontend/src/business/components/track/case/components/TestCaseEdit.vue @@ -87,7 +87,7 @@ - + Date: Mon, 8 Jun 2020 11:55:10 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E7=A1=AE=E8=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/components/MsDeleteConfirm.vue | 83 +++++++ .../track/plan/components/TestPlanList.vue | 204 +++++++++--------- frontend/src/i18n/en-US.js | 4 +- frontend/src/i18n/zh-CN.js | 4 +- frontend/src/i18n/zh-TW.js | 3 + 5 files changed, 192 insertions(+), 106 deletions(-) create mode 100644 frontend/src/business/components/common/components/MsDeleteConfirm.vue diff --git a/frontend/src/business/components/common/components/MsDeleteConfirm.vue b/frontend/src/business/components/common/components/MsDeleteConfirm.vue new file mode 100644 index 0000000000..1d7185e32b --- /dev/null +++ b/frontend/src/business/components/common/components/MsDeleteConfirm.vue @@ -0,0 +1,83 @@ + + + + + diff --git a/frontend/src/business/components/track/plan/components/TestPlanList.vue b/frontend/src/business/components/track/plan/components/TestPlanList.vue index b54e530e7c..905b0997b3 100644 --- a/frontend/src/business/components/track/plan/components/TestPlanList.vue +++ b/frontend/src/business/components/track/plan/components/TestPlanList.vue @@ -1,106 +1,107 @@