启动测试 0.2
This commit is contained in:
parent
4eaaa746df
commit
fbdd747cb7
|
@ -5,6 +5,7 @@ import java.util.Map;
|
|||
|
||||
public class EngineContext {
|
||||
private String testId;
|
||||
private String testName;
|
||||
private String namespace;
|
||||
private String engineType;
|
||||
private String fileType;
|
||||
|
@ -19,6 +20,14 @@ public class EngineContext {
|
|||
this.testId = testId;
|
||||
}
|
||||
|
||||
public String getTestName() {
|
||||
return testName;
|
||||
}
|
||||
|
||||
public void setTestName(String testName) {
|
||||
this.testName = testName;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ public class EngineFactory {
|
|||
public static EngineContext createContext(LoadTestWithBLOBs loadTest, FileMetadata fileMetadata, FileContent fileContent) throws Exception {
|
||||
final EngineContext engineContext = new EngineContext();
|
||||
engineContext.setTestId(loadTest.getId());
|
||||
engineContext.setTestName(loadTest.getName());
|
||||
engineContext.setNamespace(loadTest.getProjectId());
|
||||
engineContext.setEngineType(fileMetadata.getEngine());
|
||||
engineContext.setFileType(fileMetadata.getType());
|
||||
|
|
|
@ -2,11 +2,13 @@ package io.metersphere.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.commons.utils.LogUtil;
|
||||
import io.metersphere.engine.Engine;
|
||||
import io.metersphere.engine.EngineContext;
|
||||
import io.metersphere.engine.kubernetes.crds.jmeter.Jmeter;
|
||||
import io.metersphere.engine.kubernetes.crds.jmeter.JmeterSpec;
|
||||
import io.metersphere.engine.kubernetes.provider.ClientCredential;
|
||||
import io.metersphere.engine.kubernetes.provider.KubernetesProvider;
|
||||
|
||||
|
@ -29,12 +31,17 @@ public class KubernetesTestEngine implements Engine {
|
|||
ClientCredential credential = new ClientCredential();
|
||||
credential.setMasterUrl("https://172.16.10.93:6443");
|
||||
KubernetesProvider kubernetesProvider = new KubernetesProvider(JSON.toJSONString(credential));
|
||||
// create namespace
|
||||
kubernetesProvider.confirmNamespace(context.getNamespace());
|
||||
// create cm
|
||||
try (KubernetesClient client = kubernetesProvider.getKubernetesClient()) {
|
||||
String configMapName = 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<String, String>() {{
|
||||
put("sample.jmx", context.getContent());
|
||||
}});
|
||||
|
@ -44,10 +51,15 @@ public class KubernetesTestEngine implements Engine {
|
|||
// create jmeter
|
||||
try {
|
||||
Jmeter jmeter = new Jmeter();
|
||||
jmeter.getMetadata().setNamespace(context.getNamespace());
|
||||
jmeter.getMetadata().setName(context.getTestId());
|
||||
jmeter.getSpec().setReplicas(1);
|
||||
jmeter.getSpec().setImage("registry.fit2cloud.com/metersphere/jmeter:0.0.2");
|
||||
jmeter.setMetadata(new ObjectMeta() {{
|
||||
setNamespace(context.getNamespace());
|
||||
setName(context.getTestId());
|
||||
}});
|
||||
jmeter.setSpec(new JmeterSpec() {{
|
||||
setReplicas(1);
|
||||
setImage("registry.fit2cloud.com/metersphere/jmeter-master:0.0.2");
|
||||
}});
|
||||
LogUtil.info("Load test started. " + context.getTestId());
|
||||
kubernetesProvider.applyCustomResource(jmeter);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
|
|
|
@ -66,12 +66,11 @@ public abstract class AbstractClientProvider {
|
|||
* @param namespace namespace标识
|
||||
* @return
|
||||
*/
|
||||
public synchronized String confirmNamespace(String namespace, String displayName) {
|
||||
public synchronized String confirmNamespace(String namespace) {
|
||||
KubernetesClient kubernetesClient = getKubernetesClient();
|
||||
Namespace currentNamespace = kubernetesClient.namespaces().withName(namespace).get();
|
||||
if (currentNamespace == null) {
|
||||
Map<String, String> annotations = new HashMap<>();
|
||||
annotations.put("fit2cloud.com/workspace-name", displayName);
|
||||
Namespace newNamespace = new NamespaceBuilder()
|
||||
.withNewMetadata()
|
||||
.withName(namespace)
|
||||
|
|
|
@ -260,6 +260,8 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
collectionProp.appendChild(childCollectionProp);
|
||||
timer.appendChild(collectionProp);
|
||||
timerParent.appendChild(timer);
|
||||
// 添加一个空的hashTree
|
||||
timerParent.appendChild(document.createElement(HASH_TREE_ELEMENT));
|
||||
}
|
||||
|
||||
private Element createStringProp(Document document, String name, String value) {
|
||||
|
|
Loading…
Reference in New Issue